Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio-gpu api: host visible feature

This patch adds a new virtgpu feature that allows directly
mapping host allocated resources.

This is based on virtio shared memory regions, which allows
querying for memory regions using PCI transport. Each shared
memory region has an associated "shmid", the meaning of which
is device specific.

For virtio-gpu, we can define the shared memory region with id
VIRTIO_GPU_SHM_ID_HOST_VISIBLE to be the "host visible memory
region".

The presence of the host visible memory region means the following
hypercalls are supported:

1) VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB

This hypercall tells the host to inject the host resource's
mapping in an offset into virtio-gpu's PCI address space.
This is typically done via KVM_SET_USER_MEMORY_REGION on Linux
hosts.

On success, VIRTIO_GPU_RESP_OK_MAP_INFO is returned, which
specifies the host buffer's caching type and possibly in the
future performance hints about the buffer..

2) VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB

This hypercall tells the host to remove the host resource's
mapping from the guest VM.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Acked-by: Lingfeng Yang <lfy@google.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200924003214.662-4-gurchetansingh@chromium.org
Co-developed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>

+35
+35
include/uapi/linux/virtio_gpu.h
··· 88 88 VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, 89 89 VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D, 90 90 VIRTIO_GPU_CMD_SUBMIT_3D, 91 + VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB, 92 + VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB, 91 93 92 94 /* cursor commands */ 93 95 VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300, ··· 102 100 VIRTIO_GPU_RESP_OK_CAPSET, 103 101 VIRTIO_GPU_RESP_OK_EDID, 104 102 VIRTIO_GPU_RESP_OK_RESOURCE_UUID, 103 + VIRTIO_GPU_RESP_OK_MAP_INFO, 105 104 106 105 /* error responses */ 107 106 VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200, ··· 111 108 VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID, 112 109 VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID, 113 110 VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER, 111 + }; 112 + 113 + enum virtio_gpu_shm_id { 114 + VIRTIO_GPU_SHM_ID_UNDEFINED = 0, 115 + VIRTIO_GPU_SHM_ID_HOST_VISIBLE = 1 114 116 }; 115 117 116 118 #define VIRTIO_GPU_FLAG_FENCE (1 << 0) ··· 408 400 __le32 padding; 409 401 __le32 strides[4]; 410 402 __le32 offsets[4]; 403 + }; 404 + 405 + /* VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB */ 406 + struct virtio_gpu_resource_map_blob { 407 + struct virtio_gpu_ctrl_hdr hdr; 408 + __le32 resource_id; 409 + __le32 padding; 410 + __le64 offset; 411 + }; 412 + 413 + /* VIRTIO_GPU_RESP_OK_MAP_INFO */ 414 + #define VIRTIO_GPU_MAP_CACHE_MASK 0x0f 415 + #define VIRTIO_GPU_MAP_CACHE_NONE 0x00 416 + #define VIRTIO_GPU_MAP_CACHE_CACHED 0x01 417 + #define VIRTIO_GPU_MAP_CACHE_UNCACHED 0x02 418 + #define VIRTIO_GPU_MAP_CACHE_WC 0x03 419 + struct virtio_gpu_resp_map_info { 420 + struct virtio_gpu_ctrl_hdr hdr; 421 + __u32 map_info; 422 + __u32 padding; 423 + }; 424 + 425 + /* VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB */ 426 + struct virtio_gpu_resource_unmap_blob { 427 + struct virtio_gpu_ctrl_hdr hdr; 428 + __le32 resource_id; 429 + __le32 padding; 411 430 }; 412 431 413 432 #endif