From nobody Mon Sep 16 19:54:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114599+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706274794659387.0864772085017; Fri, 26 Jan 2024 05:13:14 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=w5zXig5iRTnRN+O8wO1ZZR5Ga8BQGiQPiygEOCVjrRM=; 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=1706274794; v=1; b=AaLOuYJvRvpnP18du644RC5c6zbyqTTE/hBQekyYbmq1+HDt8Sb6QbxoUA+o8Gqxh2TlQCC6 UmEDxPbJx3WGLWJ4OPwwDFNlsrWTQz2iPZUw0xvBwu0fXfOKxNG5u/UXV0gKT7JGYYYhZlze77T BCDudLtSiSxErHLabBC3ZoPA= X-Received: by 127.0.0.2 with SMTP id yUIVYY1788612xBGoaT3V3xV; Fri, 26 Jan 2024 05:13:14 -0800 X-Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.78]) by mx.groups.io with SMTP id smtpd.web10.15500.1706274793469174249 for ; Fri, 26 Jan 2024 05:13:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D5GjTkXiYQZpXA8q96SJ/cwub08Yt+ipWR/Bc/Tnjh/pajrKB1bK3b6snksRegFEk2AMXTDjBRnfHnHIiO/7EvW4xRzZGWbAMzOTzSqZyBwMR47IOV6Y/e1BHtlcuW6BzhBXwg+VxGiamarP6icU0vgifHnpRuXcAB4HVom109DlWF5Ibd4+Bq6GoxqYuJQaKaS/CQms4c11bHEuZ1ANISAxNXOWYrUwqmgYN9TrR5q07+mpG4ksHZl7q6YTLNhycDrcA7FrYeVbBhEdc+GR9uq+5TQQX9HMlzfkhi6o2r+MJMnZ8ltXYzE47Ul89HC1EO8t4vbaIJ4V3WqV2dvT7A== 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=G0fTUXuUNuiZk1PqfEd/LaM7J/VpHYu4TFx8Y1jnDxo=; b=Y0UwF2WSLEQSm1IxZqF+YCtfOsJD0wliwaCVSDkV7eBJmsH5omiipR2T1jPFM63mpwdduEKQGyjMhsvtFmr2oQbybPccAQtXYpwTC9jqchAyoee0stb5nlb6254bd+ODQFesOajOp3a1ajUKTazRPix5o6oSU08aKV0fbrOjLxadG6SSYyqTYdDKzfo3ZyWMxW3Db0KrbqZAXVB2WQ16MNOYPG88L0w4DYOBcWHEGDOMr87scmyf8x3yl6Sdcba4tvPai7sXCfAAqFFIkngJnrTtfUdw77oAWD+b1RK89Ym0IDwWfeYcgR34MkCP3EVlQ8UaiKvB613B9k5GYl7DkQ== 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 CYZPR05CA0043.namprd05.prod.outlook.com (2603:10b6:930:a3::25) by LV3PR12MB9119.namprd12.prod.outlook.com (2603:10b6:408:1a2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.37; Fri, 26 Jan 2024 13:13:10 +0000 X-Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:a3:cafe::9a) by CYZPR05CA0043.outlook.office365.com (2603:10b6:930:a3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.15 via Frontend Transport; Fri, 26 Jan 2024 13:13:10 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+114599+1787277+3901457@groups.io; helo=mail02.groups.io; 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=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 13:13:10 +0000 X-Received: from SHA-LX-MINGXZHA.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.34; Fri, 26 Jan 2024 07:13:08 -0600 From: "Zhai, MingXin (Duke) via groups.io" To: CC: Ken Yao , Duke Zhai , Igniculus Fu , Abner Chang Subject: [edk2-devel] [PATCH V3 23/32] AMD/VanGoghBoard: Check in AcpiPlatform Date: Fri, 26 Jan 2024 21:11:16 +0800 Message-ID: <20240126131125.1881-24-duke.zhai@amd.com> In-Reply-To: <20240126131125.1881-1-duke.zhai@amd.com> References: <20240126131125.1881-1-duke.zhai@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CD:EE_|LV3PR12MB9119:EE_ X-MS-Office365-Filtering-Correlation-Id: ae8adbc6-ba82-447e-8ae4-08dc1e708b8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: eM2mgCs9k2rbLmMdrzIAYnVhDXS4NHN1g7iHwrMPOtskKflX87TFeHEYoyDONskXtkK9gx03djHPGgGle4y+bkcR2sNEJzrX/t2bWQNUwT+hLFriRREWXvakFVDbrmWn1LR33eDkX8gHblBgRXtgG24XgPsLH8Ntvur/cShsG/S4Vl8gexkl3XOXNExo80QjLwvlcV6a62NgTf7XR4LUUcz7TgqlhgReWxvgDI05nuT8f+1gL0g57FR8qk/QksfQX91CBc8kIQcMPaV+o+w01xMbEDhIO2Wfgx6/Lu0wDYsm1DH09+ns0yiLspszG9u9vWRrpcAKMF+x00fJFWMoQp2uBJSfdBUiojZl3KsVZyYn2b35lAFTNsbn00aO/2hgun2/LhpV/GyfVjJ/SWJrR2yrHIRD9cxEhzBHLCx9oOhy8ljNgcScBfuqUgxh9/ojfgdMw+blCsJVBu1UB+6McASBsqRIRQJykKCWT7Y6iw7dVTl+R3hcV1yo1qF4nBQOcEx8gW/A4qx2FX3ReUxJOu5+AkCUfMwaAdr4eV+oBPdeYL5ptLz9nXnK5AfNSSVdWO//hRdlUZRb9/HG7VGmJ/cA3gEDVlBaNmq7dapk8+0F7NrLOUaBrXv7/5KrXFiKU/KgK3ZZM4n7Po+qMdAodUeojCOCTDy6RFRWjwY3A/ptmAA1cuwyVkH0e7LenhmjefLnmsRgnn8vD3DXkJDWZA1FUI5EN0fChU/WO/oLskEMGiXdev83I9I6UKrxajrf/ANjFs0RYrvhkxdyUfksbQvOM0+YEMq0u98ZadK7Q9o= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 13:13:10.5088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae8adbc6-ba82-447e-8ae4-08dc1e708b8c 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9119 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: rQTyqeMQiNfxXHBYe4aGewBpx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706274796176100027 Content-Type: text/plain; charset="utf-8" From: Duke Zhai BZ #:4640 In V3: Improve coding style follow edk2 C coding standard. 1.Remove macro definition extra underscores. 2.Putting some AMD copyright in the right place. In V2: Improve coding style. 1.Remove the leading underscore and use double underscore at trailing in = C header files. 2.Remove old tianocore licenses and redundant license description. 3.Improve coding style. For example: remove space between @param. In V1: 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 | 336 ++++++++++++++++++ .../AcpiPlatformDxe/AcpiPlatform.uni | 15 + .../AcpiPlatformDxe/AcpiPlatformDxe.inf | 59 +++ .../AcpiPlatformDxe/AcpiPlatformExtra.uni | 13 + .../AcpiPlatformDxe/AcpiPlatformHooks.c | 152 ++++++++ .../AcpiPlatformDxe/AcpiPlatformHooks.h | 48 +++ 6 files changed, 623 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..73a022594e --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.c @@ -0,0 +1,336 @@ +/** @file + Sample ACPI Platform Driver + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ 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 an + 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..2001da520b --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatform.uni @@ -0,0 +1,15 @@ +// /** @file +// Sample ACPI Platform Driver +// +// Sample ACPI Platform Driver +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+// 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..044218ff46 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformDxe.i= nf @@ -0,0 +1,59 @@ +## @file +# Sample ACPI Platform Driver +# +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+# 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..04a89cf3fb --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformExtra= .uni @@ -0,0 +1,13 @@ +// /** @file +// AcpiPlatform Localized Strings and Content +// +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+// 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..7cf5845772 --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformHooks= .c @@ -0,0 +1,152 @@ +/** @file + Sample ACPI Platform Driver + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ 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..10e724a2ab --- /dev/null +++ b/Platform/AMD/VanGoghBoard/Universal/AcpiPlatformDxe/AcpiPlatformHooks= .h @@ -0,0 +1,48 @@ +/** @file + Sample ACPI Platform Driver + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ 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 --=20 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 (#114599): https://edk2.groups.io/g/devel/message/114599 Mute This Topic: https://groups.io/mt/103975478/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-