From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.124]) by mx.groups.io with SMTP id smtpd.web10.9924.1631721607033104649 for ; Wed, 15 Sep 2021 09:00:07 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=A7RzMYE4; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.124, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kFPChMh9/VVAutEBg5L6oP9JEJZKjlssiIm7OLw1EP+sf9WAqNPCdIW985eqzcW5VBbZ3e7OUTXURN6KVYFZvSCUN1qHllg4c4YSm9V40FaO7aCEZCvoNFrvBxMARxMU86mVe5VjZ/G9SxOHy5EfkcPEp/UCdygnBo/IgdGRADAHrjkX5mXzkF27i2ONuCcM9spSxRR5QRKWscrHlqwL6KkVNWxouDS84ag88XzW+BxDtfcWfv9/SfCbbMItRSOjZiqp+ggVh/pqrmgiwz6JXc8CWc9bJybKPGFz3M+DRHRnHQgZuJXmtI3BqPmW7dui1NFy0Kre9VIGMQcLE1Rh7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=TciqjOgEvIzFCV/C2wDBwP+5HYvmp9ZWN2+DrDO2F90=; b=Brb5phWc1A/tcaTP44bRCcNmN88Fb5TgTPaoGQW1sDcj9VIUDaCXeGXfNjtnsE//rNR+u7SKT7NVy6IJ4NNBBlhStT2t7Zu8J0UghXFY4SHwMXMrzxpv3/O4EGfcIK1TgL6LDsDdx9DuFpzY9AfSioxmMrnklMXxjF5O3GwSxG3zEfPZ+0BNMK9+kic8GYbE4PTZwAIU/byvWdag9D9IO1AQes58oqRr9ZDZAKqDl/s8wmKuxDbgwhJaPSN6nBShxG/pqNHz2G2bdsB8edy6LA7WkCY4S0OUUegQDeLMTFUNnn7M36Cwni9XIQcJKfNTlpUp17KlRPiYIC1K4S3Ysw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TciqjOgEvIzFCV/C2wDBwP+5HYvmp9ZWN2+DrDO2F90=; b=A7RzMYE4WqzKtx13Hy2PBeMbxf8viaSf/52lSSRrxhteFp53KhkEfKd/8APv4isTQsNC+5dY0Nck+11LASG2vJ3LsoTDv2aR1L9dTLY/jaQtWpGiUQ30hsEeyUVWVBQ9tszWOkinYzW0GImMK0X48gMWFhpcrQpPNIhST4LGvqI= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR0101MB3065.prod.exchangelabs.com (2603:10b6:4:33::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.15; Wed, 15 Sep 2021 16:00:04 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3%4]) with mapi id 15.20.4523.014; Wed, 15 Sep 2021 16:00:04 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: patches@amperecomputing.com, nhi@os.amperecomputing.com, vunguyen@os.amperecomputing.com, Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [PATCH v3 14/28] Ampere: PCIe: Add PciHostBridgeLib library instance Date: Wed, 15 Sep 2021 22:55:13 +0700 Message-ID: <20210915155527.8176-15-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210915155527.8176-1-nhi@os.amperecomputing.com> References: <20210915155527.8176-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: HK2PR0302CA0012.apcprd03.prod.outlook.com (2603:1096:202::22) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from sw004.amperecomputing.com (118.69.219.201) by HK2PR0302CA0012.apcprd03.prod.outlook.com (2603:1096:202::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.5 via Frontend Transport; Wed, 15 Sep 2021 16:00:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5b9ebb6-b2bd-485b-83da-08d97861e152 X-MS-TrafficTypeDiagnostic: DM5PR0101MB3065: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:605; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WgYqrbOdaUk6BVJonLIPntirJANzpD4jyreVQ+g7AQkcLfQF8koXF0zQD0aR8S5YcnCG8ujAeOBaa1kVJmcrnWgDgK4wzb0kLmRXhHJg93B6GKU5B2Y4PNwx+rSwdaVumRGS4BsURlNf5jLhQy6AqcF/bSv1eWonK8Wza4H5XRmK1OdcO9akNF/FSgMdvqWoTXP3o/tDxX/HEeostAUAgG410umzhA5WhB1P1hSGqq5Qxzy7EqXHskgTt0Gg7he75H5i7XxPDxUu20M/RC76d7ygzUppYU83Uk9T9JQwimJZgOARE++K1yNZ2NUa+BC9Zv+9dFt7Z5C29WpEj+3WyUzVVRBShO6ihGMkbgGNOHbPBAQSN06bhyV2ZJkudBVAOD2pS6yNvOQBSH0+cnfK8dF8L8AOAxGO3NrrA1mZ9fGa1zXU1XrsdUpBZuZ3Ej4ODUpkB4VUbEV7FAOcJhPBvNFhYtuNKav3EeaYKedQzx+jcmNsTA93Ts95Eu7EsDnhp+SPfMccYsXXVxYwjPfUSyp+5GTlOcWHtKfCcklGFIwFeV5mcWt9tAdTldmwYWFvhGl60ZdQ5Nj76PgRIXr68rQuO5cLA1EHl92RHkt92yGs6VN4WsQUWIaKUlXQjXeQDfgpO3pLG1HU7nvVxPMk1J6qGbY9ZAixXuBgfAVrQ4ES+k2kKdedoD5ehDrTrAF5J2quptSwWBxscHcEOBD9eg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(396003)(366004)(376002)(39850400004)(2616005)(38100700002)(38350700002)(2906002)(6666004)(6916009)(83380400001)(30864003)(6512007)(26005)(8676002)(4326008)(186003)(19627235002)(8936002)(478600001)(6506007)(5660300002)(52116002)(1076003)(86362001)(316002)(66556008)(54906003)(956004)(6486002)(66476007)(66946007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?YKLx9tzqpXkZcfj13wEsuDXmSTzIJnyIwLCIbpB29NbiIOPM8E/GmaWuRq24?= =?us-ascii?Q?Ta7xXWF5auec1h7gb+QdMtsB1bzib7m6fdOtdxvBcCcMiTBtuInUxw55yEkh?= =?us-ascii?Q?yNAoTbXBegPSJf8E5Fda3sUMtdlldL37csor68epNK9oSsaudx/nzDwXXOcl?= =?us-ascii?Q?tU+gksiS5lOr8cI1JCHcu/NLkIChVEUfK7J8C1GppmzoAlJDw5+rEre7H3u0?= =?us-ascii?Q?Gewsueszjm4Wc29a9ZF6HIzlmMJFAuMQfz4GOhignV+4zTnjlE0HjAfLzYfc?= =?us-ascii?Q?QZU9erAxre7W/daIBxEr8ydEMuVue1QXfSzYp4pOkCz33agyfynH9dIb3Yl9?= =?us-ascii?Q?M3IzF75hfwVPCE87eGFqXBanS0Chh2qd7pylnNFYsSyxN3f34AMbWVzwCpgS?= =?us-ascii?Q?ASclfCObZw5jHYpMFoEcy3zcRM/0N2yWv+wAB9VA3sOUtcVzODwVXx5pjAye?= =?us-ascii?Q?nikkxOsj5h4U9JlRNfwAJoxyFUDLZpgKso4w/mw3AUuv3tA7TdUaLbUJIIr1?= =?us-ascii?Q?MWuFHqdXQE81MBW9gxryDLVnaqve44G2sDCFDiPGh1uWFEaqgwMzYjt2skXH?= =?us-ascii?Q?zlSbIFgoWz8v6JbiaKIWGPZ6g8XEmP3dJMJo/XhHUIZPkuHtrwVMzXZaasHC?= =?us-ascii?Q?quIHkxyL5MiLjkKNzyZu+dmMdnHVXfqyES072KHyicFKBDJsAFr4moOtybPn?= =?us-ascii?Q?b6Ay8YN9N5vfJA7Da346NhifKKyD2HHxx5wbJRubYaD5qMZrSuOg1upG1rl6?= =?us-ascii?Q?Vj38o1naMiYIQ+PD+TQ3OswNoVacAeA/cTlrvujwFrHlBK8RW8X079uQnPWE?= =?us-ascii?Q?gFpSlhvQ4DFrPbgFj+qlqdYcs5QN0byX+3VXgTh3fUor+RFEMmhJBGYndLPF?= =?us-ascii?Q?KI7+fi2VurlFcI9HyExLECHUMXddKFqTq6qKSU5tvvaUTlUZUwvXwGskWdJk?= =?us-ascii?Q?Dt7+T17jBAH0W2/adO0OynAR8wtgskrEIv8NwsGqqFKRRgTxu/ZFuldfpLxv?= =?us-ascii?Q?z2mIxhtfCuGK++mHTyKX82zN/Esw87OJnW8dpXHq6Dzop+13qzclVq6ptp1u?= =?us-ascii?Q?XJI4l5mTEl+T9cm20N+KheQ6/j+LqlN+tuqt8gou6xnaTAXwgqUQt+pWNyzm?= =?us-ascii?Q?p90OLIDZX2Ob81TwDxIvK9JGG/Kp3ZhRfyW4PKhJLuFgEYn2wReAcI7g7D3m?= =?us-ascii?Q?MJ4YQ8No7gBNg3Za2w8F+AtHGEFeCjYT0TzPAMsAt6mMYnLJGU/ZOGpx2smo?= =?us-ascii?Q?iiWdQrceuh/Ki3BeaZn59++EJCqJtTZJ0GH/9ydGpIYrr40Ss+zsMhgMJcSO?= =?us-ascii?Q?XLX5hjq0tRV9NgB9pUwODavu?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5b9ebb6-b2bd-485b-83da-08d97861e152 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2021 16:00:04.1475 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2ms6z+Y7iI1v4WtUNJPR9ENVErRmSe74/LsgMX2zPuIrd6gBzWrTVf17p93SuCHuzsedMani7xYd5C3B949FXqsbhyHnDkDXCZFqtDfcsX8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0101MB3065 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Vu Nguyen Provides the number of supported RootBridges and the resource allocated for each RootBridge. These information are essential to the HostBridge driver to initialize the PCIe subsystem. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Vu Nguyen --- Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc = | 1 + Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHostBridgeLib.in= f | 48 +++ Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c = | 378 ++++++++++++++++++++ 3 files changed, 427 insertions(+) diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon= /Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc index d4e1b84c0276..dc66b711aba8 100644 --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc @@ -228,6 +228,7 @@ [LibraryClasses.common.DXE_DRIVER] PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.= inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf FlashLib|Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf + PciHostBridgeLib|Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/= PciHostBridgeLib.inf =20 [LibraryClasses.common.UEFI_APPLICATION] UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCust= omDecompressLib.inf diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHost= BridgeLib.inf b/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciH= ostBridgeLib.inf new file mode 100644 index 000000000000..a8ee0c2b9278 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHostBridgeL= ib.inf @@ -0,0 +1,48 @@ +## @file +# +# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D PciHostBridgeLib + FILE_GUID =3D 9D0522E5-B5FD-4E3F-9D10-52AE221FA314 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PciHostBridgeLib|DXE_DRIVER + CONSTRUCTOR =3D HostBridgeConstructor + +[Sources] + PciHostBridgeLib.c + +[Packages] + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + Ac01PcieLib + AcpiLib + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + IoLib + MemoryAllocationLib + PrintLib + UefiBootServicesTableLib + +[Guids] + gEfiEventReadyToBootGuid + +[Protocols] + gEfiCpuIo2ProtocolGuid ## CONSUMES + +[Depex] + gEfiCpuIo2ProtocolGuid diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHost= BridgeLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHos= tBridgeLib.c new file mode 100644 index 000000000000..281f20b4bb63 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Library/PciHostBridgeLib/PciHostBridgeL= ib.c @@ -0,0 +1,378 @@ +/** @file + PCI Host Bridge Library instance for Ampere Altra-based platforms. + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +GLOBAL_REMOVE_IF_UNREFERENCED +STATIC CHAR16 CONST * CONST mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D= { + L"Mem", L"I/O", L"Bus" +}; + +#pragma pack(1) +typedef struct { + ACPI_HID_DEVICE_PATH AcpiDevicePath; + EFI_DEVICE_PATH_PROTOCOL EndDevicePath; +} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH; +#pragma pack () + +STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath =3D { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCIe + 0 + }, { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } +}; + +STATIC PCI_ROOT_BRIDGE mRootBridgeTemplate =3D { + 0, // Segment + 0, // Supports + 0, // Attributes + TRUE, // DmaAbove4G + FALSE, // NoExtendedConfigSpace + FALSE, // ResourceAssigned + EFI_PCI_HOST_BRIDGE_MEM64_DECODE, + { + // Bus + 0, + 0 + }, { + // Io + 0, + 0, + 0 + }, { + // Mem + MAX_UINT64, + 0, + 0 + }, { + // MemAbove4G + MAX_UINT64, + 0, + 0 + }, { + // PMem + MAX_UINT64, + 0, + 0 + }, { + // PMemAbove4G + MAX_UINT64, + 0, + 0 + }, + (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath +}; + +UINT8 mRootBridgeCount =3D 0; +PCI_ROOT_BRIDGE *mRootBridges =3D NULL; + +EFI_STATUS +UpdateStatusMethodObject ( + EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, + EFI_ACPI_HANDLE TableHandle, + CHAR8 *AsciiObjectPath, + CHAR8 ReturnValue + ) +{ + EFI_STATUS Status; + EFI_ACPI_HANDLE ObjectHandle; + EFI_ACPI_DATA_TYPE DataType; + CHAR8 *Buffer; + UINTN DataSize; + + Status =3D AcpiSdtProtocol->FindPath (TableHandle, AsciiObjectPath, &Obj= ectHandle); + if (EFI_ERROR (Status) || ObjectHandle =3D=3D NULL) { + return EFI_SUCCESS; + } + ASSERT (ObjectHandle !=3D NULL); + + Status =3D AcpiSdtProtocol->GetOption (ObjectHandle, 2, &DataType, (VOID= *)&Buffer, &DataSize); + if (!EFI_ERROR (Status) && Buffer[2] =3D=3D AML_BYTE_PREFIX) { + // + // Only patch when the initial value is byte object. + // + Buffer[3] =3D ReturnValue; + } + + AcpiSdtProtocol->Close (ObjectHandle); + return Status; +} + +/** + This function will be called when ReadyToBoot event is signaled. + + @param Event signaled event + @param Context calling context + + @retval VOID +**/ +VOID +EFIAPI +PciHostBridgeReadyToBootEvent ( + EFI_EVENT Event, + VOID *Context + ) +{ + EFI_STATUS Status; + EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINTN TableKey; + UINTN TableIndex; + EFI_ACPI_HANDLE TableHandle; + CHAR8 NodePath[256]; + UINTN Count; + UINTN Idx1; + UINTN Idx2; + + Count =3D 0; + + Status =3D gBS->LocateProtocol ( + &gEfiAcpiSdtProtocolGuid, + NULL, + (VOID **)&AcpiSdtProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to locate ACPI table protocol\n")); + return; + } + + TableIndex =3D 0; + Status =3D AcpiLocateTableBySignature ( + AcpiSdtProtocol, + EFI_ACPI_6_3_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATUR= E, + &TableIndex, + &Table, + &TableKey + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %d Status =3D %r \n", __FUNCTION__, __LINE__,= Status)); + ASSERT_EFI_ERROR (Status); + return; + } + + Status =3D AcpiSdtProtocol->OpenSdt (TableKey, &TableHandle); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + AcpiSdtProtocol->Close (TableHandle); + return; + } + + for (Idx1 =3D 0; Idx1 < Ac01PcieGetTotalHBs (); Idx1++) { + for (Idx2 =3D 0; Idx2 < Ac01PcieGetTotalRBsPerHB (Idx1); Idx2++) { + AsciiSPrint (NodePath, sizeof (NodePath), "\\_SB.PCI%X._STA", Count)= ; + if (Ac01PcieCheckRootBridgeDisabled (Idx1, Idx2)) { + UpdateStatusMethodObject (AcpiSdtProtocol, TableHandle, NodePath, = 0x0); + } else { + UpdateStatusMethodObject (AcpiSdtProtocol, TableHandle, NodePath, = 0xf); + } + Count++; + } + } + + AcpiSdtProtocol->Close (TableHandle); + AcpiUpdateChecksum ((UINT8 *)Table, Table->Length); + + // + // Close the event, so it will not be signalled again. + // + gBS->CloseEvent (Event); +} + +EFI_STATUS +HostBridgeConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINT8 Index; + EFI_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath; + EFI_EVENT EvtReadyToBoot; + + mRootBridges =3D AllocatePool (Ac01PcieGetTotalHBs () * sizeof (PCI_ROOT= _BRIDGE)); + if (mRootBridges =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D Ac01PcieSetup (); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < Ac01PcieGetTotalHBs (); Index++) { + CopyMem (&mRootBridges[mRootBridgeCount], &mRootBridgeTemplate, sizeof= (PCI_ROOT_BRIDGE)); + + Status =3D Ac01PcieSetupRootBridge (Index, 0, (VOID *)&mRootBridges[mR= ootBridgeCount]); + if (EFI_ERROR (Status)) { + continue; + } + mRootBridges[mRootBridgeCount].Segment =3D Ac01PcieGetRootBridgeSegmen= tNumber (Index, 0); + + DevicePath =3D AllocateCopyPool ( + sizeof (EFI_PCI_ROOT_BRIDGE_DEVICE_PATH), + (VOID *)&mEfiPciRootBridgeDevicePath + ); + if (DevicePath =3D=3D NULL) { + continue; + } + + // + // Embedded RC Index to the DevicePath + // This will be used later by the platform NotifyPhase() + // + DevicePath->AcpiDevicePath.UID =3D Index; + + mRootBridges[mRootBridgeCount].DevicePath =3D (EFI_DEVICE_PATH_PROTOCO= L *)DevicePath; + mRootBridgeCount++; + } + + Ac01PcieEnd (); + + // + // Register event to fixup ACPI table + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, // Type, + TPL_NOTIFY, // NotifyTpl + PciHostBridgeReadyToBootEvent, // NotifyFunction + NULL, // NotifyContext + &gEfiEventReadyToBootGuid, // EventGroup + &EvtReadyToBoot // Event + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + Return all the root bridge instances in an array. + + @param Count Return the count of root bridge instances. + + @return All the root bridge instances in an array. + The array should be passed into PciHostBridgeFreeRootBridges() + when it's not used. +**/ +PCI_ROOT_BRIDGE * +EFIAPI +PciHostBridgeGetRootBridges ( + UINTN *Count + ) +{ + *Count =3D mRootBridgeCount; + return mRootBridges; +} + +/** + Free the root bridge instances array returned from PciHostBridgeGetRootB= ridges(). + + @param Bridges The root bridge instances array. + @param Count The count of the array. +**/ +VOID +EFIAPI +PciHostBridgeFreeRootBridges ( + PCI_ROOT_BRIDGE *Bridges, + UINTN Count + ) +{ + // + // Unsupported + // +} + +/** + Inform the platform that the resource conflict happens. + + @param HostBridgeHandle Handle of the Host Bridge. + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the reso= urces + for all the root bridges. The resource for each = root + bridge is terminated with END descriptor and an + additional END is appended indicating the end of= the + entire resources. The resource descriptor field + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL + .SubmitResources(). +**/ +VOID +EFIAPI +PciHostBridgeResourceConflict ( + EFI_HANDLE HostBridgeHandle, + VOID *Configuration + ) +{ + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + UINTN RootBridgeIndex; + DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); + + RootBridgeIndex =3D 0; + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Configuration; + while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) { + DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); + for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) { + ASSERT (Descriptor->ResType < + (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) / + sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0]) + ) + ); + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", + mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ], + Descriptor->AddrLen, Descriptor->AddrRangeMax + )); + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n", + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag= , + ((Descriptor->SpecificFlag & + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE + ) !=3D 0) ? L" (Prefetchable)" : L"" + )); + } + } + // + // Skip the END descriptor for root bridge + // + ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR); + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( + (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 + ); + } +} --=20 2.17.1