ehci pci splitup
cover ehci pci splitup
Hi,
Based on Peters series, not tested much yet, sysfs dropped but adding back in should be as easy as adding a hcd-ehci-sysbus.c file simliar to the pci variant. No changes in ehci core should be needed.
Comments?
cheers,
Gerd
Gerd Hoffmann (1):
usb/ehci: split into multiple source files
Peter Crosthwaite (4):
usb/ehci: parameterise the register region offsets usb/ehci: Abstract away PCI DMA API usb/ehci: seperate out PCIisms
usb/ehci: Guard definition of EHCI_DEBUG
hw/usb/Makefile.objs | 2 +- hw/usb/hcd-ehci-pci.c | 138 +++++++++++++++ hw/usb/hcd-ehci.c | 465 ++++--------------------------------------------- hw/usb/hcd-ehci.h | 320 ++++++++++++++++++++++++++++++++++ 4 files changed, 496 insertions(+), 429 deletions(-) create mode 100644 hw/usb/hcd-ehci-pci.c create mode 100644 hw/usb/hcd-ehci.h
RFC PATCH 1/5 usb/ehci: parameterise the register region offsets
From: Peter Crosthwaite <[email protected]>
The capabilities register and operational register offsets can vary from one EHCI implementation to the next. Parameterise accordingly.
--- hw/usb/hcd-ehci.c | 68 ++++++++++++++++++++++++++++------------------------- 1 files changed, 36 insertions(+), 32 deletions(-)
hw/usb/hcd-ehci.c +36 -32
@@ -48,20 +48,18 @@#define USB_RET_PROCERR (-99)#define MMIO_SIZE 0x1000 +#define CAPA_SIZE 0x10/* Capability Registers Base Address - section 2.2 */ -#define CAPREGBASE 0x0000 -#define CAPLENGTH CAPREGBASE + 0x0000 // 1-byte, 0x0001 reserved -#define HCIVERSION CAPREGBASE + 0x0002 // 2-bytes, i/f version # -#define HCSPARAMS CAPREGBASE + 0x0004 // 4-bytes, structural params -#define HCCPARAMS CAPREGBASE + 0x0008 // 4-bytes, capability params +#define CAPLENGTH 0x0000/* 1-byte, 0x0001 reserved */ +#define HCIVERSION 0x0002/* 2-bytes, i/f version # */ +#define HCSPARAMS 0x0004/* 4-bytes, structural params */ +#define HCCPARAMS 0x0008/* 4-bytes, capability params */ #define EECP HCCPARAMS + 1 -#define HCSPPORTROUTE1 CAPREGBASE + 0x000c -#define HCSPPORTROUTE2 CAPREGBASE + 0x0010 +#define HCSPPORTROUTE1 0x000c +#define HCSPPORTROUTE2 0x0010 -#define OPREGBASE 0x0020 // Operational Registers Base Address - -#define USBCMD OPREGBASE + 0x0000 +#define USBCMD 0x0000#define USBCMD_RUNSTOP (1 << 0) // run / Stop#define USBCMD_HCRESET (1 << 1) // HC Reset#define USBCMD_FLS (3 << 2) // Frame List Size
@@ -75,7 +73,7 @@#define USBCMD_ITC (0x7f << 16) // Int Threshold Control#define USBCMD_ITC_SH 16 // Int Threshold Control Shift -#define USBSTS OPREGBASE + 0x0004 +#define USBSTS 0x0004#define USBSTS_RO_MASK 0x0000003f#define USBSTS_INT (1 << 0) // USB Interrupt#define USBSTS_ERRINT (1 << 1) // Error Interrupt
@@ -92,18 +90,18 @@* Interrupt enable bits correspond to the interrupt active bits in USBSTS * so no need to redefine here. */ -#define USBINTR OPREGBASE + 0x0008 +#define USBINTR 0x0008#define USBINTR_MASK 0x0000003f -#define FRINDEX OPREGBASE + 0x000c -#define CTRLDSSEGMENT OPREGBASE + 0x0010 -#define PERIODICLISTBASE OPREGBASE + 0x0014 -#define ASYNCLISTADDR OPREGBASE + 0x0018 +#define FRINDEX 0x000c +#define CTRLDSSEGMENT 0x0010 +#define PERIODICLISTBASE 0x0014 +#define ASYNCLISTADDR 0x0018#define ASYNCLISTADDR_MASK 0xffffffe0 -#define CONFIGFLAG OPREGBASE + 0x0040 +#define CONFIGFLAG 0x0040 -#define PORTSC (OPREGBASE + 0x0044) +#define PORTSC 0x0044#define PORTSC_BEGIN PORTSC#define PORTSC_END (PORTSC + 4 * NB_PORTS)/*
@@ -395,6 +393,8 @@ struct EHCIState {MemoryRegion mem_opreg;MemoryRegion mem_ports;int companion_count; +uint16_t capsbase; +uint16_t opregbase;/* properties */ uint32_t maxframes;
@@ -403,9 +403,9 @@ struct EHCIState {* EHCI spec version 1.0 Section 2.3 * Host Controller Operational Registers */ -uint8_t caps[OPREGBASE ]; +uint8_t caps[CAPA_SIZE ];union { -uint32_t opreg[(PORTSC_BEGIN -OPREGBASE )/sizeof (uint32_t )]; +uint32_t opreg[PORTSC_BEGIN /sizeof (uint32_t )];struct {uint32_t usbcmd;uint32_t usbsts;
@@ -506,8 +506,7 @@ static const char *state2str(uint32_t state)static const char *addr2str (hwaddr addr) { -return nr2str (ehci_mmio_names,ARRAY_SIZE (ehci_mmio_names), - addr +OPREGBASE ); +return nr2str (ehci_mmio_names,ARRAY_SIZE (ehci_mmio_names), addr); }static void ehci_trace_usbsts (uint32_t mask,int state)
@@ -1115,7 +1114,7 @@ static uint64_t ehci_opreg_read(void *ptr, hwaddr addr,uint32_t val; val = s->opreg[addr >>2 ]; -trace_usb_ehci_opreg_read (addr +OPREGBASE ,addr2str (addr), val); +trace_usb_ehci_opreg_read (addr + s->opregbase,addr2str (addr), val);return val; }
@@ -1211,9 +1210,9 @@ static void ehci_opreg_write(void *ptr, hwaddr addr,uint32_t old = *mmio;int i; -trace_usb_ehci_opreg_write (addr +OPREGBASE ,addr2str (addr), val); +trace_usb_ehci_opreg_write (addr + s->opregbase,addr2str (addr), val); -switch (addr +OPREGBASE ) { +switch (addr) {case USBCMD :if (val &USBCMD_HCRESET ) {ehci_reset (s);
@@ -1291,7 +1290,8 @@ static void ehci_opreg_write(void *ptr, hwaddr addr, } *mmio = val; -trace_usb_ehci_opreg_change (addr +OPREGBASE ,addr2str (addr), *mmio, old); +trace_usb_ehci_opreg_change (addr + s->opregbase,addr2str (addr), + *mmio, old); }
@@ -2731,8 +2731,11 @@ static int usb_ehci_initfn(PCIDevice *dev) pci_conf[0x6e ] =0x00 ; pci_conf[0x6f ] =0xc0 ;// USBLEFCTLSTS + s->capsbase =0x00 ; + s->opregbase =0x20 ; +/* 2.2 host controller interface version */ - s->caps[0x00 ] = (uint8_t )OPREGBASE ; + s->caps[0x00 ] = (uint8_t )(s->opregbase - s->capsbase); s->caps[0x01 ] =0x00 ; s->caps[0x02 ] =0x00 ; s->caps[0x03 ] =0x01 ;/* HC version */
@@ -2765,15 +2768,16 @@ static int usb_ehci_initfn(PCIDevice *dev)memory_region_init (&s->mem,"ehci" ,MMIO_SIZE );memory_region_init_io (&s->mem_caps, &ehci_mmio_caps_ops, s, -"capabilities" ,OPREGBASE ); +"capabilities" ,CAPA_SIZE );memory_region_init_io (&s->mem_opreg, &ehci_mmio_opreg_ops, s, -"operational" ,PORTSC_BEGIN -OPREGBASE ); +"operational" ,PORTSC_BEGIN );memory_region_init_io (&s->mem_ports, &ehci_mmio_port_ops, s,"ports" ,PORTSC_END -PORTSC_BEGIN ); -memory_region_add_subregion (&s->mem,0 , &s->mem_caps); -memory_region_add_subregion (&s->mem,OPREGBASE , &s->mem_opreg); -memory_region_add_subregion (&s->mem,PORTSC_BEGIN , &s->mem_ports); +memory_region_add_subregion (&s->mem, s->capsbase, &s->mem_caps); +memory_region_add_subregion (&s->mem, s->opregbase, &s->mem_opreg); +memory_region_add_subregion (&s->mem, s->opregbase +PORTSC_BEGIN , + &s->mem_ports);pci_register_bar (&s->dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->mem);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [RfC PATCH 1/5] usb/ehci: parameterise the register region offsets
Am 30.10.2012 12:28, schrieb Gerd Hoffmann:
Quoted 7 lines
From: Peter Crosthwaite <[email protected]>
The capabilities register and operational register offsets can vary from one EHCI implementation to the next. Parameterise accordingly.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
RFC PATCH 2/5 usb/ehci: Abstract away PCI DMA API
In reply to Gerd HoffmannFrom: Peter Crosthwaite <[email protected]>
Pull the DMAContext for the PCI DMA out at device init time and put it into the device state. Use dma_memory_read/write() instead of pci specific versions.
--- hw/usb/hcd-ehci.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
hw/usb/hcd-ehci.c +8 -5
@@ -389,6 +389,7 @@ struct EHCIState {USBBus bus;qemu_irq irq;MemoryRegion mem; +DMAContext *dma;MemoryRegion mem_caps;MemoryRegion mem_opreg;MemoryRegion mem_ports;
@@ -1304,7 +1305,7 @@ static inline int get_dwords(EHCIState *ehci, uint32_t addr,int i;for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) { -pci_dma_read (&ehci->dev, addr, buf,sizeof (*buf)); +dma_memory_read (ehci->dma, addr, buf,sizeof (*buf)); *buf =le32_to_cpu (*buf); }
@@ -1319,7 +1320,7 @@ static inline int put_dwords(EHCIState *ehci, uint32_t addr,for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) {uint32_t tmp =cpu_to_le32 (*buf); -pci_dma_write (&ehci->dev, addr, &tmp,sizeof (tmp)); +dma_memory_write (ehci->dma, addr, &tmp,sizeof (tmp)); }return 1 ;
@@ -1402,7 +1403,7 @@ static int ehci_init_transfer(EHCIPacket *p) cpage =get_field (p->qtd.token,QTD_TOKEN_CPAGE ); bytes =get_field (p->qtd.token,QTD_TOKEN_TBYTES ); offset = p->qtd.bufptr[0 ] & ~QTD_BUFPTR_MASK ; -pci_dma_sglist_init (&p->sgl, &p->queue->ehci->dev,5 ); +qemu_sglist_init (&p->sgl,5 , p->queue->ehci->dma);while (bytes >0 ) {if (cpage >4 ) {
@@ -1647,7 +1648,7 @@ static int ehci_process_itd(EHCIState *ehci,return USB_RET_PROCERR ; } -pci_dma_sglist_init (&ehci->isgl, &ehci->dev,2 ); +qemu_sglist_init (&ehci->isgl,2 , ehci->dma);if (off + len >4096 ) {/* transfer crosses page border */ uint32_t len2 = off + len -4096 ;
@@ -2402,7 +2403,7 @@ static void ehci_advance_periodic_state(EHCIState *ehci) } list |= ((ehci->frindex &0x1ff8 ) >>1 ); -pci_dma_read (&ehci->dev, list, &entry,sizeof entry); +dma_memory_read (ehci->dma, list, &entry,sizeof entry); entry =le32_to_cpu (entry); DPRINTF("PERIODIC state adv fr=%d. [%08X] -> %08X\n",
@@ -2750,6 +2751,8 @@ static int usb_ehci_initfn(PCIDevice *dev) s->irq = s->dev.irq[3 ]; + s->dma =pci_dma_context (dev); +usb_bus_new (&s->bus, &ehci_bus_ops, &s->dev.qdev);for (i =0 ; i <NB_PORTS ; i++) { usb_register_port(&s->bus, &s->ports[i], s, i, &ehci_port_ops,
Signature · 1 line
1.7.1
Re: [Qemu-devel] [RfC PATCH 2/5] usb/ehci: Abstract away PCI DMA API
Am 30.10.2012 12:28, schrieb Gerd Hoffmann:
Quoted 7 lines
From: Peter Crosthwaite <[email protected]>
Pull the DMAContext for the PCI DMA out at device init time and put it into the device state. Use dma_memory_read/write() instead of pci specific versions.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
RFC PATCH 3/5 usb/ehci: seperate out PCIisms
In reply to Gerd HoffmannFrom: Peter Crosthwaite <[email protected]>
Seperate the PCI stuff from the EHCI components. Extracted the PCIDevice out into a new wrapper struct to make EHCIState non-PCI-specific. Seperated tho non PCI init component out into a seperate "common" init function.
--- hw/usb/hcd-ehci.c | 124 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 72 insertions(+), 52 deletions(-)
hw/usb/hcd-ehci.c +72 -52
@@ -385,7 +385,6 @@ struct EHCIQueue { typedef QTAILQ_HEAD(EHCIQueueHead, EHCIQueue) EHCIQueueHead;struct EHCIState { -PCIDevice dev;USBBus bus;qemu_irq irq;MemoryRegion mem;
@@ -447,6 +446,11 @@ struct EHCIState {bool int_req_by_async; }; +typedef struct EHCIPCIState { +PCIDevice pcidev; +EHCIState ehci; +}EHCIPCIState ; +#define SET_LAST_RUN_CLOCK (s) \ (s)->last_run_ns = qemu_get_clock_ns(vm_clock);
@@ -2553,7 +2557,7 @@ static const MemoryRegionOps ehci_mmio_port_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int usb_ehci_initfn (PCIDevice *dev); +static int usb_ehci_pci_initfn (PCIDevice *dev);static USBPortOps ehci_port_ops = { .attach = ehci_attach,
@@ -2614,12 +2618,11 @@ static void usb_ehci_vm_state_change(void *opaque, int running, RunState state) }static const VMStateDescription vmstate_ehci = { - .name ="ehci" , + .name ="ehci-core" , .version_id =2 , .minimum_version_id =1 , .post_load = usb_ehci_post_load, .fields = (VMStateField []) { -VMSTATE_PCI_DEVICE (dev, EHCIState),/* mmio registers */ VMSTATE_UINT32 (usbcmd, EHCIState),VMSTATE_UINT32 (usbsts, EHCIState),
@@ -2650,8 +2653,19 @@ static const VMStateDescription vmstate_ehci = { } }; -static Property ehci_properties[] = { -DEFINE_PROP_UINT32 ("maxframes" , EHCIState, maxframes,128 ), +static const VMStateDescription vmstate_ehci_pci = { + .name ="ehci" , + .version_id =2 , + .minimum_version_id =1 , + .post_load = usb_ehci_post_load, + .fields = (VMStateField []) { +VMSTATE_PCI_DEVICE (pcidev, EHCIPCIState), +VMSTATE_STRUCT (ehci, EHCIPCIState,2 , vmstate_ehci, EHCIState), + } +}; + +static Property ehci_pci_properties[] = { +DEFINE_PROP_UINT32 ("maxframes" , EHCIPCIState, ehci.maxframes,128 ),DEFINE_PROP_END_OF_LIST (), };
@@ -2660,13 +2674,13 @@ static void ehci_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = usb_ehci_initfn; + k->init = usb_ehci_pci_initfn; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->device_id =PCI_DEVICE_ID_INTEL_82801D ;/* ich4 */ k->revision =0x10 ; k->class_id =PCI_CLASS_SERIAL_USB ; dc->vmsd = &vmstate_ehci; - dc->props = ehci_properties; + dc->props = ehci_pci_properties; }static TypeInfo ehci_info = {
@@ -2681,13 +2695,13 @@ static void ich9_ehci_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = usb_ehci_initfn; + k->init = usb_ehci_pci_initfn; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->device_id =PCI_DEVICE_ID_INTEL_82801I_EHCI1 ; k->revision =0x03 ; k->class_id =PCI_CLASS_SERIAL_USB ; dc->vmsd = &vmstate_ehci; - dc->props = ehci_properties; + dc->props = ehci_pci_properties; }static TypeInfo ich9_ehci_info = {
@@ -2697,44 +2711,10 @@ static TypeInfo ich9_ehci_info = { .class_init = ich9_ehci_class_init, }; -static int usb_ehci_initfn (PCIDevice *dev) +static void usb_ehci_initfn (EHCIState *s,DeviceState *dev) { -EHCIState *s =DO_UPCAST (EHCIState, dev, dev); -uint8_t *pci_conf = s->dev.config;int i; -pci_set_byte (&pci_conf[PCI_CLASS_PROG ],0x20 ); - -/* capabilities pointer */ -pci_set_byte (&pci_conf[PCI_CAPABILITY_LIST ],0x00 ); -//pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x50); - -pci_set_byte (&pci_conf[PCI_INTERRUPT_PIN ],4 );/* interrupt pin D */ -pci_set_byte (&pci_conf[PCI_MIN_GNT ],0 ); -pci_set_byte (&pci_conf[PCI_MAX_LAT ],0 ); - -// pci_conf[0x50] = 0x01; // power management caps - -pci_set_byte (&pci_conf[USB_SBRN ],USB_RELEASE_2 );// release number (2.1.4) -pci_set_byte (&pci_conf[0x61 ],0x20 );// frame length adjustment (2.1.5) -pci_set_word (&pci_conf[0x62 ],0x00 );// port wake up capability (2.1.6) - - pci_conf[0x64 ] =0x00 ; - pci_conf[0x65 ] =0x00 ; - pci_conf[0x66 ] =0x00 ; - pci_conf[0x67 ] =0x00 ; - pci_conf[0x68 ] =0x01 ; - pci_conf[0x69 ] =0x00 ; - pci_conf[0x6a ] =0x00 ; - pci_conf[0x6b ] =0x00 ;// USBLEGSUP - pci_conf[0x6c ] =0x00 ; - pci_conf[0x6d ] =0x00 ; - pci_conf[0x6e ] =0x00 ; - pci_conf[0x6f ] =0xc0 ;// USBLEFCTLSTS - - s->capsbase =0x00 ; - s->opregbase =0x20 ; -/* 2.2 host controller interface version */ s->caps[0x00 ] = (uint8_t )(s->opregbase - s->capsbase); s->caps[0x01 ] =0x00 ;
@@ -2745,15 +2725,10 @@ static int usb_ehci_initfn(PCIDevice *dev) s->caps[0x06 ] =0x00 ; s->caps[0x07 ] =0x00 ; s->caps[0x08 ] =0x80 ;/* We can cache whole frame, no 64-bit */ - s->caps[0x09 ] =0x68 ;/* EECP */ s->caps[0x0a ] =0x00 ; s->caps[0x0b ] =0x00 ; - s->irq = s->dev.irq[3 ]; - - s->dma =pci_dma_context (dev); - -usb_bus_new (&s->bus, &ehci_bus_ops, &s->dev.qdev); +usb_bus_new (&s->bus, &ehci_bus_ops, dev);for (i =0 ; i <NB_PORTS ; i++) {usb_register_port (&s->bus, &s->ports[i], s, i, &ehci_port_ops,USB_SPEED_MASK_HIGH );
@@ -2781,8 +2756,53 @@ static int usb_ehci_initfn(PCIDevice *dev)memory_region_add_subregion (&s->mem, s->opregbase, &s->mem_opreg);memory_region_add_subregion (&s->mem, s->opregbase +PORTSC_BEGIN , &s->mem_ports); +} + +static int usb_ehci_pci_initfn (PCIDevice *dev) +{ +EHCIPCIState *i =DO_UPCAST (EHCIPCIState, pcidev, dev); +EHCIState *s = &i->ehci; +uint8_t *pci_conf = dev->config; + +pci_set_byte (&pci_conf[PCI_CLASS_PROG ],0x20 ); + +/* capabilities pointer */ +pci_set_byte (&pci_conf[PCI_CAPABILITY_LIST ],0x00 ); +/* pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x50); */ + +pci_set_byte (&pci_conf[PCI_INTERRUPT_PIN ],4 );/* interrupt pin D */ +pci_set_byte (&pci_conf[PCI_MIN_GNT ],0 ); +pci_set_byte (&pci_conf[PCI_MAX_LAT ],0 ); + +/* pci_conf[0x50] = 0x01; *//* power management caps */ + +pci_set_byte (&pci_conf[USB_SBRN ],USB_RELEASE_2 );/* release # (2.1.4) */ +pci_set_byte (&pci_conf[0x61 ],0x20 );/* frame length adjustment (2.1.5) */ +pci_set_word (&pci_conf[0x62 ],0x00 );/* port wake up capability (2.1.6) */ + + pci_conf[0x64 ] =0x00 ; + pci_conf[0x65 ] =0x00 ; + pci_conf[0x66 ] =0x00 ; + pci_conf[0x67 ] =0x00 ; + pci_conf[0x68 ] =0x01 ; + pci_conf[0x69 ] =0x00 ; + pci_conf[0x6a ] =0x00 ; + pci_conf[0x6b ] =0x00 ;/* USBLEGSUP */ + pci_conf[0x6c ] =0x00 ; + pci_conf[0x6d ] =0x00 ; + pci_conf[0x6e ] =0x00 ; + pci_conf[0x6f ] =0xc0 ;/* USBLEFCTLSTS */ + + s->caps[0x09 ] =0x68 ;/* EECP */ + + s->irq = dev->irq[3 ]; + s->dma =pci_dma_context (dev); + + s->capsbase =0x00 ; + s->opregbase =0x20 ; -pci_register_bar (&s->dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->mem); +usb_ehci_initfn (s,DEVICE (dev)); +pci_register_bar (dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->mem);return 0 ; }
Signature · 1 line
1.7.1
Re: [Qemu-devel] [RfC PATCH 3/5] usb/ehci: seperate out PCIisms
Am 30.10.2012 12:28, schrieb Gerd Hoffmann:
Quoted 177 lines
From: Peter Crosthwaite <[email protected]>
Seperate the PCI stuff from the EHCI components. Extracted the PCIDevice out into a new wrapper struct to make EHCIState non-PCI-specific. Seperated tho non PCI init component out into a seperate "common" init function.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>--- hw/usb/hcd-ehci.c | 124 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 72 insertions(+), 52 deletions(-)hw/usb/hcd-ehci.c +26
-51@@ -385,7 +385,6 @@ struct EHCIQueue { typedef QTAILQ_HEAD(EHCIQueueHead, EHCIQueue) EHCIQueueHead;struct EHCIState { -PCIDevice dev;USBBus bus;qemu_irq irq;MemoryRegion mem;@@ -447,6 +446,11 @@ struct EHCIState {bool int_req_by_async; }; +typedef struct EHCIPCIState { +PCIDevice pcidev; +EHCIState ehci; +}EHCIPCIState ; +#define SET_LAST_RUN_CLOCK (s) \ (s)->last_run_ns = qemu_get_clock_ns(vm_clock);@@ -2553,7 +2557,7 @@ static const MemoryRegionOps ehci_mmio_port_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static int usb_ehci_initfn (PCIDevice *dev); +static int usb_ehci_pci_initfn (PCIDevice *dev);static USBPortOps ehci_port_ops = { .attach = ehci_attach,@@ -2614,12 +2618,11 @@ static void usb_ehci_vm_state_change(void *opaque, int running, RunState state) }static const VMStateDescription vmstate_ehci = { - .name ="ehci" , + .name ="ehci-core" , .version_id =2 , .minimum_version_id =1 , .post_load = usb_ehci_post_load, .fields = (VMStateField []) { -VMSTATE_PCI_DEVICE (dev, EHCIState),/* mmio registers */ VMSTATE_UINT32 (usbcmd, EHCIState),VMSTATE_UINT32 (usbsts, EHCIState),@@ -2650,8 +2653,19 @@ static const VMStateDescription vmstate_ehci = { } }; -static Property ehci_properties[] = { -DEFINE_PROP_UINT32 ("maxframes" , EHCIState, maxframes,128 ), +static const VMStateDescription vmstate_ehci_pci = { + .name ="ehci" , + .version_id =2 , + .minimum_version_id =1 , + .post_load = usb_ehci_post_load, + .fields = (VMStateField []) { +VMSTATE_PCI_DEVICE (pcidev, EHCIPCIState), +VMSTATE_STRUCT (ehci, EHCIPCIState,2 , vmstate_ehci, EHCIState), + } +}; + +static Property ehci_pci_properties[] = { +DEFINE_PROP_UINT32 ("maxframes" , EHCIPCIState, ehci.maxframes,128 ),DEFINE_PROP_END_OF_LIST (), };@@ -2660,13 +2674,13 @@ static void ehci_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = usb_ehci_initfn; + k->init = usb_ehci_pci_initfn; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->device_id =PCI_DEVICE_ID_INTEL_82801D ;/* ich4 */ k->revision =0x10 ; k->class_id =PCI_CLASS_SERIAL_USB ; dc->vmsd = &vmstate_ehci; - dc->props = ehci_properties; + dc->props = ehci_pci_properties; }static TypeInfo ehci_info = {@@ -2681,13 +2695,13 @@ static void ich9_ehci_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = usb_ehci_initfn; + k->init = usb_ehci_pci_initfn; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->device_id =PCI_DEVICE_ID_INTEL_82801I_EHCI1 ; k->revision =0x03 ; k->class_id =PCI_CLASS_SERIAL_USB ; dc->vmsd = &vmstate_ehci; - dc->props = ehci_properties; + dc->props = ehci_pci_properties; }static TypeInfo ich9_ehci_info = {@@ -2697,44 +2711,10 @@ static TypeInfo ich9_ehci_info = { .class_init = ich9_ehci_class_init, }; -static int usb_ehci_initfn (PCIDevice *dev) +static void usb_ehci_initfn (EHCIState *s,DeviceState *dev) { -EHCIState *s =DO_UPCAST (EHCIState, dev, dev); -uint8_t *pci_conf = s->dev.config;int i; -pci_set_byte (&pci_conf[PCI_CLASS_PROG ],0x20 ); - -/* capabilities pointer */ -pci_set_byte (&pci_conf[PCI_CAPABILITY_LIST ],0x00 ); -//pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x50); - -pci_set_byte (&pci_conf[PCI_INTERRUPT_PIN ],4 );/* interrupt pin D */ -pci_set_byte (&pci_conf[PCI_MIN_GNT ],0 ); -pci_set_byte (&pci_conf[PCI_MAX_LAT ],0 ); - -// pci_conf[0x50] = 0x01; // power management caps - -pci_set_byte (&pci_conf[USB_SBRN ],USB_RELEASE_2 );// release number (2.1.4) -pci_set_byte (&pci_conf[0x61 ],0x20 );// frame length adjustment (2.1.5) -pci_set_word (&pci_conf[0x62 ],0x00 );// port wake up capability (2.1.6) - - pci_conf[0x64 ] =0x00 ; - pci_conf[0x65 ] =0x00 ; - pci_conf[0x66 ] =0x00 ; - pci_conf[0x67 ] =0x00 ; - pci_conf[0x68 ] =0x01 ; - pci_conf[0x69 ] =0x00 ; - pci_conf[0x6a ] =0x00 ; - pci_conf[0x6b ] =0x00 ;// USBLEGSUP - pci_conf[0x6c ] =0x00 ; - pci_conf[0x6d ] =0x00 ; - pci_conf[0x6e ] =0x00 ; - pci_conf[0x6f ] =0xc0 ;// USBLEFCTLSTS - - s->capsbase =0x00 ; - s->opregbase =0x20 ; -/* 2.2 host controller interface version */ s->caps[0x00 ] = (uint8_t )(s->opregbase - s->capsbase); s->caps[0x01 ] =0x00 ;@@ -2745,15 +2725,10 @@ static int usb_ehci_initfn(PCIDevice *dev) s->caps[0x06 ] =0x00 ; s->caps[0x07 ] =0x00 ; s->caps[0x08 ] =0x80 ;/* We can cache whole frame, no 64-bit */ - s->caps[0x09 ] =0x68 ;/* EECP */ s->caps[0x0a ] =0x00 ; s->caps[0x0b ] =0x00 ; - s->irq = s->dev.irq[3 ]; - - s->dma =pci_dma_context (dev); - -usb_bus_new (&s->bus, &ehci_bus_ops, &s->dev.qdev); +usb_bus_new (&s->bus, &ehci_bus_ops, dev);for (i =0 ; i <NB_PORTS ; i++) {usb_register_port (&s->bus, &s->ports[i], s, i, &ehci_port_ops,USB_SPEED_MASK_HIGH );
hw/usb/hcd-ehci.c static int usb_ehci_initfn(PCIDevice *dev) · line 2763
Quoted 8 lines
hw/usb/hcd-ehci.c +5
-0@@ -2781,8 +2756,53 @@ static int usb_ehci_initfn(PCIDevice *dev)memory_region_add_subregion (&s->mem, s->opregbase, &s->mem_opreg);memory_region_add_subregion (&s->mem, s->opregbase +PORTSC_BEGIN , &s->mem_ports); +} + +static int usb_ehci_pci_initfn (PCIDevice *dev) +{ +EHCIPCIState *i =DO_UPCAST (EHCIPCIState, pcidev, dev);
Same as discussed for Peter's patchset, this should be using a QOM cast macro and may need an abstract base type if there is no unique type matching EHCIPCIState struct.
Should I send you a follow-up to squash if this is the approach we are going to take?
Andreas
Quoted 47 lines
hw/usb/hcd-ehci.c +41
-1+EHCIState *s = &i->ehci; +uint8_t *pci_conf = dev->config; + +pci_set_byte (&pci_conf[PCI_CLASS_PROG ],0x20 ); + +/* capabilities pointer */ +pci_set_byte (&pci_conf[PCI_CAPABILITY_LIST ],0x00 ); +/* pci_set_byte(&pci_conf[PCI_CAPABILITY_LIST], 0x50); */ + +pci_set_byte (&pci_conf[PCI_INTERRUPT_PIN ],4 );/* interrupt pin D */ +pci_set_byte (&pci_conf[PCI_MIN_GNT ],0 ); +pci_set_byte (&pci_conf[PCI_MAX_LAT ],0 ); + +/* pci_conf[0x50] = 0x01; *//* power management caps */ + +pci_set_byte (&pci_conf[USB_SBRN ],USB_RELEASE_2 );/* release # (2.1.4) */ +pci_set_byte (&pci_conf[0x61 ],0x20 );/* frame length adjustment (2.1.5) */ +pci_set_word (&pci_conf[0x62 ],0x00 );/* port wake up capability (2.1.6) */ + + pci_conf[0x64 ] =0x00 ; + pci_conf[0x65 ] =0x00 ; + pci_conf[0x66 ] =0x00 ; + pci_conf[0x67 ] =0x00 ; + pci_conf[0x68 ] =0x01 ; + pci_conf[0x69 ] =0x00 ; + pci_conf[0x6a ] =0x00 ; + pci_conf[0x6b ] =0x00 ;/* USBLEGSUP */ + pci_conf[0x6c ] =0x00 ; + pci_conf[0x6d ] =0x00 ; + pci_conf[0x6e ] =0x00 ; + pci_conf[0x6f ] =0xc0 ;/* USBLEFCTLSTS */ + + s->caps[0x09 ] =0x68 ;/* EECP */ + + s->irq = dev->irq[3 ]; + s->dma =pci_dma_context (dev); + + s->capsbase =0x00 ; + s->opregbase =0x20 ; -pci_register_bar (&s->dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->mem); +usb_ehci_initfn (s,DEVICE (dev)); +pci_register_bar (dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->mem);return 0 ; }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [RfC PATCH 3/5] usb/ehci: seperate out PCIisms
Hi,
Quoted 5 lines
Quoted 4 lines
hw/usb/hcd-ehci.c +1
-2-static int usb_ehci_initfn (PCIDevice *dev) +static void usb_ehci_initfn (EHCIState *s,DeviceState *dev) { -EHCIState *s =DO_UPCAST (EHCIState, dev, dev);
Quoted 7 lines
hw/usb/hcd-ehci.c static int usb_ehci_initfn(PCIDevice *dev) · line 2763
Quoted 3 lines
hw/usb/hcd-ehci.c +3
-0+static int usb_ehci_pci_initfn (PCIDevice *dev) +{ +EHCIPCIState *i =DO_UPCAST (EHCIPCIState, pcidev, dev);Same as discussed for Peter's patchset, this should be using a QOM cast macro and may need an abstract base type if there is no unique type matching EHCIPCIState struct.
--verbose please.
This is exactly like it used to be. PCIDeviceClass->init() gets passed in a PCIDevice pointer and uses DO_UPCAST to get the container struct carrying the ehci state (EHCIState before the patch, EHCIPCIState now).
This is common practice all over the tree.
Quoted 2 lines
Should I send you a follow-up to squash if this is the approach we are going to take?
If there is a new, more QOM-ish way to do the same feel free to send patches. I see that as independent cleanup though, not as something which should be squashed into this patch.
cheers,
Gerd
RFC PATCH 4/5 usb/ehci: Guard definition of EHCI_DEBUG
In reply to Gerd HoffmannFrom: Peter Crosthwaite <[email protected]>
Guard against re-definition of EHCI_DEBUG. Allows for turning on of debug info from configure (using --qemu-extra-cflags="-DEHCI_DEBUG=1") rather than source code hacking.
--- hw/usb/hcd-ehci.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/usb/hcd-ehci.c +2 -0
@@ -36,7 +36,9 @@#include "dma.h" #include "sysemu.h" +#ifndef EHCI_DEBUG #define EHCI_DEBUG 0 +#endif #if EHCI_DEBUG #define DPRINTF printf
Signature · 1 line
1.7.1
RFC PATCH 5/5 usb/ehci: split into multiple source files
In reply to Gerd Hoffmann--- hw/usb/Makefile.objs | 2 +- hw/usb/hcd-ehci-pci.c | 138 ++++++++++++++++ hw/usb/hcd-ehci.c | 426 +------------------------------------------------ hw/usb/hcd-ehci.h | 320 +++++++++++++++++++++++++++++++++++++ 4 files changed, 462 insertions(+), 424 deletions(-) create mode 100644 hw/usb/hcd-ehci-pci.c create mode 100644 hw/usb/hcd-ehci.h
hw/usb/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o -common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o +common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o common-obj-y += libhw.o
hw/usb/hcd-ehci-pci.c new file +138 -0
138 lines not on this page · raw message
hw/usb/hcd-ehci.c +3 -423
478 lines not on this page · raw message
hw/usb/hcd-ehci.h new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 5 lines · Gerd Hoffmann
Hi,
Based on Peters series, not tested much yet, sysfs dropped but adding back in should be as easy as adding a
hcd-ehci-sysbus.cfile simliar to the pci variant.
I can look into this tomorrow if there are no objections to this series, and ill rerun my test suite to confirm functionality for both PCI and SYSBUS. Ill send as patches ontop of this series.
Thanks for helping out,
Regards,
Peter
No changes in ehci core should be needed.
Quoted 24 lines
Comments?
cheers,
GerdGerd Hoffmann (1):
usb/ehci: split into multiple source filesPeter Crosthwaite (4):
usb/ehci: parameterise the register region offsets usb/ehci: Abstract away PCI DMA API usb/ehci: seperate out PCIisms
usb/ehci: Guard definition ofEHCI_DEBUGhw/usb/Makefile.objs | 2 +- hw/usb/hcd-ehci-pci.c | 138 +++++++++++++++ hw/usb/hcd-ehci.c | 465 ++++--------------------------------------------- hw/usb/hcd-ehci.h | 320 ++++++++++++++++++++++++++++++++++ 4 files changed, 496 insertions(+), 429 deletions(-) create mode 100644 hw/usb/hcd-ehci-pci.c create mode 100644 hw/usb/hcd-ehci.h
Quoted 10 lines · Peter Crosthwaite
Quoted 5 lines · Gerd Hoffmann
Hi,
Based on Peters series, not tested much yet, sysfs dropped but adding back in should be as easy as adding a
hcd-ehci-sysbus.cfile simliar to the pci variant.I can look into this tomorrow if there are no objections to this series, and ill rerun my test suite to confirm functionality for both PCI and SYSBUS. Ill send as patches ontop of this series.
I gave it a spin, patch attached, will send a full patch series with current usb patch queue status in a moment.
cheers,
Gerd
Quoted 1 line
From
4b818b35d5ead6d4cb97c59945a15c7c61a8f479Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Tue, 30 Oct 2012 15:08:37 +0100
Subject: [PATCH] usb/ehci: add sysbus variant
--- hw/usb/Makefile.objs | 2 +- hw/usb/hcd-ehci-sysbus.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletions(-) create mode 100644 hw/usb/hcd-ehci-sysbus.c
hw/usb/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o -common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o +common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o common-obj-y += libhw.o
hw/usb/hcd-ehci-sysbus.c new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
1.7.1