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

Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)


  • To: Thierry Escande <thierry.escande@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 28 Apr 2026 12:39:07 +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=7IkM6DYJPWEOkk4zTRWkdbZ5Vl5qZPKJws+9gqBpxn8=; b=rEbOoikp3spN8Vd+S2sjJfYNgIbGWPy0gsAdbKc3kPSGPj7caF3c5Ekdmuj0Bsyxb86wz1ilxOtBWZ66drtB6LOdyav7rUUf1T0RFVxVvp+fzKnpLZdHIpfexzo2ej2BJtNlO2t83EXbbkA1gmHAQESBqPH8PfomGqfv4mjlD7xVipUNXwWC2yXZANhC1aqwzKJ4zBpCCTjCPImAJAHmTusoJKevyKHo7nqKwGY2PTZ/+H/crLi9bt6hovlKp0BSFiLegk7HvIq26+S5aZk9JhASPPs/IPtWCWWZxADeh3F/LqH9j06E0y62OV3b48rMuYC1X2mZlUsSvPDDeTNxJQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ObeP+bLMvvF03rCUFnBjJTaExIUipBAPsmvd/4i+wOWiLimCpyD1VZ+S9lISqz01+Gju8VQ74bQgtIa6Im270JD6c/JvNAMDsDvzTKAwlVsmaTW1OUwAEymTEFgpaIo6nFZ5rJfXG3xHl0QXsgKxyfS/9yf9F06zttiAC0yUn5XunZ9cpQhwxFUffqB6+INxX0Ctu5sUVQGoJ+UzUsbyYdUfJzM2zhltNvoKISwJKLXqhxUbLXCQNGb3zn4eykeWLvukRzjyhMEKP/ZU6aG4OGxrtX5i7w4m4R29/VNa4lxKpds9XOe9QB+Y9d5sw+r4RGY2W03VzhKQNTCOLSsnuw==
  • 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 10:39:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Mar 13, 2026 at 04:35:01PM +0000, Thierry Escande wrote:
> This adds a new function init_pc_machine_type() which allows to
> determine and set the emulated chipset type. Possible values are
> MACHINE_TYPE_I440 and MACHINE_TYPE_Q35 and stored in the global variable
> machine_type.
> 
> The machine_type variable will be used from multiple places in following
> commits.

Is this initialization something that OVMF or SeaBIOS also does?
(maybe not for Xen ATM)

Asking myself because as said earlier we want to possibly get rid of
hvmloader, plus we will want ECAM support in PVH at some point.

> Signed-off-by: Alexey Gerasimenko <x1917x@xxxxxxxxx>

Same as previous patch, if the first SoB is from Alexey the From:
(patch author) should also match.

> Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxx>
> ---
>  tools/firmware/hvmloader/hvmloader.c |  2 ++
>  tools/firmware/hvmloader/pci_regs.h  |  4 +++
>  tools/firmware/hvmloader/util.c      | 42 ++++++++++++++++++++++++++++
>  tools/firmware/hvmloader/util.h      | 11 ++++++++
>  4 files changed, 59 insertions(+)
> 
> diff --git a/tools/firmware/hvmloader/hvmloader.c 
> b/tools/firmware/hvmloader/hvmloader.c
> index 6d23150fc9..626cc53649 100644
> --- a/tools/firmware/hvmloader/hvmloader.c
> +++ b/tools/firmware/hvmloader/hvmloader.c
> @@ -332,6 +332,8 @@ int main(void)
>  
>      init_hypercalls();
>  
> +    init_pc_machine_type();
> +
>      memory_map_setup();
>  
>      xenbus_setup();
> diff --git a/tools/firmware/hvmloader/pci_regs.h 
> b/tools/firmware/hvmloader/pci_regs.h
> index 7bf2d873ab..4d4dc0cd01 100644
> --- a/tools/firmware/hvmloader/pci_regs.h
> +++ b/tools/firmware/hvmloader/pci_regs.h
> @@ -107,6 +107,10 @@
>  
>  #define PCI_INTEL_OPREGION 0xfc /* 4 bits */
>  
> +#define PCI_VENDOR_ID_INTEL              0x8086
> +#define PCI_DEVICE_ID_INTEL_82441        0x1237
> +#define PCI_DEVICE_ID_INTEL_Q35_MCH      0x29c0

In Xen we have a separate file for vendor and device IDs, called
pci_ids.h.  Maybe it would be better to use a similar approach in
hvmloader, and keep pci_regs.h only containing PCI register offsets.

> +
>  #endif /* __HVMLOADER_PCI_REGS_H__ */
>  
>  /*
> diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
> index f1ed1eb48d..f9116bea4d 100644
> --- a/tools/firmware/hvmloader/util.c
> +++ b/tools/firmware/hvmloader/util.c
> @@ -22,6 +22,7 @@
>  #include "hypercall.h"
>  #include "ctype.h"
>  #include "vnuma.h"
> +#include "pci_regs.h"
>  #include <acpi2_0.h>
>  #include <libacpi.h>
>  #include <stdint.h>
> @@ -648,6 +649,47 @@ void __bug(const char *file, int line)
>      crash();
>  }
>  
> +machine_type_t machine_type;
> +
> +void init_pc_machine_type(void)

Since detection is done based on PCI device IDs, it might be better
placed in pci.c, and so you don't need to include pci_regs.h in
util.c.

> +{
> +    uint16_t vendor_id;
> +    uint16_t device_id;
> +
> +    if ( machine_type != MACHINE_TYPE_UNDEFINED )
> +        return;
> +
> +    vendor_id = pci_readw(0, PCI_VENDOR_ID);
> +    device_id = pci_readw(0, PCI_DEVICE_ID);
> +
> +    /* only Intel platforms are emulated currently */
> +    if ( vendor_id != PCI_VENDOR_ID_INTEL )
> +        goto error;
> +
> +    switch ( device_id )
> +    {
> +    case PCI_DEVICE_ID_INTEL_82441:
> +        machine_type = MACHINE_TYPE_I440;
> +        printf("Detected i440 chipset\n");
> +        break;
> +
> +    case PCI_DEVICE_ID_INTEL_Q35_MCH:
> +        machine_type = MACHINE_TYPE_Q35;
> +        printf("Detected Q35 chipset\n");
> +        break;
> +
> +    default:
> +        goto error;
> +    }
> +
> +    return;
> +
> +error:
> +    printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",

We don't usually use the h suffix in hex numbers in hvmloader, it's
more common to prefix them with 0x, so I would recommend to use the %#06x
formatter instead.

Thanks, Roger.



 


Rackspace

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