Lines Matching +full:usb +full:- +full:port +full:- +full:id

2 #include "hw/qdev-properties.h"
3 #include "hw/usb.h"
5 #include "qapi/qapi-commands-machine.h"
6 #include "qapi/type-helpers.h"
7 #include "qemu/error-report.h"
22 DEFINE_PROP_STRING("port", USBDevice, port_path),
24 DEFINE_PROP_BIT("msos-desc", USBDevice, flags,
34 k->print_dev = usb_bus_dev_print; in usb_bus_class_init()
35 k->get_dev_path = usb_get_dev_path; in usb_bus_class_init()
36 k->get_fw_dev_path = usb_get_fw_dev_path; in usb_bus_class_init()
37 hc->unplug = qdev_simple_device_unplug_cb; in usb_bus_class_init()
58 if (dev->state == USB_STATE_NOTATTACHED) { in usb_device_post_load()
59 dev->attached = false; in usb_device_post_load()
61 dev->attached = true; in usb_device_post_load()
88 bus->ops = ops; in usb_bus_new()
89 bus->busnr = next_usb_bus++; in usb_bus_new()
90 QTAILQ_INIT(&bus->free); in usb_bus_new()
91 QTAILQ_INIT(&bus->used); in usb_bus_new()
106 if (klass->realize) { in usb_device_realize()
107 klass->realize(dev, errp); in usb_device_realize()
114 if (klass->find_device) { in usb_device_find_device()
115 return klass->find_device(dev, addr); in usb_device_find_device()
124 if (klass->unrealize) { in usb_device_unrealize()
125 klass->unrealize(dev); in usb_device_unrealize()
132 if (klass->cancel_packet) { in usb_device_cancel_packet()
133 klass->cancel_packet(dev, p); in usb_device_cancel_packet()
140 if (klass->handle_attach) { in usb_device_handle_attach()
141 klass->handle_attach(dev); in usb_device_handle_attach()
148 if (klass->handle_reset) { in usb_device_handle_reset()
149 klass->handle_reset(dev); in usb_device_handle_reset()
157 if (klass->handle_control) { in usb_device_handle_control()
158 klass->handle_control(dev, p, request, value, index, length, data); in usb_device_handle_control()
165 if (klass->handle_data) { in usb_device_handle_data()
166 klass->handle_data(dev, p); in usb_device_handle_data()
173 return klass->product_desc; in usb_device_get_product_desc()
179 if (dev->usb_desc) { in usb_device_get_usb_desc()
180 return dev->usb_desc; in usb_device_get_usb_desc()
182 return klass->usb_desc; in usb_device_get_usb_desc()
189 if (klass->set_interface) { in usb_device_set_interface()
190 klass->set_interface(dev, interface, alt_old, alt_new); in usb_device_set_interface()
197 if (klass->flush_ep_queue) { in usb_device_flush_ep_queue()
198 klass->flush_ep_queue(dev, ep); in usb_device_flush_ep_queue()
205 if (klass->ep_stopped) { in usb_device_ep_stopped()
206 klass->ep_stopped(dev, ep); in usb_device_ep_stopped()
214 if (klass->alloc_streams) { in usb_device_alloc_streams()
215 return klass->alloc_streams(dev, eps, nr_eps, streams); in usb_device_alloc_streams()
223 if (klass->free_streams) { in usb_device_free_streams()
224 klass->free_streams(dev, eps, nr_eps); in usb_device_free_streams()
233 pstrcpy(dev->product_desc, sizeof(dev->product_desc), in usb_qdev_realize()
235 dev->auto_attach = 1; in usb_qdev_realize()
236 QLIST_INIT(&dev->strings); in usb_qdev_realize()
252 if (dev->auto_attach) { in usb_qdev_realize()
261 if (dev->pcap_filename) { in usb_qdev_realize()
262 int fd = qemu_open_old(dev->pcap_filename, in usb_qdev_realize()
265 error_setg(errp, "open %s failed", dev->pcap_filename); in usb_qdev_realize()
269 dev->pcap = fdopen(fd, "wb"); in usb_qdev_realize()
270 usb_pcap_init(dev->pcap); in usb_qdev_realize()
279 QLIST_FOREACH_SAFE(s, &dev->strings, next, next) { in usb_qdev_unrealize()
281 g_free(s->str); in usb_qdev_unrealize()
285 if (dev->pcap) { in usb_qdev_unrealize()
286 fclose(dev->pcap); in usb_qdev_unrealize()
289 if (dev->attached) { in usb_qdev_unrealize()
293 if (dev->port) { in usb_qdev_unrealize()
312 f->name = typename; in usb_legacy_register()
313 f->usbdevice_name = usbdevice_name; in usb_legacy_register()
314 f->usbdevice_init = usbdevice_init; in usb_legacy_register()
319 static void usb_fill_port(USBPort *port, void *opaque, int index, in usb_fill_port() argument
322 port->opaque = opaque; in usb_fill_port()
323 port->index = index; in usb_fill_port()
324 port->ops = ops; in usb_fill_port()
325 port->speedmask = speedmask; in usb_fill_port()
326 usb_port_location(port, NULL, index + 1); in usb_fill_port()
329 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, in usb_register_port() argument
332 usb_fill_port(port, opaque, index, ops, speedmask); in usb_register_port()
333 QTAILQ_INSERT_TAIL(&bus->free, port, next); in usb_register_port()
334 bus->nfree++; in usb_register_port()
346 if (strcmp(bus->qbus.name, masterbus) == 0) { in usb_register_companion()
352 error_setg(errp, "USB bus '%s' not found", masterbus); in usb_register_companion()
355 if (!bus->ops->register_companion) { in usb_register_companion()
356 error_setg(errp, "Can't use USB bus '%s' as masterbus," in usb_register_companion()
366 bus->ops->register_companion(bus, ports, portcount, firstport, errp); in usb_register_companion()
372 int l = snprintf(downstream->path, sizeof(downstream->path), "%s.%d", in usb_port_location()
373 upstream->path, portnr); in usb_port_location()
375 assert(l < sizeof(downstream->path)); in usb_port_location()
376 downstream->hubcount = upstream->hubcount + 1; in usb_port_location()
378 snprintf(downstream->path, sizeof(downstream->path), "%d", portnr); in usb_port_location()
379 downstream->hubcount = 0; in usb_port_location()
383 void usb_unregister_port(USBBus *bus, USBPort *port) in usb_unregister_port() argument
385 if (port->dev) { in usb_unregister_port()
386 object_unparent(OBJECT(port->dev)); in usb_unregister_port()
388 QTAILQ_REMOVE(&bus->free, port, next); in usb_unregister_port()
389 bus->nfree--; in usb_unregister_port()
395 USBPort *port; in usb_claim_port() local
398 assert(dev->port == NULL); in usb_claim_port()
400 if (dev->port_path) { in usb_claim_port()
401 QTAILQ_FOREACH(port, &bus->free, next) { in usb_claim_port()
402 if (strcmp(port->path, dev->port_path) == 0) { in usb_claim_port()
406 if (port == NULL) { in usb_claim_port()
407 error_setg(errp, "usb port %s (bus %s) not found (in use?)", in usb_claim_port()
408 dev->port_path, bus->qbus.name); in usb_claim_port()
412 if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) { in usb_claim_port()
414 hub = USB_DEVICE(qdev_try_new("usb-hub")); in usb_claim_port()
419 if (bus->nfree == 0) { in usb_claim_port()
420 error_setg(errp, "tried to attach usb device %s to a bus " in usb_claim_port()
421 "with no free ports", dev->product_desc); in usb_claim_port()
424 port = QTAILQ_FIRST(&bus->free); in usb_claim_port()
426 trace_usb_port_claim(bus->busnr, port->path); in usb_claim_port()
428 QTAILQ_REMOVE(&bus->free, port, next); in usb_claim_port()
429 bus->nfree--; in usb_claim_port()
431 dev->port = port; in usb_claim_port()
432 port->dev = dev; in usb_claim_port()
434 QTAILQ_INSERT_TAIL(&bus->used, port, next); in usb_claim_port()
435 bus->nused++; in usb_claim_port()
441 USBPort *port = dev->port; in usb_release_port() local
443 assert(port != NULL); in usb_release_port()
444 trace_usb_port_release(bus->busnr, port->path); in usb_release_port()
446 QTAILQ_REMOVE(&bus->used, port, next); in usb_release_port()
447 bus->nused--; in usb_release_port()
449 dev->port = NULL; in usb_release_port()
450 port->dev = NULL; in usb_release_port()
452 QTAILQ_INSERT_TAIL(&bus->free, port, next); in usb_release_port()
453 bus->nfree++; in usb_release_port()
471 pos += snprintf(dest + pos, size - pos, "%s%s", in usb_mask_to_str()
485 USBPort *port = dev->port; in usb_check_attach() local
488 assert(port != NULL); in usb_check_attach()
489 assert(!dev->attached); in usb_check_attach()
490 usb_mask_to_str(devspeed, sizeof(devspeed), dev->speedmask); in usb_check_attach()
491 usb_mask_to_str(portspeed, sizeof(portspeed), port->speedmask); in usb_check_attach()
492 trace_usb_port_attach(bus->busnr, port->path, in usb_check_attach()
495 if (!(port->speedmask & dev->speedmask)) { in usb_check_attach()
497 " usb device \"%s\" (%s speed)" in usb_check_attach()
498 " to bus \"%s\", port \"%s\" (%s speed)", in usb_check_attach()
499 dev->product_desc, devspeed, in usb_check_attach()
500 bus->qbus.name, port->path, portspeed); in usb_check_attach()
507 USBPort *port = dev->port; in usb_device_attach() local
516 dev->attached = true; in usb_device_attach()
517 usb_attach(port); in usb_device_attach()
523 USBPort *port = dev->port; in usb_device_detach() local
525 assert(port != NULL); in usb_device_detach()
526 assert(dev->attached); in usb_device_detach()
527 trace_usb_port_detach(bus->busnr, port->path); in usb_device_detach()
529 usb_detach(port); in usb_device_detach()
530 dev->attached = false; in usb_device_detach()
552 monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n", in usb_bus_dev_print()
553 indent, "", bus->busnr, dev->addr, in usb_bus_dev_print()
554 dev->port ? dev->port->path : "-", in usb_bus_dev_print()
555 usb_speed(dev->speed), dev->product_desc, in usb_bus_dev_print()
556 dev->attached ? ", attached" : ""); in usb_bus_dev_print()
562 DeviceState *hcd = qdev->parent_bus->parent; in usb_get_dev_path()
563 char *id = qdev_get_dev_path(hcd); in usb_get_dev_path() local
565 if (id) { in usb_get_dev_path()
566 char *ret = g_strdup_printf("%s/%s", id, dev->port->path); in usb_get_dev_path()
567 g_free(id); in usb_get_dev_path()
570 return g_strdup(dev->port->path); in usb_get_dev_path()
581 fw_len = 32 + strlen(dev->port->path) * 6; in usb_get_fw_dev_path()
583 in = dev->port->path; in usb_get_fw_dev_path()
584 while (fw_len - pos > 0) { in usb_get_fw_dev_path()
587 /* some hub between root port and device */ in usb_get_fw_dev_path()
588 pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/", nr); in usb_get_fw_dev_path()
592 snprintf(fw_path + pos, fw_len - pos, "%s@%lx", in usb_get_fw_dev_path()
605 USBPort *port; in qmp_x_query_usb() local
608 error_setg(errp, "USB support not enabled"); in qmp_x_query_usb()
613 QTAILQ_FOREACH(port, &bus->used, next) { in qmp_x_query_usb()
614 dev = port->dev; in qmp_x_query_usb()
618 " Device %d.%d, Port %s, Speed %s Mb/s, " in qmp_x_query_usb()
620 bus->busnr, dev->addr, port->path, in qmp_x_query_usb()
621 usb_speed(dev->speed), dev->product_desc, in qmp_x_query_usb()
622 dev->qdev.id ? ", ID: " : "", in qmp_x_query_usb()
623 dev->qdev.id ?: ""); in qmp_x_query_usb()
630 /* handle legacy -usbdevice cmd line option */
644 for (i = legacy_usb_factory; i; i = i->next) { in usbdevice_create()
645 f = i->data; in usbdevice_create()
646 if (strcmp(f->usbdevice_name, driver) == 0) { in usbdevice_create()
659 error_report("Error: no usb bus to attach usbdevice %s, " in usbdevice_create()
660 "please try -machine usb=on and check that " in usbdevice_create()
661 "the machine model supports USB", driver); in usbdevice_create()
665 dev = f->usbdevice_init ? f->usbdevice_init() in usbdevice_create()
666 : USB_DEVICE(qdev_new(f->name)); in usbdevice_create()
668 error_report("Failed to create USB device '%s'", f->name); in usbdevice_create()
672 error_reportf_err(err, "Failed to initialize USB device '%s': ", in usbdevice_create()
673 f->name); in usbdevice_create()
684 return dev->attached; in usb_get_attached()
691 if (dev->attached == value) { in usb_set_attached()
707 if (klass->attached_settable) { in usb_device_instance_init()
719 k->bus_type = TYPE_USB_BUS; in usb_device_class_init()
720 k->realize = usb_qdev_realize; in usb_device_class_init()
721 k->unrealize = usb_qdev_unrealize; in usb_device_class_init()