diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2012-01-12 13:23:01 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2012-02-10 11:31:57 +0100 |
commit | 079d0b7f1eedcc634c371fe05b617fdc55c8b762 (patch) | |
tree | 60ee42f36b295edb49fcb62af5912f769efa9991 /hw/usb.c | |
parent | 63095ab54c1ce554b1fc825fc678394ccb129e5b (diff) | |
download | qemu-079d0b7f1eedcc634c371fe05b617fdc55c8b762.zip qemu-079d0b7f1eedcc634c371fe05b617fdc55c8b762.tar.gz qemu-079d0b7f1eedcc634c371fe05b617fdc55c8b762.tar.bz2 |
usb: Set USBEndpoint in usb_packet_setup().
With the separation of the device lookup (via usb_find_device) and
packet processing we can lookup device and endpoint before setting up
the usb packet. So we can initialize USBPacket->ep early and keep it
valid for the whole lifecycle of the USBPacket. Also the devaddr and
devep fields are not needed any more.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb.c')
-rw-r--r-- | hw/usb.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -140,7 +140,7 @@ static int do_token_in(USBDevice *s, USBPacket *p) int request, value, index; int ret = 0; - assert(p->devep == 0); + assert(p->ep->nr == 0); request = (s->setup_buf[0] << 8) | s->setup_buf[1]; value = (s->setup_buf[3] << 8) | s->setup_buf[2]; @@ -186,7 +186,7 @@ static int do_token_in(USBDevice *s, USBPacket *p) static int do_token_out(USBDevice *s, USBPacket *p) { - assert(p->devep == 0); + assert(p->ep->nr == 0); switch(s->setup_state) { case SETUP_STATE_ACK: @@ -289,11 +289,11 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p) if (dev == NULL) { return USB_RET_NODEV; } - assert(dev->addr == p->devaddr); + assert(dev == p->ep->dev); assert(dev->state == USB_STATE_DEFAULT); assert(p->state == USB_PACKET_SETUP); - if (p->devep == 0) { + if (p->ep->nr == 0) { /* control pipe */ switch (p->pid) { case USB_TOKEN_SETUP: @@ -315,7 +315,6 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p) } if (ret == USB_RET_ASYNC) { - p->ep = usb_ep_get(dev, p->pid, p->devep); p->state = USB_PACKET_ASYNC; } return ret; @@ -347,13 +346,12 @@ void usb_packet_init(USBPacket *p) qemu_iovec_init(&p->iov, 1); } -void usb_packet_setup(USBPacket *p, int pid, uint8_t addr, uint8_t ep) +void usb_packet_setup(USBPacket *p, int pid, USBEndpoint *ep) { assert(!usb_packet_is_inflight(p)); p->state = USB_PACKET_SETUP; p->pid = pid; - p->devaddr = addr; - p->devep = ep; + p->ep = ep; p->result = 0; qemu_iovec_reset(&p->iov); } @@ -464,7 +462,12 @@ void usb_ep_dump(USBDevice *dev) struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep) { - struct USBEndpoint *eps = pid == USB_TOKEN_IN ? dev->ep_in : dev->ep_out; + struct USBEndpoint *eps; + + if (dev == NULL) { + return NULL; + } + eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; if (ep == 0) { return &dev->ep_ctl; } |