]> git.proxmox.com Git - qemu.git/commitdiff
usb: create USBPortOps, move attach there.
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 1 Dec 2010 10:08:44 +0000 (11:08 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 11 Jan 2011 16:01:02 +0000 (17:01 +0100)
Create USBPortOps struct, move the attach function to that struct.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb-bus.c
hw/usb-hub.c
hw/usb-musb.c
hw/usb-ohci.c
hw/usb-uhci.c
hw/usb.c
hw/usb.h

index af537c238f35f438a522dbe5fb343c920c100315..9dc879314839f31bdcff3eee58d9450172c3ca2c 100644 (file)
@@ -113,12 +113,14 @@ USBDevice *usb_create_simple(USBBus *bus, const char *name)
 }
 
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-                       USBDevice *pdev, usb_attachfn attach)
+                       USBDevice *pdev, USBPortOps *ops)
 {
     port->opaque = opaque;
     port->index = index;
-    port->attach = attach;
     port->pdev = pdev;
+    port->opaque = opaque;
+    port->index = index;
+    port->ops = ops;
     QTAILQ_INSERT_TAIL(&bus->free, port, next);
     bus->nfree++;
 }
index 3c7c3eee4364f626737543fc4002ce59ebcaeae0..b3d72987f3bcf85e108425fd3308e15d983dd763 100644 (file)
@@ -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, &s->dev, usb_hub_attach);
+                          &port->port, s, i, &s->dev, &usb_hub_port_ops);
         port->wPortStatus = PORT_STAT_POWER;
         port->wPortChange = 0;
     }
index 9efe7a63447c78a6e98bee3371c3a60e6d2d756d..592d3e67f4900e2e2a7f066b26a46890466693a8 100644 (file)
 
 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, NULL, musb_attach);
+    usb_register_port(&s->bus, &s->port, s, 0, NULL, &musb_port_ops);
 
     return s;
 }
index 240e8409af82ebd1ff43e78756b21e59fabe0ce0..7b13bdd0d32f14b3f9b96a0f916997f7e23aab58 100644 (file)
@@ -1669,6 +1669,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)
 {
@@ -1699,7 +1703,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, NULL, ohci_attach);
+        usb_register_port(&ohci->bus, &ohci->rhport[i].port, ohci, i, NULL, &ohci_port_ops);
     }
 
     ohci->async_td = 0;
index b9b822fcb142eb9fc8725d9da7e93637fa74f131..0f9ef1edc3d4fbde8c3de5f338f19abdc489100f 100644 (file)
@@ -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, NULL, uhci_attach);
+        usb_register_port(&s->bus, &s->ports[i].port, s, i, NULL, &uhci_port_ops);
     }
     s->frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
     s->expire_time = qemu_get_clock(vm_clock) +
index a326bcfffe5dcd1672b88db8063d890634c2b730..39d29f3daf845831eb5f41c1fffc6d913cc98cbc 100644 (file)
--- 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);
 }
 
 /**********************/
index 966d47e5ee5f7e253f818489d4fbc109a558781a..218788fcebaa83cd37ba6358677c78f4c425f510 100644 (file)
--- 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;
     USBDevice *pdev;
     int index; /* internal port index, may be used with the opaque */
@@ -333,7 +335,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,
-                       USBDevice *pdev, usb_attachfn attach);
+                       USBDevice *pdev, USBPortOps *ops);
 void usb_unregister_port(USBBus *bus, USBPort *port);
 int usb_device_attach(USBDevice *dev);
 int usb_device_detach(USBDevice *dev);