]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioGpuDxe: move code to GopInitialize
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 8 Apr 2022 08:23:32 +0000 (10:23 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 25 Apr 2022 21:01:13 +0000 (21:01 +0000)
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>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
OvmfPkg/VirtioGpuDxe/Gop.c

index 337a7e19bffaf95fb75dcd6206308a52088b3f1b..05daefcbfbc825adb2d4ed60ed670e488c97c315 100644 (file)
@@ -192,6 +192,32 @@ STATIC CONST GOP_RESOLUTION  mGopResolutions[] = {
 #define VGPU_GOP_FROM_GOP(GopPointer) \\r
           CR (GopPointer, VGPU_GOP, Gop, VGPU_GOP_SIG)\r
 \r
+STATIC\r
+VOID\r
+EFIAPI\r
+GopInitialize (\r
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL  *This\r
+  )\r
+{\r
+  VGPU_GOP  *VgpuGop;\r
+\r
+  VgpuGop = VGPU_GOP_FROM_GOP (This);\r
+\r
+  //\r
+  // Set up the Gop -> GopMode -> GopModeInfo pointer chain, and the other\r
+  // (nonzero) constant fields.\r
+  //\r
+  // No direct framebuffer access is supported, only Blt() is.\r
+  //\r
+  VgpuGop->Gop.Mode = &VgpuGop->GopMode;\r
+\r
+  VgpuGop->GopMode.MaxMode    = (UINT32)(ARRAY_SIZE (mGopResolutions));\r
+  VgpuGop->GopMode.Info       = &VgpuGop->GopModeInfo;\r
+  VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo;\r
+\r
+  VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;\r
+}\r
+\r
 //\r
 // EFI_GRAPHICS_OUTPUT_PROTOCOL member functions.\r
 //\r
@@ -207,7 +233,7 @@ GopQueryMode (
 {\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *GopModeInfo;\r
 \r
-  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {\r
+  if (ModeNumber >= This->Mode->MaxMode) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -247,6 +273,11 @@ GopSetMode (
   EFI_STATUS  Status;\r
   EFI_STATUS  Status2;\r
 \r
+  if (!This->Mode) {\r
+    // SetMode() call in InitVgpuGop() triggers this.\r
+    GopInitialize (This);\r
+  }\r
+\r
   Status = GopQueryMode (This, ModeNumber, &SizeOfInfo, &GopModeInfo);\r
   if (Status != EFI_SUCCESS) {\r
     return Status;\r
@@ -259,20 +290,6 @@ GopSetMode (
   // calls.\r
   //\r
   if (VgpuGop->ResourceId == 0) {\r
-    //\r
-    // Set up the Gop -> GopMode -> GopModeInfo pointer chain, and the other\r
-    // (nonzero) constant fields.\r
-    //\r
-    // No direct framebuffer access is supported, only Blt() is.\r
-    //\r
-    VgpuGop->Gop.Mode = &VgpuGop->GopMode;\r
-\r
-    VgpuGop->GopMode.MaxMode    = (UINT32)(ARRAY_SIZE (mGopResolutions));\r
-    VgpuGop->GopMode.Info       = &VgpuGop->GopModeInfo;\r
-    VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo;\r
-\r
-    VgpuGop->GopModeInfo.PixelFormat = PixelBltOnly;\r
-\r
     //\r
     // This is the first time we create a host side resource.\r
     //\r