From nobody Mon Nov 23 04:26:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.dev Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793798356048922.2736923731151; Wed, 4 Nov 2026 05:19:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOasl-0006z3-JA; Wed, 04 Nov 2026 08:18:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOasj-0006yV-RL for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:25 -0500 Received: from out-231.mta1.migadu.com ([95.215.58.231] helo=mta1.migadu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOash-0002wv-Ne for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:25 -0500 Received: by smtp.migadu.com with ESMTPS id ca093861ca1722df; Wed, 04 Nov 2026 13:18:21 +0000 X-Envelope-To: qemu-devel@nongnu.org DKIM-Signature: a=rsa-sha256; bh=/Zbc206y+Wwx6FSLQLyyZoAsYFqMOX7ooxL5fONOWAU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793798301; v=1; x=1794403101; b=W9BRdxF8q2yEjKxFQiTNr7NIwjxgYDvqurPfiersFnSTXM+dXRxV2YBPbfFzmTX64ChU0YVI 0oD4FCVKJe1cvC+fNmOzradD74zUWn5DnIwsWS9h0X2xz9AEct23gXqvsOkDqCLDVJOw75zQ0iu Q0X3TH5UWvlXvA1k100OB2TQ= X-Envelope-To: qemu-devel@nongnu.org X-Mizu-Trace-ID: ca093861ca1722df X-Migadu-Flow: FLOW_OUT From: Junjie Cao To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, philmd@oss.qualcomm.com, zhao1.liu@intel.com, richard.henderson@linaro.org, farosas@suse.de, lvivier@redhat.com, pierrick.bouvier@oss.qualcomm.com, thuth@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, berrange@redhat.com, marcandre.lureau@redhat.com, deller@gmx.de, clg@redhat.com, jamin_lin@aspeedtech.com, junjie.cao@linux.dev Subject: [RFC PATCH 1/4] hw/i386: add 12.0 machine types (NOT FOR MERGE) Date: Wed, 4 Nov 2026 07:18:07 -0600 Message-ID: <20261104131810.2063834-2-junjie.cao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104131810.2063834-1-junjie.cao@linux.dev> References: <20261104131810.2063834-1-junjie.cao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=95.215.58.231; envelope-from=junjie.cao@linux.dev; helo=mta1.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793798358499158500 Content-Type: text/plain; charset="utf-8" Placeholder for the rest of the series, which changes a default on the next machine version. The real "hw: add compat machines for 12.0" covers every versioned board; this only adds pc-i440fx-12.0 and pc-q35-12.0. Drop it once that commit lands. Signed-off-by: Junjie Cao --- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 13 +++++++++++-- hw/i386/pc_q35.c | 13 +++++++++++-- include/hw/core/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index ed9bf8f500..5305521ac5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -41,6 +41,9 @@ #include "qemu/audio.h" #include "hw/arm/smmuv3.h" =20 +GlobalProperty hw_compat_11_2[] =3D {}; +const size_t hw_compat_11_2_len =3D G_N_ELEMENTS(hw_compat_11_2); + GlobalProperty hw_compat_11_1[] =3D { { "sysbus-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4737eb471c..8a6b7978cc 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -75,6 +75,9 @@ #include "hw/xen/xen-bus.h" #endif =20 +GlobalProperty pc_compat_11_2[] =3D {}; +const size_t pc_compat_11_2_len =3D G_N_ELEMENTS(pc_compat_11_2); + GlobalProperty pc_compat_11_1[] =3D {}; const size_t pc_compat_11_1_len =3D G_N_ELEMENTS(pc_compat_11_1); =20 diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 446590e4e5..c0ddf6011f 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -397,12 +397,21 @@ static void pc_i440fx_machine_options(MachineClass *m) pc_piix_compat_defaults, pc_piix_compat_defaults_len); } =20 -static void pc_i440fx_machine_11_2_options(MachineClass *m) +static void pc_i440fx_machine_12_0_options(MachineClass *m) { pc_i440fx_machine_options(m); } =20 -DEFINE_I440FX_MACHINE_AS_LATEST(11, 2); +DEFINE_I440FX_MACHINE_AS_LATEST(12, 0); + +static void pc_i440fx_machine_11_2_options(MachineClass *m) +{ + pc_i440fx_machine_12_0_options(m); + compat_props_add(m->compat_props, hw_compat_11_2, hw_compat_11_2_len); + compat_props_add(m->compat_props, pc_compat_11_2, pc_compat_11_2_len); +} + +DEFINE_I440FX_MACHINE(11, 2); =20 static void pc_i440fx_machine_11_1_options(MachineClass *m) { diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index c3ce9c5649..e302ff283c 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -378,12 +378,21 @@ static void pc_q35_machine_options(MachineClass *m) pc_q35_compat_defaults, pc_q35_compat_defaults_len); } =20 -static void pc_q35_machine_11_2_options(MachineClass *m) +static void pc_q35_machine_12_0_options(MachineClass *m) { pc_q35_machine_options(m); } =20 -DEFINE_Q35_MACHINE_AS_LATEST(11, 2); +DEFINE_Q35_MACHINE_AS_LATEST(12, 0); + +static void pc_q35_machine_11_2_options(MachineClass *m) +{ + pc_q35_machine_12_0_options(m); + compat_props_add(m->compat_props, hw_compat_11_2, hw_compat_11_2_len); + compat_props_add(m->compat_props, pc_compat_11_2, pc_compat_11_2_len); +} + +DEFINE_Q35_MACHINE(11, 2); =20 static void pc_q35_machine_11_1_options(MachineClass *m) { diff --git a/include/hw/core/boards.h b/include/hw/core/boards.h index d0e4ad9820..2f2327079c 100644 --- a/include/hw/core/boards.h +++ b/include/hw/core/boards.h @@ -830,6 +830,9 @@ compat_props_add(GPtrArray *arr, } } =20 +extern GlobalProperty hw_compat_11_2[]; +extern const size_t hw_compat_11_2_len; + extern GlobalProperty hw_compat_11_1[]; extern const size_t hw_compat_11_1_len; =20 diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 844ae83578..caceddc74b 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -214,6 +214,9 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, siz= e_t flash_size); /* sgx.c */ void pc_machine_init_sgx_epc(PCMachineState *pcms); =20 +extern GlobalProperty pc_compat_11_2[]; +extern const size_t pc_compat_11_2_len; + extern GlobalProperty pc_compat_11_1[]; extern const size_t pc_compat_11_1_len; =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.dev Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793798335254425.97800478031286; Wed, 4 Nov 2026 05:18:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOasr-00070G-T3; Wed, 04 Nov 2026 08:18:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOasp-0006zs-My for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:31 -0500 Received: from out-246.mta1.migadu.com ([95.215.58.246] helo=mta1.migadu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOasn-0002y5-Id for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:31 -0500 Received: by smtp.migadu.com with ESMTPS id 90a5ff6a45cdb2f1; Wed, 04 Nov 2026 13:18:27 +0000 X-Envelope-To: qemu-devel@nongnu.org DKIM-Signature: a=rsa-sha256; bh=WgMvKjmjAmDoq+b+d/1gPxUFchVvWbMDgA7lbEpN1pY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793798307; v=1; x=1794403107; b=odTMKEZABhzwslGAjAjdCayWw6P5zOBWqEKQCy11WN/Ot5OOXEiU8NQCz03VFIODhUvHIhWC WafpQOwvHcFz9z6YB7zDqrB1wFhslzUD/GOu7Uql3UVA80BDtUvL2oZea6w9VBx4QxRUBEQIIFP i7Nwecu0G9ibLguWi9BqiXxs= X-Envelope-To: qemu-devel@nongnu.org X-Mizu-Trace-ID: 90a5ff6a45cdb2f1 X-Migadu-Flow: FLOW_OUT From: Junjie Cao To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, philmd@oss.qualcomm.com, zhao1.liu@intel.com, richard.henderson@linaro.org, farosas@suse.de, lvivier@redhat.com, pierrick.bouvier@oss.qualcomm.com, thuth@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, berrange@redhat.com, marcandre.lureau@redhat.com, deller@gmx.de, clg@redhat.com, jamin_lin@aspeedtech.com, junjie.cao@linux.dev Subject: [RFC PATCH 2/4] hw/i386: let -usb create qemu-xhci on new pc and q35 machine types Date: Wed, 4 Nov 2026 07:18:08 -0600 Message-ID: <20261104131810.2063834-3-junjie.cao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104131810.2063834-1-junjie.cao@linux.dev> References: <20261104131810.2063834-1-junjie.cao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=95.215.58.246; envelope-from=junjie.cao@linux.dev; helo=mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793798337864158500 Content-Type: text/plain; charset="utf-8" -usb gives the PIIX3 UHCI on pc and the ICH9 EHCI with three UHCI companions on q35, so the one-switch way to get USB still picks a USB 1.1 or 2.0 controller. libvirt disables machine-created USB controllers with usb=3Doff and adds controllers explicitly. From pc-i440fx-12.0 and pc-q35-12.0 on, create qemu-xhci at 1d.0 instead. On q35 that is where the first UHCI sat, so every other device keeps its PCI address. On pc the PIIX3's own USB function is out: the i440fx DSDT routes slot 1 INTA to the SCI link and qemu-xhci interrupts on INTA, so a guest that does not use MSI gets "PCI INT A: no GSI" and never enumerates its devices; the UHCI there uses INTD. Slot 1d is free on pc and keeps the two machines alike. The device stays optional in Kconfig. A build without it fails -usb with a message instead of a fatal "unknown type" error. Guests without an xHCI driver (Windows 7 and earlier) need an older machine type or an explicit -device piix3-usb-uhci. Suggested-by: Peter Maydell Link: https://lore.kernel.org/qemu-devel/CAFEAcA9b2oeZaZtGkn5YPMKOXWDdZQEvd= oBj5mGVh51aKi-BYw@mail.gmail.com/ Link: https://lore.kernel.org/qemu-devel/agrz1zBDwGc9Bvlo@sirius.home.kraxe= l.org/ Signed-off-by: Junjie Cao --- hw/i386/Kconfig | 2 ++ hw/i386/pc.c | 18 ++++++++++++++++++ hw/i386/pc_piix.c | 11 ++++++++++- hw/i386/pc_q35.c | 12 ++++++++++-- include/hw/i386/pc.h | 4 ++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index e27d8816e5..1d88726618 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -78,6 +78,7 @@ config I440FX imply E1000_PCI imply VMPORT imply VMMOUSE + imply USB_XHCI_PCI select ACPI_PIIX4 select PC_PCI select PC_ACPI @@ -108,6 +109,7 @@ config Q35 imply VMPORT imply VMMOUSE imply IOMMUFD + imply USB_XHCI_PCI select PC_PCI select PC_ACPI select PCI_EXPRESS_Q35 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8a6b7978cc..6b8fc2914e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -55,6 +55,7 @@ #include "hw/mem/nvdimm.h" #include "hw/cxl/cxl_host.h" #include "hw/usb/usb.h" +#include "hw/usb/xhci.h" #include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" #include "hw/virtio/virtio-iommu.h" @@ -1164,6 +1165,23 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_b= us, PCIBus *pci_bus) } } =20 +/* + * 1d.0 is where q35's first UHCI sat. On pc the PIIX3's own USB function + * is out: the DSDT routes slot 1 INTA to the SCI link and qemu-xhci + * interrupts on INTA. + */ +void pc_usb_xhci_create(PCIBus *pci_bus) +{ + DeviceState *dev =3D qdev_try_new(TYPE_QEMU_XHCI); + + if (!dev) { + error_report("-usb: this build has no %s device", TYPE_QEMU_XHCI); + exit(1); + } + qdev_prop_set_int32(dev, "addr", PCI_DEVFN(0x1d, 0)); + qdev_realize_and_unref(dev, BUS(pci_bus), &error_fatal); +} + void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) { qemu_irq *i8259; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index c0ddf6011f..845092f5f1 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -245,7 +245,8 @@ static void pc_init1(MachineState *machine, const char = *pci_type) pci_dev =3D pci_new_multifunction(-1, pc_south_bridge_type[pcms->south_bridg= e]); object_property_set_bool(OBJECT(pci_dev), "has-usb", - machine_usb(machine), &error_abort); + machine_usb(machine) && !pcmc->usb_xhci, + &error_abort); object_property_set_bool(OBJECT(pci_dev), "has-acpi", x86_machine_is_acpi_enabled(x86ms), &error_abort); @@ -305,6 +306,10 @@ static void pc_init1(MachineState *machine, const char= *pci_type) =20 pc_nic_init(pcmc, isa_bus, pcms->pcibus); =20 + if (machine_usb(machine) && pcmc->usb_xhci) { + pc_usb_xhci_create(pcms->pcibus); + } + if (piix4_pm) { smi_irq =3D qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0); =20 @@ -375,6 +380,7 @@ static void pc_i440fx_machine_options(MachineClass *m) pcmc->default_south_bridge =3D PC_SOUTH_BRIDGE_OPTION_PIIX3; pcmc->pci_root_uid =3D 0; pcmc->default_cpu_version =3D 1; + pcmc->usb_xhci =3D true; =20 m->family =3D "pc_piix"; m->desc =3D "Standard PC (i440FX + PIIX, 1996)"; @@ -406,7 +412,10 @@ DEFINE_I440FX_MACHINE_AS_LATEST(12, 0); =20 static void pc_i440fx_machine_11_2_options(MachineClass *m) { + PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); + pc_i440fx_machine_12_0_options(m); + pcmc->usb_xhci =3D false; compat_props_add(m->compat_props, hw_compat_11_2, hw_compat_11_2_len); compat_props_add(m->compat_props, pc_compat_11_2, pc_compat_11_2_len); } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index e302ff283c..8a856bf199 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -298,8 +298,12 @@ static void pc_q35_init(MachineState *machine) } =20 if (machine_usb(machine)) { - /* Should we create 6 UHCI according to ich9 spec? */ - ehci_create_ich9_with_companions(pcms->pcibus, 0x1d); + if (pcmc->usb_xhci) { + pc_usb_xhci_create(pcms->pcibus); + } else { + /* Should we create 6 UHCI according to ich9 spec? */ + ehci_create_ich9_with_companions(pcms->pcibus, 0x1d); + } } =20 if (pcms->smbus_enabled) { @@ -353,6 +357,7 @@ static void pc_q35_machine_options(MachineClass *m) ObjectClass *oc =3D OBJECT_CLASS(m); pcmc->pci_root_uid =3D 0; pcmc->default_cpu_version =3D 1; + pcmc->usb_xhci =3D true; =20 m->family =3D "pc_q35"; m->desc =3D "Standard PC (Q35 + ICH9, 2009)"; @@ -387,7 +392,10 @@ DEFINE_Q35_MACHINE_AS_LATEST(12, 0); =20 static void pc_q35_machine_11_2_options(MachineClass *m) { + PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); + pc_q35_machine_12_0_options(m); + pcmc->usb_xhci =3D false; compat_props_add(m->compat_props, hw_compat_11_2, hw_compat_11_2_len); compat_props_add(m->compat_props, pc_compat_11_2, pc_compat_11_2_len); } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index caceddc74b..c378c804f8 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -119,6 +119,9 @@ struct PCMachineClass { /* create kvmclock device even when KVM PV features are not exposed */ bool kvmclock_create_always; =20 + /* -usb creates qemu-xhci instead of the chipset's UHCI/EHCI */ + bool usb_xhci; + /* * whether the machine type implements broken 32-bit address space bou= nd * check for memory. @@ -195,6 +198,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, bool create_fdctrl, uint32_t hpet_irqs); void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus); +void pc_usb_xhci_create(PCIBus *pci_bus); =20 void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.dev Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793798370204249.1695375485133; Wed, 4 Nov 2026 05:19:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOasw-00071F-Od; Wed, 04 Nov 2026 08:18:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOasu-00070c-Uh for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:36 -0500 Received: from out-141.mta0.migadu.com ([2001:41d0:1004:224b::8d] helo=mta0.migadu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOast-0002yk-2f for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:36 -0500 Received: by smtp.migadu.com with ESMTPS id a44c55cd4cdfb42f; Wed, 04 Nov 2026 13:18:32 +0000 X-Envelope-To: qemu-devel@nongnu.org DKIM-Signature: a=rsa-sha256; bh=1GkPIVi5R/OHW4MKMzCWp4ii2U9UH3X7izv3DNUmMYo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793798312; v=1; x=1794403112; b=EJ+qSrqMaiB2TDvh/Psg2aLvGuBZZD0/LBAgvkGco3FTQD0wEC4qwoPvNydrLMWTw89YCBfA w6zeEONedaPk1sWstQUiYvtxfD9Pa0XAkSovWJXuOoJczh3GxkNewRHCpapRvEk2Ntinp0nPeBi 4AJ+yWxg+/F+UlmL8bJiy4Fs= X-Envelope-To: qemu-devel@nongnu.org X-Mizu-Trace-ID: a44c55cd4cdfb42f X-Migadu-Flow: FLOW_OUT From: Junjie Cao To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, philmd@oss.qualcomm.com, zhao1.liu@intel.com, richard.henderson@linaro.org, farosas@suse.de, lvivier@redhat.com, pierrick.bouvier@oss.qualcomm.com, thuth@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, berrange@redhat.com, marcandre.lureau@redhat.com, deller@gmx.de, clg@redhat.com, jamin_lin@aspeedtech.com, junjie.cao@linux.dev Subject: [RFC PATCH 3/4] tests/qtest: check which host controller -usb creates on pc and q35 Date: Wed, 4 Nov 2026 07:18:09 -0600 Message-ID: <20261104131810.2063834-4-junjie.cao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104131810.2063834-1-junjie.cao@linux.dev> References: <20261104131810.2063834-1-junjie.cao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2001:41d0:1004:224b::8d; envelope-from=junjie.cao@linux.dev; helo=mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793798371903158500 Content-Type: text/plain; charset="utf-8" Run query-pci on the pc and q35 aliases, the 12.0 and the 11.2 types. With -usb the former two pairs get qemu-xhci at 1d.0, the 11.2 ones PIIX3 UHCI and ICH9 EHCI plus companions; without -usb there is no USB controller. Signed-off-by: Junjie Cao --- tests/qtest/meson.build | 3 + tests/qtest/usb-pc-default-test.c | 135 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 tests/qtest/usb-pc-default-test.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ff4bf9528a..615056876d 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -91,6 +91,9 @@ qtests_i386 =3D \ (config_all_devices.has_key('CONFIG_USB_UHCI') and = \ config_all_devices.has_key('CONFIG_USB_EHCI') ? ['usb-hcd-ehci-test'] := []) + \ (config_all_devices.has_key('CONFIG_USB_XHCI_NEC') ? ['usb-hcd-xhci-test= '] : []) + \ + (config_all_devices.has_key('CONFIG_USB_UHCI') and = \ + config_all_devices.has_key('CONFIG_USB_EHCI_PCI') and = \ + config_all_devices.has_key('CONFIG_USB_XHCI_PCI') ? ['usb-pc-default-te= st'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_CRB') ? ['tpm-crb-test'] : []) += \ (config_all_devices.has_key('CONFIG_TPM_CRB') ? ['tpm-crb-swtpm-test'] := []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : [= ]) + \ diff --git a/tests/qtest/usb-pc-default-test.c b/tests/qtest/usb-pc-default= -test.c new file mode 100644 index 0000000000..060e9bc469 --- /dev/null +++ b/tests/qtest/usb-pc-default-test.c @@ -0,0 +1,135 @@ +/* + * Which USB host controller -usb creates on the pc and q35 machines + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qobject/qdict.h" +#include "qobject/qlist.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_ids.h" + +typedef struct { + int slot, func; + uint16_t vendor, device; +} Controller; + +typedef struct { + const char *machine; + bool usb; + const char *const *devices; + const Controller *ctrl; + size_t n; +} TestCase; + +static const Controller piix3_uhci[] =3D { + { 1, 2, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_2 }, +}; + +static const Controller xhci[] =3D { + { 0x1d, 0, PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_XHCI }, +}; + +static const Controller ich9_ehci[] =3D { + { 0x1d, 0, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801I_UHCI1 }, + { 0x1d, 1, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801I_UHCI2 }, + { 0x1d, 2, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801I_UHCI3 }, + { 0x1d, 7, PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801I_EHCI1 }, +}; + +/* host controller types a case needs, in case the build left them out */ +static const char *const xhci_dev[] =3D { "qemu-xhci", NULL }; +static const char *const piix3_dev[] =3D { "piix3-usb-uhci", NULL }; +static const char *const ich9_dev[] =3D { "ich9-usb-ehci1", "ich9-usb-uhci= 1", + NULL }; + +static const TestCase cases[] =3D { + { "pc", true, xhci_dev, xhci, ARRAY_SIZE(xhci) }, + { "q35", true, xhci_dev, xhci, ARRAY_SIZE(xhci) }, + { "pc-i440fx-12.0", true, xhci_dev, xhci, ARRAY_SIZE(xhci) }, + { "pc-q35-12.0", true, xhci_dev, xhci, ARRAY_SIZE(xhci) }, + { "pc-i440fx-11.2", true, piix3_dev, piix3_uhci, ARRAY_SIZE(piix3_uhci= ) }, + { "pc-q35-11.2", true, ich9_dev, ich9_ehci, ARRAY_SIZE(ich9_ehci) }, + { "pc", false, NULL, NULL, 0 }, + { "q35", false, NULL, NULL, 0 }, +}; + +static bool has_devices(const char *const *devices) +{ + for (; devices && *devices; devices++) { + if (!qtest_has_device(*devices)) { + return false; + } + } + return true; +} + +static void test_usb_controllers(const void *data) +{ + const TestCase *tc =3D data; + QTestState *qts =3D qtest_initf(tc->usb ? "-M %s -usb" : "-M %s", + tc->machine); + QDict *resp =3D qtest_qmp(qts, "{ 'execute': 'query-pci' }"); + QList *buses =3D qdict_get_qlist(resp, "return"); + QListEntry *be, *de; + size_t found =3D 0; + + QLIST_FOREACH_ENTRY(buses, be) { + QDict *bus =3D qobject_to(QDict, qlist_entry_obj(be)); + QList *devices =3D qdict_get_qlist(bus, "devices"); + + QLIST_FOREACH_ENTRY(devices, de) { + QDict *dev =3D qobject_to(QDict, qlist_entry_obj(de)); + QDict *id =3D qdict_get_qdict(dev, "id"); + int slot =3D qdict_get_int(dev, "slot"); + int func =3D qdict_get_int(dev, "function"); + int vendor =3D qdict_get_int(id, "vendor"); + int device =3D qdict_get_int(id, "device"); + size_t i; + + if (qdict_get_int(qdict_get_qdict(dev, "class_info"), "class")= !=3D + PCI_CLASS_SERIAL_USB) { + continue; + } + for (i =3D 0; i < tc->n; i++) { + if (tc->ctrl[i].slot =3D=3D slot && tc->ctrl[i].func =3D= =3D func) { + break; + } + } + if (i =3D=3D tc->n) { + g_test_message("unexpected USB controller %02x.%x %04x:%04= x", + slot, func, vendor, device); + g_assert_not_reached(); + } + g_assert_cmpint(vendor, =3D=3D, tc->ctrl[i].vendor); + g_assert_cmpint(device, =3D=3D, tc->ctrl[i].device); + found++; + } + } + g_assert_cmpuint(found, =3D=3D, tc->n); + + qobject_unref(resp); + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + size_t i; + + g_test_init(&argc, &argv, NULL); + for (i =3D 0; i < ARRAY_SIZE(cases); i++) { + static const char *const kind[] =3D { "no-usb", "usb" }; + g_autofree char *path =3D NULL; + + if (!qtest_has_machine(cases[i].machine) || + !has_devices(cases[i].devices)) { + continue; + } + path =3D g_strdup_printf("/usb/pc-default/%s/%s", kind[cases[i].us= b], + cases[i].machine); + qtest_add_data_func(path, &cases[i], test_usb_controllers); + } + return g_test_run(); +} --=20 2.43.0 From nobody Mon Nov 23 04:26:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.dev Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179379838130182.63019572065093; Wed, 4 Nov 2026 05:19:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOat3-00071v-6E; Wed, 04 Nov 2026 08:18:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOat1-00071f-A1 for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:43 -0500 Received: from out-24.mta1.migadu.com ([95.215.58.24] helo=mta1.migadu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOasz-0002zN-Iv for qemu-devel@nongnu.org; Wed, 04 Nov 2026 08:18:43 -0500 Received: by smtp.migadu.com with ESMTPS id a93b4613600de1b4; Wed, 04 Nov 2026 13:18:39 +0000 X-Envelope-To: qemu-devel@nongnu.org DKIM-Signature: a=rsa-sha256; bh=rFkLa2hwtClX0tRdpRTMgG9vYi1puXw9y1dqS4KrQRg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793798319; v=1; x=1794403119; b=LDx1uPW6cO/5CDcRLHo1g1BfwDtp5Je112UFYi3tclaHI3rDgSNEu06K5iNWFuFd66rrPcWE OmsvxCpC6XQy/JI0hrIjMPgFmXssvyRsIeDY0577AZ5GgFkFsROXcyzJLmxs9KJMPFVib+JlswK sOKripfLdrhT5sOadLseVkIc= X-Envelope-To: qemu-devel@nongnu.org X-Mizu-Trace-ID: a93b4613600de1b4 X-Migadu-Flow: FLOW_OUT From: Junjie Cao To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, philmd@oss.qualcomm.com, zhao1.liu@intel.com, richard.henderson@linaro.org, farosas@suse.de, lvivier@redhat.com, pierrick.bouvier@oss.qualcomm.com, thuth@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, berrange@redhat.com, marcandre.lureau@redhat.com, deller@gmx.de, clg@redhat.com, jamin_lin@aspeedtech.com, junjie.cao@linux.dev Subject: [RFC PATCH 4/4] docs/system/devices/usb: describe -usb after the qemu-xhci switch Date: Wed, 4 Nov 2026 07:18:10 -0600 Message-ID: <20261104131810.2063834-5-junjie.cao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104131810.2063834-1-junjie.cao@linux.dev> References: <20261104131810.2063834-1-junjie.cao@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=95.215.58.24; envelope-from=junjie.cao@linux.dev; helo=mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793798384098158500 Content-Type: text/plain; charset="utf-8" Say which machine types still get UHCI or EHCI from -usb, and point guests without an xHCI driver at them. The two examples that used -usb for a UHCI next to an EHCI now create it with -device, so they keep showing separate UHCI and EHCI buses. Signed-off-by: Junjie Cao --- docs/system/devices/usb.rst | 23 ++++++++++++++--------- qemu-options.hx | 9 ++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/system/devices/usb.rst b/docs/system/devices/usb.rst index dc694d23c2..b3cde7fc8e 100644 --- a/docs/system/devices/usb.rst +++ b/docs/system/devices/usb.rst @@ -20,6 +20,11 @@ released around 2010 or later) we recommend using it: =20 |qemu_system| -device qemu-xhci =20 +From the 12.0 machine types on, ``-usb`` creates a ``qemu-xhci`` on +the ``pc`` and ``q35`` machines. Guests without an XHCI driver, such +as Windows 7, need an older machine type or an explicit +``-device piix3-usb-uhci`` or ``-device usb-ehci``. + XHCI supports USB 1.1, USB 2.0 and USB 3.0 devices, so this is the only controller you need. With only a single USB controller (and therefore only a single USB bus) present in the system there is no @@ -42,9 +47,9 @@ bus though, so there are two completely separate USB buse= s: One USB the EHCI controller. Devices must be attached to the correct controller manually. =20 -The easiest way to add a UHCI controller to a ``pc`` machine is the -``-usb`` switch. QEMU will create the UHCI controller as function of -the PIIX3 chipset. The USB 1.1 bus will carry the name ``usb-bus.0``. +On ``pc`` machine types up to 11.2 the ``-usb`` switch creates the +UHCI controller as function of the PIIX3 chipset. The USB 1.1 bus +will carry the name ``usb-bus.0``. =20 You can use the standard ``-device`` switch to add a EHCI controller to your virtual machine. It is strongly recommended to specify an ID for @@ -59,9 +64,9 @@ bus they should be attached to. Here is a complete examp= le: =20 |qemu_system| -M pc ${otheroptions} \\ -drive if=3Dnone,id=3Dusbstick,format=3Draw,file=3D/path/to/image = \\ - -usb \\ + -device piix3-usb-uhci,id=3Duhci \\ -device usb-ehci,id=3Dehci \\ - -device usb-tablet,bus=3Dusb-bus.0 \\ + -device usb-tablet,bus=3Duhci.0 \\ -device usb-storage,bus=3Dehci.0,drive=3Dusbstick =20 This attaches a USB tablet to the UHCI adapter and a USB mass storage @@ -88,8 +93,8 @@ you, which you can use like this: =20 Then use ``bus=3Dehci.0`` to assign your USB devices to that bus. =20 -Using the ``-usb`` switch for ``q35`` machines will create a similar -USB controller configuration. +On ``q35`` machine types up to 11.2 the ``-usb`` switch creates this +configuration. =20 =20 .. _Connecting USB devices: @@ -359,9 +364,9 @@ and also assign it to the correct USB bus in QEMU like = this: .. parsed-literal:: =20 |qemu_system| -M pc [...] \\ - -usb \\ + -device piix3-usb-uhci,id=3Duhci \\ -device usb-ehci,id=3Dehci \\ - -device usb-host,bus=3Dusb-bus.0,hostbus=3D3,hostport=3D1 \\ + -device usb-host,bus=3Duhci.0,hostbus=3D3,hostport=3D1 \\ -device usb-host,bus=3Dehci.0,hostbus=3D1,hostport=3D1 =20 ``usb-host`` properties for reset behavior diff --git a/qemu-options.hx b/qemu-options.hx index 5fe9d73eaa..2429461350 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2193,9 +2193,12 @@ DEF("usb", 0, QEMU_OPTION_usb, SRST ``-usb`` Enable USB emulation on machine types with an on-board USB host - controller (if not enabled by default). Note that on-board USB host - controllers may not support USB 3.0. In this case - ``-device qemu-xhci`` can be used instead on machines with PCI. + controller (if not enabled by default). On the ``pc`` and ``q35`` + machines this is a ``qemu-xhci`` from the 12.0 machine types on; + older types get the chipset's UHCI (``pc``) or EHCI with UHCI + companions (``q35``). Other on-board USB host controllers may not + support USB 3.0. In this case ``-device qemu-xhci`` can be used + instead on machines with PCI. ERST =20 DEF("usbdevice", HAS_ARG, QEMU_OPTION_usbdevice, --=20 2.43.0