From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 104D8AC11A4 for ; Thu, 28 Mar 2024 12:30:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=h125NN2hrN9WPe7vEuIp1vc/XSpIC1gOPLQkGVJoXug=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Received-SPF:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1711629023; v=1; b=hrtnCbXs0zlWN4hYOi50a8eYHzXPjkcAA/6Dd8dUEM2sede7LXyiYKKENuygpJVyCH8MfhYu /HzvhcGSNC18GIMCbGlsXnMb4v8HTtjJ4+xfnU/zT4rsH3vnIQ2tevox2rtgjsEp7Cdl+7HHosC 5iZBMqGeUpw71LkNFDVN3XhehGLPe6yjIxZO76A6S4rGUJ77kVIaHOBuvQPBYj8dqIu8iJ9w7Av iwPNWpzWvAPtp/loi9w/v7LEHHwsIiFopaWAPz4k94aCu8p/+4+5Qm5Zj9f8LjG0RM5bw4aO1+p k6riHGYPVNZM/MFJbGFp4o5G2tazCZjsc7GSiVlMx6e7g== X-Received: by 127.0.0.2 with SMTP id 8HfRYY7687511xKzKnem3B4v; Thu, 28 Mar 2024 05:30:23 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.80]) by mx.groups.io with SMTP id smtpd.web10.14587.1711629023010771984 for ; Thu, 28 Mar 2024 05:30:23 -0700 X-Received: from BL1PR13CA0081.namprd13.prod.outlook.com (2603:10b6:208:2b8::26) by SJ2PR12MB9161.namprd12.prod.outlook.com (2603:10b6:a03:566::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Thu, 28 Mar 2024 12:30:19 +0000 X-Received: from MN1PEPF0000F0DE.namprd04.prod.outlook.com (2603:10b6:208:2b8:cafe::83) by BL1PR13CA0081.outlook.office365.com (2603:10b6:208:2b8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Thu, 28 Mar 2024 12:30:19 +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 MN1PEPF0000F0DE.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 12:30:18 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) 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, 28 Mar 2024 07:30:18 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) 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 via Frontend Transport; Thu, 28 Mar 2024 07:30:17 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Sami Mujawar , Pierre Gondois Subject: [edk2-devel] [PATCH v4 5/5] DynamicTablesPkg: Adds X64 arch MADT Table generator Date: Thu, 28 Mar 2024 17:59:59 +0530 Message-ID: <7a3ea41bc3d5b6e7e7fd7b5e8f824546af014588.1711625281.git.AbdulLateef.Attar@amd.com> In-Reply-To: References: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: AbdulLateef.Attar@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DE:EE_|SJ2PR12MB9161:EE_ X-MS-Office365-Filtering-Correlation-Id: ea6b8360-86f0-4993-c81c-08dc4f22d457 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Ti1QKNMta9pTjIW3fyCf+3Ea8tzlh4yiikJTxLQ8GsEpvu8TN5YEneW5GdA55uR/sD96sNkMXqbBYnBTZVRz9xWVDVPlUEB+/OIkG0M8wiXsQpFG0X2sp53z2FJi9S4ambuiRP8wsQ15Cr9AhQtgn9A1Z+nnUD121MvY7Tk8IxCvdgPGuUan0LwthK/yTOmyS+YNwjGxPjZAWBrTsLWurjJjXtlDHPhSfc2L/aDzEd4kDwgeBOJvx3+mQoUpKv6TvMtd+j730GCGtxos3JCOl2rjserqVSSiouy4cf/9mYMHoBUju0v5qeuJGBJ9eSNgMyu7rVUcZPyN+4SdF7Ml71pxGJUf0mwAixiaLfboYVj9ApIXtY7ug7jWQaPK7MgPG7ZTLlVBJE4XeS0+kywGPKER4tt+cMCsGRPVnk8LFCZYLk5KZm+8lSBsXZ2Fd17wXU8DrU5iAqRQxCoCslqOofdyUIE5eYr7B0riQW1QPQP31pTQ1hdqeAZtEjEgBUBLzatoqWPS4cgcAiOKGKfoR/j3makz7aD1QgTSuUibMrGeFn/Z8KqgzVgk8rFxjk1M5zAZ9wtwQBjZ4Khfzahv7SU+92RlbRxx75P/QwHPM0nt0D2qUSRHVv/7dePf63x444YIRWE4eIom2KXOm+DyxLG6JEN19WJe+TkHyAGQ7NAmXlqr4SKb5d9vv3vmMhrL/WOCdVldWgigVmnTgDsKxBdqpMcHWwY+SkozAGxnmbhSVBiSPTpyEX3sM+6Pq/4b X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 12:30:18.9304 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea6b8360-86f0-4993-c81c-08dc4f22d457 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: MN1PEPF0000F0DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9161 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, 28 Mar 2024 05:30:23 -0700 Reply-To: devel@edk2.groups.io,AbdulLateef.Attar@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: XuUTnX1VPJ3NcO1A87msO8Qcx7686176AA= 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=hrtnCbXs; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Adds X64 architecture specific MADT/APIC Table generator. Register/Deregister MADT table. Adds X64 architecture namespace objects. Cc: Sami Mujawar Cc: Pierre Gondois Signed-off-by: Abdul Lateef Attar --- DynamicTablesPkg/DynamicTables.dsc.inc | 6 + .../Include/ConfigurationManagerObject.h | 1 + .../Include/X64NameSpaceObjects.h | 48 +++ .../X64/AcpiMadtLibX64/AcpiMadtLibX64.inf | 27 ++ .../Acpi/X64/AcpiMadtLibX64/MadtGenerator.c | 375 ++++++++++++++++++ 5 files changed, 457 insertions(+) create mode 100644 DynamicTablesPkg/Include/X64NameSpaceObjects.h create mode 100644 DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMa= dtLibX64.inf create mode 100644 DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/MadtGe= nerator.c diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/Dyna= micTables.dsc.inc index fc2ac5962e..19034e6f65 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -39,6 +39,11 @@ DynamicTablesPkg/Library/Acpi/AcpiSsdtHpetLib/AcpiSsdtHpetLib.inf =20 [Components.IA32, Components.X64] + # + # Generators + # + DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMadtLibX64.inf + # # Dynamic Table Factory Dxe # @@ -48,6 +53,7 @@ NULL|DynamicTablesPkg/Library/Acpi/AcpiHpetLib/AcpiHpetLib.inf NULL|DynamicTablesPkg/Library/Acpi/AcpiWsmtLib/AcpiWsmtLib.inf NULL|DynamicTablesPkg/Library/Acpi/AcpiSsdtHpetLib/AcpiSsdtHpetLib.i= nf + NULL|DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMadtLibX64= .inf } =20 [Components.ARM, Components.AARCH64] diff --git a/DynamicTablesPkg/Include/ConfigurationManagerObject.h b/Dynami= cTablesPkg/Include/ConfigurationManagerObject.h index f2cfadf3d4..31197eb019 100644 --- a/DynamicTablesPkg/Include/ConfigurationManagerObject.h +++ b/DynamicTablesPkg/Include/ConfigurationManagerObject.h @@ -110,6 +110,7 @@ typedef enum ObjectNameSpaceID { EObjNameSpaceStandard, ///< Standard Objects Namespace EObjNameSpaceArm, ///< ARM Objects Namespace EObjNameSpaceArch, ///< Arch Objects Namespace + EObjNameSpaceX64, ///< X64 Objects Namespace EObjNameSpaceOem =3D 0x8, ///< OEM Objects Namespace EObjNameSpaceMax } EOBJECT_NAMESPACE_ID; diff --git a/DynamicTablesPkg/Include/X64NameSpaceObjects.h b/DynamicTables= Pkg/Include/X64NameSpaceObjects.h new file mode 100644 index 0000000000..cd5c1ff43c --- /dev/null +++ b/DynamicTablesPkg/Include/X64NameSpaceObjects.h @@ -0,0 +1,48 @@ +/** @file + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Cm or CM - Configuration Manager + - Obj or OBJ - Object + - X64 - X64 processor architecture + **/ + +#ifndef X64_NAMESPACE_OBJECT_H_ +#define X64_NAMESPACE_OBJECT_H_ + +/** The EX64_OBJECT_ID enum describes the Object IDs + in the X64 Namespace +*/ +typedef enum X64ObjectID { + EX64ObjReserved, ///< 0 - Reserved + EX64ObjMadtLocalInterruptInfo, ///< 1 - MADT Local Interrupt = Information + EX64ObjMadtProcessorLocalApicX2ApicInfo, ///< 2 - MADT Local APIC/x2API= C Controller Information + EX64ObjMadtIoApicInfo, ///< 3 - MADT IOAPIC Informati= on + EX64ObjMadtLocalApicX2ApicNmiInfo, ///< 4 - MADT Local APIC/x2API= C NMI Information + EX64ObjMadtInterruptSourceOverrideInfo, ///< 5 - MADT Interrupt Overri= de Information + EX64ObjMax +} E_X64_OBJECT_ID; + +/** A structure that describes the + MADT Local Interrupt Information for the Platform. + + ID: EX64ObjMadtLocalInterruptInfo +*/ +typedef struct CmX64MadtLocalInterruptInfo { + UINT32 LocalApicAddress; ///< Local Interrupt Controller Address + UINT32 Flags; ///< Flags +} CM_X64_MADT_LOCAL_INTERRUPT_INFO; + +/** A structure that describes the + MADT Interrupt controller type information for the platform. + + ID: EX64ObjMadtInterruptControllerTypeInfo +*/ +typedef struct CmX64MadtInterruptControllerTypeInfo { + VOID *InterruptControllerTypeInfo; ///< Interrupt Controller Type In= formation + UINTN Size; ///< Size of the Interrupt Contro= ller Type Information +} CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO; +#endif diff --git a/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMadtLibX6= 4.inf b/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMadtLibX64.inf new file mode 100644 index 0000000000..4d59e9023c --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/AcpiMadtLibX64.inf @@ -0,0 +1,27 @@ +## @file +# MADT Acpi table generator +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D AcpiMadtLibX64 + FILE_GUID =3D BF8A63EC-21B9-4531-9866-F3F1593282EC + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D NULL|DXE_DRIVER + CONSTRUCTOR =3D AcpiMadtLibX64Constructor + DESTRUCTOR =3D AcpiMadtLibX64Destructor + +[Sources] + MadtGenerator.c + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + + diff --git a/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/MadtGenerator= .c b/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/MadtGenerator.c new file mode 100644 index 0000000000..8cfed66c8f --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLibX64/MadtGenerator.c @@ -0,0 +1,375 @@ +/** @file + This library provides the implementation of the ACPI Multiple APIC Descr= iption Table (MADT) + for X64 architecture. + + Copyright (c) 2017 - 2023, Arm Limited. All rights reserved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** The Creator ID for the ACPI tables generated using + the standard ACPI table generators. +*/ +#define TABLE_GENERATOR_CREATOR_ID_GENERIC SIGNATURE_32('D', 'Y', 'N', 'T= ') + +/// MACRO to create GET_OBJECT_LIST for EX64ObjMadtLocalInterruptInfo +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjMadtLocalInterruptInfo, + CM_X64_MADT_LOCAL_INTERRUPT_INFO + ); + +/// MACRO to create GET_OBJECT_LIST for EX64ObjMadtProcessorLocalApicX2Api= cInfo +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjMadtProcessorLocalApicX2ApicInfo, + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO + ); + +/// MACRO to create GET_OBJECT_LIST for EX64ObjMadtIoApicInfo +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjMadtIoApicInfo, + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO + ); + +/// MACRO to create GET_OBJECT_LIST for EX64ObjMadtLocalApicX2ApicNmiInfo +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjMadtLocalApicX2ApicNmiInfo, + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO + ); + +/// MACRO to create GET_OBJECT_LIST for EX64ObjMadtInterruptSourceOverride= Info +GET_OBJECT_LIST ( + EObjNameSpaceX64, + EX64ObjMadtInterruptSourceOverrideInfo, + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO + ); + +/** + Build the ACPI MADT table. + + This function builds the ACPI MADT table as per the input configuration. + + @param[in] This Pointer to the ACPI_TABLE_GENERATOR protoc= ol. + @param[in] AcpiTableInfo Pointer to the CM_STD_OBJ_ACPI_TABLE_INFO = structure. + @param[in] CfgMgrProtocol Pointer to the EDKII_CONFIGURATION_MANAGER= _PROTOCOL protocol. + @param[out] Table Pointer to the ACPI table structure. + + @retval EFI_SUCCESS The ACPI MADT table is built successfully. + @retval EFI_INVALID_PARAMETER The input parameter is invalid. +**/ +STATIC +EFI_STATUS +BuildMadtTable ( + IN CONST ACPI_TABLE_GENERATOR *CONST This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table + ) +{ + EFI_STATUS Status; + EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt; + UINTN MadtSize; + CM_X64_MADT_LOCAL_INTERRUPT_INFO *LocalInterruptInfo= ; + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO *ProcessorLocalApic= X2ApicInfo; + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO *IoApicInfo; + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO *LocalApicX2ApicNmi= Info; + CM_X64_MADT_INTERRUPT_CONTROLLER_TYPE_INFO *InterruptSourceOve= rrideInfo; + + ASSERT (This !=3D NULL); + ASSERT (AcpiTableInfo !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (Table !=3D NULL); + ASSERT (AcpiTableInfo->TableGeneratorId =3D=3D This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature =3D=3D This->AcpiTableSignatur= e); + + if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) || + (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) + { + DEBUG (( + DEBUG_ERROR, + "ERROR: MADT: Requested table revision =3D %d, is not supported." + "Supported table revision: Minimum =3D %d, Maximum =3D %d\n", + AcpiTableInfo->AcpiTableRevision, + This->MinAcpiTableRevision, + This->AcpiTableRevision + )); + return EFI_INVALID_PARAMETER; + } + + *Table =3D NULL; + MadtSize =3D sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER= ); + + // Get Local Interrupt Info + Status =3D GetEX64ObjMadtLocalInterruptInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &LocalInterruptInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to get Local Interrupt Info\= n")); + return Status; + } + + // Get Processor Local APIC/x2APIC Info + Status =3D GetEX64ObjMadtProcessorLocalApicX2ApicInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &ProcessorLocalApicX2ApicInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to get Processor Local APIC/= x2APIC Info\n")); + return Status; + } else { + if (ProcessorLocalApicX2ApicInfo->Size =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Processor Local APIC/x2APIC Info = size is 0\n")); + return EFI_NOT_FOUND; + } + } + + MadtSize +=3D ProcessorLocalApicX2ApicInfo->Size; + + // Get IO APIC Info + Status =3D GetEX64ObjMadtIoApicInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &IoApicInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to get IO APIC Info\n")); + return Status; + } else { + if (IoApicInfo->Size =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: IO APIC Info size is 0\n")); + return EFI_NOT_FOUND; + } + } + + MadtSize +=3D IoApicInfo->Size; + + // Get Local APIC/x2APIC NMI Info + Status =3D GetEX64ObjMadtLocalApicX2ApicNmiInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &LocalApicX2ApicNmiInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to get Local APIC/x2APIC NMI= Info\n")); + return Status; + } else { + if (LocalApicX2ApicNmiInfo->Size =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Local APIC/x2APIC NMI Info size i= s 0\n")); + return EFI_NOT_FOUND; + } + } + + MadtSize +=3D LocalApicX2ApicNmiInfo->Size; + + // Get Interrupt Source Override Info + Status =3D GetEX64ObjMadtInterruptSourceOverrideInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &InterruptSourceOverrideInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "WARNING: MADT: Failed to get Interrupt Source Ove= rride Info\n")); + } + + if ((InterruptSourceOverrideInfo !=3D NULL) && (InterruptSourceOverrideI= nfo->Size !=3D 0)) { + MadtSize +=3D InterruptSourceOverrideInfo->Size; + } + + // Allocate memory for Madt pointer + Madt =3D (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *)Allocate= ZeroPool (MadtSize); + if (Madt =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to allocate memory for MADT\= n")); + return EFI_OUT_OF_RESOURCES; + } + + // Initialize the MADT header + Status =3D AddAcpiHeader ( + CfgMgrProtocol, + This, + &Madt->Header, + AcpiTableInfo, + (UINT32)MadtSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Failed to initialize MADT header\n"= )); + FreePool (Madt); + return Status; + } + + Madt->LocalApicAddress =3D LocalInterruptInfo->LocalApicAddress; + Madt->Flags =3D LocalInterruptInfo->Flags; + + CopyMem ( + (UINT8 *)Madt + sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_H= EADER), + ProcessorLocalApicX2ApicInfo->InterruptControllerTypeInfo, + ProcessorLocalApicX2ApicInfo->Size + ); + + CopyMem ( + (UINT8 *)Madt + sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_H= EADER) + ProcessorLocalApicX2ApicInfo->Size, + IoApicInfo->InterruptControllerTypeInfo, + IoApicInfo->Size + ); + + CopyMem ( + (UINT8 *)Madt + sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_H= EADER) + ProcessorLocalApicX2ApicInfo->Size + IoApicInfo->Size, + LocalApicX2ApicNmiInfo->InterruptControllerTypeInfo, + LocalApicX2ApicNmiInfo->Size + ); + + if ((InterruptSourceOverrideInfo !=3D NULL) && (InterruptSourceOverrideI= nfo->Size !=3D 0)) { + CopyMem ( + (UINT8 *)Madt + sizeof (EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE= _HEADER) + ProcessorLocalApicX2ApicInfo->Size + IoApicInfo->Size + LocalApi= cX2ApicNmiInfo->Size, + InterruptSourceOverrideInfo->InterruptControllerTypeInfo, + InterruptSourceOverrideInfo->Size + ); + } + + *Table =3D (EFI_ACPI_DESCRIPTION_HEADER *)Madt; + return EFI_SUCCESS; +} + +/** Free any resources allocated for constructing the MADT + + @param [in] This Pointer to the table generator. + @param [in] AcpiTableInfo Pointer to the ACPI Table Info. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Table Pointer to the ACPI Table. + + @retval EFI_SUCCESS The resources were freed successfully. + @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid. +**/ +STATIC +EFI_STATUS +FreeMadtTableResources ( + IN CONST ACPI_TABLE_GENERATOR *CONST This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInf= o, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtoc= ol, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table + ) +{ + ASSERT (This !=3D NULL); + ASSERT (AcpiTableInfo !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (AcpiTableInfo->TableGeneratorId =3D=3D This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature =3D=3D This->AcpiTableSignatur= e); + + if ((Table =3D=3D NULL) || (*Table =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: MADT: Invalid Table Pointer\n")); + ASSERT ((Table !=3D NULL) && (*Table !=3D NULL)); + return EFI_INVALID_PARAMETER; + } + + *Table =3D NULL; + return EFI_SUCCESS; +} + +/// Macro for MADT Table generator revision +#define MADT_GENERATOR_REVISION CREATE_REVISION (1, 0) + +/// Interface for MADT table generator +STATIC +CONST +ACPI_TABLE_GENERATOR mMadtTableGenerator =3D { + // Generator ID + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdMadt), + // Generator Description + L"ACPI.STD.MADT.GENERATOR", + // ACPI Table Signature + EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, + // ACPI Table Revision supported by this Generator + EFI_ACPI_6_5_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION, + // Minimum supported ACPI Table Revision + EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION, + // Creator ID + TABLE_GENERATOR_CREATOR_ID_GENERIC, + // Creator Revision + MADT_GENERATOR_REVISION, + // Build Table function + BuildMadtTable, + // Free Resource function + FreeMadtTableResources, + // Extended build function not needed + NULL, + // Extended build function not implemented by the generator. + // Hence extended free resource function is not required. + NULL +}; + +/** + The constructor function registers the ACPI MADT table generator. + + The constructor function registers the ACPI MADT table generator. + + @param[in] ImageHandle The firmware allocated handle for the EFI = image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor executed successfully. + @retval EFI_INVALID_PARAMETER The input parameter is invalid. +**/ +EFI_STATUS +EFIAPI +AcpiMadtLibX64Constructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D RegisterAcpiTableGenerator (&mMadtTableGenerator); + DEBUG ((DEBUG_INFO, "MADT: Register Generator. Status =3D %r\n", Status)= ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** + The destructor function unregisters the ACPI MADT table generator. + + The destructor function unregisters the ACPI MADT table generator. + + @param[in] ImageHandle The firmware allocated handle for the EFI = image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The destructor executed successfully. + @retval EFI_INVALID_PARAMETER The input parameter is invalid. +**/ +EFI_STATUS +EFIAPI +AcpiMadtLibX64Destructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D DeregisterAcpiTableGenerator (&mMadtTableGenerator); + DEBUG ((DEBUG_INFO, "MADT: Unregister Generator. Status =3D %r\n", Statu= s)); + ASSERT_EFI_ERROR (Status); + return Status; +} --=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 (#117208): https://edk2.groups.io/g/devel/message/117208 Mute This Topic: https://groups.io/mt/105195465/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-