We want to have dynaminc PCI Express variables. Which forces us to generate MCFG from C code.
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiew...@linaro.org> --- Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf | 1 - .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 83 ++++++++++++++++++++ Silicon/Qemu/SbsaQemu/AcpiTables/Mcfg.aslc | 43 ---------- 3 files changed, 83 insertions(+), 44 deletions(-) diff --git a/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf b/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf index 8d4905362edc..37abf2f4c512 100644 --- a/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf +++ b/Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf @@ -19,7 +19,6 @@ [Sources] Dbg2.aslc Dsdt.asl Fadt.aslc - Mcfg.aslc Spcr.aslc [Packages] diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c index f3d5dc9e9ba7..6c7913eead81 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c @@ -7,6 +7,7 @@ * **/ #include <IndustryStandard/IoRemappingTable.h> +#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h> #include <IndustryStandard/SbsaQemuAcpi.h> #include <IndustryStandard/SbsaQemuPlatformVersion.h> @@ -883,6 +884,83 @@ AddSsdtPcieTable ( return EFI_SUCCESS; } +/** Adds the MCFG ACPI table. + + @param AcpiTable The ACPI Table. + @param PcieCfgData PCIe configuration data. + @param NumPcieSegments Number of PCIe segments. + + @return EFI_SUCCESS on success, or an error code. + +**/ +STATIC +EFI_STATUS +AddMcfgTable ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable + ) +{ + EFI_STATUS Status; + UINTN TableHandle; + UINT32 TableSize; + EFI_PHYSICAL_ADDRESS PageAddress; + UINT8 *New; + + EFI_ACPI_DESCRIPTION_HEADER Header = + SBSAQEMU_ACPI_HEADER ( + EFI_ACPI_6_3_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE, + EFI_ACPI_DESCRIPTION_HEADER, + EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION + ); + + TableSize = sizeof (EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER) + + sizeof (EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE); + + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (TableSize), + &PageAddress + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to allocate pages for MCFG table\n")); + return EFI_OUT_OF_RESOURCES; + } + + New = (UINT8 *)(UINTN)PageAddress; + ZeroMem (New, TableSize); + + // Add the ACPI Description table header + CopyMem (New, &Header, sizeof (EFI_ACPI_DESCRIPTION_HEADER)); + ((EFI_ACPI_DESCRIPTION_HEADER *)New)->Length = TableSize; + New += sizeof (EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER); + + EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE *CfgPtr; + + CfgPtr = (VOID *)New; + + CfgPtr->BaseAddress = PcdGet64 (PcdPciExpressBaseAddress); + CfgPtr->PciSegmentGroupNumber = 0; + CfgPtr->StartBusNumber = PcdGet32 (PcdPciBusMin); + CfgPtr->EndBusNumber = PcdGet32 (PcdPciBusMax); + + New += sizeof (EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE); + + // Perform Checksum + AcpiTableChecksum ((UINT8 *)PageAddress, TableSize); + + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + (EFI_ACPI_COMMON_HEADER *)PageAddress, + TableSize, + &TableHandle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to install MCFG table\n")); + } + + return Status; +} + EFI_STATUS EFIAPI @@ -951,6 +1029,11 @@ InitializeSbsaQemuAcpiDxe ( DEBUG ((DEBUG_ERROR, "Failed to add SSDT table\n")); } + Status = AddMcfgTable (AcpiTable); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add MCFG table\n")); + } + return EFI_SUCCESS; } diff --git a/Silicon/Qemu/SbsaQemu/AcpiTables/Mcfg.aslc b/Silicon/Qemu/SbsaQemu/AcpiTables/Mcfg.aslc deleted file mode 100644 index 289f4ad4ea3a..000000000000 --- a/Silicon/Qemu/SbsaQemu/AcpiTables/Mcfg.aslc +++ /dev/null @@ -1,43 +0,0 @@ -/** @file -* ACPI Memory mapped configuration space base address Description Table (MCFG). -* -* Copyright (c) 2020, Linaro Limited. All rights reserved. -* -* SPDX-License-Identifier: BSD-2-Clause-Patent -**/ - -#include <IndustryStandard/Acpi.h> -#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h> -#include <IndustryStandard/SbsaQemuAcpi.h> - -#pragma pack(push, 1) - -typedef struct { - EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER Header; - EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE Structure[1]; -} EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE; - -EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = { - { - SBSAQEMU_ACPI_HEADER ( - EFI_ACPI_6_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE, - EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE, - EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION), - EFI_ACPI_RESERVED_QWORD - }, - { - { - FixedPcdGet32 (PcdPciExpressBaseAddress), - 0, - FixedPcdGet32 (PcdPciBusMin), - FixedPcdGet32 (PcdPciBusMax), - EFI_ACPI_RESERVED_DWORD - } - } -}; - -#pragma pack(pop) - -// Reference the table being generated to prevent the optimizer -// from removing the data structure from the executable -VOID* CONST ReferenceAcpiTable = &Mcfg; -- 2.44.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118289): https://edk2.groups.io/g/devel/message/118289 Mute This Topic: https://groups.io/mt/105728625/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-