drm/virtio: move virtio_gpu_mem_entry initialization to new function

Introduce new virtio_gpu_object_shmem_init() helper function which will
create the virtio_gpu_mem_entry array, containing the backing storage
information for the host.  For the most path this just moves code from
virtio_gpu_object_attach().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200207074638.26386-5-kraxel@redhat.com
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
This commit is contained in:
Gerd Hoffmann
2020-02-07 08:46:38 +01:00
parent 2fe4ca9d0e
commit 2f2aa13724
3 changed files with 60 additions and 50 deletions

View File

@@ -1089,56 +1089,11 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,
int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
struct virtio_gpu_object *obj,
struct virtio_gpu_fence *fence)
struct virtio_gpu_mem_entry *ents,
unsigned int nents)
{
bool use_dma_api = !virtio_has_iommu_quirk(vgdev->vdev);
struct virtio_gpu_mem_entry *ents;
struct scatterlist *sg;
int si, nents, ret;
if (WARN_ON_ONCE(!obj->created))
return -EINVAL;
if (WARN_ON_ONCE(obj->pages))
return -EINVAL;
ret = drm_gem_shmem_pin(&obj->base.base);
if (ret < 0)
return -EINVAL;
obj->pages = drm_gem_shmem_get_sg_table(&obj->base.base);
if (obj->pages == NULL) {
drm_gem_shmem_unpin(&obj->base.base);
return -EINVAL;
}
if (use_dma_api) {
obj->mapped = dma_map_sg(vgdev->vdev->dev.parent,
obj->pages->sgl, obj->pages->nents,
DMA_TO_DEVICE);
nents = obj->mapped;
} else {
nents = obj->pages->nents;
}
/* gets freed when the ring has consumed it */
ents = kmalloc_array(nents, sizeof(struct virtio_gpu_mem_entry),
GFP_KERNEL);
if (!ents) {
DRM_ERROR("failed to allocate ent list\n");
return -ENOMEM;
}
for_each_sg(obj->pages->sgl, sg, nents, si) {
ents[si].addr = cpu_to_le64(use_dma_api
? sg_dma_address(sg)
: sg_phys(sg));
ents[si].length = cpu_to_le32(sg->length);
ents[si].padding = 0;
}
virtio_gpu_cmd_resource_attach_backing(vgdev, obj->hw_res_handle,
ents, nents,
fence);
ents, nents, NULL);
return 0;
}