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

virtio-gpu api: blob resources

A blob resource is a container for:
- VIRTIO_GPU_BLOB_MEM_GUEST: a guest memory allocation
(referred to as a "guest-only blob resource")

- VIRTIO_GPU_BLOB_MEM_HOST3D: a host3d memory allocation
(referred to as a "host-only blob resource")

- VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST: a guest + host3d memory allocation
(referred to as a "default blob resource").

The memory properties of the blob resource must be described by
`blob_mem`.

For default and guest only blob resources set, `nents` guest system
pages are assigned to the resource. For default blob resources,
these guest pages are used for transfer operations. Attach/detach is
also possible to allow swap-in/swap-out, but isn't required since it
may not be applicable to future blob mem types
(shared guest/guest vram).

Host allocations depend on whether the 3D is supported. If 3D is not
supported, the only valid field for `blob_mem` is
VIRTIO_GPU_BLOB_MEM_GUEST.

If 3D is supported, the virtio-gpu resource is created from the
context local object identified by the `blob_id`. The actual host
allocation done by the CMD_SUBMIT_3D.

Userspace must specify if the blob resource is intended to be used
for userspace mapping, sharing between virtio-gpu contexts and/or
sharing between virtio devices. This is done via `blob_flags`.

For 3D hosts, both VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D and
VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D may be used to update
the host resource. There is no restriction on the image/buffer
view the guest/host userspace has on the blob resource.

VIRTIO_GPU_CMD_SET_SCANOUT_BLOB / VIRTIO_GPU_CMD_RESOURCE_FLUSH may
be used with blob resources as well. The modifier is intentionally
left out of SCANOUT_BLOB, and auxilary blobs are also left out
as a simplification.

The use case for blob resources is zero-copy, needed for coherent
memory in virglrenderer. Host only blob resources are not mappable
without the feature described in the next patch, but are shareable.

Future work:
- Emulated coherent `blob_mem` type for QEMU/vhost-user
- A `blob_mem` type for guest-only resources imported in
cache-coherent FOSS GPU/display drivers.
- Display integration involving the blob model using seamless
Wayland windows.

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

+43
+43
include/uapi/linux/virtio_gpu.h
··· 55 55 */ 56 56 #define VIRTIO_GPU_F_RESOURCE_UUID 2 57 57 58 + /* 59 + * VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB 60 + */ 61 + #define VIRTIO_GPU_F_RESOURCE_BLOB 3 62 + 58 63 enum virtio_gpu_ctrl_type { 59 64 VIRTIO_GPU_UNDEFINED = 0, 60 65 ··· 76 71 VIRTIO_GPU_CMD_GET_CAPSET, 77 72 VIRTIO_GPU_CMD_GET_EDID, 78 73 VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID, 74 + VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB, 75 + VIRTIO_GPU_CMD_SET_SCANOUT_BLOB, 79 76 80 77 /* 3d commands */ 81 78 VIRTIO_GPU_CMD_CTX_CREATE = 0x0200, ··· 364 357 struct virtio_gpu_resp_resource_uuid { 365 358 struct virtio_gpu_ctrl_hdr hdr; 366 359 __u8 uuid[16]; 360 + }; 361 + 362 + /* VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB */ 363 + struct virtio_gpu_resource_create_blob { 364 + struct virtio_gpu_ctrl_hdr hdr; 365 + __le32 resource_id; 366 + #define VIRTIO_GPU_BLOB_MEM_GUEST 0x0001 367 + #define VIRTIO_GPU_BLOB_MEM_HOST3D 0x0002 368 + #define VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST 0x0003 369 + 370 + #define VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE 0x0001 371 + #define VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE 0x0002 372 + #define VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 373 + /* zero is invalid blob mem */ 374 + __le32 blob_mem; 375 + __le32 blob_flags; 376 + __le64 blob_id; 377 + __le64 size; 378 + __le32 nr_entries; 379 + /* 380 + * sizeof(nr_entries * virtio_gpu_mem_entry) bytes follow 381 + */ 382 + }; 383 + 384 + /* VIRTIO_GPU_CMD_SET_SCANOUT_BLOB */ 385 + struct virtio_gpu_set_scanout_blob { 386 + struct virtio_gpu_ctrl_hdr hdr; 387 + struct virtio_gpu_rect r; 388 + __le32 scanout_id; 389 + __le32 resource_id; 390 + __le32 width; 391 + __le32 height; 392 + __le32 format; 393 + __le32 padding; 394 + __le32 strides[4]; 395 + __le32 offsets[4]; 367 396 }; 368 397 369 398 #endif