usb: kill USB_MSG_RESET

The USB subsystem pipes internal reset notifications through
usb_handle_packet() with a special magic PID.  This indirection
is a pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.

Replace the USB_MSG_RESET with a usb_device_reset() function
which can be called directly.  Also rename the existing usb_reset()
function to usb_port_reset() to avoid confusion.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2012-01-06 15:23:10 +01:00
parent d1f8b53618
commit d28f4e2d86
8 changed files with 25 additions and 31 deletions

View File

@ -888,7 +888,7 @@ static void ehci_reset(void *opaque)
} }
if (devs[i] && devs[i]->attached) { if (devs[i] && devs[i]->attached) {
usb_attach(&s->ports[i]); usb_attach(&s->ports[i]);
usb_send_msg(devs[i], USB_MSG_RESET); usb_device_reset(devs[i]);
} }
} }
ehci_queues_rip_all(s); ehci_queues_rip_all(s);
@ -987,7 +987,7 @@ static void handle_port_status_write(EHCIState *s, int port, uint32_t val)
if (!(val & PORTSC_PRESET) &&(*portsc & PORTSC_PRESET)) { if (!(val & PORTSC_PRESET) &&(*portsc & PORTSC_PRESET)) {
trace_usb_ehci_port_reset(port, 0); trace_usb_ehci_port_reset(port, 0);
if (dev && dev->attached) { if (dev && dev->attached) {
usb_reset(&s->ports[port]); usb_port_reset(&s->ports[port]);
*portsc &= ~PORTSC_CSC; *portsc &= ~PORTSC_CSC;
} }

View File

@ -305,7 +305,7 @@ static int usb_hub_handle_control(USBDevice *dev, USBPacket *p,
break; break;
case PORT_RESET: case PORT_RESET:
if (dev && dev->attached) { if (dev && dev->attached) {
usb_send_msg(dev, USB_MSG_RESET); usb_device_reset(dev);
port->wPortChange |= PORT_STAT_C_RESET; port->wPortChange |= PORT_STAT_C_RESET;
/* set enable bit */ /* set enable bit */
port->wPortStatus |= PORT_STAT_ENABLE; port->wPortStatus |= PORT_STAT_ENABLE;

View File

@ -1310,7 +1310,7 @@ static void musb_writeb(void *opaque, target_phys_addr_t addr, uint32_t value)
s->power = (value & 0xef) | (s->power & 0x10); s->power = (value & 0xef) | (s->power & 0x10);
/* MGC_M_POWER_RESET is also read-only in Peripheral Mode */ /* MGC_M_POWER_RESET is also read-only in Peripheral Mode */
if ((value & MGC_M_POWER_RESET) && s->port.dev) { if ((value & MGC_M_POWER_RESET) && s->port.dev) {
usb_send_msg(s->port.dev, USB_MSG_RESET); usb_device_reset(s->port.dev);
/* Negotiate high-speed operation if MGC_M_POWER_HSENAB is set. */ /* Negotiate high-speed operation if MGC_M_POWER_HSENAB is set. */
if ((value & MGC_M_POWER_HSENAB) && if ((value & MGC_M_POWER_HSENAB) &&
s->port.dev->speed == USB_SPEED_HIGH) s->port.dev->speed == USB_SPEED_HIGH)

View File

@ -449,7 +449,7 @@ static void ohci_reset(void *opaque)
port = &ohci->rhport[i]; port = &ohci->rhport[i];
port->ctrl = 0; port->ctrl = 0;
if (port->port.dev && port->port.dev->attached) { if (port->port.dev && port->port.dev->attached) {
usb_reset(&port->port); usb_port_reset(&port->port);
} }
} }
if (ohci->async_td) { if (ohci->async_td) {
@ -1435,7 +1435,7 @@ static void ohci_port_set_status(OHCIState *ohci, int portnum, uint32_t val)
if (ohci_port_set_if_connected(ohci, portnum, val & OHCI_PORT_PRS)) { if (ohci_port_set_if_connected(ohci, portnum, val & OHCI_PORT_PRS)) {
DPRINTF("usb-ohci: port %d: RESET\n", portnum); DPRINTF("usb-ohci: port %d: RESET\n", portnum);
usb_send_msg(port->port.dev, USB_MSG_RESET); usb_device_reset(port->port.dev);
port->ctrl &= ~OHCI_PORT_PRS; port->ctrl &= ~OHCI_PORT_PRS;
/* ??? Should this also set OHCI_PORT_PESC. */ /* ??? Should this also set OHCI_PORT_PESC. */
port->ctrl |= OHCI_PORT_PES | OHCI_PORT_PRSC; port->ctrl |= OHCI_PORT_PES | OHCI_PORT_PRSC;

View File

@ -342,7 +342,7 @@ static void uhci_reset(void *opaque)
port = &s->ports[i]; port = &s->ports[i];
port->ctrl = 0x0080; port->ctrl = 0x0080;
if (port->port.dev && port->port.dev->attached) { if (port->port.dev && port->port.dev->attached) {
usb_reset(&port->port); usb_port_reset(&port->port);
} }
} }
@ -440,16 +440,12 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
} }
if (val & UHCI_CMD_GRESET) { if (val & UHCI_CMD_GRESET) {
UHCIPort *port; UHCIPort *port;
USBDevice *dev;
int i; int i;
/* send reset on the USB bus */ /* send reset on the USB bus */
for(i = 0; i < NB_PORTS; i++) { for(i = 0; i < NB_PORTS; i++) {
port = &s->ports[i]; port = &s->ports[i];
dev = port->port.dev; usb_device_reset(port->port.dev);
if (dev && dev->attached) {
usb_send_msg(dev, USB_MSG_RESET);
}
} }
uhci_reset(s); uhci_reset(s);
return; return;
@ -491,7 +487,7 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
/* port reset */ /* port reset */
if ( (val & UHCI_PORT_RESET) && if ( (val & UHCI_PORT_RESET) &&
!(port->ctrl & UHCI_PORT_RESET) ) { !(port->ctrl & UHCI_PORT_RESET) ) {
usb_send_msg(dev, USB_MSG_RESET); usb_device_reset(dev);
} }
} }
port->ctrl &= UHCI_PORT_READ_ONLY; port->ctrl &= UHCI_PORT_READ_ONLY;

View File

@ -2346,9 +2346,7 @@ static void xhci_port_write(XHCIState *xhci, uint32_t reg, uint32_t val)
/* write-1-to-start bits */ /* write-1-to-start bits */
if (val & PORTSC_PR) { if (val & PORTSC_PR) {
DPRINTF("xhci: port %d reset\n", port); DPRINTF("xhci: port %d reset\n", port);
if (xhci->ports[port].port.dev) { usb_device_reset(xhci->ports[port].port.dev);
usb_send_msg(xhci->ports[port].port.dev, USB_MSG_RESET);
}
portsc |= PORTSC_PRC | PORTSC_PED; portsc |= PORTSC_PRC | PORTSC_PED;
} }
xhci->ports[port].portsc = portsc; xhci->ports[port].portsc = portsc;

View File

@ -49,14 +49,25 @@ void usb_detach(USBPort *port)
dev->state = USB_STATE_NOTATTACHED; dev->state = USB_STATE_NOTATTACHED;
} }
void usb_reset(USBPort *port) void usb_port_reset(USBPort *port)
{ {
USBDevice *dev = port->dev; USBDevice *dev = port->dev;
assert(dev != NULL); assert(dev != NULL);
usb_detach(port); usb_detach(port);
usb_attach(port); usb_attach(port);
usb_send_msg(dev, USB_MSG_RESET); usb_device_reset(dev);
}
void usb_device_reset(USBDevice *dev)
{
if (dev == NULL || !dev->attached) {
return;
}
dev->remote_wakeup = 0;
dev->addr = 0;
dev->state = USB_STATE_DEFAULT;
usb_device_handle_reset(dev);
} }
void usb_wakeup(USBDevice *dev) void usb_wakeup(USBDevice *dev)
@ -218,15 +229,6 @@ static int do_token_out(USBDevice *s, USBPacket *p)
*/ */
int usb_generic_handle_packet(USBDevice *s, USBPacket *p) int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
{ {
switch(p->pid) {
case USB_MSG_RESET:
s->remote_wakeup = 0;
s->addr = 0;
s->state = USB_STATE_DEFAULT;
usb_device_handle_reset(s);
return 0;
}
/* Rest of the PIDs must match our address */ /* Rest of the PIDs must match our address */
if (s->state < USB_STATE_DEFAULT || p->devaddr != s->addr) if (s->state < USB_STATE_DEFAULT || p->devaddr != s->addr)
return USB_RET_NODEV; return USB_RET_NODEV;

View File

@ -39,9 +39,6 @@
#define USB_TOKEN_IN 0x69 /* device -> host */ #define USB_TOKEN_IN 0x69 /* device -> host */
#define USB_TOKEN_OUT 0xe1 /* host -> device */ #define USB_TOKEN_OUT 0xe1 /* host -> device */
/* specific usb messages, also sent in the 'pid' parameter */
#define USB_MSG_RESET 0x102
#define USB_RET_NODEV (-1) #define USB_RET_NODEV (-1)
#define USB_RET_NAK (-2) #define USB_RET_NAK (-2)
#define USB_RET_STALL (-3) #define USB_RET_STALL (-3)
@ -352,7 +349,8 @@ int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep);
void usb_attach(USBPort *port); void usb_attach(USBPort *port);
void usb_detach(USBPort *port); void usb_detach(USBPort *port);
void usb_reset(USBPort *port); void usb_port_reset(USBPort *port);
void usb_device_reset(USBDevice *dev);
void usb_wakeup(USBDevice *dev); void usb_wakeup(USBDevice *dev);
int usb_generic_handle_packet(USBDevice *s, USBPacket *p); int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p); void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);