From patchwork Fri Jul 8 09:50:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 103800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0CFC8B6F76 for ; Fri, 8 Jul 2011 20:13:15 +1000 (EST) Received: from localhost ([::1]:39689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qf83b-0001p4-Bu for incoming@patchwork.ozlabs.org; Fri, 08 Jul 2011 06:13:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qf7iT-0005Vm-E3 for qemu-devel@nongnu.org; Fri, 08 Jul 2011 05:51:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qf7iQ-0004O9-HT for qemu-devel@nongnu.org; Fri, 08 Jul 2011 05:51:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qf7iP-0004Nn-P1 for qemu-devel@nongnu.org; Fri, 08 Jul 2011 05:51:18 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p689pG0m029900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Jul 2011 05:51:16 -0400 Received: from rincewind.home.kraxel.org (vpn1-4-123.ams2.redhat.com [10.36.4.123]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p689pEHd014190; Fri, 8 Jul 2011 05:51:15 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 05CC04161C; Fri, 8 Jul 2011 11:51:13 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 8 Jul 2011 11:50:54 +0200 Message-Id: <1310118673-26196-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1310118673-26196-1-git-send-email-kraxel@redhat.com> References: <1310118673-26196-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Hans de Goede , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 04/23] usb: Add a register_companion USB bus op. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Hans de Goede This is a preparation patch for adding support for USB companion controllers. Signed-off-by: Hans de Goede Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 31 +++++++++++++++++++++++++++++++ hw/usb.h | 5 +++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index e37e8a2..b511bac 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -160,6 +160,37 @@ void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, bus->nfree++; } +int usb_register_companion(const char *masterbus, USBPort *ports[], + uint32_t portcount, uint32_t firstport, + void *opaque, USBPortOps *ops, int speedmask) +{ + USBBus *bus; + int i; + + QTAILQ_FOREACH(bus, &busses, next) { + if (strcmp(bus->qbus.name, masterbus) == 0) { + break; + } + } + + if (!bus || !bus->ops->register_companion) { + qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus", + "an USB masterbus"); + if (bus) { + error_printf_unless_qmp( + "USB bus '%s' does not allow companion controllers\n", + masterbus); + } + return -1; + } + + for (i = 0; i < portcount; i++) { + usb_fill_port(ports[i], opaque, i, ops, speedmask); + } + + return bus->ops->register_companion(bus, ports, portcount, firstport); +} + void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr) { if (upstream) { diff --git a/hw/usb.h b/hw/usb.h index 076e2ff..a5f2efa 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -344,6 +344,8 @@ struct USBBus { }; struct USBBusOps { + int (*register_companion)(USBBus *bus, USBPort *ports[], + uint32_t portcount, uint32_t firstport); void (*device_destroy)(USBBus *bus, USBDevice *dev); }; @@ -356,6 +358,9 @@ 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, USBPortOps *ops, int speedmask); +int usb_register_companion(const char *masterbus, USBPort *ports[], + uint32_t portcount, uint32_t firstport, + void *opaque, USBPortOps *ops, int speedmask); void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr); void usb_unregister_port(USBBus *bus, USBPort *port); int usb_device_attach(USBDevice *dev);