From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 628EC7803E3 for ; Thu, 25 Apr 2024 12:03:04 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Z7ZhpAxBYaiy2/kwr2mpRh16uGkpGZXnGVP1kznizGQ=; c=relaxed/simple; d=groups.io; h=From:Date:Subject:MIME-Version:Message-Id:References:In-Reply-To:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20240206; t=1714046583; v=1; b=vjBC3OAHAO6R/UjCEFamLEN3oWZjuwAgTMtuQTp/vDZKUELTVk2v6fP6flABphWPyC2Pb0Kx llgLBrmw+A87e8wgbNqTeyyf2akqPWLny6veOp2IO/2J5kZcsk6GEApiCpHSrIPNckTV3X2ZECv /LZNCytRHsN4LKiThKx06KP+bMr61dbNEZ561/lpHcKXssD2jvxpcd+86aZbZWgIy/i8VU1mzEI 3Mk1IWW/CQ963Es+h0vVzRkX1rhvubnkj1ULDyZnwYGlrPIHCWxlwdSq0Jr1auX3xj76/MClZdL u75C6mVCZD+j75tpneO6cLsgT9B8GJjri6ZEgtTKzp2nA== X-Received: by 127.0.0.2 with SMTP id bLKyYY7687511xq00Yb7duN4; Thu, 25 Apr 2024 05:03:03 -0700 X-Received: from muminek.juszkiewicz.com.pl (muminek.juszkiewicz.com.pl [213.251.184.221]) by mx.groups.io with SMTP id smtpd.web11.15142.1714046581400525921 for ; Thu, 25 Apr 2024 05:03:01 -0700 X-Received: from localhost (localhost [127.0.0.1]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTP id 7D2FB26072B; Thu, 25 Apr 2024 14:02:59 +0200 (CEST) X-Virus-Scanned: Debian amavis at juszkiewicz.com.pl X-Received: from muminek.juszkiewicz.com.pl ([127.0.0.1]) by localhost (muminek.juszkiewicz.com.pl [127.0.0.1]) (amavis, port 10024) with ESMTP id JPaov27HtwIv; Thu, 25 Apr 2024 14:02:57 +0200 (CEST) X-Received: from [192.168.168.24] (83.11.4.140.ipv4.supernova.orange.pl [83.11.4.140]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTPSA id 4401D260757; Thu, 25 Apr 2024 14:02:55 +0200 (CEST) From: "Marcin Juszkiewicz" Date: Thu, 25 Apr 2024 14:02:46 +0200 Subject: [edk2-devel] [PATCH edk2-platforms WIP 3/3] SbsaQemu: generate MCFG table MIME-Version: 1.0 Message-Id: <20240425-review-multiple-pcie-0425-v1-3-68fdfd781f9e@linaro.org> References: <20240425-review-multiple-pcie-0425-v1-0-68fdfd781f9e@linaro.org> In-Reply-To: <20240425-review-multiple-pcie-0425-v1-0-68fdfd781f9e@linaro.org> To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Graeme Gregory , Ray Ni , Marcin Juszkiewicz Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 25 Apr 2024 05:03:01 -0700 Resent-From: marcin.juszkiewicz@linaro.org Reply-To: devel@edk2.groups.io,marcin.juszkiewicz@linaro.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 4w247AtZ8h5DoSIqlm5MBK2Bx7686176AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=vjBC3OAH; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linaro.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io We want to have dynaminc PCI Express variables. Which forces us to generate MCFG from C code. Signed-off-by: Marcin Juszkiewicz --- 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 =20 [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 +#include #include #include =20 @@ -883,6 +884,83 @@ AddSsdtPcieTable ( return EFI_SUCCESS; } =20 +/** 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 =3D + SBSAQEMU_ACPI_HEADER ( + EFI_ACPI_6_3_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDR= ESS_DESCRIPTION_TABLE_SIGNATURE, + EFI_ACPI_DESCRIPTION_HEADER, + EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION + ); + + TableSize =3D sizeof (EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_= TABLE_HEADER) + + sizeof (EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_= BASE_ADDRESS_ALLOCATION_STRUCTURE); + + Status =3D 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 =3D (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 =3D TableSize; + New +=3D sizeof (EFI_ACPI_MEMORY= _MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER); + + EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCAT= ION_STRUCTURE *CfgPtr; + + CfgPtr =3D (VOID *)New; + + CfgPtr->BaseAddress =3D PcdGet64 (PcdPciExpressBaseAddress); + CfgPtr->PciSegmentGroupNumber =3D 0; + CfgPtr->StartBusNumber =3D PcdGet32 (PcdPciBusMin); + CfgPtr->EndBusNumber =3D PcdGet32 (PcdPciBusMax); + + New +=3D sizeof (EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BAS= E_ADDRESS_ALLOCATION_STRUCTURE); + + // Perform Checksum + AcpiTableChecksum ((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 MCFG table\n")); + } + + return Status; +} + =20 EFI_STATUS EFIAPI @@ -951,6 +1029,11 @@ InitializeSbsaQemuAcpiDxe ( DEBUG ((DEBUG_ERROR, "Failed to add SSDT table\n")); } =20 + Status =3D AddMcfgTable (AcpiTable); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add MCFG table\n")); + } + =20 return EFI_SUCCESS; } diff --git a/Silicon/Qemu/SbsaQemu/AcpiTables/Mcfg.aslc b/Silicon/Qemu/Sbsa= Qemu/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 -#include -#include - -#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_ALLOCAT= ION_STRUCTURE Structure[1]; -} EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE; - -EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = =3D { - { - SBSAQEMU_ACPI_HEADER ( - EFI_ACPI_6_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDR= ESS_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 =3D &Mcfg; --=20 2.44.0 -=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 (#118289): https://edk2.groups.io/g/devel/message/118289 Mute This Topic: https://groups.io/mt/105728625/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-