diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-08-31 14:24:03 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-09-09 14:55:18 -0500 |
commit | 5b19d9a247c47fe52c4f3d3e844009a689ee6b28 (patch) | |
tree | 8627615e106873b5796c69e47f8fd66cb6086b7d /hw/usb-ohci.c | |
parent | 6cf9b6f17a6e06d6e15595d1f68c4bad65661c0f (diff) |
qdev/usb: convert ohci.
Drop num_ports argument for usb_ohci_init_pci(), everybody
calls it with num_ports == 3, so it is pointless.
Convert ohci pci device into qdev.
TODO: convert non-pci ohci adapters.
You can add a OHCI USB Controller to your virtual pc now using
'-device pci-ohci'. Specifying a id is a good idea, so you can
attach usb devices to it, like this:
-device pci-ohci,id=ohci
-device usb-mouse,bus=ohci.0
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/usb-ohci.c')
-rw-r--r-- | hw/usb-ohci.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 7f620c7d21..96a955516d 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1660,7 +1660,8 @@ static CPUWriteMemoryFunc * const ohci_writefn[3]={ ohci_mem_write }; -static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, +static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, + int num_ports, int devfn, qemu_irq irq, enum ohci_type type, const char *name, uint32_t localmem_base) { @@ -1689,7 +1690,7 @@ static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, ohci->irq = irq; ohci->type = type; - ohci->bus = usb_bus_new(NULL /* FIXME */); + ohci->bus = usb_bus_new(dev); ohci->num_ports = num_ports; for (i = 0; i < num_ports; i++) { usb_register_port(ohci->bus, &ohci->rhport[i].port, ohci, i, ohci_attach); @@ -1712,17 +1713,10 @@ static void ohci_mapfunc(PCIDevice *pci_dev, int i, cpu_register_physical_memory(addr, size, ohci->state.mem); } -void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) +static int usb_ohci_initfn_pci(struct PCIDevice *dev) { - OHCIPCIState *ohci; - - ohci = DO_UPCAST(OHCIPCIState, pci_dev, - pci_register_device(bus, "OHCI USB", sizeof(*ohci), - devfn, NULL, NULL)); - if (ohci == NULL) { - fprintf(stderr, "usb-ohci: Failed to register PCI device\n"); - return; - } + OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev); + int num_ports = 3; pci_config_set_vendor_id(ohci->pci_dev.config, PCI_VENDOR_ID_APPLE); pci_config_set_device_id(ohci->pci_dev.config, @@ -1731,11 +1725,18 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) pci_config_set_class(ohci->pci_dev.config, PCI_CLASS_SERIAL_USB); ohci->pci_dev.config[0x3d] = 0x01; /* interrupt pin 1 */ - usb_ohci_init(&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0], + usb_ohci_init(&ohci->state, &dev->qdev, num_ports, + ohci->pci_dev.devfn, ohci->pci_dev.irq[0], OHCI_TYPE_PCI, ohci->pci_dev.name, 0); pci_register_bar((struct PCIDevice *)ohci, 0, 256, PCI_ADDRESS_SPACE_MEM, ohci_mapfunc); + return 0; +} + +void usb_ohci_init_pci(struct PCIBus *bus, int devfn) +{ + pci_create_simple(bus, devfn, "OHCI USB PCI"); } void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, @@ -1743,7 +1744,7 @@ void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, { OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); - usb_ohci_init(ohci, num_ports, devfn, irq, + usb_ohci_init(ohci, NULL /* FIXME */, num_ports, devfn, irq, OHCI_TYPE_PXA, "OHCI USB", 0); cpu_register_physical_memory(base, 0x1000, ohci->mem); @@ -1754,9 +1755,22 @@ void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base, { OHCIState *ohci = (OHCIState *)qemu_mallocz(sizeof(OHCIState)); - usb_ohci_init(ohci, num_ports, devfn, irq, + usb_ohci_init(ohci, NULL /* FIXME */, num_ports, devfn, irq, OHCI_TYPE_SM501, "OHCI USB", localmem_base); cpu_register_physical_memory(mmio_base, 0x1000, ohci->mem); } +static PCIDeviceInfo ohci_info = { + .qdev.name = "OHCI USB PCI", + .qdev.alias = "pci-ohci", + .qdev.desc = "Apple USB Controller", + .qdev.size = sizeof(OHCIPCIState), + .init = usb_ohci_initfn_pci, +}; + +static void ohci_register(void) +{ + pci_qdev_register(&ohci_info); +} +device_init(ohci_register); |