]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/QemuVideoDxe: Shouldn't assume system in VGA alias mode.
authorMarc W Chen <marc.w.chen@intel.com>
Thu, 6 Jun 2019 07:42:37 +0000 (15:42 +0800)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 6 Jun 2019 10:27:52 +0000 (12:27 +0200)
Query the supported attributes firstly, then bitwise AND (&) both VGA_IO
and VGA_IO_16. Since the supported attributes should only have one of
VGA_IO or VGA_IO_16 set, the result of bitwise AND (&) is either VGA_IO
or IO_16. Then the result can be passed to PciIo->Attributes() to set the
attributes.

Device driver should consider both since the mReserveVgaAliases in
PciBusDxe driver is default FALSE(implies that device driver can only set
VGA_IO_16 to PCI_ROOT_BRIDGE), and Platform code may not return
EFI_RESERVE_VGA_IO_ALIAS in GetPlatformPolicy of PciPlatformProtocol to
make mReserveVgaAliases become TRUE(implies that device driver can only
set VGA_IO to PCI_ROOT_BRIDGE), Currently OvmfPkg doesn't have problem
due to it has hard code value for PCI_ROOT_BRIDGE's attributes field, so
an IO access by PciIoProtocol will be successed due to
RootBridgeIoCheckParameter of PciRootBridgeIo.c will always get pass
result for legacy IO access.

Usually the attributes field of PCI_ROOT_BRIDGE should be 0, in that case
it will have issue since the VGA_IO may not be able to be enabled, then
IO access by PciIoProtocol will be failed, hence the QemuVideoDxe driver
will not work fine.

Signed-off-by: Marc Chen <marc.w.chen@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1880
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20190606074237.81492-1-marc.w.chen@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/QemuVideoDxe/Driver.c

index e8a613ef336a164b63cba7f40cfa93048f15a4d4..522110ef4e098b5b60527036bec60f326bad1df8 100644 (file)
@@ -201,6 +201,7 @@ QemuVideoControllerDriverStart (
   PCI_TYPE00                        Pci;\r
   QEMU_VIDEO_CARD                   *Card;\r
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;\r
   PCI_TYPE00                        Pci;\r
   QEMU_VIDEO_CARD                   *Card;\r
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;\r
+  UINT64                            SupportedVgaIo;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
@@ -277,13 +278,32 @@ QemuVideoControllerDriverStart (
     goto ClosePciIo;\r
   }\r
 \r
     goto ClosePciIo;\r
   }\r
 \r
+  //\r
+  // Get supported PCI attributes\r
+  //\r
+  Status = Private->PciIo->Attributes (\r
+                             Private->PciIo,\r
+                             EfiPciIoAttributeOperationSupported,\r
+                             0,\r
+                             &SupportedVgaIo\r
+                             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ClosePciIo;\r
+  }\r
+\r
+  SupportedVgaIo &= (UINT64)(EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16);\r
+  if (SupportedVgaIo == 0) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto ClosePciIo;\r
+  }\r
+\r
   //\r
   // Set new PCI attributes\r
   //\r
   Status = Private->PciIo->Attributes (\r
                             Private->PciIo,\r
                             EfiPciIoAttributeOperationEnable,\r
   //\r
   // Set new PCI attributes\r
   //\r
   Status = Private->PciIo->Attributes (\r
                             Private->PciIo,\r
                             EfiPciIoAttributeOperationEnable,\r
-                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,\r
+                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | SupportedVgaIo,\r
                             NULL\r
                             );\r
   if (EFI_ERROR (Status)) {\r
                             NULL\r
                             );\r
   if (EFI_ERROR (Status)) {\r