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 0DD8D94147F for ; Tue, 28 May 2024 10:31:59 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7MZ/SI0vDlI3vVc+N14ilMGI9tW2FesV48UFyNFA5bg=; 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=1716892319; v=1; b=gpduOOuc7E9sA2P7xDPGhS+QEZoTzB9S03icIsEGr3k2xg0IhyUz5SJ0sU4+dQou7Kaq6wgM tlth++Vn+whctc5tQrgqW4Y5KQ589NYRcBY2xz6dSdyMn6rV1kA5n5t1kyUxVKCgXth8omPzMzh I+XeYZoVgOrxAfzklmZToWAnb4bT+dw1CuJJCOu+u5Y6XqTsZJs3uMnNaa0/mdUORtqj9sLTzGJ uqrfbR8YsdTEsvpHRMsycYz+zHNHLK4QCjY/f8Y4CnDmQ5Z/iSlCV98JBvwkStYtyWfEDjzi2kP yXxz/vHH1ZgfRqST7i/CDxG03ApbLrpF7yedwvj+z7vZw== X-Received: by 127.0.0.2 with SMTP id ZV8jYY7687511xxfpNt3xJc9; Tue, 28 May 2024 03:31:58 -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.19090.1716892317559671946 for ; Tue, 28 May 2024 03:31:57 -0700 X-Received: from localhost (localhost [127.0.0.1]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTP id 7B6852610DF; Tue, 28 May 2024 12:31:55 +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 z3cVxsJC4a3n; Tue, 28 May 2024 12:31:53 +0200 (CEST) X-Received: from applejack.lan (83.11.37.15.ipv4.supernova.orange.pl [83.11.37.15]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTPSA id B5FCC26110A; Tue, 28 May 2024 12:31:51 +0200 (CEST) From: "Marcin Juszkiewicz" Date: Tue, 28 May 2024 12:31:40 +0200 Subject: [edk2-devel] [PATCH edk2-platforms v2 3/3] SbsaQemu: generate MCFG table MIME-Version: 1.0 Message-Id: <20240528-review-multiple-pcie-0425-v2-3-e2ec9f098a78@linaro.org> References: <20240528-review-multiple-pcie-0425-v2-0-e2ec9f098a78@linaro.org> In-Reply-To: <20240528-review-multiple-pcie-0425-v2-0-e2ec9f098a78@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: Tue, 28 May 2024 03:31:57 -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: UfTZ8JD2Rtm6EdEVSvyxL79gx7686176AA= 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=gpduOOuc; 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.45.1 -=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 (#119303): https://edk2.groups.io/g/devel/message/119303 Mute This Topic: https://groups.io/mt/106345972/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-