Skip to contentSkip to conversation

usb: make host adapters hot-pluggable

PATCH In review Gerd Hoffmann 2 participants 7 messages Sep 16, 2014

lore
Share & tools
lore
#4 lore raw

PATCH 4/5 usb: tag ohci as hotpluggable

In reply to Gerd Hoffmann

FIXME: turn off hotplug for companions

---
 hw/usb/hcd-ohci.c | 1 -
 1 file changed, 1 deletion(-)
hw/usb/hcd-ohci.c +0 -1
index 83bec34..8113b5a 100644
@@ -2116,7 +2116,6 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_USB, dc->categories);
     dc->desc = "Apple USB Controller";
     dc->props = ohci_pci_properties;
-    dc->hotpluggable = false;
     dc->vmsd = &vmstate_ohci;
 }
 
Signature · 1 line
1.8.3.1
#0 lore raw

cover usb: make host adapters hot-pluggable

Hi,

This series the usb host adapters hot-pluggable. Problem is that we can NOT hotplug host adapters which are part of a companion setup. The way this is tackled now is to split the usb host adapter variants into two groups:

* All ich9-* variants (both uhci and ehci) support companion controller and are NOT hot-pluggable.
* All other variants do NOT support companion controller setups and can be hotplugged.

[ ohci is to be done, we have only one type there, so we have to create
a new one and put the existing into one of the two groups, /me wants collect feedback on the approach though. ]

Comments? Other suggestions?

cheers,
Gerd

Gerd Hoffmann (4):
usb: tag xhci as hotpluggable
usb: tag standalone uhci as hotpluggable
usb: tag standalone ehci as hotpluggable
[wip] usb: tag ohci as hotpluggable

Gonglei (1):
tests: add usb hcds hotplugging qtest

 hw/usb/hcd-ehci-pci.c        | 12 ++++++-
 hw/usb/hcd-ehci.c            |  8 +++--
 hw/usb/hcd-ehci.h            |  1 +
 hw/usb/hcd-ohci.c            |  1 -
 hw/usb/hcd-uhci.c            | 16 +++++++--
 hw/usb/hcd-xhci.c            |  1 -
 tests/Makefile               |  2 ++
 tests/usb-hcd-hotplug-test.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 119 insertions(+), 8 deletions(-)
 create mode 100644 tests/usb-hcd-hotplug-test.c
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/5 usb: tag standalone ehci as hotpluggable

Add a flag to EHCIPCIInfo saying whenever the controller supports companions or not. Make sure we only allow registering companions for ehci versions supporting that. Enable pci hotplug for the ehci variants not supporting companions.

---
 hw/usb/hcd-ehci-pci.c | 12 +++++++++++-
 hw/usb/hcd-ehci.c     |  8 ++++++--
 hw/usb/hcd-ehci.h     |  1 +
 3 files changed, 18 insertions(+), 3 deletions(-)
hw/usb/hcd-ehci-pci.c +11 -1
index 289ca3b..490f2b6 100644
@@ -23,6 +23,7 @@ typedef struct EHCIPCIInfo {
     uint16_t vendor_id;
     uint16_t device_id;
     uint8_t  revision;
+    bool companion;
 } EHCIPCIInfo;
 
 static int usb_ehci_pci_initfn(PCIDevice *dev)
@@ -71,6 +72,7 @@ static int usb_ehci_pci_initfn(PCIDevice *dev)
 
 static void usb_ehci_pci_init(Object *obj)
 {
+    DeviceClass *dc = OBJECT_GET_CLASS(DeviceClass, obj, TYPE_DEVICE);
     EHCIPCIState *i = PCI_EHCI(obj);
     EHCIState *s = &i->ehci;
 
@@ -81,6 +83,10 @@ static void usb_ehci_pci_init(Object *obj)
     s->portscbase = 0x44;
     s->portnr = NB_PORTS;
 
+    if (!dc->hotpluggable) {
+        s->companion_enable = true;
+    }
+
     usb_ehci_init(s, DEVICE(obj));
 }
 
@@ -137,7 +143,6 @@ static void ehci_class_init(ObjectClass *klass, void *data)
     k->exit = usb_ehci_pci_exit;
     k->class_id = PCI_CLASS_SERIAL_USB;
     k->config_write = usb_ehci_pci_write_config;
-    dc->hotpluggable = false;
     dc->vmsd = &vmstate_ehci_pci;
     dc->props = ehci_pci_properties;
 }
@@ -161,6 +166,9 @@ static void ehci_data_class_init(ObjectClass *klass, void *data)
     k->device_id = i->device_id;
     k->revision = i->revision;
     set_bit(DEVICE_CATEGORY_USB, dc->categories);
+    if (i->companion) {
+        dc->hotpluggable = false;
+    }
 }
 
 static struct EHCIPCIInfo ehci_pci_info[] = {
@@ -174,11 +182,13 @@ static struct EHCIPCIInfo ehci_pci_info[] = {
         .vendor_id = PCI_VENDOR_ID_INTEL,
         .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
         .revision  = 0x03,
+        .companion = true,
     },{
         .name      = "ich9-usb-ehci2", /* 00:1a.7 */
         .vendor_id = PCI_VENDOR_ID_INTEL,
         .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI2,
         .revision  = 0x03,
+        .companion = true,
     }
 };
 
hw/usb/hcd-ehci.c +6 -2
index bacb7ce..1cc0fc1 100644
@@ -2347,10 +2347,13 @@ static USBPortOps ehci_port_ops = {
     .complete = ehci_async_complete_packet,
 };
 
