From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: marc.w.chen@intel.com) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by groups.io with SMTP; Wed, 05 Jun 2019 04:14:16 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jun 2019 04:14:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,550,1549958400"; d="scan'208";a="181895067" Received: from chenmarc-mobl.gar.corp.intel.com ([10.5.245.106]) by fmsmga002.fm.intel.com with ESMTP; 05 Jun 2019 04:14:13 -0700 From: "Marc W Chen" To: devel@edk2.groups.io Cc: Marc Chen , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Anthony Perard , Julien Grall , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefan Berger Subject: [PATCH] OvmfPkg/QemuVideoDxe: Shouldn't assume system in VGA alias mode. Date: Wed, 5 Jun 2019 19:14:10 +0800 Message-Id: <20190605111410.73564-1-marc.w.chen@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Cc: Marc-André Lureau Cc: Stefan Berger 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