Skip to content

Commit 06a0f77

Browse files
vivekkreddydigetx
authored andcommitted
drm/virtio: Implement VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING cmd
This cmd is useful to let the VMM (i.e, Qemu) know that the backing store associated with a resource is no longer valid, so that the VMM can perform any cleanup or unmap operations. The fence related changes and virtio_gpu_object_detach()/ virtio_gpu_detach_object_fenced() routines are extracted from a patch by Dmitry Osipenko <[email protected]>. Cc: Gerd Hoffmann <[email protected]> Cc: Dmitry Osipenko <[email protected]> Cc: Rob Clark <[email protected]> Cc: Gurchetan Singh <[email protected]> Cc: Chia-I Wu <[email protected]> Signed-off-by: Vivek Kasireddy <[email protected]> Tested-by: Dmitry Osipenko <[email protected]> Reviewed-by: Dmitry Osipenko <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c1bae68 commit 06a0f77

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

drivers/gpu/drm/virtio/virtgpu_drv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct virtio_gpu_object {
9292
uint32_t hw_res_handle;
9393
bool dumb;
9494
bool created;
95+
bool attached;
9596
bool host3d_blob, guest_blob;
9697
uint32_t blob_mem, blob_flags;
9798

@@ -353,6 +354,10 @@ void virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
353354
struct virtio_gpu_object *obj,
354355
struct virtio_gpu_mem_entry *ents,
355356
unsigned int nents);
357+
void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev,
358+
struct virtio_gpu_object *obj,
359+
struct virtio_gpu_fence *fence);
360+
int virtio_gpu_detach_object_fenced(struct virtio_gpu_object *bo);
356361
void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
357362
struct virtio_gpu_output *output);
358363
int virtio_gpu_cmd_get_display_info(struct virtio_gpu_device *vgdev);

drivers/gpu/drm/virtio/virtgpu_object.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)
9797
virtio_gpu_cleanup_object(bo);
9898
}
9999

100+
int virtio_gpu_detach_object_fenced(struct virtio_gpu_object *bo)
101+
{
102+
struct virtio_gpu_device *vgdev = bo->base.base.dev->dev_private;
103+
struct virtio_gpu_fence *fence;
104+
105+
if (!bo->attached)
106+
return 0;
107+
108+
fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context, 0);
109+
if (!fence)
110+
return -ENOMEM;
111+
112+
virtio_gpu_object_detach(vgdev, bo, fence);
113+
virtio_gpu_notify(vgdev);
114+
115+
dma_fence_wait(&fence->f, false);
116+
dma_fence_put(&fence->f);
117+
118+
return 0;
119+
}
120+
100121
static const struct drm_gem_object_funcs virtio_gpu_shmem_funcs = {
101122
.free = virtio_gpu_free_object,
102123
.open = virtio_gpu_gem_object_open,

drivers/gpu/drm/virtio/virtgpu_vq.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,23 @@ virtio_gpu_cmd_resource_attach_backing(struct virtio_gpu_device *vgdev,
645645
virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence);
646646
}
647647

648+
static void
649+
virtio_gpu_cmd_resource_detach_backing(struct virtio_gpu_device *vgdev,
650+
uint32_t resource_id,
651+
struct virtio_gpu_fence *fence)
652+
{
653+
struct virtio_gpu_resource_detach_backing *cmd_p;
654+
struct virtio_gpu_vbuffer *vbuf;
655+
656+
cmd_p = virtio_gpu_alloc_cmd(vgdev, &vbuf, sizeof(*cmd_p));
657+
memset(cmd_p, 0, sizeof(*cmd_p));
658+
659+
cmd_p->hdr.type = cpu_to_le32(VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING);
660+
cmd_p->resource_id = cpu_to_le32(resource_id);
661+
662+
virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence);
663+
}
664+
648665
static void virtio_gpu_cmd_get_display_info_cb(struct virtio_gpu_device *vgdev,
649666
struct virtio_gpu_vbuffer *vbuf)
650667
{
@@ -1103,8 +1120,26 @@ void virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
11031120
struct virtio_gpu_mem_entry *ents,
11041121
unsigned int nents)
11051122
{
1123+
if (obj->attached)
1124+
return;
1125+
11061126
virtio_gpu_cmd_resource_attach_backing(vgdev, obj->hw_res_handle,
11071127
ents, nents, NULL);
1128+
1129+
obj->attached = true;
1130+
}
1131+
1132+
void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev,
1133+
struct virtio_gpu_object *obj,
1134+
struct virtio_gpu_fence *fence)
1135+
{
1136+
if (!obj->attached)
1137+
return;
1138+
1139+
virtio_gpu_cmd_resource_detach_backing(vgdev, obj->hw_res_handle,
1140+
fence);
1141+
1142+
obj->attached = false;
11081143
}
11091144

11101145
void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,

0 commit comments

Comments
 (0)