From patchwork Mon Jul 26 13:50:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David S. Ahern" X-Patchwork-Id: 59913 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 ozlabs.org (Postfix) with ESMTPS id A6E54B70A9 for ; Mon, 26 Jul 2010 23:51:52 +1000 (EST) Received: from localhost ([127.0.0.1]:44501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OdO5r-0006ph-9w for incoming@patchwork.ozlabs.org; Mon, 26 Jul 2010 09:51:47 -0400 Received: from [140.186.70.92] (port=55970 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OdO4y-0006pb-VU for qemu-devel@nongnu.org; Mon, 26 Jul 2010 09:50:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OdO4r-0003pr-Ae for qemu-devel@nongnu.org; Mon, 26 Jul 2010 09:50:52 -0400 Received: from sj-iport-4.cisco.com ([171.68.10.86]:55817) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OdO4q-0003p1-R0 for qemu-devel@nongnu.org; Mon, 26 Jul 2010 09:50:45 -0400 Authentication-Results: sj-iport-4.cisco.com; dkim=neutral (message not signed) header.i=none X-IronPort-AV: E=Sophos;i="4.55,261,1278288000"; d="scan'208";a="162933664" Received: from sj-core-1.cisco.com ([171.71.177.237]) by sj-iport-4.cisco.com with ESMTP; 26 Jul 2010 13:50:39 +0000 Received: from daahern-lx.cisco.com (sjc-vpn4-1455.cisco.com [10.21.85.174]) by sj-core-1.cisco.com (8.13.8/8.14.3) with ESMTP id o6QDocc3019947; Mon, 26 Jul 2010 13:50:38 GMT From: David Ahern To: qemu-devel@nongnu.org Date: Mon, 26 Jul 2010 07:50:36 -0600 Message-Id: <1280152236-12566-1-git-send-email-daahern@cisco.com> X-Mailer: git-send-email 1.7.1.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: jan.kiszka@web.de, David Ahern Subject: [Qemu-devel] [PATCH] Create USB buses and devices based on USB version. 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 Create USB buses and devices based on USB version. This addresses addresses a number of FIXME's by assigning USB devices to a specific bus. t is also groundwork for adding ehci. Signed-off-by: David Ahern --- hw/usb-bus.c | 70 ++++++++++++++++++++++++++++++++++++++++--------------- hw/usb-msd.c | 2 +- hw/usb-net.c | 2 +- hw/usb-ohci.c | 2 +- hw/usb-serial.c | 4 +- hw/usb-uhci.c | 2 +- hw/usb.h | 7 +++-- usb-bsd.c | 2 +- usb-linux.c | 2 +- 9 files changed, 63 insertions(+), 30 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index b692503..f4849f8 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -4,6 +4,12 @@ #include "sysemu.h" #include "monitor.h" +enum { + USB_VERSION_NONE, + USB_VERSION_1_1, +}; + + static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static struct BusInfo usb_bus_info = { @@ -14,27 +20,46 @@ static struct BusInfo usb_bus_info = { static int next_usb_bus = 0; static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); -void usb_bus_new(USBBus *bus, DeviceState *host) +static void usb_bus_new(USBBus *bus, int version, DeviceState *host) { qbus_create_inplace(&bus->qbus, &usb_bus_info, host, NULL); bus->busnr = next_usb_bus++; bus->qbus.allow_hotplug = 1; /* Yes, we can */ + bus->version = version; QTAILQ_INIT(&bus->free); QTAILQ_INIT(&bus->used); QTAILQ_INSERT_TAIL(&busses, bus, next); } -USBBus *usb_bus_find(int busnr) +void usb_bus_new_v1(USBBus *bus, DeviceState *host) +{ + usb_bus_new(bus, USB_VERSION_1_1, host); +} + +static USBBus *usb_bus_find(int busnr) +{ + USBBus *bus; + + QTAILQ_FOREACH(bus, &busses, next) { + if (bus->busnr == busnr) { + break; + } + } + + return bus; +} + +/* device creation should be using this one */ +USBBus *usb_bus_find_version(int version) { USBBus *bus; - if (-1 == busnr) - return QTAILQ_FIRST(&busses); QTAILQ_FOREACH(bus, &busses, next) { - if (bus->busnr == busnr) - return bus; + if (bus->version == version) { + break; + } } - return NULL; + return bus; } static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) @@ -80,20 +105,15 @@ void usb_qdev_register_many(USBDeviceInfo *info) } } -USBDevice *usb_create(USBBus *bus, const char *name) +static USBDevice *usb_create(USBBus *bus, const char *name) { DeviceState *dev; -#if 1 - /* temporary stopgap until all usb is properly qdev-ified */ if (!bus) { - bus = usb_bus_find(-1); - if (!bus) - return NULL; - fprintf(stderr, "%s: no bus specified, using \"%s\" for \"%s\"\n", - __FUNCTION__, bus->qbus.name, name); + fprintf(stderr, "%s: no bus specified for \"%s\"\n", + __FUNCTION__, name); + return NULL; } -#endif dev = qdev_create(&bus->qbus, name); return DO_UPCAST(USBDevice, qdev, dev); @@ -101,7 +121,13 @@ USBDevice *usb_create(USBBus *bus, const char *name) USBDevice *usb_create_simple(USBBus *bus, const char *name) { - USBDevice *dev = usb_create(bus, name); + USBDevice *dev; + + /* if bus not given default to USB 1.1 */ + if (!bus) + bus = usb_bus_find_version(USB_VERSION_1_1); + + dev = usb_create(bus, name); if (!dev) { hw_error("Failed to create USB device '%s'\n", name); } @@ -109,6 +135,13 @@ USBDevice *usb_create_simple(USBBus *bus, const char *name) return dev; } +/* create USB device attached to USB 1.1 controller */ +USBDevice *usb_create_v1(const char *name) +{ + USBBus *bus = usb_bus_find_version(USB_VERSION_1_1); + return usb_create(bus, name); +} + void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, usb_attachfn attach) { @@ -260,7 +293,6 @@ void usb_info(Monitor *mon) /* handle legacy -usbdevice cmd line option */ USBDevice *usbdevice_create(const char *cmdline) { - USBBus *bus = usb_bus_find(-1 /* any */); DeviceInfo *info; USBDeviceInfo *usb; char driver[32]; @@ -302,7 +334,7 @@ USBDevice *usbdevice_create(const char *cmdline) error_report("usbdevice %s accepts no params", driver); return NULL; } - return usb_create_simple(bus, usb->qdev.name); + return usb_create_simple(NULL, usb->qdev.name); } return usb->usbdevice_init(params); } diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 65e9624..d8b68f7 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -606,7 +606,7 @@ static USBDevice *usb_msd_init(const char *filename) } /* create guest device */ - dev = usb_create(NULL /* FIXME */, "usb-storage"); + dev = usb_create_v1("usb-storage"); if (!dev) { return NULL; } diff --git a/hw/usb-net.c b/hw/usb-net.c index a43bd17..b8936c5 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1484,7 +1484,7 @@ static USBDevice *usb_net_init(const char *cmdline) return NULL; } - dev = usb_create(NULL /* FIXME */, "usb-net"); + dev = usb_create_v1("usb-net"); if (!dev) { return NULL; } diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index c60fd8d..d38befc 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1702,7 +1702,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, ohci->name = dev->info->name; - usb_bus_new(&ohci->bus, dev); + usb_bus_new_v1(&ohci->bus, 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); diff --git a/hw/usb-serial.c b/hw/usb-serial.c index c19580f..f1c47b9 100644 --- a/hw/usb-serial.c +++ b/hw/usb-serial.c @@ -599,7 +599,7 @@ static USBDevice *usb_serial_init(const char *filename) if (!cdrv) return NULL; - dev = usb_create(NULL /* FIXME */, "usb-serial"); + dev = usb_create_v1("usb-serial"); if (!dev) { return NULL; } @@ -622,7 +622,7 @@ static USBDevice *usb_braille_init(const char *unused) if (!cdrv) return NULL; - dev = usb_create(NULL /* FIXME */, "usb-braille"); + dev = usb_create_v1("usb-braille"); qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); qdev_init_nofail(&dev->qdev); diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 1d83400..0528757 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -1113,7 +1113,7 @@ static int usb_uhci_common_initfn(UHCIState *s) pci_conf[PCI_INTERRUPT_PIN] = 4; // interrupt pin 3 pci_conf[0x60] = 0x10; // release number - usb_bus_new(&s->bus, &s->dev.qdev); + usb_bus_new_v1(&s->bus, &s->dev.qdev); for(i = 0; i < NB_PORTS; i++) { usb_register_port(&s->bus, &s->ports[i].port, s, i, uhci_attach); } diff --git a/hw/usb.h b/hw/usb.h index 00d2802..5c519dd 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -299,16 +299,17 @@ struct USBBus { int busnr; int nfree; int nused; + int version; QTAILQ_HEAD(, USBPort) free; QTAILQ_HEAD(, USBPort) used; QTAILQ_ENTRY(USBBus) next; }; -void usb_bus_new(USBBus *bus, DeviceState *host); -USBBus *usb_bus_find(int busnr); +void usb_bus_new_v1(USBBus *bus, DeviceState *host); +USBBus *usb_bus_find_version(int version); void usb_qdev_register(USBDeviceInfo *info); void usb_qdev_register_many(USBDeviceInfo *info); -USBDevice *usb_create(USBBus *bus, const char *name); +USBDevice *usb_create_v1(const char *name); USBDevice *usb_create_simple(USBBus *bus, const char *name); USBDevice *usbdevice_create(const char *cmdline); void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, diff --git a/usb-bsd.c b/usb-bsd.c index 48567a3..b2c3777 100644 --- a/usb-bsd.c +++ b/usb-bsd.c @@ -361,7 +361,7 @@ USBDevice *usb_host_device_open(const char *devname) goto fail; } - d = usb_create(NULL /* FIXME */, "usb-host"); + d = usb_create_v1("usb-host"); dev = DO_UPCAST(USBHostDevice, dev, d); if (dev_info.udi_speed == 1) diff --git a/usb-linux.c b/usb-linux.c index c3c38ec..c5e9cfe 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1053,7 +1053,7 @@ USBDevice *usb_host_device_open(const char *devname) USBDevice *dev; char *p; - dev = usb_create(NULL /* FIXME */, "usb-host"); + dev = usb_create_v1("usb-host"); if (strstr(devname, "auto:")) { if (parse_filter(devname, &filter) < 0) {