From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MLGG1-0006Tg-PE for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MLGFv-0006PO-Mn for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:48 -0400 Received: from [199.232.76.173] (port=41128 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MLGFu-0006Om-Ut for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:43 -0400 Received: from mx2.redhat.com ([66.187.237.31]:36461) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MLGFt-0003s6-Qy for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:42 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5TCkfPl007122 for ; Mon, 29 Jun 2009 08:46:41 -0400 From: Gerd Hoffmann Date: Mon, 29 Jun 2009 14:46:18 +0200 Message-Id: <1246279581-15749-18-git-send-email-kraxel@redhat.com> In-Reply-To: <1246279581-15749-1-git-send-email-kraxel@redhat.com> References: <1246279581-15749-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 17/20] qdev: convert ohci. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Hook pci device into qdev. TODO: convert non-pci ohci adapters. Signed-off-by: Gerd Hoffmann --- hw/usb-ohci.c | 42 ++++++++++++++++++++++++++++-------------- 1 files changed, 28 insertions(+), 14 deletions(-) diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index ba4cb9e..613104d 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1661,7 +1661,8 @@ static CPUWriteMemoryFunc *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) { @@ -1690,7 +1691,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); @@ -1713,16 +1714,9 @@ 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 void usb_ohci_initfn_pci(struct PCIDevice *dev) { - OHCIPCIState *ohci; - - ohci = (OHCIPCIState *)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); pci_config_set_vendor_id(ohci->pci_dev.config, PCI_VENDOR_ID_APPLE); pci_config_set_device_id(ohci->pci_dev.config, @@ -1730,8 +1724,17 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) ohci->pci_dev.config[0x09] = 0x10; /* OHCI */ 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], +void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) +{ + PCIDevice *dev; + OHCIPCIState *ohci; + + dev = pci_create_simple(bus, devfn, "OHCI USB"); + ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev); + + usb_ohci_init(&ohci->state, &dev->qdev, num_ports, devfn, ohci->pci_dev.irq[0], OHCI_TYPE_PCI, ohci->pci_dev.name, 0); pci_register_bar((struct PCIDevice *)ohci, 0, 256, @@ -1743,7 +1746,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 +1757,20 @@ 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", + .qdev.size = sizeof(OHCIPCIState), + .init = usb_ohci_initfn_pci, +}; + +static void ohci_register(void) +{ + pci_qdev_register(&ohci_info); +} +device_init(ohci_register); -- 1.6.2.5