From: David Ahern <daahern@cisco.com>
To: qemu-devel@nongnu.org
Cc: jan.kiszka@web.de, David Ahern <daahern@cisco.com>
Subject: [Qemu-devel] [PATCH] Create USB buses and devices based on USB version.
Date: Mon, 26 Jul 2010 07:50:36 -0600 [thread overview]
Message-ID: <1280152236-12566-1-git-send-email-daahern@cisco.com> (raw)
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 <daahern@cisco.com>
---
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) {
--
1.7.1.1
next reply other threads:[~2010-07-26 13:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 13:50 David Ahern [this message]
2010-08-03 15:15 ` [Qemu-devel] Re: [PATCH] Create USB buses and devices based on USB version David S. Ahern
-- strict thread matches above, loose matches on Subject: below --
2010-07-14 17:56 [Qemu-devel] " David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1280152236-12566-1-git-send-email-daahern@cisco.com \
--to=daahern@cisco.com \
--cc=jan.kiszka@web.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).