From nobody Mon Feb 9 10:50:04 2026 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+91193+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 1657313930262773.3598203364106; Fri, 8 Jul 2022 13:58:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YAwEYY1788612xPKZVFV7WGM; Fri, 08 Jul 2022 13:58:49 -0700 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.69]) by mx.groups.io with SMTP id smtpd.web10.4162.1657313927947450464 for ; Fri, 08 Jul 2022 13:58:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E+YaJL18UiTONCZ7lGyK20EM98lb3KYVyTYSTUzpHFqsWYgCm1EpftFEjqu4+/h2lncWKQC5YDY9XI3K3NNEEFExnG/LFolenk/glAMBN8bmZpPqhg9qGccNorasDwz4/VM8NqXU5j3WMa7UoKLCDgfo7MIC5ieCN98tYLOvPj7x+g6eYjYwKtKIh2zPHCdmzHRoBnO9e80KwPoY/lvAP/lCLSCcSiAyl3rJbQ+0mkrWNq+4xIfxsNXJw15VNLAHZh1vOP+x8Whf501AKBvX1T2d/oYiQF97q1HJjEpKfftptIFDQ4AbZMTFNEQaIdiNqqp6BYozt81t40o7nGa+Hg== 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=pI3kGEcjbd9e+x0x8hflwP63cATA7N0ILfDOxAct7Nc=; b=FELf/W5qywYPMSE3Fq8LB+1yZZC+79xTiAZvrgmZXkmJAJoGnpOhf9Idpgft28sWAchBJzP7fKUcQjBrLEtHbWn3frnZsQTSYjida5nYbDh1CvMoGAaDGMyBntuaipOXogI+nXyHgd5vyUR0EzDejVb3cv2sNbt5aoUOeP6jAqNvMuiWz/MZ1tOMghwrIqb4lPxjJWMpsyEVN6+4cPaO4DMd2/b5o5P85S5dOvHSi2OvzUZ3WEG6VNqg4yDCJ9tJG4fHMIhXRgXjgUIHKuaHnE/kx2UedQ7l72JHCJh35v7LiE+Zca8eer//4ILRKc6Q7A6Aq4H+OlCt6WB7RWl2kQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from BN9P220CA0005.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:13e::10) by BN8PR12MB3348.namprd12.prod.outlook.com (2603:10b6:408:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16; Fri, 8 Jul 2022 20:58:45 +0000 X-Received: from BN8NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13e:cafe::9a) by BN9P220CA0005.outlook.office365.com (2603:10b6:408:13e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.19 via Frontend Transport; Fri, 8 Jul 2022 20:58:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.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+91193+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT036.mail.protection.outlook.com (10.13.177.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.16 via Frontend Transport; Fri, 8 Jul 2022 20:58:44 +0000 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 8 Jul 2022 20:58:44 +0000 X-Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 8 Jul 2022 13:58:43 -0700 X-Received: from perses.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 8 Jul 2022 13:58:42 -0700 From: "Jeff Brasen via groups.io" To: , CC: , , Jeff Brasen Subject: [edk2-devel] [PATCH v3 3/3] DynamicTablesPkg: AcpiSsdtPcieLibArm: Create support library Date: Fri, 8 Jul 2022 14:59:03 -0600 Message-ID: <92bf2e8419e091c86366322ad654e5efc809627e.1657313523.git.jbrasen@nvidia.com> In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f3096e0-9c3d-481b-df5e-08da6124a589 X-MS-TrafficTypeDiagnostic: BN8PR12MB3348:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: DdckKAq4v+EfEFSSGQ7+mXBePJRFq6VCBitGqkK9c7ilvisJnPL1xvm4+HJI37N6nV2fzUwriSAWiZ6DZZev4edNI1mMsSIG9LvnPZFBkmmxpHQa1ouvlBE8zDJzl4c+t7gujhRjMZs5dus/pUThxT81NmlVlECe2mlaoxl8qTEhE+USC2lzGStOlRzVdnDxV7ZBUtkg3MX2zPuj0QWasXFj0Sl1ENDu11Zk5nqANTzI2/tlP8ic0+Eyb/bQ/Xi7x5YSOlrFrzlvGRuvjqJ6/MKxERO0SH4M0/g+7Dgt8g54lIl1xapuxZHXcRv3a6FFp8Uqg2RM124d0TdAZuITfR3DqlUUhCQhceMd7q5hNRUVCHoJff1DYnIlcoc4vlrafO01s2AQMdaZnV+MwtNTB61yoI8Q/jzebJGNd1QeuyXZn3Ve/9hAYBORlBo8iIedUg0VksjdneelExmoJEOkm+miunvMcbg6eRTw8NVdUUwFh3VAv9NR+P90/EwWknjQcaW+B3RZLG5LUNjumoiFd+mNCls3qieA2SIrtEuZw9kMbTgjv6EL/JfK53klk2u9sz6SNEYu27shQb4MRaAsZOKs0JdjotXSAplssk/TSfEGZCl5vctewPDJjXFoUKijXrIwpcIqcY8kOyoFf0pHTD9iGS1SHxoYeCBaAMI4Z57DQc50hlfzuHtum6S5PcG98JXs5flPcvs35e2GeSGSKruZA1jn5TBBOPTARCacUkdptCZ0tom46WMIRzErIqn0wXLJ0WmR3V4JvIEvaMvsfpTLthKEC2V60TovTRP6Gw7DnhhGq2OAUG2AeE7menLneeKDoigSea4rTwsga5U0HoDGFbnimcefPu61fuNBhEIHRYFXvSxy/uy65scI86OQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2022 20:58:44.7839 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3096e0-9c3d-481b-df5e-08da6124a589 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3348 Precedence: Bulk List-Unsubscribe: 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,jbrasen@nvidia.com X-Gm-Message-State: FdT9hPmwNvlum0RgltUyRQJ2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1657313929; bh=UeFwozNVq9M536vWA0AuBDtfeYa8lmzbsJyueypF6T8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ucaz+sotpYgVHdixeFunwOilhlg0noNWXNg3zCwz9YhBGOFQl8IOoL9sL4fcu3eJbvj 99xftVvANbP6PhqYK2hJog/25e7GKd2e/oGsW7KITB3xioBnK4byZ7GRejuQ919YgLYvM b5zh52PFrqc4sJszMYdh9gkTB5U157ed4bU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1657313931757100008 Content-Type: text/plain; charset="utf-8" Add support library to allow for customization of _OSC and slot info. The functions in the library are unchanged, with the exception of adding PciInfo pointer to the APIs. Signed-off-by: Jeff Brasen Reviewed-by: Sami Mujawar --- .../Include/Library/SsdtPcieSupportLib.h | 73 +++++++ .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.c | 168 +-------------- .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.h | 15 -- .../Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf | 2 +- .../SsdtPcieOscTemplate.asl | 0 .../SsdtPcieSupportLib/SsdtPcieSupportLib.c | 200 ++++++++++++++++++ .../SsdtPcieSupportLib/SsdtPcieSupportLib.inf | 30 +++ .../SsdtPcieSupportLibPrivate.h | 25 +++ 8 files changed, 332 insertions(+), 181 deletions(-) create mode 100644 DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h rename DynamicTablesPkg/Library/{Acpi/Arm/AcpiSsdtPcieLibArm =3D> Common/S= sdtPcieSupportLib}/SsdtPcieOscTemplate.asl (100%) create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLib.c create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLib.inf create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLibPrivate.h diff --git a/DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h b/Dynami= cTablesPkg/Include/Library/SsdtPcieSupportLib.h new file mode 100644 index 0000000000..f65431ef28 --- /dev/null +++ b/DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h @@ -0,0 +1,73 @@ +/** @file + Ssdt PCie Support Library + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef SSDT_PCIE_SUPPORT_LIB_H_ +#define SSDT_PCIE_SUPPORT_LIB_H_ + +#pragma pack(1) + +/** Structure used to map integer to an index. +*/ +typedef struct MappingTable { + /// Mapping table. + /// Contains the Index <-> integer mapping + UINT32 *Table; + + /// Last used index of the Table. + /// Bound by MaxIndex. + UINT32 LastIndex; + + /// Number of entries in the Table. + UINT32 MaxIndex; +} MAPPING_TABLE; + +#pragma pack() + +/** Add an _OSC template method to the PciNode. + + The _OSC method is provided as an AML blob. The blob is + parsed and attached at the end of the PciNode list of variable elements. + + @param [in] PciInfo Pci device information. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AddOscMethod ( + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ); + +/** Generate Pci slots devices. + + PCI Firmware Specification - Revision 3.3, + s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot + used. It should be possible to enumerate them, but this is additional + information. + + @param [in] PciInfo Pci device information. + @param [in] MappingTable The mapping table structure. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +GeneratePciSlots ( + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo, + IN CONST MAPPING_TABLE *MappingTable, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ); + +#endif // SSDT_PCIE_SUPPORT_LIB_H_ diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c index 68ecae96be..62cec3753c 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c @@ -29,6 +29,7 @@ #include #include #include +#include #include =20 #include "SsdtPcieGenerator.h" @@ -280,86 +281,6 @@ GeneratePciDeviceInfo ( return Status; } =20 -/** Generate Pci slots devices. - - PCI Firmware Specification - Revision 3.3, - s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot - used. It should be possible to enumerate them, but this is additional - information. - - @param [in] MappingTable The mapping table structure. - @param [in, out] PciNode Pci node to amend. - - @retval EFI_SUCCESS Success. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. -**/ -STATIC -EFI_STATUS -EFIAPI -GeneratePciSlots ( - IN CONST MAPPING_TABLE *MappingTable, - IN OUT AML_OBJECT_NODE_HANDLE PciNode - ) -{ - EFI_STATUS Status; - UINT32 Index; - UINT32 LastIndex; - UINT32 DeviceId; - CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; - AML_OBJECT_NODE_HANDLE DeviceNode; - - ASSERT (MappingTable !=3D NULL); - ASSERT (PciNode !=3D NULL); - - // Generic device name is "Dxx". - CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1); - - LastIndex =3D MappingTable->LastIndex; - - // There are at most 32 devices on a Pci bus. - if (LastIndex >=3D 32) { - ASSERT (0); - return EFI_INVALID_PARAMETER; - } - - for (Index =3D 0; Index < LastIndex; Index++) { - DeviceId =3D MappingTable->Table[Index]; - AslName[AML_NAME_SEG_SIZE - 3] =3D AsciiFromHex (DeviceId & 0xF); - AslName[AML_NAME_SEG_SIZE - 2] =3D AsciiFromHex ((DeviceId >> 4) & 0xF= ); - - // ASL: - // Device (Dxx) { - // Name (_ADR,
) - // } - Status =3D AmlCodeGenDevice (AslName, PciNode, &DeviceNode); - if (EFI_ERROR (Status)) { - ASSERT (0); - return Status; - } - - /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings" - High word-Device #, Low word-Function #. (for example, device 3, - function 2 is 0x00030002). To refer to all the functions on a devic= e #, - use a function number of FFFF). - */ - Status =3D AmlCodeGenNameInteger ( - "_ADR", - (DeviceId << 16) | 0xFFFF, - DeviceNode, - NULL - ); - if (EFI_ERROR (Status)) { - ASSERT (0); - return Status; - } - - // _SUN object is not generated as we don't know which slot will be us= ed. - } - - return Status; -} - /** Generate a _PRT object (Pci Routing Table) for the Pci device. =20 Cf. ACPI 6.4 specification, s6.2.13 "_PRT (PCI Routing Table)" @@ -495,7 +416,7 @@ GeneratePrt ( PrtNode =3D NULL; =20 // Generate the Pci slots once all the device have been added. - Status =3D GeneratePciSlots (&Generator->DeviceTable, PciNode); + Status =3D GeneratePciSlots (PciInfo, &Generator->DeviceTable, PciNode); if (EFI_ERROR (Status)) { ASSERT (0); goto exit_handler; @@ -695,89 +616,6 @@ GeneratePciCrs ( return Status; } =20 -/** Add an _OSC template method to the PciNode. - - The _OSC method is provided as an AML blob. The blob is - parsed and attached at the end of the PciNode list of variable elements. - - @param [in, out] PciNode Pci node to amend. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_OUT_OF_RESOURCES Could not allocate memory. -**/ -STATIC -EFI_STATUS -EFIAPI -AddOscMethod ( - IN OUT AML_OBJECT_NODE_HANDLE PciNode - ) -{ - EFI_STATUS Status; - EFI_STATUS Status1; - EFI_ACPI_DESCRIPTION_HEADER *SsdtPcieOscTemplate; - AML_ROOT_NODE_HANDLE OscTemplateRoot; - AML_OBJECT_NODE_HANDLE OscNode; - - ASSERT (PciNode !=3D NULL); - - // Parse the Ssdt Pci Osc Template. - SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER *) - ssdtpcieosctemplate_aml_code; - - OscNode =3D NULL; - OscTemplateRoot =3D NULL; - Status =3D AmlParseDefinitionBlock ( - SsdtPcieOscTemplate, - &OscTemplateRoot - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template." - " Status =3D %r\n", - Status - )); - return Status; - } - - Status =3D AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode); - if (EFI_ERROR (Status)) { - goto error_handler; - } - - Status =3D AmlDetachNode (OscNode); - if (EFI_ERROR (Status)) { - goto error_handler; - } - - Status =3D AmlAttachNode (PciNode, OscNode); - if (EFI_ERROR (Status)) { - // Free the detached node. - AmlDeleteTree (OscNode); - goto error_handler; - } - -error_handler: - // Cleanup - Status1 =3D AmlDeleteTree (OscTemplateRoot); - if (EFI_ERROR (Status1)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree." - " Status =3D %r\n", - Status1 - )); - // If Status was success but we failed to delete the AML Tree - // return Status1 else return the original error code, i.e. Status. - if (!EFI_ERROR (Status)) { - return Status1; - } - } - - return Status; -} - /** Generate a Pci device. =20 @param [in] Generator The SSDT Pci generator. @@ -865,7 +703,7 @@ GeneratePciDevice ( } =20 // Add the template _OSC method. - Status =3D AddOscMethod (PciNode); + Status =3D AddOscMethod (PciInfo, PciNode); ASSERT_EFI_ERROR (Status); return Status; } diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h index 515a3e1785..b302e79786 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h @@ -44,21 +44,6 @@ extern CHAR8 ssdtpcieosctemplate_aml_code[]; =20 #pragma pack(1) =20 -/** Structure used to map integer to an index. -*/ -typedef struct MappingTable { - /// Mapping table. - /// Contains the Index <-> integer mapping - UINT32 *Table; - - /// Last used index of the Table. - /// Bound by MaxIndex. - UINT32 LastIndex; - - /// Number of entries in the Table. - UINT32 MaxIndex; -} MAPPING_TABLE; - /** A structure holding the Pcie generator and additional private data. */ typedef struct AcpiPcieGenerator { diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieL= ibArm.inf b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLi= bArm.inf index 283b564801..b38a4e9d34 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.i= nf +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.i= nf @@ -19,7 +19,6 @@ [Sources] SsdtPcieGenerator.c SsdtPcieGenerator.h - SsdtPcieOscTemplate.asl =20 [Packages] DynamicTablesPkg/DynamicTablesPkg.dec @@ -30,3 +29,4 @@ AcpiHelperLib AmlLib BaseLib + SsdtPcieSupportLib diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieO= scTemplate.asl b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPci= eOscTemplate.asl similarity index 100% rename from DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieOs= cTemplate.asl rename to DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieOscTem= plate.asl diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLib.c b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupp= ortLib.c new file mode 100644 index 0000000000..4066653d0b --- /dev/null +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= .c @@ -0,0 +1,200 @@ +/** @file + SSDT Pcie Table Generator. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - PCI Firmware Specification - Revision 3.0 + - ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + - linux kernel code + - Arm Base Boot Requirements v1.0 + - Arm Base System Architecture v1.0 +**/ + +#include +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SsdtPcieSupportLibPrivate.h" + +/** Generate Pci slots devices. + + PCI Firmware Specification - Revision 3.3, + s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot + used. It should be possible to enumerate them, but this is additional + information. + + @param [in] PciInfo Pci device information. + @param [in] MappingTable The mapping table structure. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +GeneratePciSlots ( + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo, + IN CONST MAPPING_TABLE *MappingTable, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + UINT32 Index; + UINT32 LastIndex; + UINT32 DeviceId; + CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; + AML_OBJECT_NODE_HANDLE DeviceNode; + + ASSERT (MappingTable !=3D NULL); + ASSERT (PciNode !=3D NULL); + + // Generic device name is "Dxx". + CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1); + + LastIndex =3D MappingTable->LastIndex; + + // There are at most 32 devices on a Pci bus. + if (LastIndex >=3D 32) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < LastIndex; Index++) { + DeviceId =3D MappingTable->Table[Index]; + AslName[AML_NAME_SEG_SIZE - 3] =3D AsciiFromHex (DeviceId & 0xF); + AslName[AML_NAME_SEG_SIZE - 2] =3D AsciiFromHex ((DeviceId >> 4) & 0xF= ); + + // ASL: + // Device (Dxx) { + // Name (_ADR,
) + // } + Status =3D AmlCodeGenDevice (AslName, PciNode, &DeviceNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings" + High word-Device #, Low word-Function #. (for example, device 3, + function 2 is 0x00030002). To refer to all the functions on a devic= e #, + use a function number of FFFF). + */ + Status =3D AmlCodeGenNameInteger ( + "_ADR", + (DeviceId << 16) | 0xFFFF, + DeviceNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // _SUN object is not generated as we don't know which slot will be us= ed. + } + + return Status; +} + +/** Add an _OSC template method to the PciNode. + + The _OSC method is provided as an AML blob. The blob is + parsed and attached at the end of the PciNode list of variable elements. + + @param [in] PciInfo Pci device information. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AddOscMethod ( + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + EFI_STATUS Status1; + EFI_ACPI_DESCRIPTION_HEADER *SsdtPcieOscTemplate; + AML_ROOT_NODE_HANDLE OscTemplateRoot; + AML_OBJECT_NODE_HANDLE OscNode; + + ASSERT (PciNode !=3D NULL); + + // Parse the Ssdt Pci Osc Template. + SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER *) + ssdtpcieosctemplate_aml_code; + + OscNode =3D NULL; + OscTemplateRoot =3D NULL; + Status =3D AmlParseDefinitionBlock ( + SsdtPcieOscTemplate, + &OscTemplateRoot + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template." + " Status =3D %r\n", + Status + )); + return Status; + } + + Status =3D AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode); + if (EFI_ERROR (Status)) { + goto error_handler; + } + + Status =3D AmlDetachNode (OscNode); + if (EFI_ERROR (Status)) { + goto error_handler; + } + + Status =3D AmlAttachNode (PciNode, OscNode); + if (EFI_ERROR (Status)) { + // Free the detached node. + AmlDeleteTree (OscNode); + goto error_handler; + } + +error_handler: + // Cleanup + Status1 =3D AmlDeleteTree (OscTemplateRoot); + if (EFI_ERROR (Status1)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree." + " Status =3D %r\n", + Status1 + )); + // If Status was success but we failed to delete the AML Tree + // return Status1 else return the original error code, i.e. Status. + if (!EFI_ERROR (Status)) { + return Status1; + } + } + + return Status; +} diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLib.inf b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSu= pportLib.inf new file mode 100644 index 0000000000..bbdb6ac6c8 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= .inf @@ -0,0 +1,30 @@ +## @file +# Ssdt Serial Port Table Support Library +# +# Copyright (c) 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SsdtPcieSupportLib + FILE_GUID =3D 510451a0-60b2-446c-b6bf-59cbe4a41782 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D SsdtPcieSupportLib + +[Sources] + SsdtPcieSupportLib.c + SsdtPcieSupportLibPrivate.h + SsdtPcieOscTemplate.asl + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + AcpiHelperLib + AmlLib + BaseLib diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLibPrivate.h b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtP= cieSupportLibPrivate.h new file mode 100644 index 0000000000..a5dd1af660 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= Private.h @@ -0,0 +1,25 @@ +/** @file + SSDT Pcie Support Library private data. + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - PCI Firmware Specification - Revision 3.0 + - ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + - linux kernel code + - Arm Base Boot Requirements v1.0 +**/ + +#ifndef SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_ +#define SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_ + +/** C array containing the compiled AML template. + This symbol is defined in the auto generated C file + containing the AML bytecode array. +*/ +extern CHAR8 ssdtpcieosctemplate_aml_code[]; + +#endif // SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_ --=20 2.25.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 (#91193): https://edk2.groups.io/g/devel/message/91193 Mute This Topic: https://groups.io/mt/92260871/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-