]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: QemuVideoDxe: work around misreported QXL framebuffer size
authorLaszlo Ersek <lersek@redhat.com>
Fri, 29 Aug 2014 17:27:20 +0000 (17:27 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Aug 2014 17:27:20 +0000 (17:27 +0000)
When setting up the list of GOP modes offered on QEMU's stdvga ("VGA") and
QXL ("qxl-vga") video devices, QemuVideoBochsModeSetup() filters those
modes against the available framebuffer size. (Refer to SVN r15288 / git
commit ec88061e.)

The VBE_DISPI_INDEX_VIDEO_MEMORY_64K register of both stdvga and QXL is
supposed to report the size of the drawable, VGA-compatibility
framebuffer. Instead, up to and including qemu-2.1, this register actually
reports the full video RAM (PCI BAR 0) size.

In case of stdvga, this happens to be correct, because on that card the
full PCI BAR 0 is usable for drawing; there is no difference between
"drawable framebuffer size" and "video RAM (PCI BAR 0) size".

However, on the QXL card, only an initial portion of the video RAM is
suitable for drawing, as compatibility framebuffer; and the value
currently reported by VBE_DISPI_INDEX_VIDEO_MEMORY_64K overshoots the
valid size. Beyond the drawable range, the video RAM contains buffers and
structures for the QXL guest-host protocol.

Luckily, the size of the drawable QXL framebuffer can also be read from a
register in the QXL ROM BAR (PCI BAR 2), so let's retrieve it from there.

Without this fix, OVMF offers too large resolutions on the QXL card (up to
the full size of the video RAM). If a GOP client selects such a resolution
and draws into the video RAM past the compatibility segment, then the
guest corrupts its communication structures (which is invalid guest
behavior).

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15978 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/QemuVideoDxe/Driver.c
OvmfPkg/QemuVideoDxe/Initialize.c
OvmfPkg/QemuVideoDxe/Qemu.h

index 2194cbef44a47b517112c81692bdb1352bdecf60..17bd4cc2ccc3af88311a2f261f39967fab8a13ce 100644 (file)
@@ -173,6 +173,7 @@ QemuVideoControllerDriverStart (
   EFI_TPL                           OldTpl;\r
   EFI_STATUS                        Status;\r
   QEMU_VIDEO_PRIVATE_DATA           *Private;\r
+  BOOLEAN                           IsQxl;\r
   EFI_DEVICE_PATH_PROTOCOL          *ParentDevicePath;\r
   ACPI_ADR_DEVICE_PATH              AcpiDeviceNode;\r
   PCI_TYPE00                        Pci;\r
@@ -234,6 +235,12 @@ QemuVideoControllerDriverStart (
   }\r
   Private->Variant = Card->Variant;\r
 \r
+  //\r
+  // IsQxl is based on the detected Card->Variant, which at a later point might\r
+  // not match Private->Variant.\r
+  //\r
+  IsQxl = (BOOLEAN)(Card->Variant == QEMU_VIDEO_BOCHS);\r
+\r
   //\r
   // Save original PCI attributes\r
   //\r
@@ -354,7 +361,7 @@ QemuVideoControllerDriverStart (
     break;\r
   case QEMU_VIDEO_BOCHS_MMIO:\r
   case QEMU_VIDEO_BOCHS:\r
-    Status = QemuVideoBochsModeSetup (Private);\r
+    Status = QemuVideoBochsModeSetup (Private, IsQxl);\r
     break;\r
   default:\r
     ASSERT (FALSE);\r
index a536d47bbb5ed186b9d2a28972dcfcca13f8f011..9e0c3aa09fd6fbfaccd97c29af5141adc113e346 100644 (file)
@@ -253,7 +253,8 @@ QEMU_VIDEO_BOCHS_MODES  QemuVideoBochsModes[] = {
 \r
 EFI_STATUS\r
 QemuVideoBochsModeSetup (\r
-  QEMU_VIDEO_PRIVATE_DATA  *Private\r
+  QEMU_VIDEO_PRIVATE_DATA  *Private,\r
+  BOOLEAN                  IsQxl\r
   )\r
 {\r
   UINT32                                 AvailableFbSize;\r
@@ -262,10 +263,48 @@ QemuVideoBochsModeSetup (
   QEMU_VIDEO_BOCHS_MODES                 *VideoMode;\r
 \r
   //\r
-  // fetch available framebuffer size\r
+  // Fetch the available framebuffer size.\r
+  //\r
+  // VBE_DISPI_INDEX_VIDEO_MEMORY_64K is expected to return the size of the\r
+  // drawable framebuffer. Up to and including qemu-2.1 however it used to\r
+  // return the size of PCI BAR 0 (ie. the full video RAM size).\r
+  //\r
+  // On stdvga the two concepts coincide with each other; the full memory size\r
+  // is usable for drawing.\r
   //\r
-  AvailableFbSize  = BochsRead (Private, VBE_DISPI_INDEX_VIDEO_MEMORY_64K);\r
-  AvailableFbSize *= SIZE_64KB;\r
+  // On QXL however, only a leading segment, "surface 0", can be used for\r
+  // drawing; the rest of the video memory is used for the QXL guest-host\r
+  // protocol. VBE_DISPI_INDEX_VIDEO_MEMORY_64K should report the size of\r
+  // "surface 0", but since it doesn't (up to and including qemu-2.1), we\r
+  // retrieve the size of the drawable portion from a field in the QXL ROM BAR,\r
+  // where it is also available.\r
+  //\r
+  if (IsQxl) {\r
+    UINT32 Signature;\r
+    UINT32 DrawStart;\r
+\r
+    Signature = 0;\r
+    DrawStart = 0xFFFFFFFF;\r
+    AvailableFbSize = 0;\r
+    if (EFI_ERROR (\r
+          Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32,\r
+                                PCI_BAR_IDX2, 0, 1, &Signature)) ||\r
+        Signature != SIGNATURE_32 ('Q', 'X', 'R', 'O') ||\r
+        EFI_ERROR (\r
+          Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32,\r
+                                PCI_BAR_IDX2, 36, 1, &DrawStart)) ||\r
+        DrawStart != 0 ||\r
+        EFI_ERROR (\r
+          Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32,\r
+                                PCI_BAR_IDX2, 40, 1, &AvailableFbSize))) {\r
+      DEBUG ((EFI_D_ERROR, "%a: can't read size of drawable buffer from QXL "\r
+        "ROM\n", __FUNCTION__));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  } else {\r
+    AvailableFbSize  = BochsRead (Private, VBE_DISPI_INDEX_VIDEO_MEMORY_64K);\r
+    AvailableFbSize *= SIZE_64KB;\r
+  }\r
   DEBUG ((EFI_D_VERBOSE, "%a: AvailableFbSize=0x%x\n", __FUNCTION__,\r
     AvailableFbSize));\r
 \r
index 4bf51c715044ec345a3d13b220f340f1aeb4bf72..52ee20d8ba973deb33f04471d32f6f4ccbf97b6c 100644 (file)
@@ -499,7 +499,8 @@ QemuVideoCirrusModeSetup (
 \r
 EFI_STATUS\r
 QemuVideoBochsModeSetup (\r
-  QEMU_VIDEO_PRIVATE_DATA  *Private\r
+  QEMU_VIDEO_PRIVATE_DATA  *Private,\r
+  BOOLEAN                  IsQxl\r
   );\r
 \r
 VOID\r