From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-block@nongnu.org, John Snow <jsnow@redhat.com>,
Helge Deller <deller@gmx.de>, "Denis V. Lunev" <den@openvz.org>,
Abizer Lokhandwala <abizerlokhandwalastd10@gmail.com>
Subject: [PULL 4/7] hw/usb/hcd-ohci: Add big endian and consistency check support
Date: Fri, 18 Sep 2026 18:38:25 +0200 [thread overview]
Message-ID: <20260918163829.2917-5-deller@kernel.org> (raw)
In-Reply-To: <20260918163829.2917-1-deller@kernel.org>
From: Abizer Lokhandwala <abizerlokhandwalastd10@gmail.com>
The OHCI controller allows running in big endian mode. If this mode is enabled, swap the
buffer contents before accessing them since we by default run OHCI in little endian mode.
Additionally add the architected consistency check which halts OHCI on errors.
Signed-off-by: Abizer Lokhandwala <abizerlokhandwalastd10@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
hw/usb/hcd-ohci.c | 35 +++++++++++++++++++++++++++++++++++
hw/usb/hcd-ohci.h | 5 +++++
2 files changed, 40 insertions(+)
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 23990115ab..5e5fe41f47 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -74,6 +74,7 @@ struct ohci_hcca {
/* Flags in the head field of an Endpoint Descriptor. */
#define OHCI_ED_H 1
#define OHCI_ED_C 2
+#define OHCI_ED_HEAD_RSVD (1 << 2 | 1 << 3)
/* Bitfields for the first word of a Transfer Descriptor. */
#define OHCI_TD_R (1 << 18)
@@ -371,6 +372,8 @@ void ohci_hard_reset(OHCIState *ohci)
ohci_soft_reset(ohci);
ohci->ctl = 0;
ohci_roothub_reset(ohci);
+ ohci->big_endian = false;
+ ohci->consistency_check = false;
}
/* Get an array of dwords from main memory */
@@ -867,6 +870,18 @@ static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len)
}
}
+static void ohci_bswap_buf(uint8_t *buf, size_t len)
+{
+ uint32_t w;
+ while (len >= sizeof(w)) {
+ memcpy(&w, buf, sizeof(w));
+ w = bswap32(w);
+ memcpy(buf, &w, sizeof(w));
+ buf += sizeof(w);
+ len -= sizeof(w);
+ }
+}
+
/*
* Service a transport descriptor.
* Returns nonzero to terminate processing of this endpoint.
@@ -975,6 +990,9 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
DMA_DIRECTION_TO_DEVICE)) {
ohci_die(ohci);
}
+ if (ohci->big_endian) {
+ ohci_bswap_buf(ohci->usb_buf, pktlen);
+ }
}
}
}
@@ -1024,6 +1042,9 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
if (ret >= 0) {
if (dir == OHCI_TD_DIR_IN) {
+ if (ohci->big_endian) {
+ ohci_bswap_buf(ohci->usb_buf, ret);
+ }
if (ohci_copy_td(ohci, &td, ohci->usb_buf, ret,
DMA_DIRECTION_FROM_DEVICE)) {
ohci_die(ohci);
@@ -1108,6 +1129,13 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
ohci->done_count = i;
}
exit_no_retire:
+ if (ohci->media_error) {
+ int cc = OHCI_BM(td.flags, TD_CC);
+ /* only these 2 errors will ever actually be possible in qemu */
+ if (cc == OHCI_CC_DEVICENOTRESPONDING || cc == OHCI_CC_UNDEXPETEDPID) {
+ ohci->media_error(ohci);
+ }
+ }
if (ohci_put_td(ohci, addr, &td)) {
ohci_die(ohci);
return 1;
@@ -1136,6 +1164,13 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head)
ohci_die(ohci);
return 0;
}
+ if (ohci->consistency_check && (ed.head & OHCI_ED_HEAD_RSVD)) {
+ if (ohci->descriptor_error) {
+ ohci->descriptor_error(ohci);
+ }
+ ohci_die(ohci);
+ return 0;
+ }
next_ed = ed.next & OHCI_DPTR_MASK;
diff --git a/hw/usb/hcd-ohci.h b/hw/usb/hcd-ohci.h
index 243cd1f46a..d079f8d24e 100644
--- a/hw/usb/hcd-ohci.h
+++ b/hw/usb/hcd-ohci.h
@@ -93,6 +93,11 @@ struct OHCIState {
bool async_complete;
void (*ohci_die)(OHCIState *ohci);
+ void (*media_error)(OHCIState *ohci);
+ void (*descriptor_error)(OHCIState *ohci);
+
+ bool big_endian;
+ bool consistency_check;
};
#define TYPE_SYSBUS_OHCI "sysbus-ohci"
--
2.54.0
next prev parent reply other threads:[~2026-09-18 16:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:38 [PULL 0/7] Superio hppa patches Helge Deller
2026-09-18 16:38 ` [PULL 1/7] hw/pci/pci_ids: Add PCI vendor ID and IDs for NS chips Helge Deller
2026-09-18 16:38 ` [PULL 2/7] hw/isa/pc87560: Add main isa code for NS 87560 SuperIO chip Helge Deller
2026-09-21 9:51 ` Philippe Mathieu-Daudé
2026-09-21 10:17 ` Daniel P. Berrangé
2026-09-18 16:38 ` [PULL 3/7] hw/ide/pc87560-ide: Add IDE emulation of " Helge Deller
2026-09-18 16:38 ` Helge Deller [this message]
2026-09-18 16:38 ` [PULL 5/7] hw/usb/pc87560-ohci: Add USB OHCI " Helge Deller
2026-09-18 16:38 ` [PULL 6/7] hw/pc87560: Wire up " Helge Deller
2026-09-18 16:38 ` [PULL 7/7] hw/hppa: Add NS 87560 SuperIO chip to HP C3700 machine Helge Deller
2026-09-19 0:27 ` [PULL 0/7] Superio hppa patches Richard Henderson
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=20260918163829.2917-5-deller@kernel.org \
--to=deller@kernel.org \
--cc=abizerlokhandwalastd10@gmail.com \
--cc=deller@gmx.de \
--cc=den@openvz.org \
--cc=jsnow@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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.