From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from muminek.juszkiewicz.com.pl (muminek.juszkiewicz.com.pl [213.251.184.221]) by mx.groups.io with SMTP id smtpd.web10.1939.1688056882222022724 for ; Thu, 29 Jun 2023 09:41:22 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=softfail (domain: linaro.org, ip: 213.251.184.221, mailfrom: marcin.juszkiewicz@linaro.org) Received: from localhost (localhost [127.0.0.1]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTP id D1611260A89; Thu, 29 Jun 2023 18:41:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at juszkiewicz.com.pl Received: from muminek.juszkiewicz.com.pl ([127.0.0.1]) by localhost (muminek.juszkiewicz.com.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2vCSzX725d5L; Thu, 29 Jun 2023 18:41:18 +0200 (CEST) Received: from applejack.lan (83.21.150.32.ipv4.supernova.orange.pl [83.21.150.32]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTPSA id 1BED2260ACF; Thu, 29 Jun 2023 18:41:17 +0200 (CEST) From: "Marcin Juszkiewicz" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Graeme Gregory , Shashi Mallela , Marcin Juszkiewicz Subject: [PATCH edk2-platforms v2 3/3] Platform/SbsaQemu: handle systems without GIC ITS Date: Thu, 29 Jun 2023 18:41:06 +0200 Message-ID: <20230629164106.744289-4-marcin.juszkiewicz@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629164106.744289-1-marcin.juszkiewicz@linaro.org> References: <20230629164106.744289-1-marcin.juszkiewicz@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable If firmware is used with QEMU 8.0 or older then there will be no GIC ITS support. In such case we would not add information about it into MADT and IORT tables. Signed-off-by: Marcin Juszkiewicz --- .../Qemu/SbsaQemu/AcpiTables/AcpiTables.inf | 1 - .../SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf | 1 + .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 226 +++++++++++++++++- Silicon/Qemu/SbsaQemu/AcpiTables/Iort.aslc | 135 ----------- 4 files changed, 216 insertions(+), 147 deletions(-) delete mode 100644 Silicon/Qemu/SbsaQemu/AcpiTables/Iort.aslc diff --git a/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf b/Silicon/Qe= mu/SbsaQemu/AcpiTables/AcpiTables.inf index 554c5e4b6f9e..97021f7971c7 100644 --- a/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf +++ b/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf @@ -22,7 +22,6 @@ [Sources] Gtdt.aslc Mcfg.aslc Spcr.aslc - Iort.aslc =20 [Packages] ArmPlatformPkg/ArmPlatformPkg.dec diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDx= e.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf index 3ec7ffd8dd5c..14d760b36400 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf @@ -49,6 +49,7 @@ [Pcd] gArmTokenSpaceGuid.PcdGicDistributorBase gArmTokenSpaceGuid.PcdGicRedistributorsBase gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdGicItsBase + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdSmmuBase =20 [Depex] gEfiAcpiTableProtocolGuid ## CONSUMES diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDx= e.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c index 961482269678..17d47f56d611 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c @@ -8,6 +8,7 @@ **/ #include #include +#include #include #include #include @@ -21,6 +22,34 @@ #include #include =20 +#pragma pack(1) + +typedef struct { + EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE Node; + UINT32 Identifiers; +} SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE; + +typedef struct +{ + EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE SmmuNode; + EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE SmmuIdMap; +} SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE; + +typedef struct +{ + EFI_ACPI_6_0_IO_REMAPPING_RC_NODE RcNode; + EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE RcIdMap; +} SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE; + +typedef struct { + EFI_ACPI_6_0_IO_REMAPPING_TABLE Iort; + SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE ItsNode; + SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE SmmuNode; + SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE RcNode; +} SBSA_IO_REMAPPING_STRUCTURE; + +#pragma pack () + /* * A Function to Compute the ACPI Table Checksum */ @@ -40,6 +69,169 @@ AcpiPlatformChecksum ( Buffer[ChecksumOffset] =3D CalculateCheckSum8(Buffer, Size); } =20 +/* + * A function that add the IORT ACPI table. + IN EFI_ACPI_COMMON_HEADER *CurrentTable + */ +EFI_STATUS +AddIortTable ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable + ) +{ + EFI_STATUS Status; + UINTN TableHandle; + UINT32 TableSize; + EFI_PHYSICAL_ADDRESS PageAddress; + UINT8 *New; + UINTN GicItsBase; + + // Initialize IORT ACPI Header + EFI_ACPI_6_0_IO_REMAPPING_TABLE Header =3D { + SBSAQEMU_ACPI_HEADER(EFI_ACPI_6_0_IO_REMAPPING_TABLE_SIGNATURE, + SBSA_IO_REMAPPING_STRUCTURE, + EFI_ACPI_IO_REMAPPING_TABLE_REVISION_00), + 2, + sizeof(EFI_ACPI_6_0_IO_REMAPPING_TABLE), // NodeOffset + 0 }; + + // Initialize SMMU3 Structure + SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE Smmu3 =3D { + { + { + EFI_ACPI_IORT_TYPE_SMMUv3, + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE), + 2, // Revision + 0, // Reserved + 1, // NumIdMapping + OFFSET_OF (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE, SmmuIdMap)= // IdReference + }, + PcdGet64 (PcdSmmuBase), // Base address + EFI_ACPI_IORT_SMMUv3_FLAG_COHAC_OVERRIDE, // Flags + 0, // Reserved + 0, // VATOS address + EFI_ACPI_IORT_SMMUv3_MODEL_GENERIC, // SMMUv3 Model + 0, // Event + 0, // Pri + 0, // Gerror + 0, // Sync + 0, // Proximity domain + 1 // DevIDMappingIndex + }, + { + 0x0000, // InputBase + 0xffff, // NumIds + 0x0000, // OutputBase + OFFSET_OF (SBSA_IO_REMAPPING_STRUCTURE, ItsNode), // OutputRefer= ence + 0 // Flags + } + }; + + SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE Rc =3D { + { + { + EFI_ACPI_IORT_TYPE_ROOT_COMPLEX, // Type + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE), // Length + 0, // Revision + 0, // Reserved + 1, // NumIdMappings + OFFSET_OF (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE, RcIdMap) // = IdReference + }, + 1, // CacheCoherent + 0, // AllocationHints + 0, // Reserved + 0, // MemoryAccessFlags + EFI_ACPI_IORT_ROOT_COMPLEX_ATS_UNSUPPORTED, // AtsAttribute + 0x0, // PciSegmentNumber + //0, //MemoryAddressSizeLimit + }, + { + 0x0000, // InputBase + 0xffff, // NumIds + 0x0000, // OutputBase + OFFSET_OF (SBSA_IO_REMAPPING_STRUCTURE, SmmuNode), // OutputRefer= ence + 0, // Flags + } + }; + + SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE Its =3D { + // EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE + { + // EFI_ACPI_6_0_IO_REMAPPING_NODE + { + EFI_ACPI_IORT_TYPE_ITS_GROUP, // Type + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE), // Length + 0, // Revision + 0, // Identifier + 0, // NumIdMappings + 0, // IdReference + }, + 0, // ITS count + }, + 0, // GIC ITS Identifiers + }; + + // Calculate the new table size based on the number of cores + TableSize =3D sizeof (EFI_ACPI_6_0_IO_REMAPPING_TABLE) + + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE) + + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE) + + sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) ; + + Status =3D gBS->AllocatePages ( + AllocateAnyPages, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (TableSize), + &PageAddress + ); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "Failed to allocate pages for IORT table\n")); + return EFI_OUT_OF_RESOURCES; + } + + New =3D (UINT8 *)(UINTN) PageAddress; + ZeroMem (New, TableSize); + + GicItsBase =3D PcdGet64 (PcdGicItsBase); + + if (GicItsBase > 0) { + Header.NumNodes =3D 3; + } + + // Add the ACPI Description table header + CopyMem (New, &Header, sizeof (EFI_ACPI_6_0_IO_REMAPPING_TABLE)); + ((EFI_ACPI_DESCRIPTION_HEADER*) New)->Length =3D TableSize; + New +=3D sizeof (EFI_ACPI_6_0_IO_REMAPPING_TABLE); + + // SMMUv3 Node + CopyMem (New, &Smmu3, sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NOD= E)); + New +=3D sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE); + + // RC Node + CopyMem (New, &Rc, sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE)); + New +=3D sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE); + + if (GicItsBase > 0) { + Its.Node.NumItsIdentifiers =3D 1; + + // ITS Node + CopyMem (New, &Its, sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE)= ); + New +=3D sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE); + } + + AcpiPlatformChecksum ((UINT8*) PageAddress, TableSize); + + Status =3D AcpiTable->InstallAcpiTable ( + AcpiTable, + (EFI_ACPI_COMMON_HEADER *)PageAddress, + TableSize, + &TableHandle + ); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "Failed to install IORT table\n")); + } + + return Status; +} + /* * A function that add the MADT ACPI table. IN EFI_ACPI_COMMON_HEADER *CurrentTable @@ -56,6 +248,7 @@ AddMadtTable ( UINT8 *New; UINT32 NumCores; UINT32 CoreIndex; + UINTN GicItsBase; =20 // Initialize MADT ACPI Header EFI_ACPI_6_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header =3D { @@ -91,11 +284,6 @@ AddMadtTable ( // Initialize GIC Redistributor Structure EFI_ACPI_6_0_GICR_STRUCTURE Gicr =3D SBSAQEMU_MADT_GICR_INIT(); =20 - // Initialize GIC ITS Structure - EFI_ACPI_6_5_GIC_ITS_STRUCTURE Gic_Its =3D SBSAQEMU_MADT_GIC_ITS_INIT(= 0); - - DEBUG ((DEBUG_ERROR, "itsBaseAddr is 0x%4x\n", PcdGet64 (PcdGicItsBase= ))); - // Get CoreCount which was determined eariler after parsing device tre= e NumCores =3D PcdGet32 (PcdCoreCount); =20 @@ -103,8 +291,17 @@ AddMadtTable ( TableSize =3D sizeof (EFI_ACPI_6_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEA= DER) + (sizeof (EFI_ACPI_6_0_GIC_STRUCTURE) * NumCores) + sizeof (EFI_ACPI_6_0_GIC_DISTRIBUTOR_STRUCTURE) + - sizeof (EFI_ACPI_6_0_GICR_STRUCTURE) + - sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE); + sizeof (EFI_ACPI_6_0_GICR_STRUCTURE); + + // Initialize GIC ITS Structure + EFI_ACPI_6_5_GIC_ITS_STRUCTURE Gic_Its =3D SBSAQEMU_MADT_GIC_ITS_INIT(= 0); + + GicItsBase =3D PcdGet64 (PcdGicItsBase); + DEBUG ((DEBUG_ERROR, "itsBaseAddr is 0x%8x\n", GicItsBase)); + + if (GicItsBase > 0) { + TableSize +=3D sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE); + } =20 Status =3D gBS->AllocatePages ( AllocateAnyPages, @@ -144,9 +341,11 @@ AddMadtTable ( CopyMem (New, &Gicr, sizeof (EFI_ACPI_6_0_GICR_STRUCTURE)); New +=3D sizeof (EFI_ACPI_6_0_GICR_STRUCTURE); =20 - // GIC ITS Structure - CopyMem (New, &Gic_Its, sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE)); - New +=3D sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE); + if (GicItsBase > 0) { + // GIC ITS Structure + CopyMem (New, &Gic_Its, sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE)); + New +=3D sizeof (EFI_ACPI_6_5_GIC_ITS_STRUCTURE); + } =20 AcpiPlatformChecksum ((UINT8*) PageAddress, TableSize); =20 @@ -317,7 +516,7 @@ AddSsdtTable ( } =20 /* - * A function that adds the SSDT ACPI table. + * A function that adds the PPTT ACPI table. */ EFI_STATUS AddPpttTable ( @@ -448,6 +647,11 @@ InitializeSbsaQemuAcpiDxe ( return Status; } =20 + Status =3D AddIortTable (AcpiTable); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add IORT table\n")); + } + Status =3D AddMadtTable (AcpiTable); if (EFI_ERROR(Status)) { DEBUG ((DEBUG_ERROR, "Failed to add MADT table\n")); diff --git a/Silicon/Qemu/SbsaQemu/AcpiTables/Iort.aslc b/Silicon/Qemu/Sb= saQemu/AcpiTables/Iort.aslc deleted file mode 100644 index ec4ce504efd1..000000000000 --- a/Silicon/Qemu/SbsaQemu/AcpiTables/Iort.aslc +++ /dev/null @@ -1,135 +0,0 @@ -/** @file - - Copyright (c) 2023, Linaro Ltd. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include -#include -#include - -#pragma pack(1) - -typedef struct { - EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE Node; - UINT32 Identifiers; -} SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE; - -typedef struct -{ - EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE SmmuNode; - EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE SmmuIdMap; -} SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE; - -typedef struct -{ - EFI_ACPI_6_0_IO_REMAPPING_RC_NODE RcNode; - EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE RcIdMap; -} SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE; - -typedef struct { - EFI_ACPI_6_0_IO_REMAPPING_TABLE Iort; - SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE ItsNode; - SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE SmmuNode; - SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE RcNode; -} SBSA_IO_REMAPPING_STRUCTURE; - -#pragma pack () - -STATIC SBSA_IO_REMAPPING_STRUCTURE Iort =3D { - { - SBSAQEMU_ACPI_HEADER(EFI_ACPI_6_0_IO_REMAPPING_TABLE_SIGNATURE, - SBSA_IO_REMAPPING_STRUCTURE, - EFI_ACPI_IO_REMAPPING_TABLE_REVISION_00), - 3, // NumNodes - sizeof(EFI_ACPI_6_0_IO_REMAPPING_TABLE), // NodeOffset - 0 // Reserved - }, - // SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE - { - // EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE - { - // EFI_ACPI_6_0_IO_REMAPPING_NODE - { - EFI_ACPI_IORT_TYPE_ITS_GROUP, // Type - sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE), // Length - 0, // Revision - 0, // Reserved - 0, // NumIdMappings - 0, // IdReference - }, - 1, // ITS count - }, - 0, // GIC ITS Identifiers - }, - // SMMU - { - // EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE - { - // EFI_ACPI_6_0_IO_REMAPPING_NODE - { - EFI_ACPI_IORT_TYPE_SMMUv3, // Type - sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE), // Length - 2, // Revision - 0, // Reserved - 1, // NumIdMapping - OFFSET_OF (SBSA_EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE, SmmuIdMap)= , // IdReference - }, - 0x60050000, // Base address - EFI_ACPI_IORT_SMMUv3_FLAG_COHAC_OVERRIDE, // Flags - 0, // Reserved - 0, // VATOS address - EFI_ACPI_IORT_SMMUv3_MODEL_GENERIC, // SMMUv3 Model - 74, // Event - 75, // Pri - 77, // Gerror - 76, // Sync - 0, // Proximity domain - 1, // DevIDMappingIndex - }, - // EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE - { - 0x0000, // InputBase - 0xffff, // NumIds - 0x0000, // OutputBase - OFFSET_OF (SBSA_IO_REMAPPING_STRUCTURE, ItsNode), // OutputRefer= ence - 0, // Flags - }, - }, - // SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE - { - // EFI_ACPI_6_0_IO_REMAPPING_RC_NODE - { - // EFI_ACPI_6_0_IO_REMAPPING_NODE - { - EFI_ACPI_IORT_TYPE_ROOT_COMPLEX, // Type - sizeof (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE), // Length - 0, // Revision - 0, // Reserved - 1, // NumIdMappings - OFFSET_OF (SBSA_EFI_ACPI_6_0_IO_REMAPPING_RC_NODE, RcIdMap) // = IdReference - }, - 1, // CacheCoherent - 0, // AllocationHints - 0, // Reserved - 0, // MemoryAccessFlags - EFI_ACPI_IORT_ROOT_COMPLEX_ATS_UNSUPPORTED, // AtsAttribute - 0x0, // PciSegmentNumber - //0, //MemoryAddressSizeLimit - }, - // EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE - { - 0x0000, // InputBase - 0xffff, // NumIds - 0x0000, // OutputBase - OFFSET_OF (SBSA_IO_REMAPPING_STRUCTURE, SmmuNode), // OutputRefer= ence - 0, // Flags - } - } -}; - -#pragma pack() - -VOID* CONST ReferenceAcpiTable =3D &Iort; \ No newline at end of file --=20 2.41.0