Date: Thu, 15 Aug 2013 04:30:04 GMT From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255958 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb: . gpl include/hw Message-ID: <201308150430.r7F4U4OD058472@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: syuu Date: Thu Aug 15 04:30:03 2013 New Revision: 255958 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255958 Log: trying to enable device registration Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Aug 15 04:30:03 2013 (r255958) @@ -28,8 +28,6 @@ //#include "qemu/error-report.h" #include <string.h> -#define NUM_PORTS 8 - #define trace_usb_hub_attach(a,b) #define trace_usb_hub_detach(a,b) #define trace_usb_hub_reset(a) @@ -38,6 +36,8 @@ #define trace_usb_hub_set_port_feature(a,b,c) #define trace_usb_hub_clear_port_feature(a,b,c) +#if 0 +#define NUM_PORTS 8 typedef struct USBHubPort { USBPort port; @@ -51,6 +51,7 @@ USBEndpoint *intr; USBHubPort ports[NUM_PORTS]; } USBHubState; +#endif #define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE) #define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE) @@ -515,7 +516,6 @@ } } -/* static USBPortOps usb_hub_port_ops = { .attach = usb_hub_attach, .detach = usb_hub_detach, @@ -523,7 +523,6 @@ .wakeup = usb_hub_wakeup, .complete = usb_hub_complete, }; -*/ static int usb_hub_initfn(USBDevice *dev) { @@ -532,7 +531,7 @@ int i; if (dev->port->hubcount == 5) { -// error_report("usb hub chain too deep"); + error_report("usb hub chain too deep"); return -1; } @@ -541,11 +540,9 @@ s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); for (i = 0; i < NUM_PORTS; i++) { port = &s->ports[i]; - /* usb_register_port(usb_bus_from_device(dev), &port->port, s, i, &usb_hub_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); - */ usb_port_location(&port->port, dev->port, i+1); } usb_hub_handle_reset(dev); @@ -575,12 +572,12 @@ VMSTATE_END_OF_LIST() } }; +*/ -static void usb_hub_class_initfn(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - USBDeviceClass *uc = USB_DEVICE_CLASS(klass); +void usb_hub_class_initfn(USBDeviceClass *uc, void *data); +void usb_hub_class_initfn(USBDeviceClass *uc, void *data) +{ uc->init = usb_hub_initfn; uc->product_desc = "QEMU USB Hub"; uc->usb_desc = &desc_hub; @@ -589,10 +586,11 @@ uc->handle_control = usb_hub_handle_control; uc->handle_data = usb_hub_handle_data; uc->handle_destroy = usb_hub_handle_destroy; - dc->fw_name = "hub"; - dc->vmsd = &vmstate_usb_hub; +// dc->fw_name = "hub"; +// dc->vmsd = &vmstate_usb_hub; } +/* static const TypeInfo hub_info = { .name = "usb-hub", .parent = TYPE_USB_DEVICE, Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Aug 15 04:30:03 2013 (r255958) @@ -1,4 +1,6 @@ #include <string.h> +#include <stdlib.h> +#include <malloc_np.h> //#include "hw/hw.h" #include "hw/usb.h" //#include "hw/qdev.h" @@ -6,12 +8,34 @@ //#include "monitor/monitor.h" //#include "trace.h" +#define trace_usb_port_claim(a, b) +#define trace_usb_port_attach(a,b,c,d) + +void pstrcpy(char *buf, int buf_size, const char *str) +{ + int c; + char *q = buf; + + if (buf_size <= 0) + return; + + for(;;) { + c = *str++; + if (c == 0 || q >= buf + buf_size - 1) + break; + *q++ = c; + } + *q = '\0'; +} + #if 0 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); static char *usb_get_fw_dev_path(DeviceState *qdev); -static int usb_qdev_exit(DeviceState *qdev); +#endif +static int usb_qdev_exit(USBDevice *dev); +#if 0 static Property usb_props[] = { DEFINE_PROP_STRING("port", USBDevice, port_path), @@ -75,6 +99,7 @@ void usb_bus_new(USBBus *bus, USBBusOps *ops /*, DeviceState *host*/) { // qbus_create_inplace(&bus->qbus, TYPE_USB_BUS, host, NULL); + strncpy(bus->name, TYPE_USB_BUS, sizeof(bus->name)); bus->ops = ops; bus->busnr = next_usb_bus++; // bus->qbus.allow_hotplug = 1; /* Yes, we can */ @@ -96,6 +121,7 @@ } return NULL; } +#endif static int usb_device_init(USBDevice *dev) { @@ -106,6 +132,7 @@ return 0; } +#if 0 USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr) { USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); @@ -114,6 +141,7 @@ } return NULL; } +#endif static void usb_device_handle_destroy(USBDevice *dev) { @@ -123,6 +151,7 @@ } } +#if 0 void usb_device_cancel_packet(USBDevice *dev, USBPacket *p) { USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); @@ -205,10 +234,8 @@ } } -#if 0 -static int usb_qdev_init(DeviceState *qdev) +static int usb_qdev_init(USBDevice *dev) { - USBDevice *dev = USB_DEVICE(qdev); int rc; pstrcpy(dev->product_desc, sizeof(dev->product_desc), @@ -228,17 +255,15 @@ if (dev->auto_attach) { rc = usb_device_attach(dev); if (rc != 0) { - usb_qdev_exit(qdev); + usb_qdev_exit(dev); return rc; } } return 0; } -static int usb_qdev_exit(DeviceState *qdev) +static int usb_qdev_exit(USBDevice *dev) { - USBDevice *dev = USB_DEVICE(qdev); - if (dev->attached) { usb_device_detach(dev); } @@ -249,6 +274,7 @@ return 0; } +#if 0 typedef struct LegacyUSBFactory { const char *name; @@ -270,32 +296,27 @@ legacy_usb_factory = g_slist_append(legacy_usb_factory, f); } } +#endif -USBDevice *usb_create(USBBus *bus, const char *name) +USBDevice *usb_create(USBBus *bus, const char *name, size_t len) { - DeviceState *dev; + USBDevice *dev; - dev = qdev_create(&bus->qbus, name); - return USB_DEVICE(dev); + dev = (USBDevice *)calloc(1, len); + strncpy(dev->name, name, sizeof(dev->name)); + return dev; } -USBDevice *usb_create_simple(USBBus *bus, const char *name) +USBDevice *usb_create_simple(USBBus *bus, const char *name, size_t len) { - USBDevice *dev = usb_create(bus, name); - int rc; + USBDevice *dev = usb_create(bus, name, len); if (!dev) { error_report("Failed to create USB device '%s'", name); return NULL; } - rc = qdev_init(&dev->qdev); - if (rc < 0) { - error_report("Failed to initialize USB device '%s'", name); - return NULL; - } return dev; } -#endif static void usb_fill_port(USBPort *port, void *opaque, int index, USBPortOps *ops, int speedmask) @@ -322,13 +343,11 @@ USBBus *bus; int i; -#if 0 QTAILQ_FOREACH(bus, &busses, next) { - if (strcmp(bus->qbus.name, masterbus) == 0) { + if (strcmp(bus->name, masterbus) == 0) { break; } } -#endif if (!bus || !bus->ops->register_companion) { // qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus", @@ -360,11 +379,10 @@ } } -#if 0 void usb_unregister_port(USBBus *bus, USBPort *port) { - if (port->dev) - qdev_free(&port->dev->qdev); +// if (port->dev) +// qdev_free(&port->dev->qdev); QTAILQ_REMOVE(&bus->free, port, next); bus->nfree--; } @@ -384,13 +402,13 @@ } if (port == NULL) { error_report("Error: usb port %s (bus %s) not found (in use?)", - dev->port_path, bus->qbus.name); + dev->port_path, bus->name); return -1; } } else { - if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) { + if (bus->nfree == 1 && strcmp(dev->name, "usb-hub") != 0) { /* Create a new hub and chain it on */ - usb_create_simple(bus, "usb-hub"); + usb_create_simple(bus, "usb-hub", sizeof(struct USBHubState)); } if (bus->nfree == 0) { error_report("Error: tried to attach usb device %s to a bus " @@ -412,6 +430,7 @@ return 0; } +#if 0 void usb_release_port(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); @@ -429,6 +448,7 @@ QTAILQ_INSERT_TAIL(&bus->free, port, next); bus->nfree++; } +#endif static void usb_mask_to_str(char *dest, size_t size, unsigned int speedmask) @@ -470,7 +490,7 @@ " usb device \"%s\" (%s speed)" " to bus \"%s\", port \"%s\" (%s speed)", dev->product_desc, devspeed, - bus->qbus.name, port->path, portspeed); + bus->name, port->path, portspeed); return -1; } @@ -480,6 +500,7 @@ return 0; } +#if 0 int usb_device_detach(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Thu Aug 15 04:30:03 2013 (r255958) @@ -13,6 +13,7 @@ #include <string.h> #include <stdlib.h> #include <limits.h> +#include <stdio.h> //#include "qemu-common.h" //#include "qemu/error-report.h" @@ -124,6 +125,7 @@ uint8_t event_trigger; QEMUSerialSetParams params; int latency; /* ms */ + FILE *fp; // CharDriverState *cs; } USBSerialState; @@ -385,6 +387,7 @@ for (i = 0; i < p->iov.niov; i++) { iov = p->iov.iov + i; // qemu_chr_fe_write(s->cs, iov->iov_base, iov->iov_len); + fwrite(iov->iov_base, iov->iov_len, 1, s->fp); } p->actual_length = p->iov.size; break; @@ -495,8 +498,7 @@ } } -#if 0 -static int usb_serial_initfn(USBDevice *dev) +int usb_serial_initfn(USBDevice *dev) { USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); @@ -504,6 +506,7 @@ usb_desc_init(dev); dev->auto_attach = 0; +#if 0 if (!s->cs) { error_report("Property chardev is required"); return -1; @@ -511,59 +514,62 @@ qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read, usb_serial_event, s); +#endif + s->fp = fopen("/tmp/usbserial.out", "w"); usb_serial_handle_reset(dev); - if (s->cs->be_open && !dev->attached) { +// if (s->cs->be_open && !dev->attached) { usb_device_attach(dev); - } +// } return 0; } -#endif -static USBDevice *usb_serial_init(USBBus *bus, const char *filename) +USBDevice *usb_serial_init(USBBus *bus /*, const char *filename */) { USBDevice *dev; // CharDriverState *cdrv; - uint32_t vendorid = 0, productid = 0; +// uint32_t vendorid = 0, productid = 0; char label[32]; static int index; +#if 0 while (*filename && *filename != ':') { const char *p; char *e; if (strstart(filename, "vendorid=", &p)) { vendorid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { -// error_report("bogus vendor ID %s", p); + error_report("bogus vendor ID %s", p); return NULL; } filename = e; } else if (strstart(filename, "productid=", &p)) { productid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { -// error_report("bogus product ID %s", p); + error_report("bogus product ID %s", p); return NULL; } filename = e; } else { -// error_report("unrecognized serial USB option %s", filename); + error_report("unrecognized serial USB option %s", filename); return NULL; } while(*filename == ',') filename++; } if (!*filename) { -// error_report("character device specification needed"); + error_report("character device specification needed"); return NULL; } filename++; +#endif snprintf(label, sizeof(label), "usbserial%d", index++); // cdrv = qemu_chr_new(label, filename, NULL); // if (!cdrv) // return NULL; - dev = usb_create(bus, "usb-serial"); + dev = usb_create(bus, "usb-serial", sizeof(USBSerialState)); if (!dev) { return NULL; } @@ -577,23 +583,23 @@ return dev; } +#if 0 static USBDevice *usb_braille_init(USBBus *bus, const char *unused) { USBDevice *dev; -// CharDriverState *cdrv; + CharDriverState *cdrv; -// cdrv = qemu_chr_new("braille", "braille", NULL); -// if (!cdrv) -// return NULL; + cdrv = qemu_chr_new("braille", "braille", NULL); + if (!cdrv) + return NULL; dev = usb_create(bus, "usb-braille"); -// qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); -// qdev_init_nofail(&dev->qdev); + qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); + qdev_init_nofail(&dev->qdev); return dev; } -#if 0 static const VMStateDescription vmstate_usb_serial = { .name = "usb-serial", .unmigratable = 1, @@ -603,23 +609,22 @@ DEFINE_PROP_CHR("chardev", USBSerialState, cs), DEFINE_PROP_END_OF_LIST(), }; +#endif -static void usb_serial_class_initfn(ObjectClass *klass, void *data) +static void usb_serial_class_initfn(USBDeviceClass *uc, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - USBDeviceClass *uc = USB_DEVICE_CLASS(klass); - uc->init = usb_serial_initfn; uc->product_desc = "QEMU USB Serial"; uc->usb_desc = &desc_serial; uc->handle_reset = usb_serial_handle_reset; uc->handle_control = usb_serial_handle_control; uc->handle_data = usb_serial_handle_data; - dc->vmsd = &vmstate_usb_serial; - dc->props = serial_properties; - set_bit(DEVICE_CATEGORY_INPUT, dc->categories); +// dc->vmsd = &vmstate_usb_serial; +// dc->props = serial_properties; +// set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } +#if 0 static const TypeInfo serial_info = { .name = "usb-serial", .parent = TYPE_USB_DEVICE, Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Aug 15 04:30:03 2013 (r255958) @@ -1702,6 +1702,8 @@ return (value); } +extern USBDevice *usb_serial_init(USBBus *bus /*, const char *filename */); +extern int usb_serial_initfn(USBDevice *dev); static int pci_uhci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { @@ -1761,6 +1763,10 @@ uhci_reset(&sc->sc_st); pci_emul_alloc_bar(pi, 4, PCIBAR_IO, 0x20); + { + USBDevice *dev = usb_serial_init(&sc->sc_st.bus); + usb_serial_initfn(dev); + } return (0); } Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Aug 15 04:30:03 2013 (r255958) @@ -332,6 +332,7 @@ int altsetting[USB_MAX_INTERFACES]; const USBDescConfig *config; const USBDescIface *ifaces[USB_MAX_INTERFACES]; + char name[128]; }; typedef struct USBPortOps { @@ -512,6 +513,7 @@ QTAILQ_HEAD(, USBPort) free; QTAILQ_HEAD(, USBPort) used; QTAILQ_ENTRY(USBBus) next; + char name[128]; }; struct USBBusOps { @@ -525,8 +527,8 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name, USBDevice *(*usbdevice_init)(USBBus *bus, const char *params)); -USBDevice *usb_create(USBBus *bus, const char *name); -USBDevice *usb_create_simple(USBBus *bus, const char *name); +USBDevice *usb_create(USBBus *bus, const char *name, size_t len); +USBDevice *usb_create_simple(USBBus *bus, const char *name, size_t len); USBDevice *usbdevice_create(const char *cmdline); void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, USBPortOps *ops, int speedmask); @@ -595,4 +597,21 @@ uint8_t interface_protocol); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define error_report(...) fprintf(stderr, __VA_ARGS__) + +#define NUM_PORTS 8 + +typedef struct USBHubPort { + USBPort port; + uint16_t wPortStatus; + uint16_t wPortChange; + uint16_t wPortChange_reported; +} USBHubPort; + +typedef struct USBHubState { + USBDevice dev; + USBEndpoint *intr; + USBHubPort ports[NUM_PORTS]; +} USBHubState; + #endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308150430.r7F4U4OD058472>