Fix ohci_die() and move PCI code to separate file
v2 cover Fix ohci_die() and move PCI code to separate file
First patch fixes a problem with ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.
v2: Split the patch into two patches, one for the ohci_die() fix and one
for the PCI code movement.
Thomas Huth (2):
hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in
ohci_die()
hw/usb/hcd-ohci: Move PCI-related code into a separate file
hw/sh4/Kconfig | 2 +- hw/usb/Kconfig | 6 +- hw/usb/Makefile.objs | 1 + hw/usb/hcd-ohci-pci.c | 163 +++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.c | 219 ++++-------------------------------------- hw/usb/hcd-ohci.h | 104 ++++++++++++++++++++ 6 files changed, 293 insertions(+), 202 deletions(-) create mode 100644 hw/usb/hcd-ohci-pci.c create mode 100644 hw/usb/hcd-ohci.h
Signature · 1 line
2.21.0
PATCH v2 1/2 hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in ohci_die()
The ohci_die() function always assumes to be running with a PCI OHCI controller and calls the PCI-specific functions pci_set_word(). However, this function might also get called for the sysbus OHCI devices, so it likely fails in that case. To fix this issue, change the code now, so that there are two implementations now, one for sysbus and one for PCI, and use the right function via a function pointer in the OHCIState structure.
--- hw/usb/hcd-ohci.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
hw/usb/hcd-ohci.c +27 -12
@@ -52,7 +52,7 @@ typedef struct OHCIPort {uint32_t ctrl; } OHCIPort; -typedef struct { +typedef struct OHCIState { USBBus bus; qemu_irq irq; MemoryRegion mem;
@@ -108,6 +108,7 @@ typedef struct {uint32_t async_td;bool async_complete; +void (*ohci_die)(struct OHCIState *ohci); } OHCIState;/* Host Controller Communications Area */
@@ -302,7 +303,10 @@ struct ohci_iso_td {#define OHCI_HRESET_FSBIR (1 << 0) -static void ohci_die (OHCIState *ohci); +static void ohci_die (OHCIState *ohci) +{ + ohci->ohci_die (ohci); +}/* Update IRQ levels */ static inline void ohci_intr_update (OHCIState *ohci)
@@ -1854,13 +1858,14 @@ static USBBusOps ohci_bus_ops = {static void usb_ohci_init (OHCIState *ohci,DeviceState *dev,uint32_t num_ports,dma_addr_t localmem_base, -char *masterbus,uint32_t firstport, -AddressSpace *as,Error **errp) +char *masterbus,uint32_t firstport,AddressSpace *as, +void (*ohci_die_fn)(struct OHCIState *),Error **errp) {Error *err =NULL ;int i; ohci->as = as; + ohci->ohci_die = ohci_die_fn;if (num_ports >OHCI_MAX_PORTS ) { error_setg(errp, "OHCI num-ports=%u is too big (limit is %u ports)",
@@ -1933,18 +1938,28 @@ typedef struct {uint32_t firstport; } OHCIPCIState; -/** A typical O/EHCI will stop operating, set itself into error state -* (which can be queried by MMIO) and will set PERR in its config -* space to signal that it got an error +/** +* A typical OHCI will stop operating and set itself into error state +* (which can be queried by MMIO) to signal that it got an error. */ -static void ohci_die (OHCIState *ohci) +static void ohci_sysbus_die (struct OHCIState *ohci) { -OHCIPCIState *dev =container_of (ohci, OHCIPCIState, state); -trace_usb_ohci_die ();ohci_set_interrupt (ohci,OHCI_INTR_UE );ohci_bus_stop (ohci); +} + +/** +* A typical PCI OHCI will additionally set PERR in its configspace to +* signal that it got an error. +*/ +static void ohci_pci_die (struct OHCIState *ohci) +{ +OHCIPCIState *dev =container_of (ohci, OHCIPCIState, state); + +ohci_sysbus_die (ohci); +pci_set_word (dev->parent_obj.config +PCI_STATUS ,PCI_STATUS_DETECTED_PARITY ); }
@@ -1959,7 +1974,7 @@ static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp)usb_ohci_init (&ohci->state,DEVICE (dev), ohci->num_ports,0 , ohci->masterbus, ohci->firstport, -pci_get_address_space (dev), &err); +pci_get_address_space (dev), ohci_pci_die, &err);if (err) {error_propagate (errp, err);return ;
@@ -2023,7 +2038,7 @@ static void ohci_realize_pxa(DeviceState *dev, Error **errp)usb_ohci_init (&s->ohci, dev, s->num_ports, s->dma_offset, s->masterbus, s->firstport, - &address_space_memory, &err); + &address_space_memory, ohci_sysbus_die, &err);if (err) {error_propagate (errp, err);return ;
Signature · 1 line
2.21.0
PATCH v2 2/2 hw/usb/hcd-ohci: Move PCI-related code into a separate file
In reply to Thomas HuthSome machines (like the pxa2xx-based ARM machines) only have a sysbus OHCI controller, but no PCI. With the new Kconfig-style build system, it will soon be possible to create QEMU binaries that only contain such PCI-less machines. However, the two OHCI controllers, for sysbus and for PCI, are currently both located in one file, so the PCI code is still required for linking here. Move the OHCI-PCI device code into a separate file, so that it is possible to use the sysbus OHCI device also without the PCI dependency.
--- hw/sh4/Kconfig | 2 +- hw/usb/Kconfig | 6 +- hw/usb/Makefile.objs | 1 + hw/usb/hcd-ohci-pci.c | 163 +++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.c | 216 ++---------------------------------------- hw/usb/hcd-ohci.h | 104 ++++++++++++++++++++ 6 files changed, 284 insertions(+), 208 deletions(-) create mode 100644 hw/usb/hcd-ohci-pci.c create mode 100644 hw/usb/hcd-ohci.h
hw/sh4/Kconfig +1 -1
@@ -6,7 +6,7 @@ config R2D select I82378 if TEST_DEVICES select IDE_MMIO select PFLASH_CFI02 - select USB_OHCI + select USB_OHCI_PCI select PCI select SM501 select SH4
hw/usb/Kconfig +5 -1
@@ -8,10 +8,14 @@ config USB_UHCI select USB config USB_OHCI + bool + select USB + +config USB_OHCI_PCI bool default y if PCI_DEVICES depends on PCI - select USB + select USB_OHCI config USB_EHCI bool
hw/usb/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_USB) += desc.o desc-msos.o # usb host adapters common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o +common-obj-$(CONFIG_USB_OHCI_PCI) += hcd-ohci-pci.o common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci.o hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
hw/usb/hcd-ohci-pci.c new file +163 -0
163 lines not on this page · raw message
hw/usb/hcd-ohci.c +10 -206
304 lines not on this page · raw message
hw/usb/hcd-ohci.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.21.0
Hi Thomas,
Quoted 6 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.
Way cleaner. I wonder why you don't use a typedef for the void (*ohci_die_fn)(struct OHCIState *) prototype.
Anyway to this series:
Quoted 16 lines
Thomas Huth (2):
hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices inohci_die()hw/usb/hcd-ohci: Move PCI-related code into a separate file
hw/sh4/Kconfig | 2 +- hw/usb/Kconfig | 6 +- hw/usb/Makefile.objs | 1 + hw/usb/hcd-ohci-pci.c | 163 +++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.c | 219 ++++-------------------------------------- hw/usb/hcd-ohci.h | 104 ++++++++++++++++++++ 6 files changed, 293 insertions(+), 202 deletions(-) create mode 100644 hw/usb/hcd-ohci-pci.c create mode 100644 hw/usb/hcd-ohci.h
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 4 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.
Quoted 5 lines
Quoted 2 lines
v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.Way cleaner. I wonder why you don't use a typedef for the void (*ohci_die_fn)(struct OHCIState *) prototype.
It does not work in that case:
typedef struct OHCIState { // <-- struct OHCIState definition
[...]
uint32_t async_td;
bool async_complete;
void (*ohci_die)(struct OHCIState *ohci); // <-- ohci_die definition
} OHCIState; // <-- typedef OHCIState definitionThe typedef is defined after the ohci_die entry.
Quoted 3 lines
Anyway to this series:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks!
Thomas
Quoted 17 lines · Thomas Huth
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 4 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.Quoted 5 lines
Quoted 2 lines
v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.Way cleaner. I wonder why you don't use a typedef for the void (*ohci_die_fn)(struct OHCIState *) prototype.
It does not work in that case:
typedef struct OHCIState { // <-- struct OHCIState definition
Quoted 8 lines
[...] uint32_t async_td; bool async_complete; void (*ohci_die)(struct OHCIState *ohci); // <-- ohci_die definition } OHCIState; // <-- typedef OHCIState definitionThe typedef is defined after the
ohci_dieentry.
I was thinking of forward declaration:
typedef struct OHCIState OHCIState;
typedef void (ohci_die_fn)(OHCIState *ohci);
struct OHCIState {
[...]
uint32_t async_td;
bool async_complete;
ohci_die_fn *ohci_die;
} OHCIState;static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
uint32_t num_ports, dma_addr_t localmem_base, char *masterbus, uint32_t firstport, AddressSpace *as, ohci_die_fn *ohci_die, Error **errp)
{ ...
Quoted 8 lines
Quoted 4 lines
Anyway to this series:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Thanks!
Thomas
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Thomas Huth
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 4 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.Quoted 5 lines
Quoted 2 lines
v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.Way cleaner. I wonder why you don't use a typedef for the void (*ohci_die_fn)(struct OHCIState *) prototype.
It does not work in that case:
typedef struct OHCIState { // <-- struct OHCIState definition
[...] uint32_t async_td; bool async_complete; void (*ohci_die)(struct OHCIState *ohci); // <-- ohci_die definition } OHCIState; // <-- typedef OHCIState definition
Quoted 7 lines
Quoted 1 line
The typedef is defined after the
ohci_dieentry.I was thinking of forward declaration:
typedef struct OHCIState OHCIState;
typedef void (ohci_die_fn)(OHCIState *ohci);
Could work, too, but I don't like typedeferities... so unless Gerd forces me to use that here, I'd prefer to keep the patch in its current shape.
Thomas
Quoted 30 lines · Thomas Huth
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Thomas Huth
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 4 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.Quoted 5 lines
Quoted 2 lines
v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.Way cleaner. I wonder why you don't use a typedef for the void (*ohci_die_fn)(struct OHCIState *) prototype.
It does not work in that case:
typedef struct OHCIState { // <-- struct OHCIState definition
Quoted 8 lines
[...] uint32_t async_td; bool async_complete; void (*ohci_die)(struct OHCIState *ohci); // <-- ohci_die definition } OHCIState; // <-- typedef OHCIState definitionThe typedef is defined after the
ohci_dieentry.I was thinking of forward declaration:
Quoted 7 lines
Quoted 3 lines
typedef struct OHCIState OHCIState;
typedef void (ohci_die_fn)(OHCIState *ohci);
Could work, too, but I don't like typedeferities... so unless Gerd forces me to use that here, I'd prefer to keep the patch in its current shape.
Fine with me ;)
Quoted 11 lines · Thomas Huth
First patch fixes a problem with
ohci_die(), second patch moves PCI code into a separate file, so that the sysbus OHCI device can also be used without the dependency on the PCI code.v2: Split the patch into two patches, one for the
ohci_die()fix and one
for the PCI code movement.Thomas Huth (2):
hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices inohci_die()hw/usb/hcd-ohci: Move PCI-related code into a separate file
Added to usb queue.
thanks,
Gerd