From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mx.groups.io with SMTP id smtpd.web10.10472.1659245854906888865 for ; Sat, 30 Jul 2022 22:37:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Fg52/A6r; spf=pass (domain: gmail.com, ip: 209.85.215.170, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f170.google.com with SMTP id 12so7103613pga.1 for ; Sat, 30 Jul 2022 22:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=chdaux3XF/r6vpHGl8DUK2kOx5VXLWRRXn1S16guvkk=; b=Fg52/A6rm97Iu7mEjWXROmK9g74MBaFxw0/HymIv65EYbEth2eawDo8P+7sGWiPY/s KvPVlgwh6YQsdP/PoT6he4oO9AVOWH4ebS3XDlzv/96D10Kkvu8KPC+ghzGn2KiEWa7E kjwfWrUJmHZyWnFAZZNzjuC7fE0KWEmgGZwyz4IJgO+GxxHHKYvvXXAMTdMfNe5KlV1c c1r3Bo10Zr6W09eKEOg/+mhjDHAwm9c/zhcQ5Wc0bGYe6VRpIYQQmUKA/bJxnNMjUl9s cjQzLfkQA/p75ABk2aNepWqaf0xOUcKaYzwhN0j70a56pR/Jf3CeHAccPQo6LZmy/024 Hahw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=chdaux3XF/r6vpHGl8DUK2kOx5VXLWRRXn1S16guvkk=; b=Uui9cFIBOFTrTdXJFQb4Ty1itKZIRH0NrYy1mVAPr3clOm06ECFUgXofGZUQy11hVa tJ0EtpUXwSlCnS6t/ye6AXpG6lpOk5kTe0tm5sSddGRalUlNovluyGsHgLeFvgPAN+Fx hV9Fs/teIu5Jv3TXnO6koK+jeOxp4DlhYfRiWW0uNXtLn8S4z1UZufNtymJfbQsQlIVc TnScIyrYNJosniL80SMA0FA4NeVmesaL8YZ48LqnymucdcvhBmodOE2luBVnG7XY2Tvv EbSeWQWQ4zm3veu9N60nInLmEcDcB6njInYG4uzYoVBqee+xIqjgMrI6j8Ytj13CUzeM nOcw== X-Gm-Message-State: AJIora8MISUucQGJPeFFZCyfsBqainK0Jx+dtX+yRtXUiU8xI8hyHgpQ cJRVJObsT9GTCPn3cQa6jKV2aYm2KpA= X-Google-Smtp-Source: AGRyM1uVZyrxCFVEvH5RYun5JjVMJ/VTsy1RRCEiAhH6sUY6mAnCEaqaLAIo4QNTKOi6bXUIpH7MzA== X-Received: by 2002:a05:6a00:cc5:b0:52c:91b8:e88c with SMTP id b5-20020a056a000cc500b0052c91b8e88cmr10564507pfv.56.1659245854211; Sat, 30 Jul 2022 22:37:34 -0700 (PDT) Return-Path: Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:7:a09e:ed80:a0cd:1e24]) by smtp.gmail.com with ESMTPSA id x6-20020a1709029a4600b00168e83eda56sm6714524plv.3.2022.07.30.22.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 22:37:33 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Joe Lopez , Pierre Gondois Subject: [PATCH v3 5/6] DynamicTablesPkg: AcpiSsdtPcieLibArm: Added function to reserve ECAM space Date: Sat, 30 Jul 2022 22:37:26 -0700 Message-Id: <20220731053727.536-6-kuqin12@gmail.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20220731053727.536-1-kuqin12@gmail.com> References: <20220731053727.536-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3998 Certain OSes will complain if the ECAM config space is not reserved in the ACPI namespace. This change adds a function to reserve PNP motherboard resources for a given PCI node. Co-authored-by: Joe Lopez Signed-off-by: Kun Qin Reviewed-by: Pierre Gondois --- Notes: v2: - Only create RES0 after config space checking [Pierre] =20=20=20=20 v3: - Updated function names and descriptions [Pierre] - Moved translation calculation to CONFIG case [Pierre] DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c |= 171 ++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c index ceffe2838c03..658a089c8f1f 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c @@ -616,6 +616,169 @@ GeneratePciCrs ( return Status;=0D }=0D =0D +/** Generate a RES0 device node to reserve PNP motherboard resources=0D + for a given PCI node.=0D +=0D + @param [in] PciNode Parent PCI node handle of the generated=0D + resource object.=0D + @param [out] CrsNode CRS node of the AML tree to populate.=0D +=0D + @retval EFI_SUCCESS The function completed successfully.=0D + @retval EFI_INVALID_PARAMETER Invalid input parameter.=0D + @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D +**/=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +GenerateMotherboardDevice (=0D + IN AML_OBJECT_NODE_HANDLE PciNode,=0D + OUT AML_OBJECT_NODE_HANDLE *CrsNode=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 EisaId;=0D + AML_OBJECT_NODE_HANDLE ResNode;=0D +=0D + if (CrsNode =3D=3D NULL) {=0D + ASSERT (0);=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // ASL: Device (RES0) {}=0D + Status =3D AmlCodeGenDevice ("RES0", PciNode, &ResNode);=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + // ASL: Name (_HID, EISAID ("PNP0C02"))=0D + Status =3D AmlGetEisaIdFromString ("PNP0C02", &EisaId); /* PNP Motherboa= rd Resources */=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + Status =3D AmlCodeGenNameInteger ("_HID", EisaId, ResNode, NULL);=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + // ASL: Name (_CRS, ResourceTemplate () {})=0D + Status =3D AmlCodeGenNameResourceTemplate ("_CRS", ResNode, CrsNode);=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/** Reserves ECAM space for PCI config space=0D +=0D + @param [in] Generator The SSDT Pci generator.=0D + @param [in] CfgMgrProtocol Pointer to the Configuration Manager=0D + Protocol interface.=0D + @param [in] PciInfo Pci device information.=0D + @param [in, out] PciNode RootNode of the AML tree to populate.= =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 +ReserveEcamSpace (=0D + IN ACPI_PCI_GENERATOR *Generator,= =0D + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtoc= ol,=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 + AML_OBJECT_NODE_HANDLE CrsNode;=0D + BOOLEAN Translation;=0D + UINT32 Index;=0D + CM_ARM_OBJ_REF *RefInfo;=0D + UINT32 RefCount;=0D + CM_ARM_PCI_ADDRESS_MAP_INFO *AddrMapInfo;=0D + BOOLEAN IsPosDecode;=0D +=0D + // Get the array of CM_ARM_OBJ_REF referencing the=0D + // CM_ARM_PCI_ADDRESS_MAP_INFO objects.=0D + Status =3D GetEArmObjCmRef (=0D + CfgMgrProtocol,=0D + PciInfo->AddressMapToken,=0D + &RefInfo,=0D + &RefCount=0D + );=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + for (Index =3D 0; Index < RefCount; Index++) {=0D + // Get CM_ARM_PCI_ADDRESS_MAP_INFO structures one by one.=0D + Status =3D GetEArmObjPciAddressMapInfo (=0D + CfgMgrProtocol,=0D + RefInfo[Index].ReferenceToken,=0D + &AddrMapInfo,=0D + NULL=0D + );=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D + switch (AddrMapInfo->SpaceCode) {=0D + case PCI_SS_CONFIG:=0D + Translation =3D (AddrMapInfo->CpuAddress !=3D AddrMapInfo->PciAddr= ess);=0D + if (AddrMapInfo->CpuAddress >=3D AddrMapInfo->PciAddress) {=0D + IsPosDecode =3D TRUE;=0D + } else {=0D + IsPosDecode =3D FALSE;=0D + }=0D +=0D + Status =3D GenerateMotherboardDevice (PciNode, &CrsNode);=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + break;=0D + }=0D +=0D + Status =3D AmlCodeGenRdQWordMemory (=0D + FALSE,=0D + IsPosDecode,=0D + TRUE,=0D + TRUE,=0D + FALSE, // non-cacheable=0D + TRUE,=0D + 0,=0D + AddrMapInfo->PciAddress,=0D + AddrMapInfo->PciAddress + AddrMapInfo->AddressSize - 1,= =0D + Translation ? AddrMapInfo->CpuAddress - AddrMapInfo->Pc= iAddress : 0,=0D + AddrMapInfo->AddressSize,=0D + 0,=0D + NULL,=0D + 0,=0D + TRUE,=0D + CrsNode,=0D + NULL=0D + );=0D + break;=0D + default:=0D + break;=0D + } // switch=0D +=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D /** Generate a Pci device.=0D =0D @param [in] Generator The SSDT Pci generator.=0D @@ -702,9 +865,17 @@ GeneratePciDevice ( return Status;=0D }=0D =0D + // Add the PNP Motherboard Resources Device to reserve ECAM space=0D + Status =3D ReserveEcamSpace (Generator, CfgMgrProtocol, PciInfo, PciNode= );=0D + if (EFI_ERROR (Status)) {=0D + ASSERT (0);=0D + return Status;=0D + }=0D +=0D // Add the template _OSC method.=0D Status =3D AddOscMethod (PciInfo, PciNode);=0D ASSERT_EFI_ERROR (Status);=0D +=0D return Status;=0D }=0D =0D --=20 2.37.1.windows.1