public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] OvmfPkg/QemuVideoDxe: Shouldn't assume system in VGA alias mode.
@ 2019-06-05 11:14 Marc W Chen
  2019-06-05 12:00 ` Laszlo Ersek
  0 siblings, 1 reply; 5+ messages in thread
From: Marc W Chen @ 2019-06-05 11:14 UTC (permalink / raw)
  To: devel
  Cc: Marc Chen, Jordan Justen, Laszlo Ersek, Ard Biesheuvel,
	Anthony Perard, Julien Grall, Marc-André Lureau,
	Stefan Berger

Query the supported attributes firstly, then AND (&&) both
VGA_IO and VGA_IO_16. Since the supported attributes should
only have VGA_IO or VGA_IO_16 set, the result of AND (&&) is
either VGA_IO or IO_16. Then the result can be passed to
PciIo->Attributes() to set the attributes.

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
---
 OvmfPkg/QemuVideoDxe/Driver.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index e8a613ef33..ba9210f24b 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -201,6 +201,7 @@ QemuVideoControllerDriverStart (
   PCI_TYPE00                        Pci;
   QEMU_VIDEO_CARD                   *Card;
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;
+  UINT64                            Supports;
 
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
 
@@ -277,13 +278,32 @@ QemuVideoControllerDriverStart (
     goto ClosePciIo;
   }
 
+  //
+  // Get supported PCI attributes
+  //
+  Status = Private->PciIo->Attributes (
+                    Private->PciIo,
+                    EfiPciIoAttributeOperationSupported,
+                    0,
+                    &Supports
+                    );
+  if (EFI_ERROR (Status)) {
+    goto ClosePciIo;
+  }
+
+  Supports &= (UINT64)(EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16);
+  if ((Supports == 0) || (Supports == (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))) {
+    Status = EFI_UNSUPPORTED;
+    goto ClosePciIo;
+  }
+
   //
   // Set new PCI attributes
   //
   Status = Private->PciIo->Attributes (
                             Private->PciIo,
                             EfiPciIoAttributeOperationEnable,
-                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,
+                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | Supports,
                             NULL
                             );
   if (EFI_ERROR (Status)) {
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] OvmfPkg/QemuVideoDxe: Shouldn't assume system in VGA alias mode.
@ 2019-06-05 10:55 Marc W Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Marc W Chen @ 2019-06-05 10:55 UTC (permalink / raw)
  To: devel
  Cc: Marc Chen, Jordan Justen, Laszlo Ersek, Ard Biesheuvel,
	Anthony Perard, Julien Grall, Marc-André Lureau,
	Stefan Berger

Query the supported attributes firstly, then AND (&&) both
VGA_IO and VGA_IO_16. Since the supported attributes should
only have VGA_IO or VGA_IO_16 set, the result of AND (&&) is
either VGA_IO or IO_16. Then the result can be passed to
PciIo->Attributes() to set the attributes.

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>
---
 OvmfPkg/QemuVideoDxe/Driver.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index e8a613ef33..ba9210f24b 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -201,6 +201,7 @@ QemuVideoControllerDriverStart (
   PCI_TYPE00                        Pci;
   QEMU_VIDEO_CARD                   *Card;
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;
+  UINT64                            Supports;
 
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
 
@@ -277,13 +278,32 @@ QemuVideoControllerDriverStart (
     goto ClosePciIo;
   }
 
+  //
+  // Get supported PCI attributes
+  //
+  Status = Private->PciIo->Attributes (
+                    Private->PciIo,
+                    EfiPciIoAttributeOperationSupported,
+                    0,
+                    &Supports
+                    );
+  if (EFI_ERROR (Status)) {
+    goto ClosePciIo;
+  }
+
+  Supports &= (UINT64)(EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16);
+  if ((Supports == 0) || (Supports == (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))) {
+    Status = EFI_UNSUPPORTED;
+    goto ClosePciIo;
+  }
+
   //
   // Set new PCI attributes
   //
   Status = Private->PciIo->Attributes (
                             Private->PciIo,
                             EfiPciIoAttributeOperationEnable,
-                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,
+                            EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | Supports,
                             NULL
                             );
   if (EFI_ERROR (Status)) {
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-06  4:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-05 11:14 [PATCH] OvmfPkg/QemuVideoDxe: Shouldn't assume system in VGA alias mode Marc W Chen
2019-06-05 12:00 ` Laszlo Ersek
2019-06-05 17:15   ` [edk2-devel] " Laszlo Ersek
2019-06-06  4:18   ` Marc W Chen
  -- strict thread matches above, loose matches on Subject: below --
2019-06-05 10:55 Marc W Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox