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

Re: [PATCH 07/17] hvmloader: add basic Q35 support


  • To: Thierry Escande <thierry.escande@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 28 Apr 2026 15:15:36 +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=q83bzdTX69Ur04jV3IB5WpmjWLEIXSmzew5cCIO6l64=; b=mBrd2tpvqjrYAO0EMXNkNOkF1JePDj+GQ4dW11u4WsMUKwL1XjViblK57YzZp98Xj5axgn1vQUahdXLnBnTT15ag6BLszGRk8L9DLwMc0/V2JuPNArhSScBKXHdodMxLyQazLmRGPY4wreLh3IkWiCxlbyU3AZK3BVFvn11lKKuPN8rlweCc8zesbKTswkZQW1IaBybQURyPqT9NH4bPPXkPH+z9CABSU5VQMrDt/PSdYO9VSBroJCP7IZyYHVXO1IJu9lV2VX8F+xA7Tl0c0m2mgp3MZDvb4NZX7s6ddd9iaawRp1kXMbZ3341K0FAqLoe/MrdvEYOBNptyMLIQbg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UCYiv9jRI/T38x6j3bKrta0v65ACehG2V00fQm0znBPmavTZIEX725wS8wtVnt+cibXr9Pr/BmzrzsMpg3bSbajFN+MphsegXkl2ySmujv3TBAn336MZsov4I4J/FFQP6PunQ0FbdYn3yDqZcUd2QRf9DZgNOG8X2ZDFAEV8XBPJwG8fBWo1rbASPnyftwz7hg06/GUpgIsqR9PSBBQEllGM/EVDPiAnU/yA4YixvShmzybpGXeiCgvsPWWcSjHVOeD/BESbeQTsv01Lw5n05Y5roIVdfZlq79v1C9GUikBK7+olGUcIFYdcQLoZQ4qz9AYsnoTt+UIg4Ltzu9gq/g==
  • 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>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Alexey Gerasimenko <x1917x@xxxxxxxxx>
  • Delivery-date: Tue, 28 Apr 2026 13:16:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Mar 13, 2026 at 04:35:02PM +0000, Thierry Escande wrote:
> The current hvmloader implementation assumes a fixed PCI-to-ISA bridge
> at 00:01.0 (PIIX3). This patch introduces support for the ICH9 LPC
> bridge used in Q35 machine types, which resides at 00:1f.0.
> 
> It also initializes PIRQA...{PIRQD, PIRQH} routing accordingly to the
> emulated south bridge (either located on PCI_ISA_DEVFN or
> PCI_ICH9_LPC_DEVFN).
> 
> Signed-off-by: Alexey Gerasimenko <x1917x@xxxxxxxxx>
> Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxx>
> ---
>  tools/firmware/hvmloader/config.h   |  1 +
>  tools/firmware/hvmloader/pci.c      | 34 ++++++++++++++++++++++++-----
>  tools/firmware/hvmloader/pci_regs.h |  1 +
>  3 files changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/firmware/hvmloader/config.h 
> b/tools/firmware/hvmloader/config.h
> index c159db30ee..baaed91c7f 100644
> --- a/tools/firmware/hvmloader/config.h
> +++ b/tools/firmware/hvmloader/config.h
> @@ -54,6 +54,7 @@ extern uint32_t *cpu_to_apicid;
>  
>  #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
>  #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
> +#define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */

We should introduce a macro to generate BDFs more easily in the
hvmloader context.  Having them as plain numbers is not very friendly.

>  
>  #define ACPI_TIS_HDR_ADDRESS 0xFED40F00UL
>  
> diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
> index a76d051bdf..91c7fd2171 100644
> --- a/tools/firmware/hvmloader/pci.c
> +++ b/tools/firmware/hvmloader/pci.c
> @@ -84,6 +84,10 @@ static int find_next_rmrr(uint32_t base)
>      return next_rmrr;
>  }
>  
> +#define SCI_EN_IOPORT  (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x30)
> +#define GBL_SMI_EN     (1 << 0)
> +#define APMC_EN        (1 << 5)
> +
>  static void class_specific_pci_device_setup(uint16_t vendor_id,
>                                              uint16_t device_id,
>                                              uint16_t class,
> @@ -140,6 +144,17 @@ static void class_specific_pci_device_setup(uint16_t 
> vendor_id,
>              pci_writew(devfn, 0x42, 0x8000); /* enable IDE1 */
>          }
>          break;
> +    case PCI_CLASS_BRIDGE_ISA:
> +        /* LPC bridge */
> +        if ( vendor_id == 0x8086 && device_id == 0x2918 )

If you don't add parentheses around the equal comparisons please also
removing the existing ones when moving the code.  Also device ID would
batter be a constant with a proper name.

> +        {
> +            pci_writeb(devfn, 0x3c, 0x09); /* Hardcoded IRQ9 */
> +            pci_writeb(devfn, 0x3d, 0x01);

0x3c and 0x3d are PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN
respectively, let's please try to use the named constants when
available (or when they can be introduced).

> +            pci_writel(devfn, 0x40, ACPI_PM1A_EVT_BLK_ADDRESS_V1 | 1);
> +            pci_writeb(devfn, 0x44, 0x80); /* enable PM io space */
> +            outl(SCI_EN_IOPORT, inl(SCI_EN_IOPORT) | GBL_SMI_EN | APMC_EN);

Most of the above looks like black magic.  It's not like the context
of this function is great, most of the existing stuff is poorly
documented.  Can we get a bit more comments about what's this supposed
to do, and maybe a reference to the Intel specification that lists
where those PCI config space registers are coming from?

> +        }
> +        break;
>      }
>  }
>  
> @@ -152,6 +167,7 @@ void pci_setup(void)
>      uint16_t class, vendor_id, device_id;
>      unsigned int bar, pin, link, isa_irq;
>      uint8_t pci_devfn_decode_type[256] = {};
> +    int is_running_on_q35 = (machine_type == MACHINE_TYPE_Q35);

Maybe you can avoid that and instead simply store the BDF of the ISA
device?

unsigned int isa_bdf = (machine_type == MACHINE_TYPE_Q35) ? PCI_ICH9_LPC_DEVFN
                                                          : PCI_ISA_DEVFN;

Or if you really need it to be a boolean, let's make it:

bool is_q35 = ...

It makes no sense for it to be an int, and the naming could be shorter
IMO.

Thanks, Roger.



 


Rackspace

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