This patch introduces support for the VIRTIO_GPU_F_RESOURCE_USERPTR feature in virtio-gpu implementation:
- Add VIRTIO_GPU_F_RESOURCE_USERPTR feature flag definition - Implement resource_userptr property as a configurable option - Add VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED configuration flag - Enable feature negotiation when resource_userptr is enabled Usage: -device virtio-gpu-gl,userptr=on This feature allows virtio-gpu to support user pointer resources, enhancing memory management capabilities for GPU virtualization scenarios. Signed-off-by: Honglei Huang <[email protected]> --- hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 2 ++ include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 2 ++ 4 files changed, 10 insertions(+) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index 7269477a1c..f013a4ece6 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -264,6 +264,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, if (virtio_gpu_resource_uuid_enabled(g->conf)) { features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID); } + if (virtio_gpu_resource_userptr_enabled(g->conf)) { + features |= (1 << VIRTIO_GPU_F_RESOURCE_USERPTR); + } return features; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 956dc811fa..5f1dc80060 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1685,6 +1685,8 @@ static const Property virtio_gpu_properties[] = { 256 * MiB), DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_BLOB_ENABLED, false), + DEFINE_PROP_BIT("userptr", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED, false), DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0), DEFINE_PROP_UINT8("x-scanout-vmstate-version", VirtIOGPU, scanout_vmstate_version, 2), }; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index c820247db8..ff68f3c451 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -101,6 +101,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_VENUS_ENABLED, VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED, VIRTIO_GPU_FLAG_HSAKMT_ENABLED, + VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED, }; #define virtio_gpu_virgl_enabled(_cfg) \ @@ -125,6 +126,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED)) #define virtio_gpu_hsakmt_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_HSAKMT_ENABLED)) +#define virtio_gpu_resource_userptr_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RESOURCE_USERPTR_ENABLED)) struct virtio_gpu_base_conf { uint32_t max_outputs; diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h index 6c54cb745f..321477598e 100644 --- a/include/standard-headers/linux/virtio_gpu.h +++ b/include/standard-headers/linux/virtio_gpu.h @@ -65,6 +65,8 @@ */ #define VIRTIO_GPU_F_CONTEXT_INIT 4 +#define VIRTIO_GPU_F_RESOURCE_USERPTR 5 + enum virtio_gpu_ctrl_type { VIRTIO_GPU_UNDEFINED = 0, -- 2.34.1
