[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 14/17] libacpi: build ACPI MCFG table if requested


  • To: Thierry Escande <thierry.escande@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 29 Apr 2026 12:13:15 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JLhzOF7supAJ3qPCXfKOoAbySdrH7P6vKIlc01aPPqQ=; b=JBhYIOKE8viu7PFF3RxPKafCc7QWyiiPzvFgpZ/UGSjyau/39hPJz5BcimFYEhuvkgYcp3rMby4wQXGZBQD5od7g4JuiOGXqaYc5073LwoNQGhqtYYv/Ik4V2zjqJCdHWeZRBE5yCMBd9/m99z4yNHjoTL+2c8w7PIZiEvEQ3lqE7K5BD5j1OWGTkApUXwb2LTmXcYp0fX7Xvh3ely148CSOC/4emtZHaqGW6LVdUGCQe3osOa3jwmbjxfeA62n/EEuUU63xQdMSvcH6xFVIMcyDUr/BAV6KvlGIpnfUwUbfFuTnMf9396HamCP5vYQPQpoOGd5bnw4CPmZJKod6ig==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pH24UTzWbLJblT8PDPrtYGFT43xhN6FJpWkBtRxnky9f7wvJjKPpNJ6gdh2zDV7W1YRHRtVnEgpzGch20fNVFENegzZhAAzJjqCrw5IiUJSWxr0HJy8aDe0FDTCeEyGsYzMEcPk26zgTx9mPfjG29z4tohtQqMXSfRbo4IuhQX7iBOAu8er+5vN7tULoOsYXTk60RuF2lH/e3DPv+hbMnKlnSd8NvsbXVML8+qOAKPpKZ2VobPaNm0Oa7SGWhq+kIuJrZdbNGdjzJWt33hX5y5c1Y2E1G1HLVY0Eulpz8dAZc1y0WrNEaxSu3P4YodjTwDUIX1ufroEmKonZw+iNAA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Alexey Gerasimenko <x1917x@xxxxxxxxx>
  • Delivery-date: Wed, 29 Apr 2026 10:13:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Mar 13, 2026 at 04:35:04PM +0000, Thierry Escande wrote:
> This adds construct_mcfg() function to libacpi which allows to build MCFG
> table for a given mmconfig_addr/mmconfig_len pair if the ACPI_HAS_MCFG
> flag was specified in acpi_config struct.
> 
> The maximum bus number is calculated from mmconfig_size using
> MCFG_SIZE_TO_NUM_BUSES macro (1MByte of MMIO space per bus).
> 
> Signed-off-by: Alexey Gerasimenko <x1917x@xxxxxxxxx>
> Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxx>
> ---
>  tools/libacpi/acpi2_0.h | 17 ++++++++++++++++
>  tools/libacpi/build.c   | 43 +++++++++++++++++++++++++++++++++++++++++
>  tools/libacpi/libacpi.h |  6 ++++++
>  3 files changed, 66 insertions(+)
> 
> diff --git a/tools/libacpi/acpi2_0.h b/tools/libacpi/acpi2_0.h
> index 51623e2a8a..2b16bd636a 100644
> --- a/tools/libacpi/acpi2_0.h
> +++ b/tools/libacpi/acpi2_0.h
> @@ -442,6 +442,21 @@ struct acpi_20_slit {
>      uint8_t entry[0];
>  };
>  
> +/*
> + * PCI Express Memory Mapped Configuration Description Table
> + */
> +struct acpi_10_mcfg {
> +    struct acpi_header header;
> +    uint8_t reserved[8];
> +    struct {
> +        uint64_t base_address;
> +        uint16_t pci_segment;
> +        uint8_t  start_pci_bus_num;
> +        uint8_t  end_pci_bus_num;
> +        uint32_t reserved;
> +    } entries[1];
> +};
> +
>  /*
>   * Table Signatures.
>   */
> @@ -457,6 +472,7 @@ struct acpi_20_slit {
>  #define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')
>  #define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')
>  #define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T')
> +#define ACPI_MCFG_SIGNATURE     ASCII32('M','C','F','G')
>  
>  /*
>   * Table revision numbers.
> @@ -472,6 +488,7 @@ struct acpi_20_slit {
>  #define ACPI_1_0_FADT_REVISION 0x01
>  #define ACPI_2_0_SRAT_REVISION 0x01
>  #define ACPI_2_0_SLIT_REVISION 0x01
> +#define ACPI_1_0_MCFG_REVISION 0x01
>  
>  #pragma pack ()
>  
> diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c
> index 95188e217e..90080c76c4 100644
> --- a/tools/libacpi/build.c
> +++ b/tools/libacpi/build.c
> @@ -295,6 +295,37 @@ static struct acpi_20_slit *construct_slit(struct 
> acpi_ctxt *ctxt,
>      return slit;
>  }
>  
> +static struct acpi_10_mcfg *construct_mcfg(struct acpi_ctxt *ctxt,
> +                                        const struct acpi_config *config)
> +{
> +    struct acpi_10_mcfg *mcfg;
> +
> +    /* Warning: this code expects that we have only one PCI segment */

Not only one PCI segment, but just one ECAM region.  You could in
theory have multiple ECAM regions within a single PCI segment.

> +    mcfg = ctxt->mem_ops.alloc(ctxt, sizeof(*mcfg), 16);
> +    if ( !mcfg )
> +        return NULL;
> +
> +    memset(mcfg, 0, sizeof(*mcfg));
> +    mcfg->header.signature        = ACPI_MCFG_SIGNATURE;
> +    mcfg->header.revision         = ACPI_1_0_MCFG_REVISION;
> +    mcfg->header.creator_id       = ACPI_CREATOR_ID;
> +    mcfg->header.creator_revision = ACPI_CREATOR_REVISION;
> +    mcfg->header.length           = sizeof(*mcfg);
> +    mcfg->header.oem_revision     = ACPI_OEM_REVISION;
> +    fixed_strcpy(mcfg->header.oem_id, ACPI_OEM_ID);
> +    fixed_strcpy(mcfg->header.oem_table_id, ACPI_OEM_TABLE_ID);
> +
> +    mcfg->entries[0].base_address      = config->mmconfig_addr;
> +    mcfg->entries[0].pci_segment       = 0;
> +    mcfg->entries[0].start_pci_bus_num = 0;
> +    mcfg->entries[0].end_pci_bus_num   =
> +        MCFG_SIZE_TO_NUM_BUSES(config->mmconfig_size) - 1;


You might want to check that mmconfig_addr and mmconfig_size are set
ahead of using them?  Just in case some bogus toolstack/hvmloader sets
ACPI_HAS_MCFG without correctly populating the fields?

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.