Make hcd-xhci independent of pci hooks
v3 cover Make hcd-xhci independent of pci hooks
Hi
This patch series attempts to make 'hcd-xhci' an independent model so it can be used by both pci and system-bus interface.
Changes for V2:
Make XHCIState non-qom
Use container_of functions for retriving pci device instance Initialize the AddressSpace pointer in PATCH 1/3 itself
Changes for V3:
Convert XHCIState to TYPE_DEVICE and register as a child of XHCIPciState.
Sai Pavan Boddu (3):
usb/hcd-xhci: Make dma read/writes hooks pci free usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c usb/hcd-xhci: Split pci wrapper for xhci base model
hw/usb/Kconfig | 6 ++ hw/usb/Makefile.objs | 1 + hw/usb/hcd-xhci-nec.c | 18 ++-- hw/usb/hcd-xhci-pci.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci-pci.h | 45 +++++++++ hw/usb/hcd-xhci.c | 259 ++++++++++---------------------------------------- hw/usb/hcd-xhci.h | 20 ++-- 7 files changed, 367 insertions(+), 224 deletions(-) create mode 100644 hw/usb/hcd-xhci-pci.c create mode 100644 hw/usb/hcd-xhci-pci.h
Signature · 1 line
2.7.4
PATCH v3 1/3 usb/hcd-xhci: Make dma read/writes hooks pci free
This patch starts making the hcd-xhci.c pci free, as part of this restructuring dma read/writes are handled without passing pci object.
--- hw/usb/hcd-xhci.c | 24 +++++++++++------------- hw/usb/hcd-xhci.h | 3 +++ 2 files changed, 14 insertions(+), 13 deletions(-)
hw/usb/hcd-xhci.c +11 -13
@@ -495,7 +495,7 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr,assert ((len %sizeof (uint32_t )) ==0 ); -pci_dma_read (PCI_DEVICE (xhci), addr, buf, len); +dma_memory_read (xhci->as, addr, buf, len);for (i =0 ; i < (len /sizeof (uint32_t )); i++) { buf[i] =le32_to_cpu (buf[i]);
@@ -515,7 +515,7 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,for (i =0 ; i < n; i++) { tmp[i] =cpu_to_le32 (buf[i]); } -pci_dma_write (PCI_DEVICE (xhci), addr, tmp, len); +dma_memory_write (xhci->as, addr, tmp, len); }static XHCIPort *xhci_lookup_port (XHCIState *xhci,struct USBPort *uport)
@@ -644,7 +644,6 @@ static void xhci_die(XHCIState *xhci)static void xhci_write_event (XHCIState *xhci,XHCIEvent *event,int v) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);XHCIInterrupter *intr = &xhci->intr[v];XHCITRB ev_trb;dma_addr_t addr;
@@ -663,7 +662,7 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v) ev_trb.status, ev_trb.control); addr = intr->er_start +TRB_SIZE *intr->er_ep_idx; -pci_dma_write (pci_dev, addr, &ev_trb,TRB_SIZE ); +dma_memory_write (xhci->as, addr, &ev_trb,TRB_SIZE ); intr->er_ep_idx++;if (intr->er_ep_idx >= intr->er_size) {
@@ -720,12 +719,11 @@ static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring,static TRBType xhci_ring_fetch (XHCIState *xhci,XHCIRing *ring,XHCITRB *trb,dma_addr_t *addr) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);uint32_t link_cnt =0 ;while (1 ) {TRBType type; -pci_dma_read (pci_dev, ring->dequeue, trb,TRB_SIZE ); +dma_memory_read (xhci->as, ring->dequeue, trb,TRB_SIZE ); trb->addr = ring->dequeue; trb->ccs = ring->ccs;le64_to_cpus (&trb->parameter);
@@ -762,7 +760,6 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,static int xhci_ring_chain_length (XHCIState *xhci,const XHCIRing *ring) { -PCIDevice *pci_dev =PCI_DEVICE (xhci);XHCITRB trb;int length =0 ;dma_addr_t dequeue = ring->dequeue;
@@ -773,7 +770,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)while (1 ) {TRBType type; -pci_dma_read (pci_dev, dequeue, &trb,TRB_SIZE ); +dma_memory_read (xhci->as, dequeue, &trb,TRB_SIZE );le64_to_cpus (&trb.parameter);le32_to_cpus (&trb.status);le32_to_cpus (&trb.control);
@@ -828,7 +825,7 @@ static void xhci_er_reset(XHCIState *xhci, int v)xhci_die (xhci);return ; } -pci_dma_read (PCI_DEVICE (xhci), erstba, &seg,sizeof (seg)); +dma_memory_read (xhci->as, erstba, &seg,sizeof (seg));le32_to_cpus (&seg.addr_low);le32_to_cpus (&seg.addr_high);le32_to_cpus (&seg.size);
@@ -1440,7 +1437,7 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer)int i; xfer->int_req = false; -pci_dma_sglist_init (&xfer->sgl,PCI_DEVICE (xhci), xfer->trb_count); +qemu_sglist_init (&xfer->sgl,DEVICE (xhci), xfer->trb_count, xhci->as);for (i =0 ; i < xfer->trb_count; i++) {XHCITRB *trb = &xfer->trbs[i];dma_addr_t addr;
@@ -2101,7 +2098,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,assert (slotid >=1 && slotid <= xhci->numslots); dcbaap =xhci_addr64 (xhci->dcbaap_low, xhci->dcbaap_high); - poctx =ldq_le_pci_dma (PCI_DEVICE (xhci), dcbaap +8 * slotid); + poctx =ldq_le_dma (xhci->as, dcbaap +8 * slotid); ictx =xhci_mask64 (pictx); octx =xhci_mask64 (poctx);
@@ -2439,7 +2436,7 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)/* TODO: actually implement real values here */ bw_ctx[0 ] =0 ;memset (&bw_ctx[1 ],80 , xhci->numports);/* 80% */ -pci_dma_write (PCI_DEVICE (xhci), ctx, bw_ctx,sizeof (bw_ctx)); +dma_memory_write (xhci->as, ctx, bw_ctx,sizeof (bw_ctx));return CC_SUCCESS ; }
@@ -3431,6 +3428,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) }usb_xhci_init (xhci); + xhci->as =pci_get_address_space (dev); xhci->mfwrap_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , xhci_mfwrap_timer, xhci);memory_region_init (&xhci->mem,OBJECT (xhci),"xhci" ,LEN_REGS );
@@ -3531,7 +3529,7 @@ static int usb_xhci_post_load(void *opaque, int version_id)continue ; } slot->ctx = -xhci_mask64 (ldq_le_pci_dma (pci_dev, dcbaap +8 * slotid)); +xhci_mask64 (ldq_le_dma (xhci->as, dcbaap +8 * slotid));xhci_dma_read_u32s (xhci, slot->ctx, slot_ctx,sizeof (slot_ctx)); slot->uport =xhci_lookup_uport (xhci, slot_ctx);if (!slot->uport) {
hw/usb/hcd-xhci.h +3 -0
@@ -22,6 +22,8 @@#ifndef HW_USB_HCD_XHCI_H #define HW_USB_HCD_XHCI_H +#include "sysemu/dma.h" +#define TYPE_XHCI "base-xhci"#define TYPE_NEC_XHCI "nec-usb-xhci"#define TYPE_QEMU_XHCI "qemu-xhci"
@@ -189,6 +191,7 @@ struct XHCIState {USBBus bus;MemoryRegion mem; +AddressSpace *as;MemoryRegion mem_cap;MemoryRegion mem_oper;MemoryRegion mem_runtime;
Signature · 1 line
2.7.4
PATCH v3 2/3 usb/hcd-xhci: Move qemu-xhci device to hcd-xhci-pci.c
In reply to Sai Pavan BodduMove pci specific devices to new file. This set the environment to move all pci specific hooks in hcd-xhci.c to hcd-xhci-pci.c.
--- hw/usb/hcd-xhci-pci.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci.c | 40 ++------------------------------ hw/usb/hcd-xhci.h | 2 ++ 3 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 hw/usb/hcd-xhci-pci.c
hw/usb/hcd-xhci-pci.c new file +64 -0
@@ -0,0 +1,64 @@ +/* +* USB xHCI controller with PCI system bus emulation +* +* Copyright (c) 2011 Securiforest +* Date: 2011-05-11 ; Author: Hector Martin <[email protected]> +* Based on usb-ohci.c, emulates Renesas NEC USB 3.0 +* Date: 2020-03-01; Author: Sai Pavan Boddu <[email protected]> +* Moved the pci specific content for hcd-xhci.c to hcd-xhci-pci.c +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/qdev-properties.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" +#include "hcd-xhci.h" +#include "trace.h" +#include "qapi/error.h" + +static void qemu_xhci_class_init (ObjectClass *klass,void *data) +{ +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->vendor_id =PCI_VENDOR_ID_REDHAT ; + k->device_id =PCI_DEVICE_ID_REDHAT_XHCI ; + k->revision =0x01 ; +} + +static void qemu_xhci_instance_init (Object *obj) +{ +XHCIState *xhci =XHCI (obj); + + xhci->msi =ON_OFF_AUTO_OFF ; + xhci->msix =ON_OFF_AUTO_AUTO ; + xhci->numintrs =MAXINTRS ; + xhci->numslots =MAXSLOTS ; +xhci_set_flag (xhci,XHCI_FLAG_SS_FIRST ); +} + +static const TypeInfo qemu_xhci_info = { + .name =TYPE_QEMU_XHCI , + .parent =TYPE_XHCI , + .class_init = qemu_xhci_class_init, + .instance_init = qemu_xhci_instance_init, +}; + +static void xhci_register_types (void ) +{ +type_register_static (&qemu_xhci_info); +} + +type_init (xhci_register_types)
hw/usb/hcd-xhci.c +2 -38
@@ -429,12 +429,12 @@ static const char *ep_state_name(uint32_t state) ARRAY_SIZE(ep_state_names)); } -static bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit) +bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit) {return xhci->flags & (1 << bit); } -static void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit) +void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit) { xhci->flags |= (1 << bit); }
@@ -3692,13 +3692,6 @@ static Property xhci_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void xhci_instance_init (Object *obj) -{ -/* QEMU_PCI_CAP_EXPRESS initialization does not depend on QEMU command -* line, therefore, no need to wait to realize like other devices */ -PCI_DEVICE (obj)->cap_present |=QEMU_PCI_CAP_EXPRESS ; -} -static void xhci_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);
@@ -3718,7 +3711,6 @@ static const TypeInfo xhci_info = { .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(XHCIState), .class_init = xhci_class_init, - .instance_init = xhci_instance_init, .abstract = true, .interfaces = (InterfaceInfo []) { {INTERFACE_PCIE_DEVICE },
@@ -3727,37 +3719,9 @@ static const TypeInfo xhci_info = { }, }; -static void qemu_xhci_class_init (ObjectClass *klass,void *data) -{ -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - - k->vendor_id =PCI_VENDOR_ID_REDHAT ; - k->device_id =PCI_DEVICE_ID_REDHAT_XHCI ; - k->revision =0x01 ; -} - -static void qemu_xhci_instance_init (Object *obj) -{ -XHCIState *xhci =XHCI (obj); - - xhci->msi =ON_OFF_AUTO_OFF ; - xhci->msix =ON_OFF_AUTO_AUTO ; - xhci->numintrs =MAXINTRS ; - xhci->numslots =MAXSLOTS ; -xhci_set_flag (xhci,XHCI_FLAG_SS_FIRST ); -} - -static const TypeInfo qemu_xhci_info = { - .name =TYPE_QEMU_XHCI , - .parent =TYPE_XHCI , - .class_init = qemu_xhci_class_init, - .instance_init = qemu_xhci_instance_init, -}; -static void xhci_register_types (void ) {type_register_static (&xhci_info); -type_register_static (&qemu_xhci_info); }type_init (xhci_register_types)
hw/usb/hcd-xhci.h +2 -0
@@ -232,4 +232,6 @@ struct XHCIState { bool nec_quirks; }; +bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit); +void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit);#endif
Signature · 1 line
2.7.4
PATCH v3 3/3 usb/hcd-xhci: Split pci wrapper for xhci base model
In reply to Sai Pavan BodduThis patch sets the base to use xhci as sysbus model, for which pci specific hooks are moved to hcd-xhci-pci.c. As a part of this requirment msi/msix interrupts handling is moved under XHCIPCIState. Made required changes for qemu-xhci-nec.
--- hw/usb/Kconfig | 6 ++ hw/usb/Makefile.objs | 1 + hw/usb/hcd-xhci-nec.c | 18 ++--- hw/usb/hcd-xhci-pci.c | 188 +++++++++++++++++++++++++++++++++++++++++++++-- hw/usb/hcd-xhci-pci.h | 45 ++++++++++++ hw/usb/hcd-xhci.c | 197 ++++++++++---------------------------------------- hw/usb/hcd-xhci.h | 15 ++-- 7 files changed, 291 insertions(+), 179 deletions(-) create mode 100644 hw/usb/hcd-xhci-pci.h
hw/usb/Kconfig +6 -0
@@ -36,6 +36,12 @@ config USB_XHCI depends on PCI select USB +config USB_XHCI_PCI + bool + default y if PCI_DEVICES + depends on PCI + select USB_XHCI + config USB_XHCI_NEC bool default y if PCI_DEVICES
hw/usb/Makefile.objs +1 -0
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_USB_EHCI_PCI) += hcd-ehci-pci.o common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o +common-obj-$(CONFIG_USB_XHCI_PCI) += hcd-xhci-pci.o common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o
hw/usb/hcd-xhci-nec.c +9 -9
@@ -25,17 +25,17 @@#include "hw/pci/pci.h" #include "hw/qdev-properties.h" -#include "hcd-xhci.h" +#include "hcd-xhci-pci.h" static Property nec_xhci_properties[] = { -DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIState, msi,ON_OFF_AUTO_AUTO ), -DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIState, msix,ON_OFF_AUTO_AUTO ), -DEFINE_PROP_BIT ("superspeed-ports-first" , - XHCIState, flags,XHCI_FLAG_SS_FIRST , true), -DEFINE_PROP_BIT ("force-pcie-endcap" , XHCIState, flags, +DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIPciState, msi,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_ON_OFF_AUTO ("msix" , XHCIPciState, msix,ON_OFF_AUTO_AUTO ), +DEFINE_PROP_BIT ("superspeed-ports-first" , XHCIPciState, + xhci.flags,XHCI_FLAG_SS_FIRST , true), +DEFINE_PROP_BIT ("force-pcie-endcap" , XHCIPciState, xhci.flags,XHCI_FLAG_FORCE_PCIE_ENDCAP , false), -DEFINE_PROP_UINT32 ("intrs" , XHCIState, numintrs,MAXINTRS ), -DEFINE_PROP_UINT32 ("slots" , XHCIState, numslots,MAXSLOTS ), +DEFINE_PROP_UINT32 ("intrs" , XHCIPciState, xhci.numintrs,MAXINTRS ), +DEFINE_PROP_UINT32 ("slots" , XHCIPciState, xhci.numslots,MAXSLOTS ),DEFINE_PROP_END_OF_LIST (), };
@@ -52,7 +52,7 @@ static void nec_xhci_class_init(ObjectClass *klass, void *data)static const TypeInfo nec_xhci_info = { .name =TYPE_NEC_XHCI , - .parent =TYPE_XHCI , + .parent =TYPE_XHCI_PCI , .class_init = nec_xhci_class_init, };
hw/usb/hcd-xhci-pci.c +183 -5
218 lines not on this page · raw message
hw/usb/hcd-xhci-pci.h new file +45 -0
45 lines not on this page · raw message
hw/usb/hcd-xhci.c +40 -157
356 lines not on this page · raw message
hw/usb/hcd-xhci.h +7 -8
@@ -170,7 +170,7 @@ typedef struct XHCIInterrupter {uint32_t erdp_low;uint32_t erdp_high; -bool msix_used, er_pcs; +bool er_pcs;dma_addr_t er_start;uint32_t er_size;
@@ -184,10 +184,8 @@ typedef struct XHCIInterrupter { } XHCIInterrupter; -struct XHCIState { -/*< private >*/ -PCIDevice parent_obj; -/*< public >*/ +typedef struct XHCIState { + DeviceState parent; USBBus bus; MemoryRegion mem;
@@ -204,8 +202,9 @@ struct XHCIState {uint32_t numslots;uint32_t flags;uint32_t max_pstreams_mask; -OnOffAuto msi; -OnOffAuto msix; +void (*intr_update)(XHCIState *s,int n,bool enable); +void (*intr_raise)(XHCIState *s,int n,bool level); +DeviceState *hostOpaque;/* Operational Registers */ uint32_t usbcmd;
@@ -230,7 +229,7 @@ struct XHCIState {XHCIRing cmd_ring;bool nec_quirks; -}; +} XHCIState;bool xhci_get_flag (XHCIState *xhci,enum xhci_flags bit);void xhci_set_flag (XHCIState *xhci,enum xhci_flags bit);
Signature · 1 line
2.7.4
Re: [PATCH v3 3/3] usb/hcd-xhci: Split pci wrapper for xhci base model
Hi,
Quoted 2 lines
--- a/hw/usb/Kconfig
--- a/hw/usb/Makefile.objs
These two hunks need to go to patch 2/3
take care,
Gerd
Hi Gerd,
Any review on V3. So that I can work on.
Regards,
Sai Pavan
Quoted 44 lines
-----Original Message-----
From: Sai Pavan Boddu <[email protected]>
Sent: Tuesday, July 7, 2020 10:14 PM
To: Gerd Hoffmann <[email protected]>; Peter Maydell <[email protected]>; Markus Armbruster <[email protected]>
Cc: Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>; Sai Pavan Boddu <[email protected]>
Subject: [PATCH v3 0/3] Make hcd-xhci independent of pci hooksHi
This patch series attempts to make 'hcd-xhci' an independent model so it can be used by both pci and system-bus interface.
Changes for V2:
Make XHCIState non-qom
Usecontainer_offunctions for retriving pci device instance Initialize the AddressSpace pointer in PATCH 1/3 itself Changes for V3:
Convert XHCIState toTYPE_DEVICEand register as a child of XHCIPciState.Sai Pavan Boddu (3):
usb/hcd-xhci: Make dma read/writes hooks pci free usb/hcd-xhci: Move qemu-xhci device tohcd-xhci-pci.cusb/hcd-xhci: Split pci wrapper for xhci base modelhw/usb/Kconfig | 6 ++ hw/usb/Makefile.objs | 1 + hw/usb/hcd-xhci-nec.c | 18 ++-- hw/usb/hcd-xhci-pci.c | 242 ++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-xhci-pci.h | 45 +++++++++ hw/usb/hcd-xhci.c | 259 ++++++++++---------------------------------------- hw/usb/hcd-xhci.h | 20 ++-- 7 files changed, 367 insertions(+), 224 deletions(-) create mode 100644
hw/usb/hcd-xhci-pci.ccreate mode 100644hw/usb/hcd-xhci-pci.h--
2.7.4
Quoted 3 lines · Sai Pavan Boddu
Hi Gerd,
Any review on V3. So that I can work on.
Busy due to freeze, sorry for the delay.
Looks good to me overall. Not tested yet.
Wasn't the plan to include the sysbus bits too, so it's easier to see how code code separation works out on both pci and sysbus?
take care,
Gerd
Hi Gred,
Quoted 17 lines
-----Original Message-----
From: Gerd Hoffmann <[email protected]>
Sent: Wednesday, July 15, 2020 4:21 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Peter Maydell <[email protected]>; Markus Armbruster <[email protected]>; Thomas Huth <[email protected]>; Eduardo Habkost <[email protected]>; [email protected]; Alistair Francis <[email protected]>; 'Marc-André Lureau' <[email protected]>; Ying Fang <[email protected]>; Paolo Bonzini <[email protected]>; 'Philippe Mathieu-Daudé' <[email protected]>; Vikram Garhwal <[email protected]>; Paul Zimmerman <[email protected]>
Subject: Re: [PATCH v3 0/3] Make hcd-xhci independent of pci hooksQuoted 2 lines · Sai Pavan Boddu
Hi Gerd,
Quoted 7 lines
Quoted 1 line
Any review on V3. So that I can work on.
Busy due to freeze, sorry for the delay.
Looks good to me overall. Not tested yet.Wasn't the plan to include the sysbus bits too, so it's easier to see how code code separation works out on both pci and sysbus?
[Sai Pavan Boddu] Ok, I will include that in V4.
Thanks,
Sai Pavan
Quoted 3 lines
take care,
Gerd