diff mbox series

[v3,4/4] vhost-user-gpu: implement get_edid frontend feature

Message ID 20230607145455.158267-5-ernunes@redhat.com
State New
Headers show
Series vhost-user-gpu get_edid feature | expand

Commit Message

Erico Nunes June 7, 2023, 2:54 p.m. UTC
Implement the frontend side of the get_edid feature in the qemu
vhost-user-gpu frontend device.

Signed-off-by: Erico Nunes <ernunes@redhat.com>
---
 hw/display/vhost-user-gpu.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Marc-André Lureau June 12, 2023, 10:31 a.m. UTC | #1
Hi

On Wed, Jun 7, 2023 at 4:55 PM Erico Nunes <ernunes@redhat.com> wrote:

> Implement the frontend side of the get_edid feature in the qemu
> vhost-user-gpu frontend device.
>
> Signed-off-by: Erico Nunes <ernunes@redhat.com>
> ---
>  hw/display/vhost-user-gpu.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
> index 71dfd956b8..184e57dfc7 100644
> --- a/hw/display/vhost-user-gpu.c
> +++ b/hw/display/vhost-user-gpu.c
> @@ -31,6 +31,7 @@ typedef enum VhostUserGpuRequest {
>      VHOST_USER_GPU_UPDATE,
>      VHOST_USER_GPU_DMABUF_SCANOUT,
>      VHOST_USER_GPU_DMABUF_UPDATE,
> +    VHOST_USER_GPU_GET_EDID,
>  } VhostUserGpuRequest;
>
>  typedef struct VhostUserGpuDisplayInfoReply {
> @@ -78,6 +79,10 @@ typedef struct VhostUserGpuDMABUFScanout {
>      int fd_drm_fourcc;
>  } QEMU_PACKED VhostUserGpuDMABUFScanout;
>
> +typedef struct VhostUserGpuEdidRequest {
> +    uint32_t scanout_id;
> +} QEMU_PACKED VhostUserGpuEdidRequest;
> +
>  typedef struct VhostUserGpuMsg {
>      uint32_t request; /* VhostUserGpuRequest */
>      uint32_t flags;
> @@ -88,6 +93,8 @@ typedef struct VhostUserGpuMsg {
>          VhostUserGpuScanout scanout;
>          VhostUserGpuUpdate update;
>          VhostUserGpuDMABUFScanout dmabuf_scanout;
> +        VhostUserGpuEdidRequest edid_req;
> +        struct virtio_gpu_resp_edid resp_edid;
>          struct virtio_gpu_resp_display_info display_info;
>          uint64_t u64;
>      } payload;
> @@ -99,6 +106,8 @@ static VhostUserGpuMsg m __attribute__ ((unused));
>
>  #define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4
>
> +#define VHOST_USER_GPU_PROTOCOL_F_EDID 0
> +
>  static void vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked);
>
>  static void
> @@ -161,6 +170,9 @@ vhost_user_gpu_handle_display(VhostUserGPU *g,
> VhostUserGpuMsg *msg)
>              .request = msg->request,
>              .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
>              .size = sizeof(uint64_t),
> +            .payload = {
> +                .u64 = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID)
> +            }
>          };
>
>          vhost_user_gpu_send_msg(g, &reply);
> @@ -184,6 +196,30 @@ vhost_user_gpu_handle_display(VhostUserGPU *g,
> VhostUserGpuMsg *msg)
>          vhost_user_gpu_send_msg(g, &reply);
>          break;
>      }
> +    case VHOST_USER_GPU_GET_EDID: {
> +        VhostUserGpuEdidRequest *m = &msg->payload.edid_req;
> +        struct virtio_gpu_resp_edid resp = { {} };
> +        int fd = qemu_chr_fe_get_msgfd(&g->vhost_chr);
>

The message doesn't have associated FD.


> +        VhostUserGpuMsg reply = {
> +            .request = msg->request,
> +            .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
> +            .size = sizeof(reply.payload.resp_edid),
> +        };
> +
> +        if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
> +            error_report("invalid scanout: %d", m->scanout_id);
>

Thus fd will always be -1.


> +            if (fd >= 0) {
> +                close(fd);
> +            }
> +            break;
> +        }
> +
> +        resp.hdr.type = VIRTIO_GPU_RESP_OK_EDID;
> +        virtio_gpu_base_generate_edid(VIRTIO_GPU_BASE(g), m->scanout_id,
> &resp);
> +        memcpy(&reply.payload.resp_edid, &resp, sizeof(resp));
> +        vhost_user_gpu_send_msg(g, &reply);
> +        break;
> +    }
>      case VHOST_USER_GPU_SCANOUT: {
>          VhostUserGpuScanout *m = &msg->payload.scanout;
>
> --
> 2.40.1
>
>
diff mbox series

Patch

diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 71dfd956b8..184e57dfc7 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -31,6 +31,7 @@  typedef enum VhostUserGpuRequest {
     VHOST_USER_GPU_UPDATE,
     VHOST_USER_GPU_DMABUF_SCANOUT,
     VHOST_USER_GPU_DMABUF_UPDATE,
+    VHOST_USER_GPU_GET_EDID,
 } VhostUserGpuRequest;
 
 typedef struct VhostUserGpuDisplayInfoReply {
@@ -78,6 +79,10 @@  typedef struct VhostUserGpuDMABUFScanout {
     int fd_drm_fourcc;
 } QEMU_PACKED VhostUserGpuDMABUFScanout;
 
+typedef struct VhostUserGpuEdidRequest {
+    uint32_t scanout_id;
+} QEMU_PACKED VhostUserGpuEdidRequest;
+
 typedef struct VhostUserGpuMsg {
     uint32_t request; /* VhostUserGpuRequest */
     uint32_t flags;
@@ -88,6 +93,8 @@  typedef struct VhostUserGpuMsg {
         VhostUserGpuScanout scanout;
         VhostUserGpuUpdate update;
         VhostUserGpuDMABUFScanout dmabuf_scanout;
+        VhostUserGpuEdidRequest edid_req;
+        struct virtio_gpu_resp_edid resp_edid;
         struct virtio_gpu_resp_display_info display_info;
         uint64_t u64;
     } payload;
@@ -99,6 +106,8 @@  static VhostUserGpuMsg m __attribute__ ((unused));
 
 #define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4
 
+#define VHOST_USER_GPU_PROTOCOL_F_EDID 0
+
 static void vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked);
 
 static void
@@ -161,6 +170,9 @@  vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
             .request = msg->request,
             .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
             .size = sizeof(uint64_t),
+            .payload = {
+                .u64 = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID)
+            }
         };
 
         vhost_user_gpu_send_msg(g, &reply);
@@ -184,6 +196,30 @@  vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
         vhost_user_gpu_send_msg(g, &reply);
         break;
     }
+    case VHOST_USER_GPU_GET_EDID: {
+        VhostUserGpuEdidRequest *m = &msg->payload.edid_req;
+        struct virtio_gpu_resp_edid resp = { {} };
+        int fd = qemu_chr_fe_get_msgfd(&g->vhost_chr);
+        VhostUserGpuMsg reply = {
+            .request = msg->request,
+            .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
+            .size = sizeof(reply.payload.resp_edid),
+        };
+
+        if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
+            error_report("invalid scanout: %d", m->scanout_id);
+            if (fd >= 0) {
+                close(fd);
+            }
+            break;
+        }
+
+        resp.hdr.type = VIRTIO_GPU_RESP_OK_EDID;
+        virtio_gpu_base_generate_edid(VIRTIO_GPU_BASE(g), m->scanout_id, &resp);
+        memcpy(&reply.payload.resp_edid, &resp, sizeof(resp));
+        vhost_user_gpu_send_msg(g, &reply);
+        break;
+    }
     case VHOST_USER_GPU_SCANOUT: {
         VhostUserGpuScanout *m = &msg->payload.scanout;