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>
@param[in] RequestSize Size of the entire caller-allocated request object,\r
including the leading VIRTIO_GPU_CONTROL_HEADER.\r
\r
@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
@retval EFI_SUCCESS Operation successful.\r
\r
@retval EFI_DEVICE_ERROR The host rejected the request. The host error\r
**/\r
STATIC\r
EFI_STATUS\r
**/\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 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 VIRTIO_GPU_CONTROL_TYPE ResponseType,\r
+ IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Response,\r
+ IN UINTN ResponseSize\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
\r
//\r
// Initialize Header.\r
Status = VirtioMapAllBytesInSharedBuffer (\r
VgpuDev->VirtIo,\r
VirtioOperationBusMasterWrite,\r
Status = VirtioMapAllBytesInSharedBuffer (\r
VgpuDev->VirtIo,\r
VirtioOperationBusMasterWrite,\r
- (VOID *)&Response,\r
- sizeof Response,\r
+ (VOID *)Response,\r
+ ResponseSize,\r
&ResponseDeviceAddress,\r
&ResponseMap\r
);\r
&ResponseDeviceAddress,\r
&ResponseMap\r
);\r
VirtioAppendDesc (\r
&VgpuDev->Ring,\r
ResponseDeviceAddress,\r
VirtioAppendDesc (\r
&VgpuDev->Ring,\r
ResponseDeviceAddress,\r
- (UINT32)sizeof Response,\r
+ (UINT32)ResponseSize,\r
VRING_DESC_F_WRITE,\r
&Indices\r
);\r
VRING_DESC_F_WRITE,\r
&Indices\r
);\r
VIRTIO_GPU_CONTROL_QUEUE,\r
&VgpuDev->Ring,\r
&Indices,\r
VIRTIO_GPU_CONTROL_QUEUE,\r
&VgpuDev->Ring,\r
&Indices,\r
);\r
if (EFI_ERROR (Status)) {\r
goto UnmapResponse;\r
);\r
if (EFI_ERROR (Status)) {\r
goto UnmapResponse;\r
//\r
// Verify response size.\r
//\r
//\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
DEBUG ((\r
DEBUG_ERROR,\r
"%a: malformed response to Request=0x%x\n",\r
//\r
// Parse the response.\r
//\r
//\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
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
__FUNCTION__,\r
(UINT32)RequestType,\r
+ Response->Type,\r
+ ResponseType\r
));\r
return EFI_DEVICE_ERROR;\r
\r
));\r
return EFI_DEVICE_ERROR;\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
/**\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