From patchwork Thu Dec 9 12:30:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 74995 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 41D1BB6EF1 for ; Fri, 10 Dec 2010 09:01:26 +1100 (EST) Received: from localhost ([127.0.0.1]:57672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQkei-0000oi-TP for incoming@patchwork.ozlabs.org; Thu, 09 Dec 2010 12:51:49 -0500 Received: from [140.186.70.92] (port=49836 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQfeE-0001YE-GD for qemu-devel@nongnu.org; Thu, 09 Dec 2010 07:31:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQfeC-0005Ih-R9 for qemu-devel@nongnu.org; Thu, 09 Dec 2010 07:30:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQfeC-0005IK-Js for qemu-devel@nongnu.org; Thu, 09 Dec 2010 07:30:56 -0500 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.13.8/8.13.8) with ESMTP id oB9CUtn5016441 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 9 Dec 2010 07:30:56 -0500 Received: from rincewind.home.kraxel.org (vpn1-4-138.ams2.redhat.com [10.36.4.138]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB9CUeEt004283; Thu, 9 Dec 2010 07:30:45 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id F0D7B45230; Thu, 9 Dec 2010 13:30:28 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 9 Dec 2010 13:30:17 +0100 Message-Id: <1291897827-11424-15-git-send-email-kraxel@redhat.com> In-Reply-To: <1291897827-11424-1-git-send-email-kraxel@redhat.com> References: <1291897827-11424-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. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 14/24] usb: create USBPortOps, move attach there. 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 USBPortOps struct, move the attach function to that struct. Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 4 ++-- hw/usb-hub.c | 6 +++++- hw/usb-musb.c | 6 +++++- hw/usb-ohci.c | 6 +++++- hw/usb-uhci.c | 6 +++++- hw/usb.c | 2 +- hw/usb.h | 8 +++++--- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 15a42ff..f534bc3 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -111,11 +111,11 @@ USBDevice *usb_create_simple(USBBus *bus, const char *name) } void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, - usb_attachfn attach) + USBPortOps *ops) { port->opaque = opaque; port->index = index; - port->attach = attach; + port->ops = ops; QTAILQ_INSERT_TAIL(&bus->free, port, next); bus->nfree++; } diff --git a/hw/usb-hub.c b/hw/usb-hub.c index 5a7bc44..1de2e0f 100644 --- a/hw/usb-hub.c +++ b/hw/usb-hub.c @@ -506,6 +506,10 @@ static void usb_hub_handle_destroy(USBDevice *dev) } } +static USBPortOps usb_hub_port_ops = { + .attach = usb_hub_attach, +}; + static int usb_hub_initfn(USBDevice *dev) { USBHubState *s = DO_UPCAST(USBHubState, dev, dev); @@ -516,7 +520,7 @@ static int usb_hub_initfn(USBDevice *dev) for (i = 0; i < NUM_PORTS; i++) { port = &s->ports[i]; usb_register_port(usb_bus_from_device(dev), - &port->port, s, i, usb_hub_attach); + &port->port, s, i, &usb_hub_port_ops); port->wPortStatus = PORT_STAT_POWER; port->wPortChange = 0; } diff --git a/hw/usb-musb.c b/hw/usb-musb.c index 7f15842..916aa06 100644 --- a/hw/usb-musb.c +++ b/hw/usb-musb.c @@ -261,6 +261,10 @@ static void musb_attach(USBPort *port, USBDevice *dev); +static USBPortOps musb_port_ops = { + .attach = musb_attach, +}; + typedef struct { uint16_t faddr[2]; uint8_t haddr[2]; @@ -343,7 +347,7 @@ struct MUSBState { } usb_bus_new(&s->bus, NULL /* FIXME */); - usb_register_port(&s->bus, &s->port, s, 0, musb_attach); + usb_register_port(&s->bus, &s->port, s, 0, &musb_port_ops); return s; } diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 8fb2f83..3f71291 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1676,6 +1676,10 @@ static CPUWriteMemoryFunc * const ohci_writefn[3]={ ohci_mem_write }; +static USBPortOps ohci_port_ops = { + .attach = ohci_attach, +}; + static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, int num_ports, uint32_t localmem_base) { @@ -1705,7 +1709,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, usb_bus_new(&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); + usb_register_port(&ohci->bus, &ohci->rhport[i].port, ohci, i, &ohci_port_ops); } ohci->async_td = 0; diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 1d83400..1427c2f 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -1101,6 +1101,10 @@ static void uhci_map(PCIDevice *pci_dev, int region_num, register_ioport_read(addr, 32, 1, uhci_ioport_readb, s); } +static USBPortOps uhci_port_ops = { + .attach = uhci_attach, +}; + static int usb_uhci_common_initfn(UHCIState *s) { uint8_t *pci_conf = s->dev.config; @@ -1115,7 +1119,7 @@ static int usb_uhci_common_initfn(UHCIState *s) usb_bus_new(&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); + usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops); } s->frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s); s->expire_time = qemu_get_clock(vm_clock) + diff --git a/hw/usb.c b/hw/usb.c index a326bcf..39d29f3 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -28,7 +28,7 @@ void usb_attach(USBPort *port, USBDevice *dev) { - port->attach(port, dev); + port->ops->attach(port, dev); } /**********************/ diff --git a/hw/usb.h b/hw/usb.h index b8f13cc..e98808a 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -216,12 +216,14 @@ struct USBDeviceInfo { USBDevice *(*usbdevice_init)(const char *params); }; -typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev); +typedef struct USBPortOps { + void (*attach)(USBPort *port, USBDevice *dev); +} USBPortOps; /* USB port on which a device can be connected */ struct USBPort { USBDevice *dev; - usb_attachfn attach; + USBPortOps *ops; void *opaque; int index; /* internal port index, may be used with the opaque */ QTAILQ_ENTRY(USBPort) next; @@ -332,7 +334,7 @@ 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); + USBPortOps *ops); void usb_unregister_port(USBBus *bus, USBPort *port); int usb_device_attach(USBDevice *dev); int usb_device_detach(USBDevice *dev);