*/
#include "qemu-common.h"
-#include "console.h"
+#include "monitor.h"
#include "hw/usb.h"
/* usb.h declares these */
#undef USB_SPEED_LOW
#include <sys/ioctl.h>
+#ifndef __DragonFly__
#include <dev/usb/usb.h>
-#include <signal.h>
+#else
+#include <bus/usb/usb.h>
+#endif
/* This value has maximum potential at 16.
* You should also set hw.usb.debug to gain
ep = UE_GET_ADDR(ep);
if (dev->ep_fd[ep] < 0) {
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
snprintf(buf, sizeof(buf) - 1, "%s.%d", dev->devpath, ep);
#else
snprintf(buf, sizeof(buf) - 1, "%s.%02d", dev->devpath, ep);
* and return appropriate response
*/
static int usb_host_handle_control(USBDevice *dev,
+ USBPacket *p,
int request,
int value,
int index,
int ret, fd, mode;
int one = 1, shortpacket = 0, timeout = 50;
sigset_t new_mask, old_mask;
- uint8_t devep = p->devep;
+ uint8_t devep = p->ep->nr;
/* protect data transfers from SIGALRM signal */
sigemptyset(&new_mask);
}
if (p->pid == USB_TOKEN_IN)
- ret = read(fd, p->data, p->len);
+ ret = readv(fd, p->iov.iov, p->iov.niov);
else
- ret = write(fd, p->data, p->len);
+ ret = writev(fd, p->iov.iov, p->iov.niov);
sigprocmask(SIG_SETMASK, &old_mask, NULL);
close(s->devfd);
- qemu_free(s);
+ g_free(s);
+}
+
+static int usb_host_initfn(USBDevice *dev)
+{
+ return 0;
}
USBDevice *usb_host_device_open(const char *devname)
{
struct usb_device_info bus_info, dev_info;
+ USBDevice *d = NULL, *ret = NULL;
USBHostDevice *dev;
char ctlpath[PATH_MAX + 1];
char buspath[PATH_MAX + 1];
int bfd, dfd, bus, address, i;
int ugendebug = UGEN_DEBUG_LEVEL;
- if (usb_host_find_device(&bus, &address, devname) < 0)
- return NULL;
+ if (usb_host_find_device(&bus, &address, devname) < 0) {
+ goto fail;
+ }
snprintf(buspath, PATH_MAX, "/dev/usb%d", bus);
printf("usb_host_device_open: failed to open usb bus - %s\n",
strerror(errno));
#endif
- return NULL;
+ goto fail;
}
bus_info.udi_addr = address;
printf("usb_host_device_open: failed to grab bus information - %s\n",
strerror(errno));
#endif
- return NULL;
+ goto fail_bfd;
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
snprintf(ctlpath, PATH_MAX, "/dev/%s", bus_info.udi_devnames[0]);
#else
snprintf(ctlpath, PATH_MAX, "/dev/%s.00", bus_info.udi_devnames[0]);
ctlpath, strerror(errno));
#endif
}
+ goto fail_dfd;
}
- if (dfd >= 0) {
- dev = qemu_mallocz(sizeof(USBHostDevice));
- dev->devfd = dfd;
-
- if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
+ if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
#ifdef DEBUG
- printf("usb_host_device_open: failed to grab device info - %s\n",
- strerror(errno));
+ printf("usb_host_device_open: failed to grab device info - %s\n",
+ strerror(errno));
#endif
- goto fail;
- }
-
- if (dev_info.udi_speed == 1)
- dev->dev.speed = USB_SPEED_LOW - 1;
- else
- dev->dev.speed = USB_SPEED_FULL - 1;
+ goto fail_dfd;
+ }
- dev->dev.handle_packet = usb_generic_handle_packet;
+ d = usb_create(NULL /* FIXME */, "usb-host");
+ dev = DO_UPCAST(USBHostDevice, dev, d);
- dev->dev.handle_reset = usb_host_handle_reset;
- dev->dev.handle_control = usb_host_handle_control;
- dev->dev.handle_data = usb_host_handle_data;
- dev->dev.handle_destroy = usb_host_handle_destroy;
+ if (dev_info.udi_speed == 1) {
+ dev->dev.speed = USB_SPEED_LOW - 1;
+ dev->dev.speedmask = USB_SPEED_MASK_LOW;
+ } else {
+ dev->dev.speed = USB_SPEED_FULL - 1;
+ dev->dev.speedmask = USB_SPEED_MASK_FULL;
+ }
- if (strncmp(dev_info.udi_product, "product", 7) != 0)
- pstrcpy(dev->dev.devname, sizeof(dev->dev.devname),
- dev_info.udi_product);
- else
- snprintf(dev->dev.devname, sizeof(dev->dev.devname),
- "host:%s", devname);
+ if (strncmp(dev_info.udi_product, "product", 7) != 0) {
+ pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),
+ dev_info.udi_product);
+ } else {
+ snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),
+ "host:%s", devname);
+ }
- pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");
- pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);
+ pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");
+ pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);
- /* Mark the endpoints as not yet open */
- for (i = 0; i < USB_MAX_ENDPOINTS; i++)
- dev->ep_fd[i] = -1;
+ /* Mark the endpoints as not yet open */
+ for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
+ dev->ep_fd[i] = -1;
+ }
- ioctl(dfd, USB_SETDEBUG, &ugendebug);
+ ioctl(dfd, USB_SETDEBUG, &ugendebug);
- return (USBDevice *)dev;
- }
+ ret = (USBDevice *)dev;
+fail_dfd:
+ close(dfd);
+fail_bfd:
+ close(bfd);
fail:
- return NULL;
+ return ret;
+}
+
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->product_desc = "USB Host Device";
+ uc->init = usb_host_initfn;
+ uc->handle_reset = usb_host_handle_reset;
+ uc->handle_control = usb_host_handle_control;
+ uc->handle_data = usb_host_handle_data;
+ uc->handle_destroy = usb_host_handle_destroy;
}
+static TypeInfo usb_host_dev_info = {
+ .name = "usb-host",
+ .parent = TYPE_USB_DEVICE,
+ .instance_size = sizeof(USBHostDevice),
+ .class_init = usb_host_class_initfn,
+};
+
+static void usb_host_register_types(void)
+{
+ type_register_static(&usb_host_dev_info);
+}
+
+type_init(usb_host_register_types)
+
static int usb_host_scan(void *opaque, USBScanFunc *func)
{
struct usb_device_info bus_info;
if (strncmp(bus_info.udi_devnames[0], "ugen", 4) != 0)
continue;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
snprintf(devbuf, sizeof(devbuf) - 1, "/dev/%s", bus_info.udi_devnames[0]);
#else
snprintf(devbuf, sizeof(devbuf) - 1, "/dev/%s.00", bus_info.udi_devnames[0]);
printf("usb_host_scan: couldn't get device information for %s - %s\n",
devbuf, strerror(errno));
- // XXX: might need to fixup endianess of word values before copying over
+ /* XXX: might need to fixup endianness of word values before copying over */
vendor_id = dev_info.udi_vendorNo;
product_id = dev_info.udi_productNo;
return p->class_name;
}
-static void usb_info_device(int bus_num, int addr, int class_id,
+static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id,
int vendor_id, int product_id,
const char *product_name,
int speed)
break;
}
- term_printf(" Device %d.%d, speed %s Mb/s\n",
- bus_num, addr, speed_str);
+ monitor_printf(mon, " Device %d.%d, speed %s Mb/s\n",
+ bus_num, addr, speed_str);
class_str = usb_class_str(class_id);
if (class_str)
- term_printf(" %s:", class_str);
+ monitor_printf(mon, " %s:", class_str);
else
- term_printf(" Class %02x:", class_id);
- term_printf(" USB device %04x:%04x", vendor_id, product_id);
+ monitor_printf(mon, " Class %02x:", class_id);
+ monitor_printf(mon, " USB device %04x:%04x", vendor_id, product_id);
if (product_name[0] != '\0')
- term_printf(", %s", product_name);
- term_printf("\n");
+ monitor_printf(mon, ", %s", product_name);
+ monitor_printf(mon, "\n");
}
-static int usb_host_info_device(void *opaque, int bus_num, int addr,
+static int usb_host_info_device(void *opaque,
+ int bus_num, int addr,
int class_id,
int vendor_id, int product_id,
const char *product_name,
int speed)
{
- usb_info_device(bus_num, addr, class_id, vendor_id, product_id,
+ Monitor *mon = opaque;
+
+ usb_info_device(mon, bus_num, addr, class_id, vendor_id, product_id,
product_name, speed);
return 0;
}
-void usb_host_info(void)
+void usb_host_info(Monitor *mon)
{
- usb_host_scan(NULL, usb_host_info_device);
+ usb_host_scan(mon, usb_host_info_device);
}
/* XXX add this */