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 83194D80056 for ; Fri, 19 Jan 2024 14:57:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=onTYieUKA8vADUXVSqF9u5f/Byj7118XSwpflKfgQ/4=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results: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:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705676271; v=1; b=aNaOdSUaOZZ1IiZ+wqDVB9VPDFohYKp7ui80SL0ct4KLM6ADh0PP2Ana1iw+p+d2kqMqsljJ /ybQFAXmneTj9vJlyqnNbhQTpH1OtJuHEoWoYlE+KasR5aMfeh4j25rZTc7uIZ+NCLyWfikh3Os KNDYs/NMWVRpycq9ai3xozNw= X-Received: by 127.0.0.2 with SMTP id 8QPqYY7687511xqRVFvJIZqI; Fri, 19 Jan 2024 06:57:51 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.65]) by mx.groups.io with SMTP id smtpd.web10.5979.1705560758118375507 for ; Wed, 17 Jan 2024 22:52:38 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YBkr4n1qy4fP4vZfsTvDVnLtCg1KnLrvuxXrQO8xIP/5qXkOLsFwrkVjfpl4EnyqXDuaMVezDoTosv5nKop1cs6WhuWMcaEZHtp8hWjvpEhI8zJblAztPHTeVY7/Kig6+gcwlmruhprtt04WaO87juKoDGAZYkuzRaYpKfa3ga39+iVxP1Vq8z8jfAg6WsnJjuvPB8fejSXCI9z/wEf5ePSsIz8hy4rnJwB5jhBtWxa3kkC20Y7WhpX1h43ahfCSoZPGUAzfyuuTJbjzqI+lD3s1Je4VSaGg3KBVrYY6X/PoVLXik99z53ttskmhVd7hyFGmkO3l9C6Z/RfMujqdtw== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7n5AxcSeuDQuFDdaLgveuWGMJDWEKJ6L3sS4ZhCQZ+w=; b=CooHhDC6xsQsLHITrwlc+wlXYluJZn8tk6QLd7eA6DPoCfRYZlekOD2/BNMHWECFGmR5w6AmQsoD6KSBL95Ok5INV8KPvKoTpJSDBWa6AON11lS5+0mpSp2PFSTXWkS6y5Suk7EoAKm9kZNc81D1yyCkde1jmqazWL+Z/mSLUWlsP4JGt4aYo51SGVW8R25pSopagbVa12Xkw+DPjUmEznVrqz2+YOXnAh9XTjG9XARHJKJTR2S4IJrPODrla9cghJXvlxhZRkrL4MV65KKYW/Xs3wyoLlxoMBtbKHnD7uLrop8lPrSdCZWXX5DO2SHh4n/1/AykSLRBDJkkfJMmHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from MW4PR04CA0298.namprd04.prod.outlook.com (2603:10b6:303:89::33) by IA0PR12MB8745.namprd12.prod.outlook.com (2603:10b6:208:48d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23; Thu, 18 Jan 2024 06:52:35 +0000 X-Received: from CO1PEPF000044EE.namprd05.prod.outlook.com (2603:10b6:303:89:cafe::23) by MW4PR04CA0298.outlook.office365.com (2603:10b6:303:89::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24 via Frontend Transport; Thu, 18 Jan 2024 06:52:34 +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 CO1PEPF000044EE.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Thu, 18 Jan 2024 06:52:34 +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.34; Thu, 18 Jan 2024 00:52:33 -0600 X-Received: from SHA-LX-MINGXZHA.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.34 via Frontend Transport; Thu, 18 Jan 2024 00:52:32 -0600 From: "duke.zhai via groups.io" To: CC: Ken Yao , Duke Zhai , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH 23/33] AMD/VanGoghBoard: Check in AcpiPlatform. Date: Thu, 18 Jan 2024 14:50:36 +0800 Message-ID: <20240118065046.961-24-duke.zhai@amd.com> In-Reply-To: <20240118065046.961-1-duke.zhai@amd.com> References: <20240118065046.961-1-duke.zhai@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044EE:EE_|IA0PR12MB8745:EE_ X-MS-Office365-Filtering-Correlation-Id: b75bf763-6df1-4d21-c4c2-08dc17f20d0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: W+wa//+IV9TtfRJ0dEhD+zrp4Ax95KkVH92z6H9/VtnKVKPueXVAEu4CFzzzpgR6CsfdsdMdAgvbq2F188OO5qDrTvFO8JoWjc1BmIw0TAmWD2cPK1jEdw9V0xovreAbT3zqLvU6fczs2Etli7mlFOMzAWH1P04McRetbNf3UdPvQOg5QTbNDSlwBjSMgROYb1ID2m9LdutPNnp4DS/eKn8wKMbW9yi7OTan164kHKOpG6bR9WphZmQmrp/wW05F3gff+8jDhwkBVhFy64VH1ZPduongZsnwHjrd/sPDtjkqL0qg9xSAYELtrg0ZFQr3QBtYC8LF0z+Gry31DtXm0ChHsMg52ZmM7LfscNkOGdLxpSuJjLMubcLW0218z30Y7vaymdhy9pHDsY6wXms9e5dqB7YwHMfE8L1BeDkG2FDLmyUwJXp0j8neOb2AWtg0cLGxig1WT7vXhQxPVzCpN3/vy2uODOlcM2Ox6m7ECojw05i7wNbL2BR6YTfIhZnNQMYmBbxBbCvg2GEJd9LUJe3dh5OjaVz9F/0qcxhVpPMsUa5GbuHl0pQ7aXxsPR/REImUzLSSzW+creC4Jz98x8cf27zZcaGQ+36IggRKkB32FT6weGyMVktg8IjqRwHdpbEQFeiT5KhcwuBrrbFxfY39cEHJAiNX5NXPgzu6flF4dGQ6LnoPxf1K/RVbAGSBkd2Najq1VQyG53Ozp1JKziRgQzOJjNa25ObOhbU/7UisHr/tXSU7X1iWii2ueBun26+6masHSQ9y3ykqYoIaBKKIjfHo/tH0bsxNtWGVs+Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2024 06:52:34.6826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b75bf763-6df1-4d21-c4c2-08dc17f20d0c 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: CO1PEPF000044EE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8745 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 Reply-To: devel@edk2.groups.io,duke.zhai@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: oSXJBrLPqDCngGMsFj6zRcQCx7686176AA= 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=20140610 header.b=aNaOdSUa; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") From: Duke Zhai BZ #:4640 Initial Acpi platform dxe drivers. Use firmware volume protocol to update global NVS area for ASL and SMM init code. Signed-off-by: Eric Xing Cc: Ken Yao Cc: Duke Zhai Cc: Igniculus Fu Cc: Abner Chang --- .../Universal/AcpiPlatformDxe/AcpiPlatform.c | 343 ++++++++++++++++++ .../AcpiPlatformDxe/AcpiPlatform.uni | 24 ++ .../AcpiPlatformDxe/AcpiPlatformDxe.inf | 65 ++++ .../AcpiPlatformDxe/AcpiPlatformExtra.uni | 22 ++ .../AcpiPlatformDxe/AcpiPlatformHooks.c | 159 ++++++++ .../AcpiPlatformDxe/AcpiPlatformHooks.h | 55 +++ 6 files changed, 668 insertions(+) create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatform.c create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatform.uni create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatformDxe.inf create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatformExtra.uni create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatformHooks.c create mode 100644 Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/Acp= iPlatformHooks.h diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rm.c b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.c new file mode 100644 index 0000000000..4ac29ca17e --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.c @@ -0,0 +1,343 @@ +/** @file + Implements AcpiPlatform in Board Package + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +/* This file includes code originally published under the following licens= e. */ + +/** @file + Sample ACPI Platform Driver + + Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include "AcpiPlatformHooks.h" +#include + +EFI_GLOBAL_NVS_AREA_PROTOCOL mGlobalNvsArea; + +/** + Locate the first instance of a protocol. If the protocol requested is a= n + FV protocol, then it will return the first FV that contains the ACPI tab= le + storage file. + + @param Instance Return pointer to the first instance of the protoc= ol + + @return EFI_SUCCESS The function completed successfully. + @return EFI_NOT_FOUND The protocol could not be located. + @return EFI_OUT_OF_RESOURCES There are not enough resources to find the= protocol. + +**/ +EFI_STATUS +LocateFvInstanceWithTables ( + OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + EFI_FV_FILETYPE FileType; + UINT32 FvStatus; + EFI_FV_FILE_ATTRIBUTES Attributes; + UINTN Size; + UINTN Index; + EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance; + + FvStatus =3D 0; + + // + // Locate protocol. + // + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolume2ProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + // + // Defined errors at this time are not found and out of resources. + // + return Status; + } + + // + // Looking for FV with ACPI storage file + // + + for (Index =3D 0; Index < NumberOfHandles; Index++) { + // + // Get the protocol on this handle + // This should not fail because of LocateHandleBuffer + // + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **)&FvInstance + ); + ASSERT_EFI_ERROR (Status); + + // + // See if it has the ACPI storage file + // + Status =3D FvInstance->ReadFile ( + FvInstance, + (EFI_GUID *)PcdGetPtr (PcdAcpiTableStorageFile)= , + NULL, + &Size, + &FileType, + &Attributes, + &FvStatus + ); + + // + // If we found it, then we are done + // + if (Status =3D=3D EFI_SUCCESS) { + *Instance =3D FvInstance; + break; + } + } + + // + // Our exit status is determined by the success of the previous operatio= ns + // If the protocol was found, Instance already points to it. + // + + // + // Free any allocated buffers + // + gBS->FreePool (HandleBuffer); + + return Status; +} + +/** + This function calculates and updates an UINT8 checksum. + + @param Buffer Pointer to buffer to checksum + @param Size Number of bytes to checksum + +**/ +VOID +AcpiPlatformChecksum ( + IN UINT8 *Buffer, + IN UINTN Size + ) +{ + UINTN ChecksumOffset; + + ChecksumOffset =3D OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum); + + // + // Set checksum to 0 first + // + Buffer[ChecksumOffset] =3D 0; + + // + // Update checksum value + // + Buffer[ChecksumOffset] =3D CalculateCheckSum8 (Buffer, Size); +} + +/** + This function will update any runtime platform specific information. + This currently includes: + Setting OEM table values, ID, table ID, creator ID and creator revisio= n. + Enabling the proper processor entries in the APIC tables. + + @param[in] Table The table to update. + + @retval EFI_SUCCESS The function completed successfully. + +**/ +EFI_STATUS +PlatformUpdateTables ( + IN OUT EFI_ACPI_COMMON_HEADER *Table + ) +{ + switch (Table->Signature) { + case EFI_ACPI_5_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE: + // + // Patch the memory resource. + // + PatchDsdtTable ((EFI_ACPI_DESCRIPTION_HEADER *)Table); + break; + + case EFI_ACPI_5_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE: + PatchMadtTable ((EFI_ACPI_DESCRIPTION_HEADER *)Table); + break; + + default: + break; + } + + return EFI_SUCCESS; +} + +/** + Entrypoint of Acpi Platform driver. + + @param ImageHandle + @param SystemTable + + @return EFI_SUCCESS + @return EFI_LOAD_ERROR + @return EFI_OUT_OF_RESOURCES + +**/ +EFI_STATUS +EFIAPI +AcpiPlatformEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_STATUS AcpiStatus; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; + INTN Instance; + EFI_ACPI_COMMON_HEADER *CurrentTable; + UINTN TableHandle; + UINT32 FvStatus; + UINTN TableSize; + UINTN Size; + EFI_HANDLE Handle; + + Instance =3D 0; + CurrentTable =3D NULL; + TableHandle =3D 0; + + // + // Find the AcpiTable protocol + // + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID = **)&AcpiTable); + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } + + // + // Allocate and initialize the NVS area for SMM and ASL communication. + // + Status =3D gBS->AllocatePool ( + EfiACPIMemoryNVS, + sizeof (EFI_GLOBAL_NVS_AREA), + (void **)&mGlobalNvsArea.Area + ); + ASSERT_EFI_ERROR (Status); + gBS->SetMem ( + mGlobalNvsArea.Area, + sizeof (EFI_GLOBAL_NVS_AREA), + 0 + ); + DEBUG ((DEBUG_INFO, "mGlobalNvsArea.Area is at 0x%X\n", mGlobalNvsArea.A= rea)); + + // + // Update global NVS area for ASL and SMM init code to use. + // + mGlobalNvsArea.Area->PcieBaseAddress =3D (UINT32)PcdGet64 (PcdPciExpress= BaseAddress); + mGlobalNvsArea.Area->PcieBaseLimit =3D (UINT32)(PcdGet64 (PcdPciExpres= sBaseAddress) + (PcdGet32 (PcdPciExpressSize) - 1)); + + if (FeaturePcdGet (PcdNbIoApicSupport)) { + mGlobalNvsArea.Area->NbIoApic =3D TRUE; + } else { + mGlobalNvsArea.Area->NbIoApic =3D FALSE; + } + + mGlobalNvsArea.Area->TopOfMem =3D (UINT32)AsmReadMsr64 (0xC001001A); + + Handle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiGlobalNvsAreaProtocolGuid, + &mGlobalNvsArea, + NULL + ); + + // + // Locate the firmware volume protocol + // + Status =3D LocateFvInstanceWithTables (&FwVol); + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } + + // + // Read tables from the storage file. + // + while (Status =3D=3D EFI_SUCCESS) { + Status =3D FwVol->ReadSection ( + FwVol, + (EFI_GUID *)PcdGetPtr (PcdAcpiTableStorageFile), + EFI_SECTION_RAW, + Instance, + (VOID **)&CurrentTable, + &Size, + &FvStatus + ); + if (!EFI_ERROR (Status)) { + AcpiStatus =3D PlatformUpdateTables (CurrentTable); + if (!EFI_ERROR (AcpiStatus)) { + // + // Add the table + // + TableHandle =3D 0; + + TableSize =3D ((EFI_ACPI_DESCRIPTION_HEADER *)CurrentTable)->Lengt= h; + ASSERT (Size >=3D TableSize); + + // + // Checksum ACPI table + // + AcpiPlatformChecksum ((UINT8 *)CurrentTable, TableSize); + + // + // Install ACPI table + // + Status =3D AcpiTable->InstallAcpiTable ( + AcpiTable, + CurrentTable, + TableSize, + &TableHandle + ); + } + + // + // Free memory allocated by ReadSection + // + gBS->FreePool (CurrentTable); + + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } + + // + // Increment the instance + // + Instance++; + CurrentTable =3D NULL; + } + } + + // + // The driver does not require to be kept loaded. + // + return EFI_SUCCESS; +} diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rm.uni b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.u= ni new file mode 100644 index 0000000000..f79d718588 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.uni @@ -0,0 +1,24 @@ +// /** @file +// Acpi Platform uni file +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ +// This file includes code originally published under the following licens= e. +// */ +// /** @file +// Sample ACPI Platform Driver +// +// Sample ACPI Platform Driver +// +// Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Sample ACPI Platf= orm Driver" + +#string STR_MODULE_DESCRIPTION #language en-US "Sample ACPI Platf= orm Driver" diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rmDxe.inf b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfor= mDxe.inf new file mode 100644 index 0000000000..b197e2c6e7 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformDxe.i= nf @@ -0,0 +1,65 @@ +## @file +# Acpi Platform Dxe driver +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## +# This file includes code originally published under the following license= . +## @file +# Sample ACPI Platform Driver +# +# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D AcpiPlatform + MODULE_UNI_FILE =3D AcpiPlatform.uni + FILE_GUID =3D 6A462E1D-7B1A-95BE-DCF1-241320F01646 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D AcpiPlatformEntryPoint + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + AcpiPlatform.c + AcpiPlatformHooks.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + VanGoghCommonPkg/AmdCommonPkg.dec + ChachaniBoardPkg/Project.dec + +[LibraryClasses] + UefiLib + DxeServicesLib + PcdLib + BaseMemoryLib + DebugLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiAcpiTableProtocolGuid ## CONSUMES + gEfiGlobalNvsAreaProtocolGuid + gEfiMpServiceProtocolGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile ## CONSUMES + gPlatformPkgTokenSpaceGuid.PcdNbIoApicSupport + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + gPlatformPkgTokenSpaceGuid.PcdPciExpressSize + +[Depex] + gEfiAcpiTableProtocolGuid + +[UserExtensions.TianoCore."ExtraFiles"] + AcpiPlatformExtra.uni diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rmExtra.uni b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatf= ormExtra.uni new file mode 100644 index 0000000000..b0d84752d6 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformExtra= .uni @@ -0,0 +1,22 @@ +// /** @file +// Acpi Platform extra uni file +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ +// This file includes code originally published under the following licens= e. +// */ +// /** @file +// AcpiPlatform Localized Strings and Content +// +// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"ACPI Platform Sample DXE Driver" diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rmHooks.c b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfor= mHooks.c new file mode 100644 index 0000000000..9ac9c15e18 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformHooks= .c @@ -0,0 +1,159 @@ +/** @file + Implements AcpiPlatform Hooks in Board Package + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +/* This file includes code originally published under the following licens= e. */ + +/** @file + Sample ACPI Platform Driver + + Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +// Statements that include other files. +// +#include "AcpiPlatformHooks.h" +#include + +extern EFI_GLOBAL_NVS_AREA_PROTOCOL mGlobalNvsArea; + +/** + Update the DSDT table. + + @param TableHeader The table to be set. + + @retval EFI_SUCCESS Update DSDT table sucessfully. + +**/ +EFI_STATUS +PatchDsdtTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader + ) +{ + UINT8 *CurrPtr; + UINT8 *DsdtPointer; + UINT32 *Signature; + UINT8 *Operation; + UINT32 *Address; + UINT16 *Size; + + // + // Loop through the ASL looking for values that we must fix up. + // + CurrPtr =3D (UINT8 *)TableHeader; + for (DsdtPointer =3D CurrPtr; DsdtPointer <=3D (CurrPtr + ((EFI_ACPI_COM= MON_HEADER *)CurrPtr)->Length); DsdtPointer++) { + Signature =3D (UINT32 *)DsdtPointer; + + switch (*Signature) { + // + // GNVS operation region. + // + case (SIGNATURE_32 ('G', 'N', 'V', 'S')): + // + // Conditional match. For Region Objects, the Operator will alway= s be the + // byte immediately before the specific name. Therefore, subtract= 1 to check + // the Operator. + // + Operation =3D DsdtPointer - 1; + if (*Operation =3D=3D AML_OPREGION_OP) { + Address =3D (UINT32 *)(DsdtPointer + 6); + *Address =3D (UINT32)(UINTN)mGlobalNvsArea.Area; + Size =3D (UINT16 *)(DsdtPointer + 11); + *Size =3D sizeof (EFI_GLOBAL_NVS_AREA); + } + + break; + default: + break; + } + } + + return EFI_SUCCESS; +} + +/** + Update the MADT table. + + @param TableHeader The table to be set. + + @retval EFI_SUCCESS Update MADT table sucessfully. + +**/ +EFI_STATUS +PatchMadtTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader + ) +{ + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpService; + UINTN NumCPUs =3D 1; + UINTN NumEnabledCPUs; + UINT8 CurrProcessor =3D 0; + EFI_PROCESSOR_INFORMATION ProcessorInfo; + UINT8 *CurrPtr; + EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_STRUCTURE *ApicPtr =3D NULL; + EFI_ACPI_5_0_IO_APIC_STRUCTURE *IoApicPtr =3D NULL; + + // Find the MP Protocol. + Status =3D gBS->LocateProtocol ( + &gEfiMpServiceProtocolGuid, + NULL, + (VOID **)&MpService + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Determine the number of processors + MpService->GetNumberOfProcessors ( + MpService, + &NumCPUs, + &NumEnabledCPUs + ); + + CurrPtr =3D (UINT8 *)TableHeader; + CurrPtr +=3D sizeof (EFI_ACPI_5_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER= ); + while (CurrPtr < ((UINT8 *)TableHeader + ((EFI_ACPI_COMMON_HEADER *)Tabl= eHeader)->Length)) { + // Local APIC + ApicPtr =3D (EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_STRUCTURE *)CurrPtr; + if (ApicPtr->Type =3D=3D EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC) { + // Disable at first + ApicPtr->Flags =3D 0; + ApicPtr->ApicId =3D 0; + + // retrieve processor information + Status =3D MpService->GetProcessorInfo ( + MpService, + CurrProcessor, + &ProcessorInfo + ); + if (!EFI_ERROR (Status)) { + if (ProcessorInfo.StatusFlag & PROCESSOR_ENABLED_BIT) { + ApicPtr->Flags =3D EFI_ACPI_5_0_LOCAL_APIC_ENABLED; + } + + ApicPtr->ApicId =3D (UINT8)(ProcessorInfo.ProcessorId); + } + + // Increment the procesor count + CurrProcessor++; + } + + // IO APIC (IOHUB and FCH) + IoApicPtr =3D (EFI_ACPI_5_0_IO_APIC_STRUCTURE *)CurrPtr; + if (IoApicPtr->Type =3D=3D EFI_ACPI_5_0_IO_APIC) { + // IoApicPtr->IoApicId =3D PcdGet8 (PcdCfgFchIoapicId); + // IoApicPtr->IoApicId =3D PcdGet8 (PcdCfgGnbIoapicId); + } + + // Go to the next structure in the APIC table + CurrPtr +=3D (ApicPtr->Length); + } + + return EFI_SUCCESS; +} diff --git a/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfo= rmHooks.h b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatfor= mHooks.h new file mode 100644 index 0000000000..5d1b7ac38c --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformHooks= .h @@ -0,0 +1,55 @@ +/** @file + Implements AcpiPlatform Hooks head file in Board Package + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +/* This file includes code originally published under the following licens= e. */ + +/** @file + Sample ACPI Platform Driver + + Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _ACPI_PLATFORM_HOOKS_H_ +#define _ACPI_PLATFORM_HOOKS_H_ + +// +// Statements that include other header files +// +#include +#include +#include + +#define AML_OPREGION_OP 0x80 + +/** + Update the DSDT table. + + @param TableHeader The table to be set. + + @retval EFI_SUCCESS Update DSDT table sucessfully. + +**/ +EFI_STATUS +PatchDsdtTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader + ); + +/** + Update the MADT table. + + @param TableHeader The table to be set. + + @retval EFI_SUCCESS Update MADT table successfully. + +**/ +EFI_STATUS +PatchMadtTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader + ); + +#endif -- 2.31.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 (#114069): https://edk2.groups.io/g/devel/message/114069 Mute This Topic: https://groups.io/mt/103831192/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-