From: Jamin Lin <jamin_lin@aspeedtech.com>
To: "Cédric Le Goater" <clg@kaod.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Kane Chen" <kane_chen@aspeedtech.com>,
"open list:ASPEED BMCs" <qemu-arm@nongnu.org>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Cc: Jamin Lin <jamin_lin@aspeedtech.com>, Troy Lee <troy_lee@aspeedtech.com>
Subject: [PATCH v1 3/3] hw/usb/hcd-ehci-pci-aspeed: Add the AST2700 PCIe EHCI
Date: Wed, 25 Nov 2026 03:12:30 +0000 [thread overview]
Message-ID: <20261125031225.3810653-4-jamin_lin@aspeedtech.com> (raw)
In-Reply-To: <20261125031225.3810653-1-jamin_lin@aspeedtech.com>
The AST2700 PCIe EHCI (1a03:2603, rev 0x72, subsystem 1a03:2603) has
an MSI capability at 0x50 and uses INTA. It supports 64-bit
addressing.
Add it as a new type, "aspeed-usb-ehci", based on the EHCI PCI device.
The new type sets the IDs and the interrupt pin, adds the MSI
capability, and turns on caps-64bit-addr by default.
The guest decides whether to use MSI. If MSI is on, the device sends
an MSI each time the EHCI raises an interrupt. If MSI is off, the
device uses INTA. If the board has no MSI support, the device uses
INTA only.
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
hw/usb/hcd-ehci-pci-aspeed.c | 118 +++++++++++++++++++++++++++++++++++
hw/usb/meson.build | 3 +-
2 files changed, 120 insertions(+), 1 deletion(-)
create mode 100644 hw/usb/hcd-ehci-pci-aspeed.c
diff --git a/hw/usb/hcd-ehci-pci-aspeed.c b/hw/usb/hcd-ehci-pci-aspeed.c
new file mode 100644
index 0000000000..e18fc047b5
--- /dev/null
+++ b/hw/usb/hcd-ehci-pci-aspeed.c
@@ -0,0 +1,118 @@
+/*
+ * ASPEED PCIe EHCI
+ *
+ * Copyright (c) 2026 ASPEED Technology Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/pci/msi.h"
+#include "hw/usb/hcd-ehci.h"
+
+#define TYPE_ASPEED_EHCI_PCI "aspeed-usb-ehci"
+OBJECT_DECLARE_TYPE(AspeedEHCIPCIState, AspeedEHCIPCIClass, ASPEED_EHCI_PCI)
+
+struct AspeedEHCIPCIState {
+ EHCIPCIState parent_obj;
+};
+
+struct AspeedEHCIPCIClass {
+ PCIDeviceClass parent_class;
+
+ void (*parent_realize)(PCIDevice *dev, Error **errp);
+ PCIUnregisterFunc *parent_exit;
+};
+
+#define ASPEED_EHCI_PCI_MSI_CAP 0x50
+
+/* The EHCI core calls this function when its interrupt changes. */
+static void aspeed_ehci_pci_set_irq(void *opaque, int n, int level)
+{
+ PCIDevice *dev = opaque;
+
+ /* MSI */
+ if (msi_enabled(dev)) {
+ if (level) {
+ msi_notify(dev, 0);
+ }
+ return;
+ }
+
+ /* INTx */
+ pci_set_irq(dev, level);
+}
+
+static void aspeed_ehci_pci_init(Object *obj)
+{
+ qdev_prop_set_bit(DEVICE(obj), "caps-64bit-addr", true);
+}
+
+static void aspeed_ehci_pci_realize(PCIDevice *dev, Error **errp)
+{
+ AspeedEHCIPCIClass *ac = ASPEED_EHCI_PCI_GET_CLASS(dev);
+ AspeedEHCIPCIState *s = ASPEED_EHCI_PCI(dev);
+ EHCIState *ehci = &s->parent_obj.ehci;
+ Error *err = NULL;
+ int ret;
+
+ ac->parent_realize(dev, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+
+ /*
+ * INTx uses INTA. Send the EHCI interrupt to
+ * aspeed_ehci_pci_set_irq(), which picks MSI or INTx.
+ */
+ pci_set_byte(&dev->config[PCI_INTERRUPT_PIN], 1);
+ qemu_free_irq(ehci->irq);
+ ehci->irq = qemu_allocate_irq(aspeed_ehci_pci_set_irq, dev, 0);
+
+ /* If the board has no MSI, use INTx only. */
+ ret = msi_init(dev, ASPEED_EHCI_PCI_MSI_CAP, 1, true, false, NULL);
+ assert(!ret || ret == -ENOTSUP);
+}
+
+static void aspeed_ehci_pci_exit(PCIDevice *dev)
+{
+ AspeedEHCIPCIClass *ac = ASPEED_EHCI_PCI_GET_CLASS(dev);
+
+ msi_uninit(dev);
+ ac->parent_exit(dev);
+}
+
+static void aspeed_ehci_pci_class_init(ObjectClass *klass, const void *data)
+{
+ AspeedEHCIPCIClass *ac = ASPEED_EHCI_PCI_CLASS(klass);
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ ac->parent_realize = k->realize;
+ ac->parent_exit = k->exit;
+ k->realize = aspeed_ehci_pci_realize;
+ k->exit = aspeed_ehci_pci_exit;
+ k->vendor_id = PCI_VENDOR_ID_ASPEED;
+ k->device_id = 0x2603;
+ k->revision = 0x72;
+ k->subsystem_vendor_id = PCI_VENDOR_ID_ASPEED;
+ k->subsystem_id = 0x2603;
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
+}
+
+static const TypeInfo aspeed_ehci_pci_types[] = {
+ {
+ .name = TYPE_ASPEED_EHCI_PCI,
+ .parent = TYPE_PCI_EHCI,
+ .instance_size = sizeof(AspeedEHCIPCIState),
+ .instance_init = aspeed_ehci_pci_init,
+ .class_size = sizeof(AspeedEHCIPCIClass),
+ .class_init = aspeed_ehci_pci_class_init,
+ },
+};
+
+DEFINE_TYPES(aspeed_ehci_pci_types)
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index 240c5344b7..9e09310d1a 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -18,7 +18,8 @@ system_ss.add(when: 'CONFIG_USB_OHCI', if_true: files('hcd-ohci.c'))
system_ss.add(when: 'CONFIG_USB_OHCI_PCI', if_true: files('hcd-ohci-pci.c'))
system_ss.add(when: 'CONFIG_USB_OHCI_SYSBUS', if_true: files('hcd-ohci-sysbus.c'))
system_ss.add(when: 'CONFIG_USB_EHCI', if_true: files('hcd-ehci.c'))
-system_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c'))
+system_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c',
+ 'hcd-ehci-pci-aspeed.c'))
system_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci-sysbus.c'))
system_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c'))
system_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.c'))
--
2.53.0
prev parent reply other threads:[~2026-11-25 3:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 3:12 [PATCH v1 0/3] Add the AST2700 PCIe EHCI Jamin Lin
2026-11-25 3:12 ` [PATCH v1 1/3] hw/pci-host/aspeed_pcie: Fix lost INTx interrupts Jamin Lin
2026-11-25 3:12 ` [PATCH v1 2/3] hw/usb/hcd-ehci-pci: Use DEFINE_TYPES Jamin Lin
2026-11-25 3:12 ` Jamin Lin [this message]
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=20261125031225.3810653-4-jamin_lin@aspeedtech.com \
--to=jamin_lin@aspeedtech.com \
--cc=clg@kaod.org \
--cc=kane_chen@aspeedtech.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=troy_lee@aspeedtech.com \
/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.