]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 8 Apr 2022 08:23:28 +0000 (10:23 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 25 Apr 2022 21:01:13 +0000 (21:01 +0000)
Extend VirtioGpuSendCommand() to support commands which return data,
rename the function to VirtioGpuSendCommandWithReply() to indicate that.

Add a new VirtioGpuSendCommand() function which is just a thin wrapper
around VirtioGpuSendCommandWithReply() so existing code continues to
work without changes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
OvmfPkg/VirtioGpuDxe/Commands.c

index 873a71656700acf4f725f507ba5d5cb76759f626..b9a3ea9230214da0d6eed54378cff2a4460aa23e 100644 (file)
@@ -393,6 +393,14 @@ VirtioGpuExitBoot (
   @param[in] RequestSize  Size of the entire caller-allocated request object,\r
                           including the leading VIRTIO_GPU_CONTROL_HEADER.\r
 \r
+  @param[in] ResponseType The type of the response (VirtioGpuResp*).\r
+\r
+  @param[in,out] Response Pointer to the caller-allocated response object. The\r
+                          request must start with VIRTIO_GPU_CONTROL_HEADER.\r
+\r
+  @param[in] ResponseSize Size of the entire caller-allocated response object,\r
+                          including the leading VIRTIO_GPU_CONTROL_HEADER.\r
+\r
   @retval EFI_SUCCESS            Operation successful.\r
 \r
   @retval EFI_DEVICE_ERROR       The host rejected the request. The host error\r
@@ -404,22 +412,24 @@ VirtioGpuExitBoot (
 **/\r
 STATIC\r
 EFI_STATUS\r
-VirtioGpuSendCommand (\r
+VirtioGpuSendCommandWithReply (\r
   IN OUT VGPU_DEV                            *VgpuDev,\r
   IN     VIRTIO_GPU_CONTROL_TYPE             RequestType,\r
   IN     BOOLEAN                             Fence,\r
   IN OUT volatile VIRTIO_GPU_CONTROL_HEADER  *Header,\r
-  IN     UINTN                               RequestSize\r
+  IN     UINTN                               RequestSize,\r
+  IN     VIRTIO_GPU_CONTROL_TYPE             ResponseType,\r
+  IN OUT volatile VIRTIO_GPU_CONTROL_HEADER  *Response,\r
+  IN     UINTN                               ResponseSize\r
   )\r
 {\r
-  DESC_INDICES                        Indices;\r
-  volatile VIRTIO_GPU_CONTROL_HEADER  Response;\r
-  EFI_STATUS                          Status;\r
-  UINT32                              ResponseSize;\r
-  EFI_PHYSICAL_ADDRESS                RequestDeviceAddress;\r
-  VOID                                *RequestMap;\r
-  EFI_PHYSICAL_ADDRESS                ResponseDeviceAddress;\r
-  VOID                                *ResponseMap;\r
+  DESC_INDICES          Indices;\r
+  EFI_STATUS            Status;\r
+  UINT32                ResponseSizeRet;\r
+  EFI_PHYSICAL_ADDRESS  RequestDeviceAddress;\r
+  VOID                  *RequestMap;\r
+  EFI_PHYSICAL_ADDRESS  ResponseDeviceAddress;\r
+  VOID                  *ResponseMap;\r
 \r
   //\r
   // Initialize Header.\r
@@ -457,8 +467,8 @@ VirtioGpuSendCommand (
   Status = VirtioMapAllBytesInSharedBuffer (\r
              VgpuDev->VirtIo,\r
              VirtioOperationBusMasterWrite,\r
-             (VOID *)&Response,\r
-             sizeof Response,\r
+             (VOID *)Response,\r
+             ResponseSize,\r
              &ResponseDeviceAddress,\r
              &ResponseMap\r
              );\r
@@ -480,7 +490,7 @@ VirtioGpuSendCommand (
   VirtioAppendDesc (\r
     &VgpuDev->Ring,\r
     ResponseDeviceAddress,\r
-    (UINT32)sizeof Response,\r
+    (UINT32)ResponseSize,\r
     VRING_DESC_F_WRITE,\r
     &Indices\r
     );\r
@@ -493,7 +503,7 @@ VirtioGpuSendCommand (
              VIRTIO_GPU_CONTROL_QUEUE,\r
              &VgpuDev->Ring,\r
              &Indices,\r
-             &ResponseSize\r
+             &ResponseSizeRet\r
              );\r
   if (EFI_ERROR (Status)) {\r
     goto UnmapResponse;\r
@@ -502,7 +512,7 @@ VirtioGpuSendCommand (
   //\r
   // Verify response size.\r
   //\r
-  if (ResponseSize != sizeof Response) {\r
+  if (ResponseSize != ResponseSizeRet) {\r
     DEBUG ((\r
       DEBUG_ERROR,\r
       "%a: malformed response to Request=0x%x\n",\r
@@ -531,16 +541,17 @@ VirtioGpuSendCommand (
   //\r
   // Parse the response.\r
   //\r
-  if (Response.Type == VirtioGpuRespOkNodata) {\r
+  if (Response->Type == (UINT32)ResponseType) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   DEBUG ((\r
     DEBUG_ERROR,\r
-    "%a: Request=0x%x Response=0x%x\n",\r
+    "%a: Request=0x%x Response=0x%x (expected 0x%x)\n",\r
     __FUNCTION__,\r
     (UINT32)RequestType,\r
-    Response.Type\r
+    Response->Type,\r
+    ResponseType\r
     ));\r
   return EFI_DEVICE_ERROR;\r
 \r
@@ -553,6 +564,34 @@ UnmapRequest:
   return Status;\r
 }\r
 \r
+/**\r
+  Simplified version of VirtioGpuSendCommandWithReply() for commands\r
+  which do not send back any data.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+VirtioGpuSendCommand (\r
+  IN OUT VGPU_DEV                            *VgpuDev,\r
+  IN     VIRTIO_GPU_CONTROL_TYPE             RequestType,\r
+  IN     BOOLEAN                             Fence,\r
+  IN OUT volatile VIRTIO_GPU_CONTROL_HEADER  *Header,\r
+  IN     UINTN                               RequestSize\r
+  )\r
+{\r
+  volatile VIRTIO_GPU_CONTROL_HEADER  Response;\r
+\r
+  return VirtioGpuSendCommandWithReply (\r
+           VgpuDev,\r
+           RequestType,\r
+           Fence,\r
+           Header,\r
+           RequestSize,\r
+           VirtioGpuRespOkNodata,\r
+           &Response,\r
+           sizeof (Response)\r
+           );\r
+}\r
+\r
 /**\r
   The following functions send requests to the VirtIo GPU device model, await\r
   the answer from the host, and return a status. They share the following\r