From nobody Sat Apr 27 03:08:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+65272+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+65272+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=9elements.com ARC-Seal: i=1; a=rsa-sha256; t=1600172783; cv=none; d=zohomail.com; s=zohoarc; b=JtrMAT/ThUDT1Ltk/R6mlmS/ikj2aUlVxJTI6G9cNgsM4XMOFp1LUkGBOLP4xvI0TAdKUofWdnTKHHO+Ga9J8CFH9SQf0r/S+O7tCNDg0LZTNhoZaVCI/wevTxyOn3XJNDfjtF9M7E/tzCJRl4d5nNr8NWSiTejH0oP+4KobQ2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600172783; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=QegvDxBUikd/xonh/85/+FnUB6cFIBqvYMMVL62W1NI=; b=NuFveDqmeY7EMY0pGNjtT6tKovZaDA/4j3ElLBfCVPp4jbcyhwFf6DqRa7vtct7UtXnh4AnHRKErrSdaWOKep5aiax5yS7LDoE21Sxpbxx5n7yoz+iVW58j5Pr+gkB7PywDbalODjznaf6duWWl11uIAWxwrilr8vz8XsW6v8yw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+65272+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1600172783218241.5726423394259; Tue, 15 Sep 2020 05:26:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id B6ouYY1788612xkR1lhCeyzI; Tue, 15 Sep 2020 05:26:22 -0700 X-Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by mx.groups.io with SMTP id smtpd.web10.12065.1600172782228063603 for ; Tue, 15 Sep 2020 05:26:22 -0700 X-Received: by mail-ej1-f68.google.com with SMTP id q13so4718730ejo.9 for ; Tue, 15 Sep 2020 05:26:21 -0700 (PDT) X-Gm-Message-State: rnrRtZlNh1H5Oy5bLPIR5TW1x1787277AA= X-Google-Smtp-Source: ABdhPJyxvn/rU7G1/kiRiA0fCp/d5jOg35V9EIjQMcoEGL53bGjOtjnEfVEEzAahu5cKUrIibYxoDA== X-Received: by 2002:a17:906:474f:: with SMTP id j15mr21054891ejs.468.1600172780437; Tue, 15 Sep 2020 05:26:20 -0700 (PDT) X-Received: from T14.n1ce.space ([2a02:908:e851:d750:5f43:5410:2022:1d7c]) by smtp.gmail.com with ESMTPSA id x25sm11217064edv.42.2020.09.15.05.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 05:26:20 -0700 (PDT) From: "Marcello Sylvester Bauer" To: devel@edk2.groups.io Cc: Patrick Rudolph , Christian Walter , Hao A Wu , Jian J Wang , Ray Ni Subject: [edk2-devel] [PATCH v2 1/2] MdeModulePkg: Fix OptionROM scanning Date: Tue, 15 Sep 2020 14:26:15 +0200 Message-Id: <20200915122616.17196-2-marcello.bauer@9elements.com> In-Reply-To: <20200915122616.17196-1-marcello.bauer@9elements.com> References: <20200915122616.17196-1-marcello.bauer@9elements.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,marcello.bauer@9elements.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1600172782; bh=c+ETo20LZLpdXmRjzve5buLqYXF/gE7JwkE821wuVcI=; h=Cc:Date:From:Reply-To:Subject:To; b=M5mioz6ki4J4SkTckaKR00mkHxSDWVeeP5eCr6ROxy9HWohI+spSiIt4KhIp3NNXPuC Nsm/UURD/+04qXnVJlJbHeo2VYoI4nojUURbc/iBskkZih73F3Q/7l/qvMI08UI4CMQo9 GipTiGd5HSnwNmjPnheIy/C42BkHOdfDOkk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Patrick Rudolph The Option ROM scanner can't work as enumeration was done by the first stage bootloader. Running it will disable the ability of the PCIPlatform code to scan for ROMs. Required for the following patch that enables custom Option ROM scanning using gPciPlatformProtocol. Signed-off-by: Patrick Rudolph Signed-off-by: Marcello Sylvester Bauer Cc: Patrick Rudolph Cc: Christian Walter Cc: Hao A Wu Cc: Jian J Wang Cc: Ray Ni --- MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeMod= ulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c index 6c68a97d4e46..7420f0079f7d 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c @@ -2530,10 +2530,12 @@ PciEnumeratorLight ( // RemoveRejectedPciDevices (RootBridgeDev->Handle, RootBridgeDev); =20 - // - // Process option rom light - // - ProcessOptionRomLight (RootBridgeDev); + if (!PcdGetBool (PcdPciDisableBusEnumeration)) { + // + // Process option rom light + // + ProcessOptionRomLight (RootBridgeDev); + } =20 // // Determine attributes for all devices under this root bridge --=20 2.28.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#65272): https://edk2.groups.io/g/devel/message/65272 Mute This Topic: https://groups.io/mt/76863516/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 27 03:08:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+65273+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+65273+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=9elements.com ARC-Seal: i=1; a=rsa-sha256; t=1600172784; cv=none; d=zohomail.com; s=zohoarc; b=YtcYR4evf9mrwYgBUcirgx25MwcHpM4Bi+2n368zxrR9aWK0LX/ULNBSljgozQAoTKXscKFVdegng+I7uxB/toMnFvqCPHaqk50LXcWTzLvixnQeTRxS6k66uQRSs3UV7RQG44d73JPAjxWzbGZ4kuxaW3OamAQoQXIzztaVkC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600172784; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=78gQgZCIqKnG3Umq6nQbYnXKx7aQCGvgsVomagwTQB8=; b=EzOVr4C6uiTbOpN7D+nQtj0G/UQ/LcJ/wr2o7yTVtHURG0hsLB7YlJKYGSjwgtiE9vgmzIviXcK0+w1q/ZPOJylGXysXQ1NO/J1UA0ZQCiL4Pl7sLL5/Z+T/BG3nwt1d/4rhcJPd5kWAmCE6vGqJyCQz4X6cRG8Gbb5y0lVJYmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+65273+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1600172784555385.5136386133528; Tue, 15 Sep 2020 05:26:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WFEWYY1788612xadTl0uLEYD; Tue, 15 Sep 2020 05:26:24 -0700 X-Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by mx.groups.io with SMTP id smtpd.web11.12052.1600172783330556694 for ; Tue, 15 Sep 2020 05:26:23 -0700 X-Received: by mail-ed1-f66.google.com with SMTP id a12so2769207eds.13 for ; Tue, 15 Sep 2020 05:26:23 -0700 (PDT) X-Gm-Message-State: YH46CRHjxPdzLfp5txGasilOx1787277AA= X-Google-Smtp-Source: ABdhPJznPjvm+P7isUBRYprUJrAUL+LClyUgiAvSG8u6l4N98iPx9hCyX5K8um5V7UB4Qbjfry2Nuw== X-Received: by 2002:aa7:dd11:: with SMTP id i17mr21627998edv.170.1600172781406; Tue, 15 Sep 2020 05:26:21 -0700 (PDT) X-Received: from T14.n1ce.space ([2a02:908:e851:d750:5f43:5410:2022:1d7c]) by smtp.gmail.com with ESMTPSA id x25sm11217064edv.42.2020.09.15.05.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 05:26:20 -0700 (PDT) From: "Marcello Sylvester Bauer" To: devel@edk2.groups.io Cc: Patrick Rudolph , Christian Walter , Maurice Ma , Nate DeSimone , Star Zeng Subject: [edk2-devel] [PATCH v2 2/2] UefiPayloadPkg: Scan for Option ROMs Date: Tue, 15 Sep 2020 14:26:16 +0200 Message-Id: <20200915122616.17196-3-marcello.bauer@9elements.com> In-Reply-To: <20200915122616.17196-1-marcello.bauer@9elements.com> References: <20200915122616.17196-1-marcello.bauer@9elements.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,marcello.bauer@9elements.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1600172784; bh=pu2d1c5nQp6HJYAhzLNZw1QhyzT/AcaFhWWzgpE2GlY=; h=Cc:Date:From:Reply-To:Subject:To; b=p51gEODxOBGLaoBKPGmEyc0XEalJDlg0hV5APisMIRDSP/6wuiHJm3mieYG6ALWG1Q9 BMVhLuDyGRB9e5EuCoeaoqfwjfOzmBq5pzeJ60VtkzW/MoV9BHNrWKYOILzdY2dOFu5GM 6TBkr4zAwrPgnwcNkFnbA7tGw+SvtUrtZXg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Patrick Rudolph Install the gPciPlatformProtocol to scan for Option ROMs. For every device we probe the Option ROM and provide a pointer to the activated BAR if found. It's safe to assume that all ROM bars have been enumerated, reserved in the bridge resources and are disabled by default. Enabling them and leaving them enabled will do no harm. Signed-off-by: Patrick Rudolph Signed-off-by: Marcello Sylvester Bauer Cc: Patrick Rudolph Cc: Christian Walter Cc: Maurice Ma Cc: Nate DeSimone Cc: Star Zeng --- UefiPayloadPkg/UefiPayloadPkgIa32.dsc | 1 + UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 1 + UefiPayloadPkg/UefiPayloadPkg.fdf | 1 + UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf | 46 +++ UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h | 19 + UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c | 426 ++++++++++++++++++++ 6 files changed, 494 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPay= loadPkgIa32.dsc index 12d7ffe81416..9f42d2cd6b74 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -513,6 +513,7 @@ [Components.IA32] MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf !endif UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf + UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf =20 #------------------------------ # Build the shell diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/Uefi= PayloadPkgIa32X64.dsc index 9bae1daa09bb..59fc1b79457b 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -514,6 +514,7 @@ [Components.X64] MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf !endif UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf + UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf =20 #------------------------------ # Build the shell diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayload= Pkg.fdf index 570a8ee7fdc1..9b188724221d 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.fdf +++ b/UefiPayloadPkg/UefiPayloadPkg.fdf @@ -151,6 +151,7 @@ [FV.DXEFV] INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf !endif INF UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf +INF UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf =20 # # SCSI/ATA/IDE/DISK Support diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf b/UefiPayload= Pkg/PciPlatformDxe/PciPlatformDxe.inf new file mode 100644 index 000000000000..96cedad5afc3 --- /dev/null +++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf @@ -0,0 +1,46 @@ +## @file +# This driver produces gEfiPciPlatform protocol to load PCI Option ROMs +# +# Copyright (c) 2020, 9elements Agency GmbH +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PciPlatformDxe + FILE_GUID =3D 86D58F7B-6E7C-401F-BDD4-E32E6D582AAD + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D InstallPciPlatformProtocol + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources.common] + PciPlatformDxe.h + PciPlatformDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + DxeServicesTableLib + DebugLib + MemoryAllocationLib + BaseMemoryLib + DevicePathLib + UefiLib + HobLib + +[Protocols] + gEfiPciPlatformProtocolGuid ## PRODUCES + gEfiPciIoProtocolGuid ## COMSUMES diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h b/UefiPayloadPk= g/PciPlatformDxe/PciPlatformDxe.h new file mode 100644 index 000000000000..c40518c703f8 --- /dev/null +++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.h @@ -0,0 +1,19 @@ +/** @file + Header file for a PCI platform driver. + +Copyright (c) 2016, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + + +**/ +#ifndef _PCI_PLATFORM_DXE_H_ +#define _PCI_PLATFORM_DXE_H_ +#include + +#include +#include +#include +#include +#include + +#endif diff --git a/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c b/UefiPayloadPk= g/PciPlatformDxe/PciPlatformDxe.c new file mode 100644 index 000000000000..65a1ba967314 --- /dev/null +++ b/UefiPayloadPkg/PciPlatformDxe/PciPlatformDxe.c @@ -0,0 +1,426 @@ +/** @file + This driver will probe for the Option Rom and provide a pointer to + the activated BAR if found. + +Copyright (c) 2016, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + + +**/ + +#include "PciPlatformDxe.h" +#include +#include + +// +// The driver should only start on one graphics controller. +// So a global flag is used to remember that the driver is already started. +// +EFI_HANDLE mDriverHandle =3D NULL; + +/** + The notification from the PCI bus enumerator to the platform that it is + about to enter a certain phase during the enumeration process. + + @param[in] This The pointer to the EFI_PCI_PLATFORM_PROTOCOL i= nstance. + @param[in] HostBridge The handle of the host bridge controller. + @param[in] Phase The phase of the PCI bus enumeration. + @param[in] ExecPhase Defines the execution phase of the PCI chipset= driver. + + @retval EFI_SUCCESS The function completed successfully. + +**/ +EFI_STATUS +EFIAPI +PciPlatformNotify( + IN EFI_PCI_PLATFORM_PROTOCOL *This, + IN EFI_HANDLE HostBridge, + IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase, + IN EFI_PCI_EXECUTION_PHASE ExecPhase + ) +{ + return EFI_SUCCESS; +} + + +/** + The notification from the PCI bus enumerator to the platform for each PCI + controller at several predefined points during PCI controller initializa= tion. + + @param[in] This The pointer to the EFI_PCI_PLATFORM_PROTOCOL i= nstance. + @param[in] HostBridge The associated PCI host bridge handle. + @param[in] RootBridge The associated PCI root bridge handle. + @param[in] PciAddress The address of the PCI device on the PCI bus. + @param[in] Phase The phase of the PCI controller enumeration. + @param[in] ExecPhase Defines the execution phase of the PCI chipset= driver. + + @retval EFI_SUCCESS The function completed successfully. + +**/ +EFI_STATUS +EFIAPI +PciPlatformPrepController( + IN EFI_PCI_PLATFORM_PROTOCOL *This, + IN EFI_HANDLE HostBridge, + IN EFI_HANDLE RootBridge, + IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress, + IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase, + IN EFI_PCI_EXECUTION_PHASE ExecPhase + ) +{ + return EFI_SUCCESS; +} + +/** + Gets the PCI device's option ROM. + + @param[in] This The pointer to the EFI_PCI_PLATFORM_PROTOCOL ins= tance. + @param[in] PciHandle The handle of the PCI device. + @param[out] RomImage If the call succeeds, the pointer to the pointer= to the option ROM image. + Otherwise, this field is undefined. The memory f= or RomImage is allocated + by EFI_PCI_PLATFORM_PROTOCOL.GetPciRom() using t= he EFI Boot Service AllocatePool(). + It is the caller's responsibility to free the me= mory using the EFI Boot Service + FreePool(), when the caller is done with the opt= ion ROM. + @param[out] RomSize If the call succeeds, a pointer to the size of t= he option ROM size. Otherwise, + this field is undefined. + + @retval EFI_SUCCESS The option ROM was available for this dev= ice and loaded into memory. + @retval EFI_NOT_FOUND No option ROM was available for this devi= ce. + @retval EFI_OUT_OF_RESOURCES No memory was available to load the optio= n ROM. + @retval EFI_DEVICE_ERROR An error occurred in obtaining the option= ROM. + +**/ +EFI_STATUS +EFIAPI +PciGetPciRom ( + IN CONST EFI_PCI_PLATFORM_PROTOCOL *This, + IN EFI_HANDLE PciHandle, + OUT VOID **RomImage, + OUT UINTN *RomSize + ) +{ + EFI_STATUS Status; + IN EFI_PCI_IO_PROTOCOL *PciIo; + UINTN PciSegment; + UINTN PciBus; + UINTN PciDevice; + UINTN PciFunction; + UINTN RomBarIndex; + UINT32 Buffer; + UINT32 AllOnes; + PCI_IO_DEVICE *PciIoDevice; + UINT8 Indicator; + UINT16 OffsetPcir; + UINT32 RomBarOffset; + UINT32 RomBar; + BOOLEAN FirstCheck; + PCI_EXPANSION_ROM_HEADER *RomHeader; + PCI_DATA_STRUCTURE *RomPcir; + UINT64 RomImageSize; + UINT32 LegacyImageLength; + UINT8 *RomInMemory; + UINT8 CodeType; + + if (!RomImage || !RomSize) { + return EFI_INVALID_PARAMETER; + } + + *RomImage =3D NULL; + *RomSize =3D 0; + + Status =3D gBS->HandleProtocol ( + PciHandle, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: Failed to open gEfiPciIoProtocolGuid\n", __= FUNCTION__)); + + return EFI_UNSUPPORTED; + } + PciIoDevice =3D PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo); + + // + // Get the location of the PCI device + // + PciIo->GetLocation ( + PciIo, + &PciSegment, + &PciBus, + &PciDevice, + &PciFunction + ); + + DEBUG ((DEBUG_INFO, "%a: Searching Option ROM on device:\n", __FUNCTION_= _)); + DEBUG ((DEBUG_INFO, " PciSegment - %02x\n", PciSegment)); + DEBUG ((DEBUG_INFO, " PciBus - %02x\n", PciBus)); + DEBUG ((DEBUG_INFO, " PciDevice - %02x\n", PciDevice)); + DEBUG ((DEBUG_INFO, " PciFunction - %02x\n", PciFunction)); + + // + // Offset is 0x30 if is not ppb + // + RomBarIndex =3D PCI_EXPANSION_ROM_BASE; + + if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) { + // + // If is ppb, 0x38 + // + RomBarIndex =3D PCI_BRIDGE_ROMBAR; + } + + // + // Backup BAR + // + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciWidthUint32, + RomBarIndex, + 1, + &Buffer + ); + if (EFI_ERROR (Status)) { + goto CloseAndReturn; + return Status; + } + + // + // The bit0 is 0 to prevent the enabling of the Rom address decoder + // + AllOnes =3D 0xfffffffe; + + Status =3D PciIo->Pci.Write ( + PciIo, + EfiPciWidthUint32, + RomBarIndex, + 1, + &AllOnes + ); + if (EFI_ERROR (Status)) { + goto CloseAndReturn; + } + + // + // Read back + // + Status =3D PciIo->Pci.Read( + PciIo, + EfiPciWidthUint32, + RomBarIndex, + 1, + &AllOnes + ); + if (EFI_ERROR (Status)) { + goto CloseAndReturn; + } + + // + // Bits [1, 10] are reserved + // + AllOnes &=3D 0xFFFFF800; + if ((AllOnes =3D=3D 0) || (AllOnes =3D=3D 0xFFFFF800)) { + DEBUG ((DEBUG_INFO, "%a: No Option ROM found\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + + *RomSize =3D (~AllOnes) + 1; + + DEBUG ((DEBUG_INFO, "%a: Option ROM with size %d\n", __FUNCTION__, *RomS= ize)); + + // + // Restore BAR and enable it + // + Buffer |=3D 1; + Status =3D PciIo->Pci.Write ( + PciIo, + EfiPciWidthUint32, + RomBarIndex, + 1, + &Buffer + ); + if (EFI_ERROR (Status)) { + goto CloseAndReturn; + } + + // + // Allocate memory for Rom header and PCIR + // + RomHeader =3D AllocatePool (sizeof (PCI_EXPANSION_ROM_HEADER)); + if (RomHeader =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto CloseAndReturn; + } + + RomPcir =3D AllocatePool (sizeof (PCI_DATA_STRUCTURE)); + if (RomPcir =3D=3D NULL) { + FreePool (RomHeader); + Status =3D EFI_OUT_OF_RESOURCES; + goto CloseAndReturn; + } + + // FIXME: Use gEfiPciRootBridgeIoProtocolGuid + RomBar =3D (UINT32) Buffer &~1; + + RomBarOffset =3D RomBar; + FirstCheck =3D TRUE; + LegacyImageLength =3D 0; + RomImageSize =3D 0; + + do { + // FIXME: Use gEfiPciRootBridgeIoProtocolGuid + CopyMem(RomHeader, (VOID *)(UINTN)RomBarOffset, sizeof (PCI_EXPANSION_= ROM_HEADER)); + + DEBUG ((DEBUG_INFO, "%a: RomHeader->Signature %x\n", __FUNCTION__, Rom= Header->Signature)); + + if (RomHeader->Signature !=3D PCI_EXPANSION_ROM_HEADER_SIGNATURE) { + + RomBarOffset =3D RomBarOffset + 512; + if (FirstCheck) { + break; + } else { + RomImageSize =3D RomImageSize + 512; + continue; + } + } + + FirstCheck =3D FALSE; + OffsetPcir =3D RomHeader->PcirOffset; + // + // If the pointer to the PCI Data Structure is invalid, no further ima= ges can be located. + // The PCI Data Structure must be DWORD aligned. + // + if (OffsetPcir =3D=3D 0 || + (OffsetPcir & 3) !=3D 0 || + RomImageSize + OffsetPcir + sizeof (PCI_DATA_STRUCTURE) > *RomSize= ) { + break; + } + // FIXME: Use gEfiPciRootBridgeIoProtocolGuid + CopyMem(RomPcir, (VOID *)(UINTN)RomBarOffset + OffsetPcir, sizeof (PCI= _DATA_STRUCTURE)); + + DEBUG ((DEBUG_INFO, "%a: RomPcir->Signature %x\n", __FUNCTION__, RomPc= ir->Signature)); + + // + // If a valid signature is not present in the PCI Data Structure, no f= urther images can be located. + // + if (RomPcir->Signature !=3D PCI_DATA_STRUCTURE_SIGNATURE) { + break; + } + if (RomImageSize + RomPcir->ImageLength * 512 > *RomSize) { + break; + } + if (RomPcir->CodeType =3D=3D PCI_CODE_TYPE_PCAT_IMAGE) { + CodeType =3D PCI_CODE_TYPE_PCAT_IMAGE; + LegacyImageLength =3D ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)R= omHeader)->Size512) * 512; + } + Indicator =3D RomPcir->Indicator; + RomImageSize =3D RomImageSize + RomPcir->ImageLength * 512; + RomBarOffset =3D RomBarOffset + RomPcir->ImageLength * 512; + } while (((Indicator & 0x80) =3D=3D 0x00) && ((RomBarOffset - RomBar) < = *RomSize)); + + // + // Some Legacy Cards do not report the correct ImageLength so used the m= aximum + // of the legacy length and the PCIR Image Length + // + if (CodeType =3D=3D PCI_CODE_TYPE_PCAT_IMAGE) { + RomImageSize =3D MAX (RomImageSize, LegacyImageLength); + } + + if (RomImageSize > 0) { + // FIXME: Use gEfiPciRootBridgeIoProtocolGuid + RomInMemory =3D (VOID *)(UINTN)RomBar; + } + + // + // Free allocated memory + // + FreePool (RomHeader); + FreePool (RomPcir); + + if (RomImageSize > 0) { + *RomImage =3D RomInMemory; + *RomSize =3D RomImageSize; + DEBUG ((DEBUG_INFO, "%a: Found Option ROM at %p, length 0x%x\n", __FUN= CTION__, + RomInMemory, RomImageSize)); + + Status =3D EFI_SUCCESS; + } else { + Status =3D EFI_NOT_FOUND; + } + +CloseAndReturn: + // + // Close the I/O Abstraction(s) used to perform the supported test + // + gBS->CloseProtocol ( + PciHandle, + &gEfiPciIoProtocolGuid, + PciIo, + PciHandle + ); + + return Status; +} + +/** + Retrieves the platform policy regarding enumeration. + + The GetPlatformPolicy() function retrieves the platform policy regarding= PCI + enumeration. The PCI bus driver and the PCI Host Bridge Resource Allocat= ion Protocol + driver can call this member function to retrieve the policy. + + @param[in] This The pointer to the EFI_PCI_PLATFORM_PROTOCOL ins= tance. + @param[out] PciPolicy The platform policy with respect to VGA and ISA = aliasing. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER PciPolicy is NULL. + +**/ +EFI_STATUS +EFIAPI +PciGetPlatformPolicy ( + IN CONST EFI_PCI_PLATFORM_PROTOCOL *This, + OUT EFI_PCI_PLATFORM_POLICY *PciPolicy + ) +{ + if (PciPolicy =3D=3D NULL) + return EFI_INVALID_PARAMETER; + + *PciPolicy =3D 0; + + return EFI_SUCCESS; +} + +EFI_PCI_PLATFORM_PROTOCOL mPciPlatformProtocol =3D { + PciPlatformNotify, + PciPlatformPrepController, + PciGetPlatformPolicy, + PciGetPciRom, +}; + +/** + The Entry Point for Option ROM driver. + + It installs DriverBinding. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry po= int. + +**/ +EFI_STATUS +EFIAPI +InstallPciPlatformProtocol ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D gBS->InstallProtocolInterface ( + &mDriverHandle, + &gEfiPciPlatformProtocolGuid, + EFI_NATIVE_INTERFACE, + &mPciPlatformProtocol + ); + + return Status; +} --=20 2.28.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#65273): https://edk2.groups.io/g/devel/message/65273 Mute This Topic: https://groups.io/mt/76863517/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-