From patchwork Mon Oct 26 14:56:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36920 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 597DBB7BCF for ; Tue, 27 Oct 2009 02:02:13 +1100 (EST) Received: from localhost ([127.0.0.1]:38017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2R5G-00014X-DA for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2009 11:02:10 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2R0K-00083Z-Qi for qemu-devel@nongnu.org; Mon, 26 Oct 2009 10:57:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2R0F-00081q-IM for qemu-devel@nongnu.org; Mon, 26 Oct 2009 10:57:03 -0400 Received: from [199.232.76.173] (port=54443 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2R0F-00081b-40 for qemu-devel@nongnu.org; Mon, 26 Oct 2009 10:56:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25205) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2R0D-0007v3-Tn for qemu-devel@nongnu.org; Mon, 26 Oct 2009 10:56:58 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9QEuuB0016767 for ; Mon, 26 Oct 2009 10:56:57 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-193.ams2.redhat.com [10.36.5.193]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9QEurEh006507; Mon, 26 Oct 2009 10:56:54 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id BC33A700E5; Mon, 26 Oct 2009 15:56:51 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 26 Oct 2009 15:56:45 +0100 Message-Id: <1256569011-20256-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1256569011-20256-1-git-send-email-kraxel@redhat.com> References: <1256569011-20256-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/7] usb core: use qdev for -usbdevice 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 This patchs adds infrastructure to handle -usbdevice via qdev callbacks. USBDeviceInfo gets a name field (for the -usbdevice driver name) and a callback for -usbdevice parameter parsing. The new usbdevice_create() function walks the qdev driver list and looks for a usb driver with a matching name. When a parameter parsing callback is present it is called, otherwise the device is created via usb_create_simple(). Signed-off-by: Gerd Hoffmann --- hw/qdev.c | 2 +- hw/qdev.h | 1 + hw/usb-bus.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ hw/usb.h | 5 +++++ vl.c | 5 +++++ 5 files changed, 59 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 20f931c..b0d92d2 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -35,7 +35,7 @@ static int qdev_hotplug = 0; /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ static BusState *main_system_bus; -static DeviceInfo *device_info_list; +DeviceInfo *device_info_list; static BusState *qbus_find_recursive(BusState *bus, const char *name, const BusInfo *info); diff --git a/hw/qdev.h b/hw/qdev.h index b79f3e3..738470b 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -140,6 +140,7 @@ struct DeviceInfo { BusInfo *bus_info; struct DeviceInfo *next; }; +extern DeviceInfo *device_info_list; void qdev_register(DeviceInfo *info); diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 98987a1..28b517f 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -252,3 +252,50 @@ 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], *params; + int len; + + params = strchr(cmdline,':'); + if (params) { + params++; + len = params - cmdline; + if (len > sizeof(driver)) + len = sizeof(driver); + pstrcpy(driver, len, cmdline); + } else { + pstrcpy(driver, sizeof(driver), cmdline); + } + + for (info = device_info_list; info != NULL; info = info->next) { + if (info->bus_info != &usb_bus_info) + continue; + usb = DO_UPCAST(USBDeviceInfo, qdev, info); + if (usb->usbdevice_name == NULL) + continue; + if (strcmp(usb->usbdevice_name, driver) != 0) + continue; + break; + } + if (info == NULL) { +#if 0 + /* no error because some drivers are not converted (yet) */ + qemu_error("usbdevice %s not found\n", driver); +#endif + return NULL; + } + + if (!usb->usbdevice_init) { + if (params) { + qemu_error("usbdevice %s accepts no params\n", driver); + return NULL; + } + return usb_create_simple(bus, usb->qdev.name); + } + return usb->usbdevice_init(params); +} diff --git a/hw/usb.h b/hw/usb.h index be4fcf6..62362a7 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -183,6 +183,10 @@ struct USBDeviceInfo { * Returns length or one of the USB_RET_ codes. */ int (*handle_data)(USBDevice *dev, USBPacket *p); + + /* handle legacy -usbdevice command line options */ + const char *usbdevice_name; + USBDevice *(*usbdevice_init)(const char *params); }; typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev); @@ -309,6 +313,7 @@ void usb_qdev_register(USBDeviceInfo *info); void usb_qdev_register_many(USBDeviceInfo *info); USBDevice *usb_create(USBBus *bus, 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, usb_attachfn attach); void usb_unregister_port(USBBus *bus, USBPort *port); diff --git a/vl.c b/vl.c index eb2744e..30b5306 100644 --- a/vl.c +++ b/vl.c @@ -2562,6 +2562,11 @@ static int usb_device_add(const char *devname, int is_hotplug) if (!usb_enabled) return -1; + /* drivers with .usbdevice_name entry in USBDeviceInfo */ + dev = usbdevice_create(devname); + if (dev) + goto done; + /* simple devices which don't need extra care */ for (i = 0; i < ARRAY_SIZE(usbdevs); i++) { if (strcmp(devname, usbdevs[i].name) != 0)