public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: Pawel Polawski <ppolawsk@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [PATCH v2 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply
Date: Fri, 11 Mar 2022 06:43:10 +0100	[thread overview]
Message-ID: <20220311054315.876774-2-kraxel@redhat.com> (raw)
In-Reply-To: <20220311054315.876774-1-kraxel@redhat.com>

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>
---
 OvmfPkg/VirtioGpuDxe/Commands.c | 75 +++++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 18 deletions(-)

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


  reply	other threads:[~2022-03-11  5:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11  5:43 [PATCH v2 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
2022-03-11  5:43 ` Gerd Hoffmann [this message]
2022-03-11  5:43 ` [PATCH v2 2/6] OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header Gerd Hoffmann
2022-03-11  5:43 ` [PATCH v2 3/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo Gerd Hoffmann
2022-03-11  5:43 ` [PATCH v2 4/6] OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode Gerd Hoffmann
2022-03-11  5:43 ` [PATCH v2 5/6] OvmfPkg/VirtioGpuDxe: move code to GopInitialize Gerd Hoffmann
2022-03-11  5:43 ` [PATCH v2 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311054315.876774-2-kraxel@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox