drm/virtio: switch from ttm to gem shmem helpers

virtio-gpu basically needs a sg_table for the bo, to tell the host where
the backing pages for the object are.  So the gem shmem helpers are a
perfect fit.  Some drm_gem_object_funcs need thin wrappers to update the
host state, but otherwise the helpers handle everything just fine.

Once the fencing was sorted the switch was surprisingly easy and for the
most part just removing the ttm code.

v4: fix drm_gem_object_funcs name.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190829103301.3539-15-kraxel@redhat.com
This commit is contained in:
Gerd Hoffmann
2019-08-29 12:32:57 +02:00
parent ad75f4f057
commit c66df701e7
11 changed files with 80 additions and 535 deletions

View File

@@ -993,17 +993,21 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
bool use_dma_api = !virtio_has_iommu_quirk(vgdev->vdev);
struct virtio_gpu_mem_entry *ents;
struct scatterlist *sg;
int si, nents;
int si, nents, ret;
if (WARN_ON_ONCE(!obj->created))
return -EINVAL;
if (WARN_ON_ONCE(obj->pages))
return -EINVAL;
if (!obj->pages) {
int ret;
ret = drm_gem_shmem_pin(&obj->base.base);
if (ret < 0)
return -EINVAL;
ret = virtio_gpu_object_get_sg_table(vgdev, obj);
if (ret)
return ret;
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) {
@@ -1042,6 +1046,9 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev,
{
bool use_dma_api = !virtio_has_iommu_quirk(vgdev->vdev);
if (WARN_ON_ONCE(!obj->pages))
return;
if (use_dma_api && obj->mapped) {
struct virtio_gpu_fence *fence = virtio_gpu_fence_alloc(vgdev);
/* detach backing and wait for the host process it ... */
@@ -1057,6 +1064,11 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev,
} else {
virtio_gpu_cmd_resource_inval_backing(vgdev, obj->hw_res_handle, NULL);
}
sg_free_table(obj->pages);
obj->pages = NULL;
drm_gem_shmem_unpin(&obj->base.base);
}
void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,