Add #defines needed by OpenSolaris, fix breakage by the #defines
[qemu] / usb-bsd.c
index 22610ab..6e8c526 100644 (file)
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -25,7 +25,7 @@
  */
 
 #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>
+#else
+#include <bus/usb/usb.h>
+#endif
 #include <signal.h>
 
 /* This value has maximum potential at 16.
@@ -59,6 +63,7 @@ typedef struct USBHostDevice {
 } USBHostDevice;
 
 
+#if 0
 static int ensure_ep_open(USBHostDevice *dev, int ep, int mode)
 {
     char buf[32];
@@ -68,7 +73,7 @@ static int ensure_ep_open(USBHostDevice *dev, int ep, int mode)
     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);
@@ -106,6 +111,7 @@ static void ensure_eps_closed(USBHostDevice *dev)
         epnum++;
     }
 }
+#endif
 
 static void usb_host_handle_reset(USBDevice *dev)
 {
@@ -114,6 +120,7 @@ static void usb_host_handle_reset(USBDevice *dev)
 #endif
 }
 
+#if 0
 /* XXX:
  * -check device states against transfer requests
  *  and return appropriate response
@@ -271,6 +278,7 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
         return ret;
     }
 }
+#endif
 
 static void usb_host_handle_destroy(USBDevice *opaque)
 {
@@ -289,9 +297,15 @@ static void usb_host_handle_destroy(USBDevice *opaque)
     qemu_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;
     USBHostDevice *dev;
     char ctlpath[PATH_MAX + 1];
     char buspath[PATH_MAX + 1];
@@ -321,7 +335,7 @@ USBDevice *usb_host_device_open(const char *devname)
         return NULL;
     }
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || 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]);
@@ -339,9 +353,6 @@ USBDevice *usb_host_device_open(const char *devname)
     }
 
     if (dfd >= 0) {
-        dev = qemu_mallocz(sizeof(USBHostDevice));
-        dev->devfd = dfd;
-
         if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
 #ifdef DEBUG
             printf("usb_host_device_open: failed to grab device info - %s\n",
@@ -350,18 +361,14 @@ USBDevice *usb_host_device_open(const char *devname)
             goto fail;
         }
 
+        d = usb_create(NULL /* FIXME */, "USB Host Device");
+        dev = DO_UPCAST(USBHostDevice, dev, d);
+
         if (dev_info.udi_speed == 1)
             dev->dev.speed = USB_SPEED_LOW - 1;
         else
             dev->dev.speed = USB_SPEED_FULL - 1;
 
-        dev->dev.handle_packet = usb_generic_handle_packet;
-
-        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 (strncmp(dev_info.udi_product, "product", 7) != 0)
             pstrcpy(dev->dev.devname, sizeof(dev->dev.devname),
                     dev_info.udi_product);
@@ -385,6 +392,25 @@ fail:
     return NULL;
 }
 
+static struct USBDeviceInfo usb_host_dev_info = {
+    .qdev.name      = "USB Host Device",
+    .qdev.size      = sizeof(USBHostDevice),
+    .init           = usb_host_initfn,
+    .handle_packet  = usb_generic_handle_packet,
+    .handle_reset   = usb_host_handle_reset,
+#if 0
+    .handle_control = usb_host_handle_control,
+    .handle_data    = usb_host_handle_data,
+#endif
+    .handle_destroy = usb_host_handle_destroy,
+};
+
+static void usb_host_register_devices(void)
+{
+    usb_qdev_register(&usb_host_dev_info);
+}
+device_init(usb_host_register_devices)
+
 static int usb_host_scan(void *opaque, USBScanFunc *func)
 {
     struct usb_device_info bus_info;
@@ -411,7 +437,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
             if (strncmp(bus_info.udi_devnames[0], "ugen", 4) != 0)
                 continue;
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || 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]);
@@ -548,13 +574,12 @@ static const char *usb_class_str(uint8_t class)
     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)
 {
     const char *class_str, *speed_str;
-    Monitor *mon = cur_mon;
 
     switch(speed) {
     case USB_SPEED_LOW:
@@ -591,14 +616,16 @@ static int usb_host_info_device(void *opaque,
                                 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(Monitor *mon)
 {
-    usb_host_scan(NULL, usb_host_info_device);
+    usb_host_scan(mon, usb_host_info_device);
 }
 
 /* XXX add this */