summaryrefslogtreecommitdiff
path: root/hw/usb.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-12-01 11:27:05 +0100
committerGerd Hoffmann <kraxel@redhat.com>2011-01-11 17:01:02 +0100
commit618c169b577db64ac6589ad48825d2e11760d1a6 (patch)
treeb9b60ddfcf2d07041117ec425118deb06437cf01 /hw/usb.c
parent0d86d2bebb625a222f70b76972139f6a272e3e0b (diff)
downloadqemu-618c169b577db64ac6589ad48825d2e11760d1a6.zip
usb: rework attach/detach workflow
Add separate detach callback to USBPortOps, split uhci/ohci/musb/usbhub attach functions into two. Move common code to the usb_attach() function, only the hardware-specific bits remain in the attach/detach callbacks. Keep track of the port it is attached to for each usb device. [ v3: fix tyops in usb-musb.c ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb.c')
-rw-r--r--hw/usb.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/hw/usb.c b/hw/usb.c
index 39d29f3daf..2eda86a58c 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -28,7 +28,25 @@
void usb_attach(USBPort *port, USBDevice *dev)
{
- port->ops->attach(port, dev);
+ if (dev != NULL) {
+ /* attach */
+ if (port->dev) {
+ usb_attach(port, NULL);
+ }
+ dev->port = port;
+ port->dev = dev;
+ port->ops->attach(port);
+ usb_send_msg(dev, USB_MSG_ATTACH);
+ } else {
+ /* detach */
+ dev = port->dev;
+ port->ops->detach(port);
+ if (dev) {
+ usb_send_msg(dev, USB_MSG_DETACH);
+ dev->port = NULL;
+ port->dev = NULL;
+ }
+ }
}
/**********************/