From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 215FAAC0A2F for ; Fri, 17 May 2024 03:49:49 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=pXHeZoEP0FK2c00YBJBxmCO0da7dBHdqFAels/bnYBs=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1715917788; v=1; b=PKEIYjjLBAGUZ1qzXPpvs0XD9HO/c9XJAgXa2LKfNuGVKevwPmIDyueilBtxzX8zCC047h2a 49NU3EunWbM4d2Upn0pGxOJy701oofIae7h+46XuOsdLWS4L8wIfbehLGvnBCbmRLjc1TikiFgW Mbpq3/pQIJtQPhOCWXPzy8ccDoieeeAY/FzWW/aCpgzOZo+aAgsq2nQ9LI+Icqn2SZ+3wtJBbEB YMpCcYvg/s7CMHEOZFaMNODXsduq1xctqeTzfcrgF7ZIdrfmTX3HG7xiYJGJNeMhgOvK1FP9rzc 0vq1SEwA3LIYk3dasjmVC6HMOBFUAET/STCN2MrzR/0sw== X-Received: by 127.0.0.2 with SMTP id OJwCYY7687511xuU91hA8JQL; Thu, 16 May 2024 20:49:48 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.43]) by mx.groups.io with SMTP id smtpd.web10.32153.1715917787502216312 for ; Thu, 16 May 2024 20:49:47 -0700 X-Received: from BYAPR01CA0008.prod.exchangelabs.com (2603:10b6:a02:80::21) by DS7PR12MB8291.namprd12.prod.outlook.com (2603:10b6:8:e6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Fri, 17 May 2024 03:49:44 +0000 X-Received: from CO1PEPF000044F0.namprd05.prod.outlook.com (2603:10b6:a02:80:cafe::4d) by BYAPR01CA0008.outlook.office365.com (2603:10b6:a02:80::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Fri, 17 May 2024 03:49:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F0.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Fri, 17 May 2024 03:49:43 +0000 X-Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 16 May 2024 22:49:42 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 16 May 2024 22:49:41 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Thu, 16 May 2024 22:49:40 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Abner Chang , Paul Grimes Subject: [edk2-devel] [PATCH 4/5] AmdMinBoardPkg: Implement BoardInitLib for DXE phase Date: Fri, 17 May 2024 09:19:12 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F0:EE_|DS7PR12MB8291:EE_ X-MS-Office365-Filtering-Correlation-Id: 345d3ca8-8810-405c-2bf7-08dc7624631f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mjZyS9a6spGn4DkbOIM3Tqvoxxaf1gM/RRDOXhyeiZwPpicgvFUGe1bjkBWX?= =?us-ascii?Q?PifRI9D+gMA6ivuR1lgSoTjQK9APbDkBMsfV19o0KVr1+e4SU6GrDOO7ETRL?= =?us-ascii?Q?1I/3FJtCdpt7ll49DX+P834xMVvPADvTpYK/MdttZ48p2Y9kYH6K6NStj2Ub?= =?us-ascii?Q?pMZ5VcBM8KOlaRalolX1M4XaWSuGij2Q+aq+gsMIwLNUuKmfuMMoEBH1EWO6?= =?us-ascii?Q?dp+PXfZabGOmzyhFQOLRiuRpliFpe/2UX6U2/nMVV29ecYPsOba0dZtuO8zh?= =?us-ascii?Q?SwSo0ftS44ntD5J5qN/JSwoBiEKzNBIlcWYLvI3NLwvoNNkn5XOuKD9q+LJ8?= =?us-ascii?Q?EI2kllta+iufpyUXfumv59idK/wyYfIlrDQXvDMSyDbH9iAMWyA/DF3IhJHb?= =?us-ascii?Q?xDqsmb0BHd/eH+F/1i75VBZn4GcBED0JHUfIiELuJ6J4rx1D0t3YdUFYbsZ8?= =?us-ascii?Q?UU0sBiB5OF/RNhpKCRRERmeNFIAmqUhe0+fuyNeZXKqmVgkEmFBylAJZkPXj?= =?us-ascii?Q?BX86xF7sjVIEmfib+LAqX7Ko6W90YtQlP66DF7ih5g2ySY5EKPbtz1qHusqP?= =?us-ascii?Q?x6ndnzxrSrwQLLA7ap+pqoBl0LtP2uwkRxcIqELxglJ4B9zagtTDsMDMVyRj?= =?us-ascii?Q?rL/EwYjKXLPUAT/xlEGeW5CXH/9Xyt7t5tXNX5uhcntezEE1hjJ01idzcGau?= =?us-ascii?Q?ZMVavd7y0DsEPlinCk9ivX6/iR5YcV0mKE3HlxZTpRGpvQ+uUEDabtZom477?= =?us-ascii?Q?nDzn00L3uScnw3JveNtBCp4G0osOSux6NfIXGnxN5sBrAEgA2vO5vjVjdR76?= =?us-ascii?Q?3b+mjYwcfb/vGVU9kX43UxMH09B1x91DylY9J4gJbh/znOX1TkYQsQOdiwfl?= =?us-ascii?Q?CuwuK3xtrIhrYM6vNNv47KcnBQPWJSHVLUKW+Xcdqe/rFiIzAX9i7Atd0oku?= =?us-ascii?Q?qkuWKitUWA6VBgKyrACe0qPhK+RRH6FDJOt8zE77BOeGIBjoeSeH5a62lQ/V?= =?us-ascii?Q?GWe21tJwvieplwFyiZKlhSV3KPeSr+nQ4puDvxGNDdDqlvUUCEOZ+l3hUdea?= =?us-ascii?Q?p3sLcA71W0WdwN1hr9BsBut1t5oo5gimSMuC8g5FRhr9imnUdRZywhsSUF6g?= =?us-ascii?Q?oENQ8XwO5D4O+WejKfJWHs9OyBVwJS3LAxreqi+SVO6uqsyXFo0sXKT11JUu?= =?us-ascii?Q?EopFvq3mug5r9gb3WA6zzjfVRFdoCg633B50LsWTEIwkRec5loUEcvUF+hRr?= =?us-ascii?Q?kvKHm0yxMi7yfgaEo44lQH0smzqk8n+689XS75oxyrAzfCbk5JQ9NcYyRQLo?= =?us-ascii?Q?leX3C0Yn0dq2ilkY+PKrXx+rWbn2OpOOhOdH2oZUKPWRrFayP2HL9Kk3UgB1?= =?us-ascii?Q?GjKQdN0g8kuwtR0RO5tm0bDgeNn8?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 03:49:43.1936 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 345d3ca8-8810-405c-2bf7-08dc7624631f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8291 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 16 May 2024 20:49:47 -0700 Resent-From: AbdulLateef.Attar@amd.com Reply-To: devel@edk2.groups.io,AbdulLateef.Attar@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: TLWjkMDnVh82yv1gIitIVe71x7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=PKEIYjjL; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io DxeBoardInitLib library provides board-specific initialization functions for the DXE phase. Cc: Abner Chang Cc: Paul Grimes Signed-off-by: Abdul Lateef Attar --- .../AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc | 6 +- .../Library/DxeBoardInitLib/DxeBoardInitLib.c | 253 +++++++++++++++ .../DxeBoardInitLib/DxeBoardInitLib.inf | 51 +++ .../DxeBoardInitLib/DxeBoardInitLibInternal.c | 306 ++++++++++++++++++ .../DxeBoardInitLib/DxeBoardInitLibInternal.h | 159 +++++++++ .../DxeBoardInitLib/MadtAcpiTablePatch.c | 243 ++++++++++++++ 6 files changed, 1017 insertions(+), 1 deletion(-) create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/Dxe= BoardInitLib.c create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/Dxe= BoardInitLib.inf create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/Dxe= BoardInitLibInternal.c create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/Dxe= BoardInitLibInternal.h create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/Mad= tAcpiTablePatch.c diff --git a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc b/Platform/AMD/= AmdMinBoardPkg/AmdMinBoardPkg.dsc index 335e875f70..e0afe1e755 100644 --- a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc +++ b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc @@ -40,6 +40,9 @@ SetCacheMtrrLib|AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.i= nf BoardInitLib|AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardInitPr= eMemLib.inf =20 +[LibraryClasses.common.DXE_DRIVER] + BoardInitLib|AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLib.inf + [Components] AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf =20 @@ -49,4 +52,5 @@ AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardInitPreMemLib.inf =20 [Components.X64] - AmdMinBoardPkg/PciHotPlug/PciHotPlugInit.inf + AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLib.inf + AmdMinBoardPkg/PciHotPlug/PciHotPlugInit.inf \ No newline at end of file diff --git a/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardIn= itLib.c b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitL= ib.c new file mode 100644 index 0000000000..7c41d3e38b --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLib.c @@ -0,0 +1,253 @@ +/** @file + BoardInitLib library implementation for DXE phase. + + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include "DxeBoardInitLibInternal.h" + +EFI_HANDLE mImageHandle; +EFI_SYSTEM_TABLE *mSystemTable; + +/** + This board service detects the board type. + + @retval EFI_SUCCESS The board was detected successfully. + @retval EFI_NOT_FOUND The board could not be detected. +**/ +EFI_STATUS +EFIAPI +BoardDetect ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + This board service initializes board-specific debug devices. + + @retval EFI_SUCCESS Board-specific debug initialization was successful= . + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardDebugInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + This board service detects the boot mode. + + @retval EFI_BOOT_MODE The boot mode. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_BOOT_MODE +EFIAPI +BoardBootModeDetect ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +/** + A hook for board-specific initialization prior to memory initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeMemoryInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after memory initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterMemoryInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization prior to disabling temporary RA= M. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after disabling temporary RAM. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization prior to silicon initialization= . + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after silicon initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after PCI enumeration. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterPciEnumeration ( + VOID + ) +{ + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a - ENTRY\n", __FUNCTION__)); + + Status =3D ReserveLegacyVgaIoSpace (); + DEBUG ((DEBUG_INFO, "ReserveLegacyVgaIoSpace...%r.\n", Status)); + + Status =3D ReservePcieExtendedConfigSpace (mImageHandle, mSystemTable); + DEBUG ((DEBUG_INFO, "ReservePcieExtendedConfigSpace...%r.\n", Status)); + + return Status; +} + +/** + A hook for board-specific functionality for the ReadyToBoot event. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitReadyToBoot ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D UpdateReinstallAcpiTable ( + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + (PATCH_ACPITABLE)FadtAcpiTablePatch + ); + DEBUG ((DEBUG_INFO, "Patching FADT ACPI Table ... Status =3D %r.\n", Sta= tus)); + + Status =3D UpdateReinstallAcpiTable ( + EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, + (PATCH_ACPITABLE)MadtAcpiTablePatch + ); + DEBUG ((DEBUG_INFO, "Patching MADT ACPI Table ... Status =3D %r.\n", Sta= tus)); + + UpdateReinstallAcpiTable ( + EFI_ACPI_6_5_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, + (PATCH_ACPITABLE)AcpiTableAmlUpdate + ); + + UpdateReinstallAcpiTable ( + EFI_ACPI_6_5_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, + (PATCH_ACPITABLE)AcpiTableAmlUpdate + ); + + return EFI_SUCCESS; +} + +/** + A hook for board-specific functionality for the ExitBootServices event. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitEndOfFirmware ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + The constructor function caches the PCI Express Base Address and creates= a + Set Virtual Address Map event to convert physical address to virtual add= resses. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor completed successfully. + @retval Other value The constructor did not complete successfully. + +**/ +EFI_STATUS +EFIAPI +DxeBoardInitLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + mImageHandle =3D ImageHandle; + mSystemTable =3D SystemTable; + return EFI_SUCCESS; +} diff --git a/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardIn= itLib.inf b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardIni= tLib.inf new file mode 100644 index 0000000000..919777d016 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLib.i= nf @@ -0,0 +1,51 @@ +## @file +# Implements BoardInitLib Library Class in DXE phase. +# +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D DxeBoardInitLib + FILE_GUID =3D B3C8F348-B528-4CA0-928E-3193ADEA65E6 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D BoardInitLib + CONSTRUCTOR =3D DxeBoardInitLibConstructor + +[LibraryClasses] + BaseLib + DebugLib + LocalApicLib + PcdLib + PcieConfigLib + PlatformSocLib + SortLib + +[Packages] + AmdPlatformPkg/AmdPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + DxeBoardInitLib.c + DxeBoardInitLibInternal.c + DxeBoardInitLibInternal.h + MadtAcpiTablePatch.c + +[Protocols] + gEfiAcpiSdtProtocolGuid + gEfiAcpiTableProtocolGuid + gEfiMpServiceProtocolGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId + gMinPlatformPkgTokenSpaceGuid.PcdMaxCpuSocketCount + +[DEPEX] + gEfiMpServiceProtocolGuid diff --git a/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardIn= itLibInternal.c b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBo= ardInitLibInternal.c new file mode 100644 index 0000000000..2ffc249792 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLibIn= ternal.c @@ -0,0 +1,306 @@ +/** @file + BoardInitLib library internal implementation for DXE phase. + +Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include "DxeBoardInitLibInternal.h" + +/** + A helper function to uninstall or update the ACPI table. + It searches for ACPI table for provided table signature, + if found then creates a copy of the table and calls the callbackfunction= . + + @param[in] Signature ACPI table signature + @param[in] CallbackFunction The function to call to patch the searchi= ng ACPI table. + If NULL then uninstalls the table. + + @return EFI_SUCCESS Successfully Re-install the ACPI Table + @return EFI_NOT_FOUND Table not found + @return EFI_STATUS returns non-EFI_SUCCESS value in case of = failure + +**/ +EFI_STATUS +EFIAPI +UpdateReinstallAcpiTable ( + IN UINT32 Signature, + IN PATCH_ACPITABLE CallbackFunction + ) +{ + EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol; + EFI_STATUS Status; + UINTN Index; + EFI_ACPI_SDT_HEADER *Table; + EFI_ACPI_TABLE_VERSION Version; + UINTN OriginalTableKey; + EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol; + EFI_ACPI_SDT_HEADER *NewTable; + UINTN NewTableKey; + BOOLEAN Found; + + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID = **)&AcpiTableProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Error(%r): Unable to locate ACPI Table protocol.= \n", Status)); + return Status; + } + + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **= )&AcpiSdtProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Error(%r): Unable to locate ACPI SDT protocol.\n= ", Status)); + return Status; + } + + Found =3D FALSE; + Index =3D 0; + do { + Status =3D AcpiSdtProtocol->GetAcpiTable (Index, &Table, &Version, &Or= iginalTableKey); + if (EFI_ERROR (Status)) { + goto END_OF_SEARCH; + } + + // Look for given table + if (Table->Signature =3D=3D Signature) { + if (CallbackFunction =3D=3D NULL) { + Status =3D AcpiTableProtocol->UninstallAcpiTable (AcpiTableProtoco= l, OriginalTableKey); + return Status; + } + + NewTable =3D AllocateCopyPool (Table->Length, Table); + if (NULL =3D=3D NewTable) { + Status =3D EFI_OUT_OF_RESOURCES; + DEBUG ((DEBUG_ERROR, "Error(%r): Not enough resource to allocate t= able.\n", Status)); + return Status; + } + + Status =3D CallbackFunction (NewTable); + if (!EFI_ERROR (Status)) { + // Uninstall the old table + Status =3D AcpiTableProtocol->UninstallAcpiTable (AcpiTableProtoco= l, OriginalTableKey); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Error(%r): Uninstall old table error.\n", = Status)); + FreePool (NewTable); + return Status; + } + + // Install the new table + Status =3D AcpiTableProtocol->InstallAcpiTable (AcpiTableProtocol,= NewTable, NewTable->Length, &NewTableKey); + FreePool (NewTable); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Error(%r): Failed to install new table.\n"= , Status)); + return Status; + } + + // If non SSDT table, then return status + if (Table->Signature !=3D EFI_ACPI_6_5_SECONDARY_SYSTEM_DESCRIPTIO= N_TABLE_SIGNATURE) { + return Status; + } + + // Atleast one SSDT table update is success + Found =3D TRUE; + } + + // continue to search next SSDT table. + Status =3D EFI_SUCCESS; + } + + Index++; + } while (!EFI_ERROR (Status)); + +END_OF_SEARCH: + if (!Found) { + DEBUG ((DEBUG_ERROR, "Error(%r): Unable to locate ACPI Table.\n", Stat= us)); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** + A Callback function to patch the ACPI FADT table. + Updates FADT table with AMD specific values, which + are different than MinPlatformPkg. + + @param[in, out] NewTable Pointer to ACPI FADT table + + @return EFI_SUCCESS Always return EFI_SUCCESSe + +**/ +EFI_STATUS +EFIAPI +FadtAcpiTablePatch ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ) +{ + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *NewFadt; + + NewFadt =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)NewTable; + // Patch the Table + NewFadt->PLvl2Lat =3D 0x64; + NewFadt->Pm2CntLen =3D 0; + NewFadt->XGpe0Blk.RegisterBitWidth =3D 0x40; + NewFadt->FlushSize =3D 0x400; + NewFadt->FlushStride =3D 0x10; + NewFadt->XGpe1Blk.AccessSize =3D 0x01; + + return EFI_SUCCESS; +} + +/** + A Callback function to patch the ACPI DSDT/SSDT table. + Which has ASL code that needs to be updated. + + @param[in, out] NewTable Pointer to ACPI FADT table + + @return EFI_SUCCESS If table is modified. + EFI_NOT_FOUND If table is not modified. + +**/ +EFI_STATUS +EFIAPI +AcpiTableAmlUpdate ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ) +{ + UINT64 OemTableId; + + if ((AsciiStrnCmp (NewTable->OemTableId, "AmdTable", 8) =3D=3D 0)) { + DEBUG ((DEBUG_INFO, "Found (D/S)SDT table for patching OemTableId.\n")= ); + OemTableId =3D PcdGet64 (PcdAcpiDefaultOemTableId); + CopyMem (NewTable->OemTableId, &OemTableId, 8); + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + +/** + Reserve Legacy VGA IO space. + + @retval EFI_SUCCESS MMIO at Legacy VGA region has been allocated. + @retval !EFI_SUCCESS Error allocating the legacy VGA region. + +**/ +EFI_STATUS +EFIAPI +ReserveLegacyVgaIoSpace ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS VgaMemAddress; + + VgaMemAddress =3D (EFI_PHYSICAL_ADDRESS)VGA_MEM_BASE; + Status =3D gBS->AllocatePages ( + AllocateAddress, + EfiMemoryMappedIO, + EFI_SIZE_TO_PAGES (VGA_MEM_SIZE), + &VgaMemAddress + ); + return Status; +} + +/** + Helper function to get size of MMIO region required for the Bus Range + configured. + + @param[in] BusRange Chipset representation of Bus Range + + @retval Size of MMIO required for bus range +**/ +UINT64 +DecodeMmioBusRange ( + UINT64 BusRange + ) +{ + // Minimum MMIO region required is 1MB (1 Segment - 1 Bus). + // Set Mmio Size to 1MB. + UINT64 MmioSize; + + MmioSize =3D 0x100000; + + if (BusRange > 0x0E) { + MmioSize =3D SIZE_32GB; + } else { + MmioSize =3D (MmioSize << BusRange); + } + + return MmioSize; +} + +/** + Reserve PCIe Extended Config Space MMIO in the GCD and mark it runtime + + @param[in] ImageHandle ImageHandle of the loaded driver. + @param[in] SystemTable Pointer to the EFI System Table. + + @retval EFI_SUCCESS One or more of the drivers returned a success code= . + @retval !EFI_SUCCESS Error initializing the Legacy PIC. + +**/ +EFI_STATUS +EFIAPI +ReservePcieExtendedConfigSpace ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + AMD_MMIO_CFG_MSR MmioCfgMsr; + UINT64 MmioCfgBase; + UINT64 MmioCfgSize; + + Status =3D EFI_SUCCESS; + // + // Reserve MMIO for PCI-Config space + // + MmioCfgMsr.AsUint64 =3D AsmReadMsr64 (AMD_MMIO_CFG_MSR_ADDR); + MmioCfgBase =3D MmioCfgMsr.AsUint64 & AMD_MMIO_CFG_ADDR_MASK; + MmioCfgSize =3D DecodeMmioBusRange (MmioCfgMsr.AsBits.BusRange); + DEBUG ((DEBUG_INFO, "\nMMIO_CFG MSR =3D 0x%08lX\n", MmioCfgMsr.AsUint64)= ); + DEBUG ((DEBUG_INFO, " Enable =3D %d\n", MmioCfgMsr.AsBits.Enable)); + DEBUG ((DEBUG_INFO, " BusRange =3D %d\n", MmioCfgMsr.AsBits.BusRange)); + DEBUG ((DEBUG_INFO, " MmioCfgBase =3D 0x%08lX\n", MmioCfgBase)); + DEBUG ((DEBUG_INFO, " MmioCfgSize =3D 0x%08lX\n", MmioCfgSize)); + + if (MmioCfgMsr.AsBits.Enable) { + // Free Memory if it is allocated (call will likely return Not Found) + Status =3D gDS->FreeMemorySpace ( + MmioCfgBase, + MmioCfgSize + ); + // Remove Memory Space from GCD map (could return Not Found) + Status =3D gDS->RemoveMemorySpace ( + MmioCfgBase, + MmioCfgSize + ); + // Make sure Adding memory space succeeds or assert + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeReserved, + MmioCfgBase, + MmioCfgSize, + EFI_MEMORY_RUNTIME | EFI_MEMORY_UC + ); + ASSERT_EFI_ERROR (Status); + // Make sure Allocating memory space succeed or assert + Status =3D gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypeReserved, + 0, + MmioCfgSize, + &MmioCfgBase, + ImageHandle, + NULL + ); + ASSERT_EFI_ERROR (Status); + + DEBUG (( + DEBUG_INFO, + "\nReserved PciCfg MMIO: Base =3D 0x%lX, Size =3D 0x%lX\n", + MmioCfgBase, + MmioCfgSize + )); + } + + return Status; +} diff --git a/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardIn= itLibInternal.h b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBo= ardInitLibInternal.h new file mode 100644 index 0000000000..037328a34c --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/DxeBoardInitLibIn= ternal.h @@ -0,0 +1,159 @@ +/** @file + +Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef DXE_BOARD_INIT_LIB_INTERNAL_H_ +#define DXE_BOARD_INIT_LIB_INTERNAL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Define temp buffer length for save IoApic data +#define MAX_IOAPIC_NUM 0x20 + +#define VGA_MEM_BASE 0xA0000 +#define VGA_MEM_SIZE 0x20000 + +// +// 48-bit MMIO space (MB-aligned) +// +#define AMD_MMIO_CFG_MSR_ADDR 0xC0010058UL +#define AMD_MMIO_CFG_ADDR_MASK 0xFFFFFFF00000ULL + +typedef struct { + UINT8 Type; + UINT8 Length; +} STRUCTURE_HEADER; + +#pragma pack(1) +typedef union { + struct { + // HACK-HACK: Use UINT32 to keep compiler from using SHIFT intrinsics = on NOOPT build + UINT32 Enable : 1; // [0] + UINT32 Reserved1 : 1; // [1] + UINT32 BusRange : 4; // [5:2] + UINT32 Reserved2 : 14; // [19:6] + UINT32 MmioCfgBaseAddr : 28; // [47:20] + UINT32 Reserved3 : 16; // [63:48] + } AsBits; + + UINT64 AsUint64; +} AMD_MMIO_CFG_MSR; +#pragma pack() + +/** + Reserve PCIe Extended Config Space MMIO in the GCD and mark it runtime + + @param[in] ImageHandle ImageHandle of the loaded driver. + @param[in] SystemTable Pointer to the EFI System Table. + + @retval EFI_SUCCESS One or more of the drivers returned a success code= . + @retval !EFI_SUCCESS Error initializing the Legacy PIC. +**/ +EFI_STATUS +EFIAPI +ReservePcieExtendedConfigSpace ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Prototype for callback function to patch ACPI table. + + @param[in, out] NewTable The pointer to ACPI table. + @return EFI_SUCCESS Always return EFI_SUCCESS +**/ +typedef +EFI_STATUS +(EFIAPI *PATCH_ACPITABLE)( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ); + +/** + A helper function to update and re-install ACPI table. + It search for ACPI table for provided table signature, + if found then creates a copy of the table and invokes + the call back function. + + @param[in] Signature ACPI table signature + @param[in] CallbackFunction The function to call to patch the searchi= ng ACPI table. + + @return EFI_SUCCESS Successfully Re-install the ACPI Table + @return EFI_NOT_FOUND Table not found + @return EFI_STATUS returns non-EFI_SUCCESS value in case of = failure + +**/ +EFI_STATUS +EFIAPI +UpdateReinstallAcpiTable ( + IN UINT32 Signature, + IN PATCH_ACPITABLE CallbackFunction + ); + +/** + A Callback function to patch the ACPI FADT table. + Updates FADT table with AMD specific values, which + are different than MinPlatformPkg. + + @param[in, out] NewTable Pointer to ACPI FADT table + + @return EFI_SUCCESS Always return EFI_SUCCESSe + +**/ +EFI_STATUS +EFIAPI +FadtAcpiTablePatch ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ); + +EFI_STATUS +EFIAPI +MadtAcpiTablePatch ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ); + +/** + A Callback function to patch the ACPI DSDT/SSDT table. + Which has ASL code that needs to be updated. + + @param[in, out] NewTable Pointer to ACPI FADT table + + @return EFI_SUCCESS Always return EFI_SUCCESSe + +**/ +EFI_STATUS +EFIAPI +AcpiTableAmlUpdate ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ); + +/** + Reserve Legacy VGA IO space. + + @retval EFI_SUCCESS MMIO at Legacy VGA region has been allocated. + @retval !EFI_SUCCESS Error allocating the legacy VGA region. + +**/ +EFI_STATUS +EFIAPI +ReserveLegacyVgaIoSpace ( + VOID + ); + +#endif diff --git a/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/MadtAcpiTa= blePatch.c b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/MadtAcpiTa= blePatch.c new file mode 100644 index 0000000000..aefb378981 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/DxeBoardInitLib/MadtAcpiTablePatc= h.c @@ -0,0 +1,243 @@ +/** @file + This file patches the ACPI MADT table for AMD specific values. + + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "DxeBoardInitLibInternal.h" +#include +#include +#define AMD_CPUID_EXTENDED_TOPOLOGY_V2 0x26 +#define AMD_CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_CCX 0x03 +#define AMD_CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_CCD 0x04 +#define AMD_CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE 0x05 + +UINT32 mCcdOrder[16] =3D { 0, 4, 8, 12, 2, 6, 10, 14, 3, 7, 11, 15, 1, 5,= 9, 13 }; + +/** + Callback compare function. + Compares CCD number of provided arguments. + + @param[in] LocalX2ApicLeft Pointer to Left Buffer. + @param[in] LocalX2ApicRight Pointer to Right Buffer. + @return 0 If both are same + -1 If left value is less than righ value. + 1 If left value is greater than righ value. + +**/ +INTN +EFIAPI +SortByCcd ( + CONST VOID *LocalX2ApicLeft, + CONST VOID *LocalX2ApicRight + ) +{ + CONST EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *Left; + CONST EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *Right; + EFI_CPU_PHYSICAL_LOCATION2 LeftLocation; + EFI_CPU_PHYSICAL_LOCATION2 RightLocation; + UINT32 LeftCcdIndex; + UINT32 RightCcdIndex; + UINT32 Index; + + Left =3D (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *)LocalX2ApicLe= ft; + Right =3D (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *)LocalX2ApicRi= ght; + + GetProcessorLocation2ByApicId ( + Left->X2ApicId, + &LeftLocation.Package, + &LeftLocation.Die, + &LeftLocation.Tile, + &LeftLocation.Module, + &LeftLocation.Core, + &LeftLocation.Thread + ); + + GetProcessorLocation2ByApicId ( + Right->X2ApicId, + &RightLocation.Package, + &RightLocation.Die, + &RightLocation.Tile, + &RightLocation.Module, + &RightLocation.Core, + &RightLocation.Thread + ); + + // Get the CCD Index number + LeftCcdIndex =3D MAX_UINT32; + for (Index =3D 0; Index < ARRAY_SIZE (mCcdOrder); Index++) { + if (LeftLocation.Die =3D=3D mCcdOrder[Index]) { + LeftCcdIndex =3D Index; + break; + } + } + + RightCcdIndex =3D MAX_UINT32; + for (Index =3D 0; Index < ARRAY_SIZE (mCcdOrder); Index++) { + if (RightLocation.Die =3D=3D mCcdOrder[Index]) { + RightCcdIndex =3D Index; + break; + } + } + + // Now compare for quick sort + if (LeftCcdIndex < RightCcdIndex) { + return -1; + } + + if (LeftCcdIndex > RightCcdIndex) { + return 1; + } + + return 0; +} + +/** + A Callback function to patch the ACPI MADT table. + Updates MADT table with AMD specific values, which + are different than MinPlatformPkg. + + @param[in, out] NewTable Pointer to ACPI MADT table + + @return EFI_SUCCESS Always return EFI_SUCCESSe + +**/ +EFI_STATUS +EFIAPI +MadtAcpiTablePatch ( + IN OUT EFI_ACPI_SDT_HEADER *NewTable + ) +{ + UINT32 Index; + EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *NewMadtTable; + UINT8 *TablePtr; + UINT64 Length; + EFI_ACPI_6_5_IO_APIC_STRUCTURE *NbioIoApic; + UINT8 IoApicCount; + UINTN LapicCount; + EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *LocalX2ApicPtr; + EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *SortedItem; + EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *Src; + EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE *Dst; + + // Patch the Table + NewMadtTable =3D (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTIO= N_TABLE_HEADER *)NewTable; + NewMadtTable->Header.Revision =3D 6; + // Get the IoApic information + NbioIoApic =3D NULL; + IoApicCount =3D 0; + LapicCount =3D 0; + LocalX2ApicPtr =3D NULL; + GetIoApicInfo (&NbioIoApic, &IoApicCount); + if ((NbioIoApic =3D=3D NULL) || (IoApicCount =3D=3D 0)) { + DEBUG ((DEBUG_INFO, "%a:%d Cannot obtain NBIO IOAPIC information.\n", = __FUNCTION__, __LINE__)); + return EFI_SUCCESS; + } + + // Create MADT header + TablePtr =3D (UINT8 *)NewMadtTable; + TablePtr =3D TablePtr + sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_T= ABLE_HEADER); + Length =3D sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER= ); + + // Get the IOAPIC structure + Index =3D 0; // now holds the IoApic Index + do { + if (((STRUCTURE_HEADER *)TablePtr)->Type =3D=3D EFI_ACPI_6_5_IO_APIC) = { + // Patch the IoApic Strucure + if (Index >=3D IoApicCount) { + /// Mark the extra IOAPIC structure Type as reserved, so that OSPM= can ignore it. + /// As per ACPI specification 6.5 for MADT table + /// Subtype 0x18-0x7F are reserved, OSPM skips structures of the r= eserved type. + ((EFI_ACPI_6_5_IO_APIC_STRUCTURE *)TablePtr)->Type =3D 0x7F; + } else { + ((EFI_ACPI_6_5_IO_APIC_STRUCTURE *)TablePtr)->IoApicId = =3D NbioIoApic[Index].IoApicId; + ((EFI_ACPI_6_5_IO_APIC_STRUCTURE *)TablePtr)->IoApicAddress = =3D NbioIoApic[Index].IoApicAddress; + ((EFI_ACPI_6_5_IO_APIC_STRUCTURE *)TablePtr)->GlobalSystemInterrup= tBase =3D NbioIoApic[Index].GlobalSystemInterruptBase; + } + + Index++; + } + + if (((STRUCTURE_HEADER *)TablePtr)->Type =3D=3D EFI_ACPI_6_5_INTERRUPT= _SOURCE_OVERRIDE) { + // Patch Flags + ((EFI_ACPI_6_5_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *)TablePtr)->Flag= s =3D 0xF; + } + + if (((STRUCTURE_HEADER *)TablePtr)->Type =3D=3D EFI_ACPI_6_5_LOCAL_X2A= PIC_NMI) { + // Patch Flags - Edge-triggered, Active High + ((EFI_ACPI_6_5_LOCAL_X2APIC_NMI_STRUCTURE *)TablePtr)->Flags =3D 0x0= 005; + } + + if (((STRUCTURE_HEADER *)TablePtr)->Type =3D=3D EFI_ACPI_6_5_PROCESSOR= _LOCAL_X2APIC) { + if (LapicCount =3D=3D 0) { + // Get the first entry pointer + LocalX2ApicPtr =3D (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE = *)TablePtr; + } + + LapicCount +=3D 1; + } + + Length +=3D ((STRUCTURE_HEADER *)TablePtr)->Length; + TablePtr +=3D ((STRUCTURE_HEADER *)TablePtr)->Length; + } while (Length < NewMadtTable->Header.Length); + + FreePool (NbioIoApic); + + if (LocalX2ApicPtr !=3D NULL) { + if (FixedPcdGet32 (PcdMaxCpuSocketCount) > 1) { + /// Sort by CCD location + PerformQuickSort (LocalX2ApicPtr, LapicCount/2, sizeof (EFI_ACPI_6_5= _PROCESSOR_LOCAL_X2APIC_STRUCTURE), SortByCcd); + PerformQuickSort (LocalX2ApicPtr+(LapicCount/2), LapicCount/2, sizeo= f (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_STRUCTURE), SortByCcd); + } else { + /// Sort by CCD location + PerformQuickSort (LocalX2ApicPtr, LapicCount, sizeof (EFI_ACPI_6_5_P= ROCESSOR_LOCAL_X2APIC_STRUCTURE), SortByCcd); + } + + /// Now allocate the Uid + SortedItem =3D LocalX2ApicPtr; + for (Index =3D 0; Index < LapicCount; Index++, SortedItem++) { + SortedItem->AcpiProcessorUid =3D Index; + } + + // Now separate the second thread list + SortedItem =3D LocalX2ApicPtr + 1; + if ((SortedItem->X2ApicId & 0x1) =3D=3D 0x1) { + // It has multi-thread on + SortedItem =3D NULL; + SortedItem =3D AllocateZeroPool (sizeof (EFI_ACPI_6_5_PROCESSOR_LOCA= L_X2APIC_STRUCTURE) * LapicCount); + if (SortedItem =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Src =3D LocalX2ApicPtr; + Dst =3D SortedItem; + for (Index =3D 0; Index < LapicCount; Index++) { + if ((Src->X2ApicId & 0x1) =3D=3D 0) { + CopyMem (Dst, Src, sizeof (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_S= TRUCTURE)); + Src++; + Dst++; + } else { + Src++; + } + } + + Src =3D LocalX2ApicPtr; + for (Index =3D 0; Index < LapicCount; Index++) { + if ((Src->X2ApicId & 0x1) =3D=3D 1) { + CopyMem (Dst, Src, sizeof (EFI_ACPI_6_5_PROCESSOR_LOCAL_X2APIC_S= TRUCTURE)); + Src++; + Dst++; + } else { + Src++; + } + } + + CopyMem (LocalX2ApicPtr, SortedItem, sizeof (EFI_ACPI_6_5_PROCESSOR_= LOCAL_X2APIC_STRUCTURE) * LapicCount); + FreePool (SortedItem); + } + } + + return EFI_SUCCESS; +} --=20 2.34.1 -=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 (#118977): https://edk2.groups.io/g/devel/message/118977 Mute This Topic: https://groups.io/mt/106148092/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-