From patchwork Mon Aug 31 12:24:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 32630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 87238B6F1F for ; Mon, 31 Aug 2009 22:37:29 +1000 (EST) Received: from localhost ([127.0.0.1]:58213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mi68L-0003VW-KG for incoming@patchwork.ozlabs.org; Mon, 31 Aug 2009 08:37:17 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mi5vy-0005Lr-9L for qemu-devel@nongnu.org; Mon, 31 Aug 2009 08:24:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mi5vt-0005I1-6j for qemu-devel@nongnu.org; Mon, 31 Aug 2009 08:24:29 -0400 Received: from [199.232.76.173] (port=46682 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mi5vs-0005Hk-OK for qemu-devel@nongnu.org; Mon, 31 Aug 2009 08:24:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54366) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mi5vs-0001ix-7M for qemu-devel@nongnu.org; Mon, 31 Aug 2009 08:24:24 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7VCON6s018358 for ; Mon, 31 Aug 2009 08:24:23 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-244.ams2.redhat.com [10.36.8.244]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n7VCOFAq008825; Mon, 31 Aug 2009 08:24:18 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 50628700E4; Mon, 31 Aug 2009 14:24:06 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 31 Aug 2009 14:24:03 +0200 Message-Id: <1251721445-17824-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1251721445-17824-1-git-send-email-kraxel@redhat.com> References: <1251721445-17824-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 7/9] qdev/usb: convert ohci. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/pci.h | 2 +- hw/ppc_newworld.c | 2 +- hw/ppc_oldworld.c | 2 +- hw/ppc_prep.c | 2 +- hw/realview.c | 2 +- hw/usb-ohci.c | 44 +++++++++++++++++++++++++++++--------------- hw/versatilepb.c | 2 +- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/hw/pci.h b/hw/pci.h index fd1d35c..f94341a 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -341,7 +341,7 @@ void usb_uhci_piix3_init(PCIBus *bus, int devfn); void usb_uhci_piix4_init(PCIBus *bus, int devfn); /* usb-ohci.c */ -void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn); +void usb_ohci_init_pci(struct PCIBus *bus, int devfn); /* prep_pci.c */ PCIBus *pci_prep_init(qemu_irq *pic); diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c index 3ad0057..ecd79fb 100644 --- a/hw/ppc_newworld.c +++ b/hw/ppc_newworld.c @@ -334,7 +334,7 @@ static void ppc_core99_init (ram_addr_t ram_size, escc_mem_index); if (usb_enabled) { - usb_ohci_init_pci(pci_bus, 3, -1); + usb_ohci_init_pci(pci_bus, -1); } if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c index fc0e6f7..2986d67 100644 --- a/hw/ppc_oldworld.c +++ b/hw/ppc_oldworld.c @@ -361,7 +361,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size, escc_mem_index); if (usb_enabled) { - usb_ohci_init_pci(pci_bus, 3, -1); + usb_ohci_init_pci(pci_bus, -1); } if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c index 1cad17f..d336b7f 100644 --- a/hw/ppc_prep.c +++ b/hw/ppc_prep.c @@ -746,7 +746,7 @@ static void ppc_prep_init (ram_addr_t ram_size, #endif if (usb_enabled) { - usb_ohci_init_pci(pci_bus, 3, -1); + usb_ohci_init_pci(pci_bus, -1); } m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59); diff --git a/hw/realview.c b/hw/realview.c index 8e176b9..a55fba7 100644 --- a/hw/realview.c +++ b/hw/realview.c @@ -111,7 +111,7 @@ static void realview_init(ram_addr_t ram_size, pic[48], pic[49], pic[50], pic[51], NULL); pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci"); if (usb_enabled) { - usb_ohci_init_pci(pci_bus, 3, -1); + usb_ohci_init_pci(pci_bus, -1); } n = drive_get_max_bus(IF_SCSI); while (n >= 0) { diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 7f620c7..96a9555 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); diff --git a/hw/versatilepb.c b/hw/versatilepb.c index 4c01720..29b85ae 100644 --- a/hw/versatilepb.c +++ b/hw/versatilepb.c @@ -217,7 +217,7 @@ static void versatile_init(ram_addr_t ram_size, } } if (usb_enabled) { - usb_ohci_init_pci(pci_bus, 3, -1); + usb_ohci_init_pci(pci_bus, -1); } n = drive_get_max_bus(IF_SCSI); while (n >= 0) {