usb: add usb_handle_packet

Add a usb_handle_packet function, put it into use everywhere.
Right now it just calls dev->info->handle_packet(), that will
change in future patches though.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2011-05-12 13:20:39 +02:00
parent ebd669a19f
commit 53aa8c0e2a
6 changed files with 22 additions and 7 deletions

View File

@ -495,7 +495,7 @@ static int usb_hub_broadcast_packet(USBHubState *s, USBPacket *p)
port = &s->ports[i]; port = &s->ports[i];
dev = port->port.dev; dev = port->port.dev;
if (dev && (port->wPortStatus & PORT_STAT_ENABLE)) { if (dev && (port->wPortStatus & PORT_STAT_ENABLE)) {
ret = dev->info->handle_packet(dev, p); ret = usb_handle_packet(dev, p);
if (ret != USB_RET_NODEV) { if (ret != USB_RET_NODEV) {
return ret; return ret;
} }

View File

@ -601,7 +601,7 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep,
ep->packey[dir].dir = dir; ep->packey[dir].dir = dir;
if (s->port.dev) if (s->port.dev)
ret = s->port.dev->info->handle_packet(s->port.dev, &ep->packey[dir].p); ret = usb_handle_packet(s->port.dev, &ep->packey[dir].p);
else else
ret = USB_RET_NODEV; ret = USB_RET_NODEV;

View File

@ -748,7 +748,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN); ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN);
ohci->usb_packet.data = ohci->usb_buf; ohci->usb_packet.data = ohci->usb_buf;
ohci->usb_packet.len = len; ohci->usb_packet.len = len;
ret = dev->info->handle_packet(dev, &ohci->usb_packet); ret = usb_handle_packet(dev, &ohci->usb_packet);
if (ret != USB_RET_NODEV) if (ret != USB_RET_NODEV)
break; break;
} }
@ -944,7 +944,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN); ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN);
ohci->usb_packet.data = ohci->usb_buf; ohci->usb_packet.data = ohci->usb_buf;
ohci->usb_packet.len = len; ohci->usb_packet.len = len;
ret = dev->info->handle_packet(dev, &ohci->usb_packet); ret = usb_handle_packet(dev, &ohci->usb_packet);
if (ret != USB_RET_NODEV) if (ret != USB_RET_NODEV)
break; break;
} }

View File

@ -632,7 +632,7 @@ static int uhci_broadcast_packet(UHCIState *s, USBPacket *p)
USBDevice *dev = port->port.dev; USBDevice *dev = port->port.dev;
if (dev && (port->ctrl & UHCI_PORT_EN)) if (dev && (port->ctrl & UHCI_PORT_EN))
ret = dev->info->handle_packet(dev, p); ret = usb_handle_packet(dev, p);
} }
DPRINTF("uhci: packet exit. ret %d len %d\n", ret, p->len); DPRINTF("uhci: packet exit. ret %d len %d\n", ret, p->len);

View File

@ -297,9 +297,22 @@ int set_usb_string(uint8_t *buf, const char *str)
void usb_send_msg(USBDevice *dev, int msg) void usb_send_msg(USBDevice *dev, int msg)
{ {
USBPacket p; USBPacket p;
int ret;
memset(&p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
p.pid = msg; p.pid = msg;
dev->info->handle_packet(dev, &p); ret = usb_handle_packet(dev, &p);
/* This _must_ be synchronous */ /* This _must_ be synchronous */
assert(ret != USB_RET_ASYNC);
}
/* Hand over a packet to a device for processing. Return value
USB_RET_ASYNC indicates the processing isn't finished yet, the
driver will call usb_packet_complete() when done processing it. */
int usb_handle_packet(USBDevice *dev, USBPacket *p)
{
int ret;
ret = dev->info->handle_packet(dev, p);
return ret;
} }

View File

@ -266,6 +266,8 @@ struct USBPacket {
void *cancel_opaque; void *cancel_opaque;
}; };
int usb_handle_packet(USBDevice *dev, USBPacket *p);
/* Defer completion of a USB packet. The hadle_packet routine should then /* Defer completion of a USB packet. The hadle_packet routine should then
return USB_RET_ASYNC. Packets that complete immediately (before return USB_RET_ASYNC. Packets that complete immediately (before
handle_packet returns) should not call this method. */ handle_packet returns) should not call this method. */