#include <linux/usbdevice_fs.h>
#include <linux/version.h>
#include "hw/usb.h"
+#include "hw/usb/desc.h"
/* We redefine it to avoid version problems */
struct usb_ctrltransfer {
uint32_t product_id;
};
+enum USBHostDeviceOptions {
+ USB_HOST_OPT_PIPELINE,
+};
+
typedef struct USBHostDevice {
USBDevice dev;
int fd;
int descr_len;
int closing;
uint32_t iso_urb_count;
+ uint32_t options;
Notifier exit;
+ QEMUBH *bh;
struct endp_data ep_in[USB_MAX_ENDPOINTS];
struct endp_data ep_out[USB_MAX_ENDPOINTS];
int addr;
char port[MAX_PORTLEN];
struct USBAutoFilter match;
+ int32_t bootindex;
int seen, errcount;
QTAILQ_ENTRY(USBHostDevice) next;
static void usb_host_auto_check(void *unused);
static int usb_host_read_file(char *line, size_t line_size,
const char *device_file, const char *device_name);
-static int usb_linux_update_endp_table(USBHostDevice *s);
+static void usb_linux_update_endp_table(USBHostDevice *s);
static int usb_host_usbfs_type(USBHostDevice *s, USBPacket *p)
{
static void clear_iso_started(USBHostDevice *s, int pid, int ep)
{
- trace_usb_host_ep_stop_iso(s->bus_num, s->addr, ep);
+ trace_usb_host_iso_stop(s->bus_num, s->addr, ep);
get_endp(s, pid, ep)->iso_started = 0;
}
{
struct endp_data *e = get_endp(s, pid, ep);
- trace_usb_host_ep_start_iso(s->bus_num, s->addr, ep);
+ trace_usb_host_iso_start(s->bus_num, s->addr, ep);
if (!e->iso_started) {
e->iso_started = 1;
e->inflight = 0;
if (r < 0) {
if (errno == EAGAIN) {
if (urbs > 2) {
- fprintf(stderr, "husb: %d iso urbs finished at once\n", urbs);
+ /* indicates possible latency issues */
+ trace_usb_host_iso_many_urbs(s->bus_num, s->addr, urbs);
}
return;
}
urbs++;
inflight = change_iso_inflight(s, pid, ep, -1);
if (inflight == 0 && is_iso_started(s, pid, ep)) {
- fprintf(stderr, "husb: out of buffers for iso stream\n");
+ /* can be latency issues, or simply end of stream */
+ trace_usb_host_iso_out_of_bufs(s->bus_num, s->addr, ep);
}
continue;
}
if (p) {
switch (aurb->urb.status) {
case 0:
- p->result += aurb->urb.actual_length;
+ p->actual_length += aurb->urb.actual_length;
+ if (!aurb->more) {
+ /* Clear previous ASYNC status */
+ p->status = USB_RET_SUCCESS;
+ }
break;
case -EPIPE:
set_halt(s, p->pid, p->ep->nr);
- p->result = USB_RET_STALL;
+ p->status = USB_RET_STALL;
break;
case -EOVERFLOW:
- p->result = USB_RET_BABBLE;
+ p->status = USB_RET_BABBLE;
break;
default:
- p->result = USB_RET_IOERROR;
+ p->status = USB_RET_IOERROR;
break;
}
if (aurb->urb.type == USBDEVFS_URB_TYPE_CONTROL) {
- trace_usb_host_req_complete(s->bus_num, s->addr, p->result);
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, aurb->urb.actual_length);
usb_generic_async_ctrl_complete(&s->dev, p);
} else if (!aurb->more) {
- trace_usb_host_req_complete(s->bus_num, s->addr, p->result);
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, aurb->urb.actual_length);
usb_packet_complete(&s->dev, p);
}
}
USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
AsyncURB *aurb;
+ trace_usb_host_req_canceled(s->bus_num, s->addr, p);
+
QLIST_FOREACH(aurb, &s->aurbs, next) {
if (p != aurb->packet) {
continue;
}
- DPRINTF("husb: async cancel: packet %p, aurb %p\n", p, aurb);
+ trace_usb_host_urb_canceled(s->bus_num, s->addr, aurb);
/* Mark it as dead (see async_complete above) */
aurb->packet = NULL;
clear_iso_started(s, pid, ep);
}
-static int urb_status_to_usb_ret(int status)
+static void urb_status_to_usb_ret(int status, USBPacket *p)
{
switch (status) {
case -EPIPE:
- return USB_RET_STALL;
+ p->status = USB_RET_STALL;
+ break;
case -EOVERFLOW:
- return USB_RET_BABBLE;
+ p->status = USB_RET_BABBLE;
+ break;
default:
- return USB_RET_IOERROR;
+ p->status = USB_RET_IOERROR;
}
}
-static int usb_host_handle_iso_data(USBHostDevice *s, USBPacket *p, int in)
+static void usb_host_handle_iso_data(USBHostDevice *s, USBPacket *p, int in)
{
AsyncURB *aurb;
- int i, j, ret, max_packet_size, offset, len = 0;
+ int i, j, max_packet_size, offset, len;
uint8_t *buf;
max_packet_size = p->ep->max_packet_size;
- if (max_packet_size == 0)
- return USB_RET_NAK;
+ if (max_packet_size == 0) {
+ p->status = USB_RET_NAK;
+ return;
+ }
aurb = get_iso_urb(s, p->pid, p->ep->nr);
if (!aurb) {
if (in) {
/* Check urb status */
if (aurb[i].urb.status) {
- len = urb_status_to_usb_ret(aurb[i].urb.status);
+ urb_status_to_usb_ret(aurb[i].urb.status, p);
/* Move to the next urb */
aurb[i].iso_frame_idx = ISO_FRAME_DESC_PER_URB - 1;
/* Check frame status */
} else if (aurb[i].urb.iso_frame_desc[j].status) {
- len = urb_status_to_usb_ret(
- aurb[i].urb.iso_frame_desc[j].status);
+ urb_status_to_usb_ret(aurb[i].urb.iso_frame_desc[j].status, p);
/* Check the frame fits */
} else if (aurb[i].urb.iso_frame_desc[j].actual_length
> p->iov.size) {
printf("husb: received iso data is larger then packet\n");
- len = USB_RET_BABBLE;
+ p->status = USB_RET_BABBLE;
/* All good copy data over */
} else {
len = aurb[i].urb.iso_frame_desc[j].actual_length;
/* Check the frame fits */
if (len > max_packet_size) {
printf("husb: send iso data is larger then max packet size\n");
- return USB_RET_NAK;
+ p->status = USB_RET_NAK;
+ return;
}
/* All good copy data over */
/* (Re)-submit all fully consumed / filled urbs */
for (i = 0; i < s->iso_urb_count; i++) {
if (aurb[i].iso_frame_idx == ISO_FRAME_DESC_PER_URB) {
- ret = ioctl(s->fd, USBDEVFS_SUBMITURB, &aurb[i]);
- if (ret < 0) {
+ if (ioctl(s->fd, USBDEVFS_SUBMITURB, &aurb[i]) < 0) {
perror("USBDEVFS_SUBMITURB");
- if (!in || len == 0) {
+ if (!in || p->status == USB_RET_SUCCESS) {
switch(errno) {
case ETIMEDOUT:
- len = USB_RET_NAK;
+ p->status = USB_RET_NAK;
break;
case EPIPE:
default:
- len = USB_RET_STALL;
+ p->status = USB_RET_STALL;
}
}
break;
}
}
}
-
- return len;
}
-static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
+static void usb_host_handle_data(USBDevice *dev, USBPacket *p)
{
USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
struct usbdevfs_urb *urb;
uint8_t *pbuf;
uint8_t ep;
- trace_usb_host_req_data(s->bus_num, s->addr,
+ trace_usb_host_req_data(s->bus_num, s->addr, p,
p->pid == USB_TOKEN_IN,
p->ep->nr, p->iov.size);
if (!is_valid(s, p->pid, p->ep->nr)) {
- trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK);
- return USB_RET_NAK;
+ p->status = USB_RET_NAK;
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, p->actual_length);
+ return;
}
if (p->pid == USB_TOKEN_IN) {
ret = ioctl(s->fd, USBDEVFS_CLEAR_HALT, &arg);
if (ret < 0) {
perror("USBDEVFS_CLEAR_HALT");
- trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK);
- return USB_RET_NAK;
+ p->status = USB_RET_NAK;
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, p->actual_length);
+ return;
}
clear_halt(s, p->pid, p->ep->nr);
}
if (is_isoc(s, p->pid, p->ep->nr)) {
- return usb_host_handle_iso_data(s, p, p->pid == USB_TOKEN_IN);
+ usb_host_handle_iso_data(s, p, p->pid == USB_TOKEN_IN);
+ return;
}
v = 0;
- prem = p->iov.iov[v].iov_len;
- pbuf = p->iov.iov[v].iov_base;
+ prem = 0;
+ pbuf = NULL;
rem = p->iov.size;
- while (rem) {
- if (prem == 0) {
- v++;
+ do {
+ if (prem == 0 && rem > 0) {
assert(v < p->iov.niov);
prem = p->iov.iov[v].iov_len;
pbuf = p->iov.iov[v].iov_base;
assert(prem <= rem);
+ v++;
}
aurb = async_alloc(s);
aurb->packet = p;
switch(errno) {
case ETIMEDOUT:
- trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK);
- return USB_RET_NAK;
+ p->status = USB_RET_NAK;
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, p->actual_length);
+ break;
case EPIPE:
default:
- trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_STALL);
- return USB_RET_STALL;
+ p->status = USB_RET_STALL;
+ trace_usb_host_req_complete(s->bus_num, s->addr, p,
+ p->status, p->actual_length);
}
+ return;
}
- }
+ } while (rem > 0);
- return USB_RET_ASYNC;
+ p->status = USB_RET_ASYNC;
}
static int ctrl_error(void)
}
}
-static int usb_host_set_address(USBHostDevice *s, int addr)
+static void usb_host_set_address(USBHostDevice *s, int addr)
{
trace_usb_host_set_address(s->bus_num, s->addr, addr);
s->dev.addr = addr;
- return 0;
}
-static int usb_host_set_config(USBHostDevice *s, int config)
+static void usb_host_set_config(USBHostDevice *s, int config, USBPacket *p)
{
int ret, first = 1;
}
if (ret < 0) {
- return ctrl_error();
+ p->status = ctrl_error();
+ return;
}
usb_host_claim_interfaces(s, config);
usb_linux_update_endp_table(s);
- return 0;
}
-static int usb_host_set_interface(USBHostDevice *s, int iface, int alt)
+static void usb_host_set_interface(USBHostDevice *s, int iface, int alt,
+ USBPacket *p)
{
struct usbdevfs_setinterface si;
int i, ret;
}
if (iface >= USB_MAX_INTERFACES) {
- return USB_RET_STALL;
+ p->status = USB_RET_STALL;
+ return;
}
si.interface = iface;
iface, alt, ret, errno);
if (ret < 0) {
- return ctrl_error();
+ p->status = ctrl_error();
+ return;
}
s->dev.altsetting[iface] = alt;
usb_linux_update_endp_table(s);
- return 0;
}
-static int usb_host_handle_control(USBDevice *dev, USBPacket *p,
+static void usb_host_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
*/
/* Note request is (bRequestType << 8) | bRequest */
- trace_usb_host_req_control(s->bus_num, s->addr, request, value, index);
+ trace_usb_host_req_control(s->bus_num, s->addr, p, request, value, index);
switch (request) {
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
- return usb_host_set_address(s, value);
+ usb_host_set_address(s, value);
+ trace_usb_host_req_emulated(s->bus_num, s->addr, p, p->status);
+ return;
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
- return usb_host_set_config(s, value & 0xff);
+ usb_host_set_config(s, value & 0xff, p);
+ trace_usb_host_req_emulated(s->bus_num, s->addr, p, p->status);
+ return;
case InterfaceOutRequest | USB_REQ_SET_INTERFACE:
- return usb_host_set_interface(s, index, value);
+ usb_host_set_interface(s, index, value, p);
+ trace_usb_host_req_emulated(s->bus_num, s->addr, p, p->status);
+ return;
+
+ case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
+ if (value == 0) { /* clear halt */
+ int pid = (index & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT;
+ ioctl(s->fd, USBDEVFS_CLEAR_HALT, &index);
+ clear_halt(s, pid, index & 0x0f);
+ trace_usb_host_req_emulated(s->bus_num, s->addr, p, 0);
+ return;
+ }
}
/* The rest are asynchronous */
-
if (length > sizeof(dev->data_buf)) {
fprintf(stderr, "husb: ctrl buffer too small (%d > %zu)\n",
length, sizeof(dev->data_buf));
- return USB_RET_STALL;
+ p->status = USB_RET_STALL;
+ return;
}
aurb = async_alloc(s);
switch(errno) {
case ETIMEDOUT:
- return USB_RET_NAK;
+ p->status = USB_RET_NAK;
+ break;
case EPIPE:
default:
- return USB_RET_STALL;
+ p->status = USB_RET_STALL;
+ break;
}
+ return;
}
- return USB_RET_ASYNC;
-}
-
-static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
- uint8_t configuration, uint8_t interface)
-{
- char device_name[64], line[1024];
- int alt_setting;
-
- sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port,
- (int)configuration, (int)interface);
-
- if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting",
- device_name)) {
- /* Assume alt 0 on error */
- return 0;
- }
- if (sscanf(line, "%d", &alt_setting) != 1) {
- /* Assume alt 0 on error */
- return 0;
- }
- return alt_setting;
+ p->status = USB_RET_ASYNC;
}
-/* returns 1 on problem encountered or 0 for success */
-static int usb_linux_update_endp_table(USBHostDevice *s)
+static void usb_linux_update_endp_table(USBHostDevice *s)
{
- uint8_t *descriptors;
- uint8_t devep, type, alt_interface;
- uint16_t raw;
- int interface, length, i, ep, pid;
+ static const char *tname[] = {
+ [USB_ENDPOINT_XFER_CONTROL] = "control",
+ [USB_ENDPOINT_XFER_ISOC] = "isoc",
+ [USB_ENDPOINT_XFER_BULK] = "bulk",
+ [USB_ENDPOINT_XFER_INT] = "int",
+ };
+ uint8_t devep, type;
+ uint16_t mps, v, p;
+ int ep, pid;
+ unsigned int i, configuration = -1, interface = -1, altsetting = -1;
struct endp_data *epd;
+ USBDescriptor *d;
+ bool active = false;
- usb_ep_init(&s->dev);
-
- if (s->dev.configuration == 0) {
- /* not configured yet -- leave all endpoints disabled */
- return 0;
- }
-
- /* get the desired configuration, interface, and endpoint descriptors
- * from device description */
- descriptors = &s->descr[18];
- length = s->descr_len - 18;
- i = 0;
-
- while (i < length) {
- if (descriptors[i + 1] != USB_DT_CONFIG) {
- fprintf(stderr, "invalid descriptor data\n");
- return 1;
- } else if (descriptors[i + 5] != s->dev.configuration) {
- DPRINTF("not requested configuration %d\n", s->dev.configuration);
- i += (descriptors[i + 3] << 8) + descriptors[i + 2];
- continue;
- }
- i += descriptors[i];
+ usb_ep_reset(&s->dev);
- if (descriptors[i + 1] != USB_DT_INTERFACE ||
- (descriptors[i + 1] == USB_DT_INTERFACE &&
- descriptors[i + 4] == 0)) {
- i += descriptors[i];
- continue;
+ for (i = 0;; i += d->bLength) {
+ if (i+2 >= s->descr_len) {
+ break;
}
-
- interface = descriptors[i + 2];
- alt_interface = usb_linux_get_alt_setting(s, s->dev.configuration,
- interface);
-
- /* the current interface descriptor is the active interface
- * and has endpoints */
- if (descriptors[i + 3] != alt_interface) {
- i += descriptors[i];
- continue;
+ d = (void *)(s->descr + i);
+ if (d->bLength < 2) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "descriptor too short");
+ return;
}
-
- /* advance to the endpoints */
- while (i < length && descriptors[i +1] != USB_DT_ENDPOINT) {
- i += descriptors[i];
+ if (i + d->bLength > s->descr_len) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "descriptor too long");
+ return;
}
-
- if (i >= length)
+ switch (d->bDescriptorType) {
+ case 0:
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "invalid descriptor type");
+ return;
+ case USB_DT_DEVICE:
+ if (d->bLength < 0x12) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "device descriptor too short");
+ return;
+ }
+ v = (d->u.device.idVendor_hi << 8) | d->u.device.idVendor_lo;
+ p = (d->u.device.idProduct_hi << 8) | d->u.device.idProduct_lo;
+ trace_usb_host_parse_device(s->bus_num, s->addr, v, p);
break;
-
- while (i < length) {
- if (descriptors[i + 1] != USB_DT_ENDPOINT) {
- break;
+ case USB_DT_CONFIG:
+ if (d->bLength < 0x09) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "config descriptor too short");
+ return;
}
-
- devep = descriptors[i + 2];
+ configuration = d->u.config.bConfigurationValue;
+ active = (configuration == s->dev.configuration);
+ trace_usb_host_parse_config(s->bus_num, s->addr,
+ configuration, active);
+ break;
+ case USB_DT_INTERFACE:
+ if (d->bLength < 0x09) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "interface descriptor too short");
+ return;
+ }
+ interface = d->u.interface.bInterfaceNumber;
+ altsetting = d->u.interface.bAlternateSetting;
+ active = (configuration == s->dev.configuration) &&
+ (altsetting == s->dev.altsetting[interface]);
+ trace_usb_host_parse_interface(s->bus_num, s->addr,
+ interface, altsetting, active);
+ break;
+ case USB_DT_ENDPOINT:
+ if (d->bLength < 0x07) {
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "endpoint descriptor too short");
+ return;
+ }
+ devep = d->u.endpoint.bEndpointAddress;
pid = (devep & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT;
ep = devep & 0xf;
if (ep == 0) {
- fprintf(stderr, "usb-linux: invalid ep descriptor, ep == 0\n");
- return 1;
+ trace_usb_host_parse_error(s->bus_num, s->addr,
+ "invalid endpoint address");
+ return;
}
- type = descriptors[i + 3] & 0x3;
- raw = descriptors[i + 4] + (descriptors[i + 5] << 8);
- usb_ep_set_max_packet_size(&s->dev, pid, ep, raw);
- assert(usb_ep_get_type(&s->dev, pid, ep) ==
- USB_ENDPOINT_XFER_INVALID);
- usb_ep_set_type(&s->dev, pid, ep, type);
- usb_ep_set_ifnum(&s->dev, pid, ep, interface);
- if (type == USB_ENDPOINT_XFER_BULK) {
- usb_ep_set_pipeline(&s->dev, pid, ep, true);
- }
+ type = d->u.endpoint.bmAttributes & 0x3;
+ mps = d->u.endpoint.wMaxPacketSize_lo |
+ (d->u.endpoint.wMaxPacketSize_hi << 8);
+ trace_usb_host_parse_endpoint(s->bus_num, s->addr, ep,
+ (devep & USB_DIR_IN) ? "in" : "out",
+ tname[type], active);
+
+ if (active) {
+ usb_ep_set_max_packet_size(&s->dev, pid, ep, mps);
+ assert(usb_ep_get_type(&s->dev, pid, ep) ==
+ USB_ENDPOINT_XFER_INVALID);
+ usb_ep_set_type(&s->dev, pid, ep, type);
+ usb_ep_set_ifnum(&s->dev, pid, ep, interface);
+ if ((s->options & (1 << USB_HOST_OPT_PIPELINE)) &&
+ (type == USB_ENDPOINT_XFER_BULK) &&
+ (pid == USB_TOKEN_OUT)) {
+ usb_ep_set_pipeline(&s->dev, pid, ep, true);
+ }
- epd = get_endp(s, pid, ep);
- epd->halted = 0;
+ epd = get_endp(s, pid, ep);
+ epd->halted = 0;
+ }
- i += descriptors[i];
+ break;
+ default:
+ trace_usb_host_parse_unknown(s->bus_num, s->addr,
+ d->bLength, d->bDescriptorType);
+ break;
}
}
-#ifdef DEBUG
- usb_ep_dump(&s->dev);
-#endif
- return 0;
}
/*
goto fail;
}
- ret = usb_linux_update_endp_table(dev);
- if (ret) {
- goto fail;
- }
+ usb_ep_init(&dev->dev);
+ usb_linux_update_endp_table(dev);
if (speed == -1) {
struct usbdevfs_connectinfo ci;
}
}
+/*
+ * This is *NOT* about restoring state. We have absolutely no idea
+ * what state the host device is in at the moment and whenever it is
+ * still present in the first place. Attemping to contine where we
+ * left off is impossible.
+ *
+ * What we are going to to to here is emulate a surprise removal of
+ * the usb device passed through, then kick host scan so the device
+ * will get re-attached (and re-initialized by the guest) in case it
+ * is still present.
+ *
+ * As the device removal will change the state of other devices (usb
+ * host controller, most likely interrupt controller too) we have to
+ * wait with it until *all* vmstate is loaded. Thus post_load just
+ * kicks a bottom half which then does the actual work.
+ */
+static void usb_host_post_load_bh(void *opaque)
+{
+ USBHostDevice *dev = opaque;
+
+ if (dev->fd != -1) {
+ usb_host_close(dev);
+ }
+ if (dev->dev.attached) {
+ usb_device_detach(&dev->dev);
+ }
+ usb_host_auto_check(NULL);
+}
+
+static int usb_host_post_load(void *opaque, int version_id)
+{
+ USBHostDevice *dev = opaque;
+
+ qemu_bh_schedule(dev->bh);
+ return 0;
+}
+
static int usb_host_initfn(USBDevice *dev)
{
USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev);
+ dev->flags |= (1 << USB_DEV_FLAG_IS_HOST);
dev->auto_attach = 0;
s->fd = -1;
s->hub_fd = -1;
QTAILQ_INSERT_TAIL(&hostdevs, s, next);
s->exit.notify = usb_host_exit_notifier;
qemu_add_exit_notifier(&s->exit);
+ s->bh = qemu_bh_new(usb_host_post_load_bh, s);
usb_host_auto_check(NULL);
if (s->match.bus_num != 0 && s->match.port != NULL) {
usb_host_claim_port(s);
}
+ add_boot_device_path(s->bootindex, &dev->qdev, NULL);
return 0;
}
static const VMStateDescription vmstate_usb_host = {
.name = "usb-host",
- .unmigratable = 1,
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .post_load = usb_host_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_USB_DEVICE(dev, USBHostDevice),
+ VMSTATE_END_OF_LIST()
+ }
};
static Property usb_host_dev_properties[] = {
DEFINE_PROP_HEX32("vendorid", USBHostDevice, match.vendor_id, 0),
DEFINE_PROP_HEX32("productid", USBHostDevice, match.product_id, 0),
DEFINE_PROP_UINT32("isobufs", USBHostDevice, iso_urb_count, 4),
+ DEFINE_PROP_INT32("bootindex", USBHostDevice, bootindex, -1),
+ DEFINE_PROP_BIT("pipeline", USBHostDevice, options,
+ USB_HOST_OPT_PIPELINE, true),
DEFINE_PROP_END_OF_LIST(),
};
}
static QEMUTimer *usb_auto_timer;
+static VMChangeStateEntry *usb_vmstate;
static int usb_host_auto_scan(void *opaque, int bus_num,
int addr, const char *port,
return 0;
}
+static void usb_host_vm_state(void *unused, int running, RunState state)
+{
+ if (running) {
+ usb_host_auto_check(unused);
+ }
+}
+
static void usb_host_auto_check(void *unused)
{
struct USBHostDevice *s;
int unconnected = 0;
- usb_host_scan(NULL, usb_host_auto_scan);
+ if (runstate_is_running()) {
+ usb_host_scan(NULL, usb_host_auto_scan);
- QTAILQ_FOREACH(s, &hostdevs, next) {
- if (s->fd == -1) {
- unconnected++;
- }
- if (s->seen == 0) {
- s->errcount = 0;
+ QTAILQ_FOREACH(s, &hostdevs, next) {
+ if (s->fd == -1) {
+ unconnected++;
+ }
+ if (s->seen == 0) {
+ s->errcount = 0;
+ }
+ s->seen = 0;
}
- s->seen = 0;
- }
- if (unconnected == 0) {
- /* nothing to watch */
- if (usb_auto_timer) {
- qemu_del_timer(usb_auto_timer);
- trace_usb_host_auto_scan_disabled();
+ if (unconnected == 0) {
+ /* nothing to watch */
+ if (usb_auto_timer) {
+ qemu_del_timer(usb_auto_timer);
+ trace_usb_host_auto_scan_disabled();
+ }
+ return;
}
- return;
}
+ if (!usb_vmstate) {
+ usb_vmstate = qemu_add_vm_change_state_handler(usb_host_vm_state, NULL);
+ }
if (!usb_auto_timer) {
usb_auto_timer = qemu_new_timer_ms(rt_clock, usb_host_auto_check, NULL);
if (!usb_auto_timer) {