-static USBBusOps ehci_bus_ops = {
+static USBBusOps ehci_bus_ops_companion = {
     .register_companion = ehci_register_companion,
     .wakeup_endpoint = ehci_wakeup_endpoint,
 };
+static USBBusOps ehci_bus_ops_standalone = {
+    .wakeup_endpoint = ehci_wakeup_endpoint,
+};
 
 static void usb_ehci_pre_save(void *opaque)
 {
@@ -2456,7 +2459,8 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp)
         return;
     }
 
-    usb_bus_new(&s->bus, sizeof(s->bus), &ehci_bus_ops, dev);
+    usb_bus_new(&s->bus, sizeof(s->bus), s->companion_enable ?
+                &ehci_bus_ops_companion : &ehci_bus_ops_standalone, dev);
     for (i = 0; i < s->portnr; i++) {
         usb_register_port(&s->bus, &s->ports[i], s, i, &ehci_port_ops,
                           USB_SPEED_MASK_HIGH);
hw/usb/hcd-ehci.h +1 -0
index 4858b7e..2bc259c 100644
@@ -262,6 +262,7 @@ struct EHCIState {
     MemoryRegion mem_opreg;
     MemoryRegion mem_ports;
     int companion_count;
+    bool companion_enable;
     uint16_t capsbase;
     uint16_t opregbase;
     uint16_t portscbase;
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/5 usb: tag xhci as hotpluggable

In reply to Gerd Hoffmann
---
 hw/usb/hcd-xhci.c | 1 -
 1 file changed, 1 deletion(-)
hw/usb/hcd-xhci.c +0 -1
index 73ced1f..c556367 100644
@@ -3874,7 +3874,6 @@ static void xhci_class_init(ObjectClass *klass, void *data)
     dc->vmsd    = &vmstate_xhci;
     dc->props   = xhci_properties;
     dc->reset   = xhci_reset;
-    dc->hotpluggable   = false;
     set_bit(DEVICE_CATEGORY_USB, dc->categories);
     k->init         = usb_xhci_initfn;
     k->exit         = usb_xhci_exit;
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/5 usb: tag standalone uhci as hotpluggable

In reply to Gerd Hoffmann

uhci hostadapters in companion setups can't be hotplugged. So leave hotplug disabled for all ich9 variants (which are already tagged with unplug = true in the info struct). For the other variants we'll enable hotplug and remove the companion setup properties.

---
 hw/usb/hcd-uhci.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/usb/hcd-uhci.c +13 -3
index 3b3ebcd..5b88f30 100644
@@ -1279,13 +1279,18 @@ static void usb_uhci_exit(PCIDevice *dev)
     }
 }
 
-static Property uhci_properties[] = {
+static Property uhci_properties_companion[] = {
     DEFINE_PROP_STRING("masterbus", UHCIState, masterbus),
     DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0),
     DEFINE_PROP_UINT32("bandwidth", UHCIState, frame_bandwidth, 1280),
     DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128),
     DEFINE_PROP_END_OF_LIST(),
 };
+static Property uhci_properties_standalone[] = {
+    DEFINE_PROP_UINT32("bandwidth", UHCIState, frame_bandwidth, 1280),
+    DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128),
+    DEFINE_PROP_END_OF_LIST(),
+};
 
 static void uhci_class_init(ObjectClass *klass, void *data)
 {
@@ -1300,9 +1305,14 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     k->device_id = info->device_id;
     k->revision  = info->revision;
     k->class_id  = PCI_CLASS_SERIAL_USB;
-    dc->hotpluggable = false;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    if (!info->unplug) {
+        /* uhci controllers in companion setups can't be hotplugged */
+        dc->hotpluggable = false;
+        dc->props = uhci_properties_companion;
+    } else {
+        dc->props = uhci_properties_standalone;
+    }
     set_bit(DEVICE_CATEGORY_USB, dc->categories);
     u->info = *info;
 }
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/5 tests: add usb hcds hotplugging qtest

In reply to Gerd Hoffmann

From: Gonglei <[email protected]>

Because of we now support usb hcds hotplugging, and collect all hcds hotplugging tests into one file for code sharing.

---
 tests/Makefile               |  2 ++
 tests/usb-hcd-hotplug-test.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 tests/usb-hcd-hotplug-test.c
tests/Makefile +2 -0
index d5db97b..7c4d0b7 100644
@@ -165,6 +165,7 @@ gcov-files-i386-y += hw/usb/dev-hid.c
 gcov-files-i386-y += hw/usb/dev-storage.c
 check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
+check-qtest-i386-y += tests/usb-hcd-hotplug-test$(EXESUF)
 check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF)
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
@@ -345,6 +346,7 @@ tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o
 tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o
 tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-pc-obj-y)
 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o
+tests/usb-hcd-hotplug-test$(EXESUF): tests/usb-hcd-hotplug-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
tests/usb-hcd-hotplug-test.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw
In reply to Gerd Hoffmann

Hi,

Quoted 14 lines

Subject: [Qemu-devel] [PATCH 0/5] usb: make host adapters hot-pluggable

Hi,

This series the usb host adapters hot-pluggable. Problem is that we can NOT hotplug host adapters which are part of a companion setup. The way this is tackled now is to split the usb host adapter variants into two groups:

* All ich9-* variants (both uhci and ehci) support companion controller and are NOT hot-pluggable.
* All other variants do NOT support companion controller setups and can be hotplugged.

Quoted 6 lines

[ ohci is to be done, we have only one type there, so we have to create
a new one and put the existing into one of the two groups, /me wants collect feedback on the approach though. ]

Comments? Other suggestions?

I agree with you.

Because we must set 'dc->hotpluggable = false or true' at $hci_class_init() to assure the host adapters whether supporting hotplugging or not. And we can only pass parameters from Typeinfo struct's class_data property to $hci_class_init() at present.

Best regards,
-Gonglei