From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Thierry Escande <thierry.escande@vates.tech>
Cc: xen-devel@lists.xenproject.org, Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Anthony PERARD <anthony.perard@vates.tech>
Subject: Re: [PATCH 06/17] hvmloader: Move pci devices setup to a separate function
Date: Tue, 28 Apr 2026 14:48:10 +0200 [thread overview]
Message-ID: <afCsimOpaMIr50Ua@macbook.local> (raw)
In-Reply-To: <20260313163455.790692-7-thierry.escande@vates.tech>
On Fri, Mar 13, 2026 at 04:35:02PM +0000, Thierry Escande wrote:
> For readability and code simplification, this patch moves PCI-device
> specific initializations out of the pci_setup() function to a new
> function class_specific_pci_device_setup().
AFAICT this is a non-functional change. Should likely be mentioned in
the commit message to avoid any doubts.
> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
> ---
> tools/firmware/hvmloader/pci.c | 117 +++++++++++++++-------------
> tools/firmware/hvmloader/pci_regs.h | 4 +
> 2 files changed, 68 insertions(+), 53 deletions(-)
>
> diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
> index c41c8d946a..a76d051bdf 100644
> --- a/tools/firmware/hvmloader/pci.c
> +++ b/tools/firmware/hvmloader/pci.c
> @@ -84,12 +84,71 @@ static int find_next_rmrr(uint32_t base)
> return next_rmrr;
> }
>
> +static void class_specific_pci_device_setup(uint16_t vendor_id,
> + uint16_t device_id,
> + uint16_t class,
It's a bit weird to pass the class value into the function, the value
is only used inside the function itself, and hence could be fetched
inside the function as the device BDF is provided as parameters?
> + uint8_t bus,
> + uint8_t devfn, uint8_t *vga_devfn)
> +{
> + switch ( class )
> + {
> + case PCI_CLASS_DISPLAY_VGA:
> + /* If emulated VGA is found, preserve it as primary VGA. */
> + if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
> + {
> + *vga_devfn = devfn;
> + virtual_vga = VGA_std;
> + }
> + else if ( (vendor_id == 0x1013) && (device_id == 0xb8) )
Since you introduce defines for the device classes, could you also
introduce defines for the vendor and device IDs used here?
> + {
> + *vga_devfn = devfn;
> + virtual_vga = VGA_cirrus;
> + }
> + else if ( virtual_vga == VGA_none )
> + {
> + *vga_devfn = devfn;
> + virtual_vga = VGA_pt;
> + if ( vendor_id == 0x8086 )
This one is PCI_VENDOR_ID_INTEL, also a couple of more instances below.
> + {
> + igd_opregion_pgbase = mem_hole_alloc(IGD_OPREGION_PAGES);
> + /*
> + * Write the the OpRegion offset to give the opregion
> + * address to the device model. The device model will trap
> + * and map the OpRegion at the give address.
> + */
> + pci_writel(*vga_devfn, PCI_INTEL_OPREGION,
> + igd_opregion_pgbase << PAGE_SHIFT);
> + }
> + }
> + break;
Newlines after break statements.
> + case PCI_CLASS_BRIDGE_OTHER:
> + /* PIIX4 ACPI PM. Special device with special PCI config space. */
> + ASSERT((vendor_id == 0x8086) && (device_id == 0x7113));
> + pci_writew(devfn, 0x20, 0x0000); /* No smb bus IO enable */
> + pci_writew(devfn, 0xd2, 0x0000); /* No smb bus IO enable */
> + pci_writew(devfn, 0x22, 0x0000);
> + pci_writew(devfn, 0x3c, 0x0009); /* Hardcoded IRQ9 */
> + pci_writew(devfn, 0x3d, 0x0001);
> + pci_writel(devfn, 0x40, ACPI_PM1A_EVT_BLK_ADDRESS_V1 | 1);
> + pci_writeb(devfn, 0x80, 0x01); /* enable PM io space */
> + break;
> + case PCI_CLASS_STORAGE_IDE:
> + if ( vendor_id == 0x8086 )
> + {
> + /* Intel ICHs since PIIX3: enable IDE legacy mode. */
> + pci_writew(devfn, 0x40, 0x8000); /* enable IDE0 */
> + pci_writew(devfn, 0x42, 0x8000); /* enable IDE1 */
> + }
> + break;
> + }
> +}
> +
> void pci_setup(void)
> {
> uint8_t is_64bar, using_64bar, bar64_relocate = 0;
> uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;
> uint64_t base, bar_sz, bar_sz_upper, mmio_total = 0;
> - uint32_t vga_devfn = 256;
> + uint8_t vga_devfn = 0xff;
> uint16_t class, vendor_id, device_id;
> unsigned int bar, pin, link, isa_irq;
> uint8_t pci_devfn_decode_type[256] = {};
> @@ -170,57 +229,9 @@ void pci_setup(void)
> ASSERT((devfn != PCI_ISA_DEVFN) ||
> ((vendor_id == 0x8086) && (device_id == 0x7000)));
>
> - switch ( class )
> - {
> - case 0x0300:
> - /* If emulated VGA is found, preserve it as primary VGA. */
> - if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
> - {
> - vga_devfn = devfn;
> - virtual_vga = VGA_std;
> - }
> - else if ( (vendor_id == 0x1013) && (device_id == 0xb8) )
> - {
> - vga_devfn = devfn;
> - virtual_vga = VGA_cirrus;
> - }
> - else if ( virtual_vga == VGA_none )
> - {
> - vga_devfn = devfn;
> - virtual_vga = VGA_pt;
> - if ( vendor_id == 0x8086 )
> - {
> - igd_opregion_pgbase = mem_hole_alloc(IGD_OPREGION_PAGES);
> - /*
> - * Write the the OpRegion offset to give the opregion
> - * address to the device model. The device model will trap
> - * and map the OpRegion at the give address.
> - */
> - pci_writel(vga_devfn, PCI_INTEL_OPREGION,
> - igd_opregion_pgbase << PAGE_SHIFT);
> - }
> - }
> - break;
> - case 0x0680:
> - /* PIIX4 ACPI PM. Special device with special PCI config space. */
> - ASSERT((vendor_id == 0x8086) && (device_id == 0x7113));
> - pci_writew(devfn, 0x20, 0x0000); /* No smb bus IO enable */
> - pci_writew(devfn, 0xd2, 0x0000); /* No smb bus IO enable */
> - pci_writew(devfn, 0x22, 0x0000);
> - pci_writew(devfn, 0x3c, 0x0009); /* Hardcoded IRQ9 */
> - pci_writew(devfn, 0x3d, 0x0001);
> - pci_writel(devfn, 0x40, ACPI_PM1A_EVT_BLK_ADDRESS_V1 | 1);
> - pci_writeb(devfn, 0x80, 0x01); /* enable PM io space */
> - break;
> - case 0x0101:
> - if ( vendor_id == 0x8086 )
> - {
> - /* Intel ICHs since PIIX3: enable IDE legacy mode. */
> - pci_writew(devfn, 0x40, 0x8000); /* enable IDE0 */
> - pci_writew(devfn, 0x42, 0x8000); /* enable IDE1 */
> - }
> - break;
> - }
> + class_specific_pci_device_setup(vendor_id, device_id, class,
> + 0 /* virt_bus support TBD */,
> + devfn, &vga_devfn);
>
> /*
> * It is recommended that BAR programming be done whilst decode
> @@ -583,7 +594,7 @@ void pci_setup(void)
> ((pci_hi_mem_start & -pci_hi_mem_start) - 1)) + 1;
> }
>
> - if ( vga_devfn != 256 )
> + if ( vga_devfn != 0xff )
> {
> /*
> * VGA registers live in I/O space so ensure that primary VGA
> diff --git a/tools/firmware/hvmloader/pci_regs.h b/tools/firmware/hvmloader/pci_regs.h
> index 4d4dc0cd01..c94278855b 100644
> --- a/tools/firmware/hvmloader/pci_regs.h
> +++ b/tools/firmware/hvmloader/pci_regs.h
> @@ -111,6 +111,10 @@
> #define PCI_DEVICE_ID_INTEL_82441 0x1237
> #define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0
>
> +#define PCI_CLASS_STORAGE_IDE 0x0101
> +#define PCI_CLASS_DISPLAY_VGA 0x0300
> +#define PCI_CLASS_BRIDGE_OTHER 0x0680
As mentioned in a previous patch, this would better be placed in a
pci_ids.h header.
Thanks, Roger.
next prev parent reply other threads:[~2026-04-28 12:48 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 16:35 [PATCH 00/17] Q35 initial support for HVM guests Thierry Escande
2026-03-13 16:35 ` [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts Thierry Escande
2026-04-28 9:05 ` Roger Pau Monné
2026-05-04 14:34 ` Jan Beulich
2026-05-04 14:35 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 06/17] hvmloader: Move pci devices setup to a separate function Thierry Escande
2026-04-28 12:48 ` Roger Pau Monné [this message]
2026-05-04 14:52 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 02/17] libacpi: new DSDT ACPI table for Q35 Thierry Escande
2026-04-28 10:17 ` Roger Pau Monné
2026-05-04 14:39 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 05/17] hvmloader: add Q35 DSDT table loading Thierry Escande
2026-04-28 11:08 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35) Thierry Escande
2026-04-28 10:39 ` Roger Pau Monné
2026-05-04 10:58 ` Jan Beulich
2026-05-04 14:43 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 08/17] hvmloader: Extend PCI BAR struct Thierry Escande
2026-04-28 13:31 ` Roger Pau Monné
2026-05-04 15:01 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 10/17] hvmloader: Add support for HVMOP_set|get_ecam_space hypercalls Thierry Escande
2026-04-28 14:14 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 07/17] hvmloader: add basic Q35 support Thierry Escande
2026-04-28 13:15 ` Roger Pau Monné
2026-05-10 23:32 ` Alexey G
2026-05-04 14:55 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls Thierry Escande
2026-04-28 13:59 ` Roger Pau Monné
2026-05-04 11:09 ` Jan Beulich
2026-05-04 15:12 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 14/17] libacpi: build ACPI MCFG table if requested Thierry Escande
2026-04-29 10:13 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 13/17] libxl: Add xen-platform device for Q35 machine Thierry Escande
2026-03-13 16:35 ` [PATCH 12/17] libxl: Q35 support (new option device_model_machine) Thierry Escande
2026-04-29 10:01 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole Thierry Escande
2026-04-29 9:29 ` Roger Pau Monné
2026-05-04 11:11 ` Jan Beulich
2026-05-04 12:23 ` Roger Pau Monné
2026-05-04 12:36 ` Jan Beulich
2026-03-13 16:35 ` [PATCH 15/17] hvmloader: Set MCFG in ACPI table Thierry Escande
2026-04-29 12:33 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 04/17] hvmloader: add ACPI enabling for Q35 Thierry Escande
2026-04-28 10:48 ` Roger Pau Monné
2026-05-05 13:58 ` Alexey G
2026-05-05 14:25 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 17/17] docs: provide description for device_model_machine option Thierry Escande
2026-04-29 12:43 ` Roger Pau Monné
2026-03-13 16:35 ` [PATCH 16/17] Handle PCIe ECAM space access from guests Thierry Escande
2026-04-29 12:42 ` Roger Pau Monné
2026-05-04 15:22 ` Jan Beulich
2026-03-15 22:43 ` [PATCH 00/17] Q35 initial support for HVM guests Alexey G
2026-04-28 7:48 ` Roger Pau Monné
2026-05-04 10:45 ` Jan Beulich
2026-05-05 5:48 ` Jan Beulich
2026-05-05 5:49 ` Jan Beulich
2026-05-05 13:29 ` Alexey G
2026-05-05 13:07 ` Alexey G
2026-05-05 14:15 ` Roger Pau Monné
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afCsimOpaMIr50Ua@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=thierry.escande@vates.tech \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.