Patchwork [1/2] usb: add ich9_ehci_with_companion_init()

login
register
mail settings
Submitter Gerd Hoffmann
Date July 1, 2011, 11:27 a.m.
Message ID <1309519646-3206-2-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/102897/
State New
Headers show

Comments

Gerd Hoffmann - July 1, 2011, 11:27 a.m.
Add convinience function which creates a ehci controller with three
companion uhci controllers, with all properties are setup correctly.

The guest will see this:

[root@fedora64 ~]# lspci -s2
00:02.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)
00:02.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)
00:02.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)
00:02.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-ehci.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb.h      |    3 +++
 2 files changed, 52 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index a4758f9..d24eecb 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -2354,6 +2354,55 @@  static void ehci_register(void)
 }
 device_init(ehci_register);
 
+int ich9_ehci_with_companion_init(PCIBus *bus, int devfn, const char *id)
+{
+    PCIDevice *ehci = NULL, *uhci1 = NULL, *uhci2 = NULL, *uhci3 = NULL;
+    char masterbus[32];
+    int slot = PCI_SLOT(devfn);
+
+    snprintf(masterbus, sizeof(masterbus), "%s.0", id);
+
+    ehci = pci_create_multifunction(bus, PCI_DEVFN(slot, 7), true,
+                                    "ich9-usb-ehci1");
+    if (NULL == ehci) {
+        goto fail;
+    }
+    ehci->qdev.id = id;
+    qdev_init_nofail(&ehci->qdev);
+
+    uhci1 = pci_create_multifunction(bus, PCI_DEVFN(slot, 0), true,
+                                     "ich9-usb-uhci1");
+    if (NULL == uhci1) {
+        goto fail;
+    }
+    qdev_prop_set_string(&uhci1->qdev, "masterbus", masterbus);
+    qdev_prop_set_uint32(&uhci1->qdev, "firstport", 0);
+    qdev_init_nofail(&uhci1->qdev);
+
+    uhci2 = pci_create_multifunction(bus, PCI_DEVFN(slot, 1), true,
+                                     "ich9-usb-uhci2");
+    if (NULL == uhci2) {
+        goto fail;
+    }
+    qdev_prop_set_string(&uhci2->qdev, "masterbus", masterbus);
+    qdev_prop_set_uint32(&uhci2->qdev, "firstport", 2);
+    qdev_init_nofail(&uhci2->qdev);
+
+    uhci3 = pci_create_multifunction(bus, PCI_DEVFN(slot, 2), true,
+                                     "ich9-usb-uhci3");
+    if (NULL == uhci3) {
+        goto fail;
+    }
+    qdev_prop_set_string(&uhci3->qdev, "masterbus", masterbus);
+    qdev_prop_set_uint32(&uhci3->qdev, "firstport", 4);
+    qdev_init_nofail(&uhci3->qdev);
+    return 0;
+
+fail:
+    return -1;
+}
+
+
 /*
  * vim: expandtab ts=4
  */
diff --git a/hw/usb.h b/hw/usb.h
index ded2de2..2f90b3a 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -313,6 +313,9 @@  void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
 /* usb-bt.c */
 USBDevice *usb_bt_init(HCIInfo *hci);
 
+/* usb-ehci.c */
+int ich9_ehci_with_companion_init(PCIBus *bus, int devfn, const char *id);
+
 /* usb ports of the VM */
 
 #define VM_USB_HUB_SIZE 8