diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2011-09-01 13:56:37 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2011-09-07 09:58:26 +0200 |
commit | 891fb2cd4592b6fe76106a69e0ca40efbf82726a (patch) | |
tree | 9f7c75abb2c3de0e1f856cdd4179518f1603b04b /hw/usb-ehci.c | |
parent | 7755260f015dcbb8fa47bcc6f1e2ca317b2205aa (diff) |
usb: claim port at device initialization time.
This patch makes qemu assign a port when creating the device, not when
attaching it. For most usb devices this isn't a noticable difference
because they are in attached state all the time.
The change affects usb-host devices which live in detached state while
the real device is unplugged from the host. They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.
The change also allows to simplify usb-hub. It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now. The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases. For example it is not possible
any more to plug the hub into one of its own downstream ports.
The usb host adapters must care too. USBPort->dev being non-NULL
doesn't imply any more the device is in attached state. The host
adapters must additionally check the USBPort->dev->attached flag.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb-ehci.c')
-rw-r--r-- | hw/usb-ehci.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c index d8ef0cb422..e9e0789795 100644 --- a/hw/usb-ehci.c +++ b/hw/usb-ehci.c @@ -857,8 +857,8 @@ static void ehci_reset(void *opaque) */ for(i = 0; i < NB_PORTS; i++) { devs[i] = s->ports[i].dev; - if (devs[i]) { - usb_attach(&s->ports[i], NULL); + if (devs[i] && devs[i]->attached) { + usb_detach(&s->ports[i]); } } @@ -878,8 +878,8 @@ static void ehci_reset(void *opaque) } else { s->portsc[i] = PORTSC_PPOWER; } - if (devs[i]) { - usb_attach(&s->ports[i], devs[i]); + if (devs[i] && devs[i]->attached) { + usb_attach(&s->ports[i]); } } ehci_queues_rip_all(s); @@ -945,15 +945,15 @@ static void handle_port_owner_write(EHCIState *s, int port, uint32_t owner) return; } - if (dev) { - usb_attach(&s->ports[port], NULL); + if (dev && dev->attached) { + usb_detach(&s->ports[port]); } *portsc &= ~PORTSC_POWNER; *portsc |= owner; - if (dev) { - usb_attach(&s->ports[port], dev); + if (dev && dev->attached) { + usb_attach(&s->ports[port]); } } @@ -977,8 +977,8 @@ static void handle_port_status_write(EHCIState *s, int port, uint32_t val) if (!(val & PORTSC_PRESET) &&(*portsc & PORTSC_PRESET)) { trace_usb_ehci_port_reset(port, 0); - if (dev) { - usb_attach(&s->ports[port], dev); + if (dev && dev->attached) { + usb_attach(&s->ports[port]); usb_send_msg(dev, USB_MSG_RESET); *portsc &= ~PORTSC_CSC; } @@ -987,7 +987,7 @@ static void handle_port_status_write(EHCIState *s, int port, uint32_t val) * Table 2.16 Set the enable bit(and enable bit change) to indicate * to SW that this port has a high speed device attached */ - if (dev && (dev->speedmask & USB_SPEED_MASK_HIGH)) { + if (dev && dev->attached && (dev->speedmask & USB_SPEED_MASK_HIGH)) { val |= PORTSC_PED; } } |