From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=L3Rpq9Hp; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.102.69, mailfrom: jbrasen@nvidia.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pI3kGEcjbd9e+x0x8hflwP63cATA7N0ILfDOxAct7Nc=; b=L3Rpq9HpvYSYWRvH5FeeVw4mYbwGFVx1TN3vY8hu4j3NRXcbXTAOlw512UjPFOplCTUfjZgXtH+JqUmvQjL5EyQEadrtbl1rDiLdeBISI0yggBDkk0DKy5zX948d3FBE6I7zY8XOFdDiQrb2VNxYnliGrBjBfuJEHgT+Uevqvqzor2oaRiRsIVQc73OGoTByLMn2c2leYNT8olY53E10dFCvQoX+GeMXEC1WkOWJjuhYV/cJgbGNfyYarMtUirJfFQIOnhPGmCTxUJXB1F4PvX5i1AbO2Etw+eOyQbbXGQmLrXcWerDtIyO11a4/khT3qDBQxWHtam/vlBqx68uZzw== 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 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 (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 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 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 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 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" To: , CC: , , Jeff Brasen Subject: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com 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: BCL: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-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(376002)(39860400002)(396003)(346002)(40470700004)(36840700001)(46966006)(26005)(54906003)(4326008)(8936002)(2616005)(40460700003)(8676002)(478600001)(30864003)(86362001)(110136005)(316002)(6666004)(5660300002)(70586007)(7696005)(70206006)(40480700001)(336012)(186003)(47076005)(41300700001)(356005)(81166007)(82740400003)(2906002)(83380400001)(107886003)(36860700001)(82310400005)(426003)(36756003)(213903007)(36900700001);DIR:OUT;SFP:1101; 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Add support library to allow for customization of _OSC and slot info.=0D The functions in the library are unchanged,=0D with the exception of adding PciInfo pointer to the APIs.=0D =0D Signed-off-by: Jeff Brasen =0D ---=0D .../Include/Library/SsdtPcieSupportLib.h | 73 +++++++=0D .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.c | 168 +--------------=0D .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.h | 15 --=0D .../Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf | 2 +-=0D .../SsdtPcieOscTemplate.asl | 0=0D .../SsdtPcieSupportLib/SsdtPcieSupportLib.c | 200 ++++++++++++++++++=0D .../SsdtPcieSupportLib/SsdtPcieSupportLib.inf | 30 +++=0D .../SsdtPcieSupportLibPrivate.h | 25 +++=0D 8 files changed, 332 insertions(+), 181 deletions(-)=0D create mode 100644 DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h=0D rename DynamicTablesPkg/Library/{Acpi/Arm/AcpiSsdtPcieLibArm =3D> Common/S= sdtPcieSupportLib}/SsdtPcieOscTemplate.asl (100%)=0D create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLib.c=0D create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLib.inf=0D create mode 100644 DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/Ssdt= PcieSupportLibPrivate.h=0D =0D diff --git a/DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h b/Dynami= cTablesPkg/Include/Library/SsdtPcieSupportLib.h=0D new file mode 100644=0D index 0000000000..f65431ef28=0D --- /dev/null=0D +++ b/DynamicTablesPkg/Include/Library/SsdtPcieSupportLib.h=0D @@ -0,0 +1,73 @@=0D +/** @file=0D + Ssdt PCie Support Library=0D +=0D + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef SSDT_PCIE_SUPPORT_LIB_H_=0D +#define SSDT_PCIE_SUPPORT_LIB_H_=0D +=0D +#pragma pack(1)=0D +=0D +/** Structure used to map integer to an index.=0D +*/=0D +typedef struct MappingTable {=0D + /// Mapping table.=0D + /// Contains the Index <-> integer mapping=0D + UINT32 *Table;=0D +=0D + /// Last used index of the Table.=0D + /// Bound by MaxIndex.=0D + UINT32 LastIndex;=0D +=0D + /// Number of entries in the Table.=0D + UINT32 MaxIndex;=0D +} MAPPING_TABLE;=0D +=0D +#pragma pack()=0D +=0D +/** Add an _OSC template method to the PciNode.=0D +=0D + The _OSC method is provided as an AML blob. The blob is=0D + parsed and attached at the end of the PciNode list of variable elements.= =0D +=0D + @param [in] PciInfo Pci device information.=0D + @param [in, out] PciNode Pci node to amend.=0D +=0D + @retval EFI_SUCCESS The function completed successfully.=0D + @retval EFI_INVALID_PARAMETER Invalid parameter.=0D + @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +AddOscMethod (=0D + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo,=0D + IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D + );=0D +=0D +/** Generate Pci slots devices.=0D +=0D + PCI Firmware Specification - Revision 3.3,=0D + s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot=0D + used. It should be possible to enumerate them, but this is additional=0D + information.=0D +=0D + @param [in] PciInfo Pci device information.=0D + @param [in] MappingTable The mapping table structure.=0D + @param [in, out] PciNode Pci node to amend.=0D +=0D + @retval EFI_SUCCESS Success.=0D + @retval EFI_INVALID_PARAMETER Invalid parameter.=0D + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GeneratePciSlots (=0D + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo,=0D + IN CONST MAPPING_TABLE *MappingTable,=0D + IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D + );=0D +=0D +#endif // SSDT_PCIE_SUPPORT_LIB_H_=0D diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c=0D index 68ecae96be..62cec3753c 100644=0D --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c=0D +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c=0D @@ -29,6 +29,7 @@=0D #include =0D #include =0D #include =0D +#include =0D #include =0D =0D #include "SsdtPcieGenerator.h"=0D @@ -280,86 +281,6 @@ GeneratePciDeviceInfo (=0D return Status;=0D }=0D =0D -/** Generate Pci slots devices.=0D -=0D - PCI Firmware Specification - Revision 3.3,=0D - s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot=0D - used. It should be possible to enumerate them, but this is additional=0D - information.=0D -=0D - @param [in] MappingTable The mapping table structure.=0D - @param [in, out] PciNode Pci node to amend.=0D -=0D - @retval EFI_SUCCESS Success.=0D - @retval EFI_INVALID_PARAMETER Invalid parameter.=0D - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.=0D -**/=0D -STATIC=0D -EFI_STATUS=0D -EFIAPI=0D -GeneratePciSlots (=0D - IN CONST MAPPING_TABLE *MappingTable,=0D - IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D - )=0D -{=0D - EFI_STATUS Status;=0D - UINT32 Index;=0D - UINT32 LastIndex;=0D - UINT32 DeviceId;=0D - CHAR8 AslName[AML_NAME_SEG_SIZE + 1];=0D - AML_OBJECT_NODE_HANDLE DeviceNode;=0D -=0D - ASSERT (MappingTable !=3D NULL);=0D - ASSERT (PciNode !=3D NULL);=0D -=0D - // Generic device name is "Dxx".=0D - CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1);=0D -=0D - LastIndex =3D MappingTable->LastIndex;=0D -=0D - // There are at most 32 devices on a Pci bus.=0D - if (LastIndex >=3D 32) {=0D - ASSERT (0);=0D - return EFI_INVALID_PARAMETER;=0D - }=0D -=0D - for (Index =3D 0; Index < LastIndex; Index++) {=0D - DeviceId =3D MappingTable->Table[Index];=0D - AslName[AML_NAME_SEG_SIZE - 3] =3D AsciiFromHex (DeviceId & 0xF);=0D - AslName[AML_NAME_SEG_SIZE - 2] =3D AsciiFromHex ((DeviceId >> 4) & 0xF= );=0D -=0D - // ASL:=0D - // Device (Dxx) {=0D - // Name (_ADR,
)=0D - // }=0D - Status =3D AmlCodeGenDevice (AslName, PciNode, &DeviceNode);=0D - if (EFI_ERROR (Status)) {=0D - ASSERT (0);=0D - return Status;=0D - }=0D -=0D - /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings"=0D - High word-Device #, Low word-Function #. (for example, device 3,=0D - function 2 is 0x00030002). To refer to all the functions on a devic= e #,=0D - use a function number of FFFF).=0D - */=0D - Status =3D AmlCodeGenNameInteger (=0D - "_ADR",=0D - (DeviceId << 16) | 0xFFFF,=0D - DeviceNode,=0D - NULL=0D - );=0D - if (EFI_ERROR (Status)) {=0D - ASSERT (0);=0D - return Status;=0D - }=0D -=0D - // _SUN object is not generated as we don't know which slot will be us= ed.=0D - }=0D -=0D - return Status;=0D -}=0D -=0D /** Generate a _PRT object (Pci Routing Table) for the Pci device.=0D =0D Cf. ACPI 6.4 specification, s6.2.13 "_PRT (PCI Routing Table)"=0D @@ -495,7 +416,7 @@ GeneratePrt (=0D PrtNode =3D NULL;=0D =0D // Generate the Pci slots once all the device have been added.=0D - Status =3D GeneratePciSlots (&Generator->DeviceTable, PciNode);=0D + Status =3D GeneratePciSlots (PciInfo, &Generator->DeviceTable, PciNode);= =0D if (EFI_ERROR (Status)) {=0D ASSERT (0);=0D goto exit_handler;=0D @@ -695,89 +616,6 @@ GeneratePciCrs (=0D return Status;=0D }=0D =0D -/** Add an _OSC template method to the PciNode.=0D -=0D - The _OSC method is provided as an AML blob. The blob is=0D - parsed and attached at the end of the PciNode list of variable elements.= =0D -=0D - @param [in, out] PciNode Pci node to amend.=0D -=0D - @retval EFI_SUCCESS The function completed successfully.=0D - @retval EFI_INVALID_PARAMETER Invalid parameter.=0D - @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D -**/=0D -STATIC=0D -EFI_STATUS=0D -EFIAPI=0D -AddOscMethod (=0D - IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D - )=0D -{=0D - EFI_STATUS Status;=0D - EFI_STATUS Status1;=0D - EFI_ACPI_DESCRIPTION_HEADER *SsdtPcieOscTemplate;=0D - AML_ROOT_NODE_HANDLE OscTemplateRoot;=0D - AML_OBJECT_NODE_HANDLE OscNode;=0D -=0D - ASSERT (PciNode !=3D NULL);=0D -=0D - // Parse the Ssdt Pci Osc Template.=0D - SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER *)=0D - ssdtpcieosctemplate_aml_code;=0D -=0D - OscNode =3D NULL;=0D - OscTemplateRoot =3D NULL;=0D - Status =3D AmlParseDefinitionBlock (=0D - SsdtPcieOscTemplate,=0D - &OscTemplateRoot=0D - );=0D - if (EFI_ERROR (Status)) {=0D - DEBUG ((=0D - DEBUG_ERROR,=0D - "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template."=0D - " Status =3D %r\n",=0D - Status=0D - ));=0D - return Status;=0D - }=0D -=0D - Status =3D AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode);=0D - if (EFI_ERROR (Status)) {=0D - goto error_handler;=0D - }=0D -=0D - Status =3D AmlDetachNode (OscNode);=0D - if (EFI_ERROR (Status)) {=0D - goto error_handler;=0D - }=0D -=0D - Status =3D AmlAttachNode (PciNode, OscNode);=0D - if (EFI_ERROR (Status)) {=0D - // Free the detached node.=0D - AmlDeleteTree (OscNode);=0D - goto error_handler;=0D - }=0D -=0D -error_handler:=0D - // Cleanup=0D - Status1 =3D AmlDeleteTree (OscTemplateRoot);=0D - if (EFI_ERROR (Status1)) {=0D - DEBUG ((=0D - DEBUG_ERROR,=0D - "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree."=0D - " Status =3D %r\n",=0D - Status1=0D - ));=0D - // If Status was success but we failed to delete the AML Tree=0D - // return Status1 else return the original error code, i.e. Status.=0D - if (!EFI_ERROR (Status)) {=0D - return Status1;=0D - }=0D - }=0D -=0D - return Status;=0D -}=0D -=0D /** Generate a Pci device.=0D =0D @param [in] Generator The SSDT Pci generator.=0D @@ -865,7 +703,7 @@ GeneratePciDevice (=0D }=0D =0D // Add the template _OSC method.=0D - Status =3D AddOscMethod (PciNode);=0D + Status =3D AddOscMethod (PciInfo, PciNode);=0D ASSERT_EFI_ERROR (Status);=0D return Status;=0D }=0D diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h=0D index 515a3e1785..b302e79786 100644=0D --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h=0D +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h=0D @@ -44,21 +44,6 @@ extern CHAR8 ssdtpcieosctemplate_aml_code[];=0D =0D #pragma pack(1)=0D =0D -/** Structure used to map integer to an index.=0D -*/=0D -typedef struct MappingTable {=0D - /// Mapping table.=0D - /// Contains the Index <-> integer mapping=0D - UINT32 *Table;=0D -=0D - /// Last used index of the Table.=0D - /// Bound by MaxIndex.=0D - UINT32 LastIndex;=0D -=0D - /// Number of entries in the Table.=0D - UINT32 MaxIndex;=0D -} MAPPING_TABLE;=0D -=0D /** A structure holding the Pcie generator and additional private data.=0D */=0D typedef struct AcpiPcieGenerator {=0D diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieL= ibArm.inf b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLi= bArm.inf=0D index 283b564801..b38a4e9d34 100644=0D --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.i= nf=0D +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.i= nf=0D @@ -19,7 +19,6 @@=0D [Sources]=0D SsdtPcieGenerator.c=0D SsdtPcieGenerator.h=0D - SsdtPcieOscTemplate.asl=0D =0D [Packages]=0D DynamicTablesPkg/DynamicTablesPkg.dec=0D @@ -30,3 +29,4 @@=0D AcpiHelperLib=0D AmlLib=0D BaseLib=0D + SsdtPcieSupportLib=0D diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieO= scTemplate.asl b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPci= eOscTemplate.asl=0D similarity index 100%=0D rename from DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieOs= cTemplate.asl=0D rename to DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieOscTem= plate.asl=0D diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLib.c b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupp= ortLib.c=0D new file mode 100644=0D index 0000000000..4066653d0b=0D --- /dev/null=0D +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= .c=0D @@ -0,0 +1,200 @@=0D +/** @file=0D + SSDT Pcie Table Generator.=0D +=0D + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D + @par Reference(s):=0D + - PCI Firmware Specification - Revision 3.0=0D + - ACPI 6.4 specification:=0D + - s6.2.13 "_PRT (PCI Routing Table)"=0D + - s6.1.1 "_ADR (Address)"=0D + - linux kernel code=0D + - Arm Base Boot Requirements v1.0=0D + - Arm Base System Architecture v1.0=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +// Module specific include files.=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include "SsdtPcieSupportLibPrivate.h"=0D +=0D +/** Generate Pci slots devices.=0D +=0D + PCI Firmware Specification - Revision 3.3,=0D + s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot=0D + used. It should be possible to enumerate them, but this is additional=0D + information.=0D +=0D + @param [in] PciInfo Pci device information.=0D + @param [in] MappingTable The mapping table structure.=0D + @param [in, out] PciNode Pci node to amend.=0D +=0D + @retval EFI_SUCCESS Success.=0D + @retval EFI_INVALID_PARAMETER Invalid parameter.=0D + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GeneratePciSlots (=0D + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo,=0D + IN CONST MAPPING_TABLE *MappingTable,=0D + IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 Index;=0D + UINT32 LastIndex;=0D + UINT32 DeviceId;=0D + CHAR8 AslName[AML_NAME_SEG_SIZE + 1];=0D + AML_OBJECT_NODE_HANDLE DeviceNode;=0D +=0D + ASSERT (MappingTable !=3D NULL);=0D + ASSERT (PciNode !=3D NULL);=0D +=0D + // Generic device name is "Dxx".=0D + CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1);=0D +=0D + LastIndex =3D MappingTable->LastIndex;=0D +=0D + // There are at most 32 devices on a Pci bus.=0D + if (LastIndex >=3D 32) {=0D + ASSERT (0);=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + for (Index =3D 0; Index < LastIndex; Index++) {=0D + DeviceId =3D MappingTable->Table[Index];=0D + AslName[AML_NAME_SEG_SIZE - 3] =3D AsciiFromHex (DeviceId & 0xF);=0D + AslName[AML_NAME_SEG_SIZE - 2] =3D AsciiFromHex ((DeviceId >> 4) & 0xF= );=0D +=0D + // ASL:=0D + // Device (Dxx) {=0D + // Name (_ADR,
)=0D + // }=0D + Status =3D AmlCodeGenDevice (AslName, PciNode, &DeviceNode);=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings"=0D + High word-Device #, Low word-Function #. (for example, device 3,=0D + function 2 is 0x00030002). To refer to all the functions on a devic= e #,=0D + use a function number of FFFF).=0D + */=0D + Status =3D AmlCodeGenNameInteger (=0D + "_ADR",=0D + (DeviceId << 16) | 0xFFFF,=0D + DeviceNode,=0D + NULL=0D + );=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + // _SUN object is not generated as we don't know which slot will be us= ed.=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/** Add an _OSC template method to the PciNode.=0D +=0D + The _OSC method is provided as an AML blob. The blob is=0D + parsed and attached at the end of the PciNode list of variable elements.= =0D +=0D + @param [in] PciInfo Pci device information.=0D + @param [in, out] PciNode Pci node to amend.=0D +=0D + @retval EFI_SUCCESS The function completed successfully.=0D + @retval EFI_INVALID_PARAMETER Invalid parameter.=0D + @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +AddOscMethod (=0D + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo,=0D + IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_STATUS Status1;=0D + EFI_ACPI_DESCRIPTION_HEADER *SsdtPcieOscTemplate;=0D + AML_ROOT_NODE_HANDLE OscTemplateRoot;=0D + AML_OBJECT_NODE_HANDLE OscNode;=0D +=0D + ASSERT (PciNode !=3D NULL);=0D +=0D + // Parse the Ssdt Pci Osc Template.=0D + SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER *)=0D + ssdtpcieosctemplate_aml_code;=0D +=0D + OscNode =3D NULL;=0D + OscTemplateRoot =3D NULL;=0D + Status =3D AmlParseDefinitionBlock (=0D + SsdtPcieOscTemplate,=0D + &OscTemplateRoot=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template."=0D + " Status =3D %r\n",=0D + Status=0D + ));=0D + return Status;=0D + }=0D +=0D + Status =3D AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode);=0D + if (EFI_ERROR (Status)) {=0D + goto error_handler;=0D + }=0D +=0D + Status =3D AmlDetachNode (OscNode);=0D + if (EFI_ERROR (Status)) {=0D + goto error_handler;=0D + }=0D +=0D + Status =3D AmlAttachNode (PciNode, OscNode);=0D + if (EFI_ERROR (Status)) {=0D + // Free the detached node.=0D + AmlDeleteTree (OscNode);=0D + goto error_handler;=0D + }=0D +=0D +error_handler:=0D + // Cleanup=0D + Status1 =3D AmlDeleteTree (OscTemplateRoot);=0D + if (EFI_ERROR (Status1)) {=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree."=0D + " Status =3D %r\n",=0D + Status1=0D + ));=0D + // If Status was success but we failed to delete the AML Tree=0D + // return Status1 else return the original error code, i.e. Status.=0D + if (!EFI_ERROR (Status)) {=0D + return Status1;=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLib.inf b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSu= pportLib.inf=0D new file mode 100644=0D index 0000000000..bbdb6ac6c8=0D --- /dev/null=0D +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= .inf=0D @@ -0,0 +1,30 @@=0D +## @file=0D +# Ssdt Serial Port Table Support Library=0D +#=0D +# Copyright (c) 2021, Arm Limited. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001B=0D + BASE_NAME =3D SsdtPcieSupportLib=0D + FILE_GUID =3D 510451a0-60b2-446c-b6bf-59cbe4a41782=0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D DXE_DRIVER=0D + LIBRARY_CLASS =3D SsdtPcieSupportLib=0D +=0D +[Sources]=0D + SsdtPcieSupportLib.c=0D + SsdtPcieSupportLibPrivate.h=0D + SsdtPcieOscTemplate.asl=0D +=0D +[Packages]=0D + DynamicTablesPkg/DynamicTablesPkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + MdePkg/MdePkg.dec=0D +=0D +[LibraryClasses]=0D + AcpiHelperLib=0D + AmlLib=0D + BaseLib=0D diff --git a/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSup= portLibPrivate.h b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtP= cieSupportLibPrivate.h=0D new file mode 100644=0D index 0000000000..a5dd1af660=0D --- /dev/null=0D +++ b/DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib= Private.h=0D @@ -0,0 +1,25 @@=0D +/** @file=0D + SSDT Pcie Support Library private data.=0D +=0D + Copyright (c) 2021, Arm Limited. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D + @par Reference(s):=0D + - PCI Firmware Specification - Revision 3.0=0D + - ACPI 6.4 specification:=0D + - s6.2.13 "_PRT (PCI Routing Table)"=0D + - s6.1.1 "_ADR (Address)"=0D + - linux kernel code=0D + - Arm Base Boot Requirements v1.0=0D +**/=0D +=0D +#ifndef SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_=0D +#define SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_=0D +=0D +/** C array containing the compiled AML template.=0D + This symbol is defined in the auto generated C file=0D + containing the AML bytecode array.=0D +*/=0D +extern CHAR8 ssdtpcieosctemplate_aml_code[];=0D +=0D +#endif // SSDT_PCIE_SUPPORT_LIB_PRIVATE_H_=0D -- =0D 2.25.1=0D =0D