* [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution
@ 2022-04-08 8:23 Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply Gerd Hoffmann
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
QemuVideoDxe recently got support for picking up
display resolution configuration from the host.
This series does the same for VirtioGpuDxe.
v3:
- rebase to latest master.
Gerd Hoffmann (6):
OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply
OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header.
OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo
OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode
OvmfPkg/VirtioGpuDxe: move code to GopInitialize
OvmfPkg/VirtioGpuDxe: query native display resolution from host
OvmfPkg/VirtioGpuDxe/VirtioGpu.inf | 6 +
OvmfPkg/Include/IndustryStandard/VirtioGpu.h | 19 +-
OvmfPkg/VirtioGpuDxe/VirtioGpu.h | 12 ++
OvmfPkg/VirtioGpuDxe/Commands.c | 95 +++++++--
OvmfPkg/VirtioGpuDxe/Gop.c | 197 ++++++++++++++-----
5 files changed, 262 insertions(+), 67 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 2/6] OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header Gerd Hoffmann
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/6] OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header.
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 3/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo Gerd Hoffmann
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
Add GetDisplayInfo command, reply and data struct to the
virtio-gpu specification header file.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/Include/IndustryStandard/VirtioGpu.h | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/Include/IndustryStandard/VirtioGpu.h b/OvmfPkg/Include/IndustryStandard/VirtioGpu.h
index 12559ccef5b1..13f719d4c0f2 100644
--- a/OvmfPkg/Include/IndustryStandard/VirtioGpu.h
+++ b/OvmfPkg/Include/IndustryStandard/VirtioGpu.h
@@ -37,6 +37,7 @@ typedef enum {
//
// - create/release a host-side 2D resource,
//
+ VirtioGpuCmdGetDisplayInfo = 0x0100,
VirtioGpuCmdResourceCreate2d = 0x0101,
VirtioGpuCmdResourceUnref = 0x0102,
//
@@ -64,7 +65,8 @@ typedef enum {
//
// Success code for all of the above commands.
//
- VirtioGpuRespOkNodata = 0x1100,
+ VirtioGpuRespOkNodata = 0x1100,
+ VirtioGpuRespOkDisplayInfo = 0x1101,
} VIRTIO_GPU_CONTROL_TYPE;
//
@@ -207,4 +209,19 @@ typedef struct {
} VIRTIO_GPU_RESOURCE_FLUSH;
#pragma pack ()
+//
+// Response structure for VirtioGpuCmdGetDisplayInfo
+//
+#define VIRTIO_GPU_MAX_SCANOUTS 16
+#pragma pack (1)
+typedef struct {
+ VIRTIO_GPU_CONTROL_HEADER Header;
+ struct {
+ VIRTIO_GPU_RECTANGLE Rectangle;
+ UINT32 Enabled;
+ UINT32 Flags;
+ } Pmodes[VIRTIO_GPU_MAX_SCANOUTS];
+} VIRTIO_GPU_RESP_DISPLAY_INFO;
+#pragma pack ()
+
#endif // _VIRTIO_GPU_H_
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 3/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 2/6] OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 4/6] OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode Gerd Hoffmann
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
Add support for sending a GetDisplayInfo command.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/VirtioGpuDxe/VirtioGpu.h | 6 ++++++
OvmfPkg/VirtioGpuDxe/Commands.c | 20 ++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
index 2155b261d43e..1d781088bb3f 100644
--- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
+++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
@@ -366,6 +366,12 @@ VirtioGpuResourceFlush (
IN UINT32 ResourceId
);
+EFI_STATUS
+VirtioGpuGetDisplayInfo (
+ IN OUT VGPU_DEV *VgpuDev,
+ volatile VIRTIO_GPU_RESP_DISPLAY_INFO *Response
+ );
+
/**
Release guest-side and host-side resources that are related to an initialized
VGPU_GOP.Gop.
diff --git a/OvmfPkg/VirtioGpuDxe/Commands.c b/OvmfPkg/VirtioGpuDxe/Commands.c
index b9a3ea923021..4318d3d771c5 100644
--- a/OvmfPkg/VirtioGpuDxe/Commands.c
+++ b/OvmfPkg/VirtioGpuDxe/Commands.c
@@ -828,3 +828,23 @@ VirtioGpuResourceFlush (
sizeof Request
);
}
+
+EFI_STATUS
+VirtioGpuGetDisplayInfo (
+ IN OUT VGPU_DEV *VgpuDev,
+ volatile VIRTIO_GPU_RESP_DISPLAY_INFO *Response
+ )
+{
+ volatile VIRTIO_GPU_CONTROL_HEADER Request;
+
+ return VirtioGpuSendCommandWithReply (
+ VgpuDev,
+ VirtioGpuCmdGetDisplayInfo,
+ FALSE, // Fence
+ &Request,
+ sizeof Request,
+ VirtioGpuRespOkDisplayInfo,
+ &Response->Header,
+ sizeof *Response
+ );
+}
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 4/6] OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
` (2 preceding siblings ...)
2022-04-08 8:23 ` [PATCH v3 3/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 5/6] OvmfPkg/VirtioGpuDxe: move code to GopInitialize Gerd Hoffmann
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
Call GopQueryMode() in GopSetMode(), use the ModeInfo returned when
setting the mode. This is needed to properly handle modes which are
not on the static mGopResolutions list.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/VirtioGpuDxe/Gop.c | 60 ++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
index 2c15d542e3b1..337a7e19bffa 100644
--- a/OvmfPkg/VirtioGpuDxe/Gop.c
+++ b/OvmfPkg/VirtioGpuDxe/Gop.c
@@ -234,19 +234,22 @@ GopSetMode (
IN UINT32 ModeNumber
)
{
- VGPU_GOP *VgpuGop;
- UINT32 NewResourceId;
- UINTN NewNumberOfBytes;
- UINTN NewNumberOfPages;
- VOID *NewBackingStore;
- EFI_PHYSICAL_ADDRESS NewBackingStoreDeviceAddress;
- VOID *NewBackingStoreMap;
+ VGPU_GOP *VgpuGop;
+ UINT32 NewResourceId;
+ UINTN NewNumberOfBytes;
+ UINTN NewNumberOfPages;
+ VOID *NewBackingStore;
+ EFI_PHYSICAL_ADDRESS NewBackingStoreDeviceAddress;
+ VOID *NewBackingStoreMap;
+ UINTN SizeOfInfo;
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo;
EFI_STATUS Status;
EFI_STATUS Status2;
- if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
- return EFI_UNSUPPORTED;
+ Status = GopQueryMode (This, ModeNumber, &SizeOfInfo, &GopModeInfo);
+ if (Status != EFI_SUCCESS) {
+ return Status;
}
VgpuGop = VGPU_GOP_FROM_GOP (This);
@@ -292,8 +295,8 @@ GopSetMode (
VgpuGop->ParentBus, // VgpuDev
NewResourceId, // ResourceId
VirtioGpuFormatB8G8R8X8Unorm, // Format
- mGopResolutions[ModeNumber].Width, // Width
- mGopResolutions[ModeNumber].Height // Height
+ GopModeInfo->HorizontalResolution, // Width
+ GopModeInfo->VerticalResolution // Height
);
if (EFI_ERROR (Status)) {
return Status;
@@ -303,8 +306,8 @@ GopSetMode (
// Allocate, zero and map guest backing store, for bus master common buffer
// operation.
//
- NewNumberOfBytes = mGopResolutions[ModeNumber].Width *
- mGopResolutions[ModeNumber].Height * sizeof (UINT32);
+ NewNumberOfBytes = GopModeInfo->HorizontalResolution *
+ GopModeInfo->VerticalResolution * sizeof (UINT32);
NewNumberOfPages = EFI_SIZE_TO_PAGES (NewNumberOfBytes);
Status = VirtioGpuAllocateZeroAndMapBackingStore (
VgpuGop->ParentBus, // VgpuDev
@@ -337,8 +340,8 @@ GopSetMode (
VgpuGop->ParentBus, // VgpuDev
0, // X
0, // Y
- mGopResolutions[ModeNumber].Width, // Width
- mGopResolutions[ModeNumber].Height, // Height
+ GopModeInfo->HorizontalResolution, // Width
+ GopModeInfo->VerticalResolution, // Height
0, // ScanoutId
NewResourceId // ResourceId
);
@@ -356,8 +359,8 @@ GopSetMode (
VgpuGop->ParentBus, // VgpuDev
0, // X
0, // Y
- mGopResolutions[ModeNumber].Width, // Width
- mGopResolutions[ModeNumber].Height, // Height
+ GopModeInfo->HorizontalResolution, // Width
+ GopModeInfo->VerticalResolution, // Height
NewResourceId // ResourceId
);
if (EFI_ERROR (Status)) {
@@ -367,13 +370,13 @@ GopSetMode (
// therefore non-recoverable.
//
Status2 = VirtioGpuSetScanout (
- VgpuGop->ParentBus, // VgpuDev
- 0, // X
- 0, // Y
- mGopResolutions[This->Mode->Mode].Width, // Width
- mGopResolutions[This->Mode->Mode].Height, // Height
- 0, // ScanoutId
- VgpuGop->ResourceId // ResourceId
+ VgpuGop->ParentBus, // VgpuDev
+ 0, // X
+ 0, // Y
+ VgpuGop->GopModeInfo.HorizontalResolution, // Width
+ VgpuGop->GopModeInfo.VerticalResolution, // Height
+ 0, // ScanoutId
+ VgpuGop->ResourceId // ResourceId
);
ASSERT_EFI_ERROR (Status2);
if (EFI_ERROR (Status2)) {
@@ -406,11 +409,9 @@ GopSetMode (
//
// Populate Mode and ModeInfo (mutable fields only).
//
- VgpuGop->GopMode.Mode = ModeNumber;
- VgpuGop->GopModeInfo.HorizontalResolution =
- mGopResolutions[ModeNumber].Width;
- VgpuGop->GopModeInfo.VerticalResolution = mGopResolutions[ModeNumber].Height;
- VgpuGop->GopModeInfo.PixelsPerScanLine = mGopResolutions[ModeNumber].Width;
+ VgpuGop->GopMode.Mode = ModeNumber;
+ VgpuGop->GopModeInfo = *GopModeInfo;
+ FreePool (GopModeInfo);
return EFI_SUCCESS;
DetachBackingStore:
@@ -435,6 +436,7 @@ GopSetMode (
CpuDeadLoop ();
}
+ FreePool (GopModeInfo);
return Status;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 5/6] OvmfPkg/VirtioGpuDxe: move code to GopInitialize
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
` (3 preceding siblings ...)
2022-04-08 8:23 ` [PATCH v3 4/6] OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host Gerd Hoffmann
2022-04-25 10:36 ` [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
Add new function to initialize the GOP, move over setup code. Handle
initialization first, specifically before calling GopQueryMode(), so
GopQueryMode is never called before GopInitialize() did complete.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/VirtioGpuDxe/Gop.c | 47 ++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 15 deletions(-)
diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
index 337a7e19bffa..05daefcbfbc8 100644
--- a/OvmfPkg/VirtioGpuDxe/Gop.c
+++ b/OvmfPkg/VirtioGpuDxe/Gop.c
@@ -192,6 +192,32 @@ STATIC CONST GOP_RESOLUTION mGopResolutions[] = {
#define VGPU_GOP_FROM_GOP(GopPointer) \
CR (GopPointer, VGPU_GOP, Gop, VGPU_GOP_SIG)
+STATIC
+VOID
+EFIAPI
+GopInitialize (
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This
+ )
+{
+ VGPU_GOP *VgpuGop;
+
+ VgpuGop = VGPU_GOP_FROM_GOP (This);
+
+ //
+ // Set up the Gop -> GopMode -> GopModeInfo pointer chain, and the other
+ // (nonzero) constant fields.
+ //
+ // No direct framebuffer access is supported, only Blt() is.
+ //
+ VgpuGop->Gop.Mode = &VgpuGop->GopMode;
+
+ VgpuGop->GopMode.MaxMode = (UINT32)(ARRAY_SIZE (mGopResolutions));
+ VgpuGop->GopMode.Info = &VgpuGop->GopModeInfo;
+ VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo;
+
+ VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;
+}
+
//
// EFI_GRAPHICS_OUTPUT_PROTOCOL member functions.
//
@@ -207,7 +233,7 @@ GopQueryMode (
{
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo;
- if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
+ if (ModeNumber >= This->Mode->MaxMode) {
return EFI_INVALID_PARAMETER;
}
@@ -247,6 +273,11 @@ GopSetMode (
EFI_STATUS Status;
EFI_STATUS Status2;
+ if (!This->Mode) {
+ // SetMode() call in InitVgpuGop() triggers this.
+ GopInitialize (This);
+ }
+
Status = GopQueryMode (This, ModeNumber, &SizeOfInfo, &GopModeInfo);
if (Status != EFI_SUCCESS) {
return Status;
@@ -259,20 +290,6 @@ GopSetMode (
// calls.
//
if (VgpuGop->ResourceId == 0) {
- //
- // Set up the Gop -> GopMode -> GopModeInfo pointer chain, and the other
- // (nonzero) constant fields.
- //
- // No direct framebuffer access is supported, only Blt() is.
- //
- VgpuGop->Gop.Mode = &VgpuGop->GopMode;
-
- VgpuGop->GopMode.MaxMode = (UINT32)(ARRAY_SIZE (mGopResolutions));
- VgpuGop->GopMode.Info = &VgpuGop->GopModeInfo;
- VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo;
-
- VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;
-
//
// This is the first time we create a host side resource.
//
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
` (4 preceding siblings ...)
2022-04-08 8:23 ` [PATCH v3 5/6] OvmfPkg/VirtioGpuDxe: move code to GopInitialize Gerd Hoffmann
@ 2022-04-08 8:23 ` Gerd Hoffmann
2022-04-25 10:36 ` [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
6 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-08 8:23 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Gerd Hoffmann, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
Try query native display resolution from the host. When successfull
setup PcdVideoHorizontalResolution and PcdVideoVerticalResolution
accordingly and add the video mode to the GOP mode list if needed.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/VirtioGpuDxe/VirtioGpu.inf | 6 ++
OvmfPkg/VirtioGpuDxe/VirtioGpu.h | 6 ++
OvmfPkg/VirtioGpuDxe/Gop.c | 92 ++++++++++++++++++++++++++++--
3 files changed, 99 insertions(+), 5 deletions(-)
diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf b/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
index 9e66bcd4b97f..d88c87e129f0 100644
--- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
+++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
@@ -25,6 +25,7 @@ [Sources]
[Packages]
MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec
[LibraryClasses]
@@ -43,3 +44,8 @@ [Protocols]
gEfiGraphicsOutputProtocolGuid ## BY_START
gEfiPciIoProtocolGuid ## TO_START
gVirtioDeviceProtocolGuid ## TO_START
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution
diff --git a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
index 1d781088bb3f..45da56415297 100644
--- a/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
+++ b/OvmfPkg/VirtioGpuDxe/VirtioGpu.h
@@ -151,6 +151,12 @@ struct VGPU_GOP_STRUCT {
// BackingStore is non-NULL.
//
VOID *BackingStoreMap;
+
+ //
+ // native display resolution
+ //
+ UINT32 NativeXRes;
+ UINT32 NativeYRes;
};
//
diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
index 05daefcbfbc8..70a81c10c8b5 100644
--- a/OvmfPkg/VirtioGpuDxe/Gop.c
+++ b/OvmfPkg/VirtioGpuDxe/Gop.c
@@ -9,6 +9,7 @@
**/
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include "VirtioGpu.h"
@@ -192,6 +193,47 @@ STATIC CONST GOP_RESOLUTION mGopResolutions[] = {
#define VGPU_GOP_FROM_GOP(GopPointer) \
CR (GopPointer, VGPU_GOP, Gop, VGPU_GOP_SIG)
+STATIC
+VOID
+EFIAPI
+GopNativeResolution (
+ IN VGPU_GOP *VgpuGop,
+ OUT UINT32 *XRes,
+ OUT UINT32 *YRes
+ )
+{
+ volatile VIRTIO_GPU_RESP_DISPLAY_INFO DisplayInfo;
+ EFI_STATUS Status;
+ UINTN Index;
+
+ Status = VirtioGpuGetDisplayInfo (VgpuGop->ParentBus, &DisplayInfo);
+ if (Status != EFI_SUCCESS) {
+ return;
+ }
+
+ for (Index = 0; Index < VIRTIO_GPU_MAX_SCANOUTS; Index++) {
+ if (!DisplayInfo.Pmodes[Index].Enabled ||
+ !DisplayInfo.Pmodes[Index].Rectangle.Width ||
+ !DisplayInfo.Pmodes[Index].Rectangle.Height)
+ {
+ continue;
+ }
+
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: #%d: %dx%d\n",
+ __FUNCTION__,
+ Index,
+ DisplayInfo.Pmodes[Index].Rectangle.Width,
+ DisplayInfo.Pmodes[Index].Rectangle.Height
+ ));
+ if ((*XRes == 0) || (*YRes == 0)) {
+ *XRes = DisplayInfo.Pmodes[Index].Rectangle.Width;
+ *YRes = DisplayInfo.Pmodes[Index].Rectangle.Height;
+ }
+ }
+}
+
STATIC
VOID
EFIAPI
@@ -199,7 +241,9 @@ GopInitialize (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This
)
{
- VGPU_GOP *VgpuGop;
+ VGPU_GOP *VgpuGop;
+ EFI_STATUS Status;
+ UINT32 XRes = 0, YRes = 0, Index;
VgpuGop = VGPU_GOP_FROM_GOP (This);
@@ -216,6 +260,37 @@ GopInitialize (
VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo;
VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;
+
+ //
+ // query host for display resolution
+ //
+ GopNativeResolution (VgpuGop, &XRes, &YRes);
+ if ((XRes == 0) || (YRes == 0)) {
+ return;
+ }
+
+ if (PcdGet8 (PcdVideoResolutionSource) == 0) {
+ Status = PcdSet32S (PcdVideoHorizontalResolution, XRes);
+ ASSERT_RETURN_ERROR (Status);
+ Status = PcdSet32S (PcdVideoVerticalResolution, YRes);
+ ASSERT_RETURN_ERROR (Status);
+ Status = PcdSet8S (PcdVideoResolutionSource, 2);
+ ASSERT_RETURN_ERROR (Status);
+ }
+
+ VgpuGop->NativeXRes = XRes;
+ VgpuGop->NativeYRes = YRes;
+ for (Index = 0; Index < ARRAY_SIZE (mGopResolutions); Index++) {
+ if ((mGopResolutions[Index].Width == XRes) &&
+ (mGopResolutions[Index].Height == YRes))
+ {
+ // native resolution already is in mode list
+ return;
+ }
+ }
+
+ // add to mode list
+ VgpuGop->GopMode.MaxMode++;
}
//
@@ -242,10 +317,17 @@ GopQueryMode (
return EFI_OUT_OF_RESOURCES;
}
- GopModeInfo->HorizontalResolution = mGopResolutions[ModeNumber].Width;
- GopModeInfo->VerticalResolution = mGopResolutions[ModeNumber].Height;
- GopModeInfo->PixelFormat = PixelBltOnly;
- GopModeInfo->PixelsPerScanLine = mGopResolutions[ModeNumber].Width;
+ if (ModeNumber < ARRAY_SIZE (mGopResolutions)) {
+ GopModeInfo->HorizontalResolution = mGopResolutions[ModeNumber].Width;
+ GopModeInfo->VerticalResolution = mGopResolutions[ModeNumber].Height;
+ } else {
+ VGPU_GOP *VgpuGop = VGPU_GOP_FROM_GOP (This);
+ GopModeInfo->HorizontalResolution = VgpuGop->NativeXRes;
+ GopModeInfo->VerticalResolution = VgpuGop->NativeYRes;
+ }
+
+ GopModeInfo->PixelFormat = PixelBltOnly;
+ GopModeInfo->PixelsPerScanLine = GopModeInfo->HorizontalResolution;
*SizeOfInfo = sizeof *GopModeInfo;
*Info = GopModeInfo;
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
` (5 preceding siblings ...)
2022-04-08 8:23 ` [PATCH v3 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host Gerd Hoffmann
@ 2022-04-25 10:36 ` Gerd Hoffmann
2022-04-25 10:38 ` Ard Biesheuvel
6 siblings, 1 reply; 10+ messages in thread
From: Gerd Hoffmann @ 2022-04-25 10:36 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Jiewen Yao, Pawel Polawski, Oliver Steffen,
Ard Biesheuvel
On Fri, Apr 08, 2022 at 10:23:27AM +0200, Gerd Hoffmann wrote:
> QemuVideoDxe recently got support for picking up
> display resolution configuration from the host.
> This series does the same for VirtioGpuDxe.
>
> v3:
> - rebase to latest master.
Ping. Anything blocking the merge id this series?
thanks,
Gerd
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution
2022-04-25 10:36 ` [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
@ 2022-04-25 10:38 ` Ard Biesheuvel
2022-04-26 6:50 ` Ard Biesheuvel
0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2022-04-25 10:38 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: edk2-devel-groups-io, Jordan Justen, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
On Mon, 25 Apr 2022 at 12:36, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Fri, Apr 08, 2022 at 10:23:27AM +0200, Gerd Hoffmann wrote:
> > QemuVideoDxe recently got support for picking up
> > display resolution configuration from the host.
> > This series does the same for VirtioGpuDxe.
> >
> > v3:
> > - rebase to latest master.
>
> Ping. Anything blocking the merge id this series?
>
No, I'll pick these up today.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution
2022-04-25 10:38 ` Ard Biesheuvel
@ 2022-04-26 6:50 ` Ard Biesheuvel
0 siblings, 0 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2022-04-26 6:50 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: edk2-devel-groups-io, Jordan Justen, Jiewen Yao, Pawel Polawski,
Oliver Steffen, Ard Biesheuvel
On Mon, 25 Apr 2022 at 12:38, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Mon, 25 Apr 2022 at 12:36, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > On Fri, Apr 08, 2022 at 10:23:27AM +0200, Gerd Hoffmann wrote:
> > > QemuVideoDxe recently got support for picking up
> > > display resolution configuration from the host.
> > > This series does the same for VirtioGpuDxe.
> > >
> > > v3:
> > > - rebase to latest master.
> >
> > Ping. Anything blocking the merge id this series?
> >
>
> No, I'll pick these up today.
Merged as #2826
Thanks,
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-04-26 6:50 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-08 8:23 [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 2/6] OvmfPkg/VirtioGpuDxe: add GetDisplayInfo to virtio-gpu spec header Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 3/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuGetDisplayInfo Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 4/6] OvmfPkg/VirtioGpuDxe: use GopQueryMode in GopSetMode Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 5/6] OvmfPkg/VirtioGpuDxe: move code to GopInitialize Gerd Hoffmann
2022-04-08 8:23 ` [PATCH v3 6/6] OvmfPkg/VirtioGpuDxe: query native display resolution from host Gerd Hoffmann
2022-04-25 10:36 ` [PATCH v3 0/6] OvmfPkg/VirtioGpuDxe: use host display resolution Gerd Hoffmann
2022-04-25 10:38 ` Ard Biesheuvel
2022-04-26 6:50 ` Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox