qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Large USB patch


From: Lonnie Mendez
Subject: Re: [Qemu-devel] Large USB patch
Date: Fri, 21 Apr 2006 15:50:30 -0500
User-agent: Mozilla Thunderbird 1.0.7 (X11/20050923)

  Another patch.  This one does a few things:

-fixes minor output bugs and some various OBO bugs
-adds some improvements to the emulated hub
-sets up the emulated devices to use the generic message handler (they now work again)
-makes tablet device visible to usb_add

There are of course more bugs I've found. Namely being able to usb_add any particular string with that string showing up as a new device even though no valid entry for it exists.
--- a/qemu/hw/usb.c     2006-04-21 11:15:40.000000000 -0500
+++ b/qemu/hw/usb.c     2006-04-21 15:27:19.000000000 -0500
@@ -455,6 +455,10 @@
         /* we found a guest usb mouse */
         tree->dev= usb_mouse_init ();
         return add_usb_device (tree);
+    } else if (strcmp (tree->name,"tablet") == 0) {
+        /* we found a guest usb tablet */
+        tree->dev = usb_tablet_init ();
+        return add_usb_device (tree);
     }
     return 1;
 }
@@ -491,6 +495,7 @@
     usb_host_info();
     usb_hub_info();
     usb_mouse_info();
+    usb_tablet_info();
 }
 
 void usb_print_childs (USBTree *tree, int layer) {
--- a/qemu/hw/usb.h     2006-04-21 11:15:40.000000000 -0500
+++ b/qemu/hw/usb.h     2006-04-21 15:27:58.000000000 -0500
@@ -242,7 +242,9 @@
 void        usb_hub_info                (void);
 /* usb-hid.c */
 USBDevice*  usb_mouse_init              (void);
+USBDevice*  usb_tablet_init             (void);
 void        usb_mouse_info              (void);
+void        usb_tablet_info             (void);
 
 
 /* The usb dummy device functions, they exist only to make it easier to
--- a/qemu/hw/usb-hub.c 2006-04-21 11:15:40.000000000 -0500
+++ b/qemu/hw/usb-hub.c 2006-04-21 15:23:05.000000000 -0500
@@ -165,9 +165,9 @@
     0x0a,           /* u16  wHubCharacteristics; */
     0x00,           /*   (per-port OC, no power switching) */
     0x01,           /*  u8  bPwrOn2pwrGood; 2ms */
-    0x00,           /*  u8  bHubContrCurrent; 0 mA */
-    0x00,           /*  u8  DeviceRemovable; *** 7 Ports max *** */
-    0xff            /*  u8  PortPwrCtrlMask; *** 7 ports max *** */
+    0x00            /*  u8  bHubContrCurrent; 0 mA */
+
+    /* DeviceRemovable and PortPwrCtrlMask patched in later */
 };
 
 static int usb_hub_attach (USBDevice *hub, USBDevice *dev, int portnum)
@@ -260,6 +260,12 @@
         }
         ret = 0;
         break;
+    case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
+        if (value == 0 && index != 0x81) { /* clear ep halt */
+            goto fail;
+        }
+        ret = 0;
+        break;
     case DeviceOutRequest | USB_REQ_SET_FEATURE:
         if (value == USB_DEVICE_REMOTE_WAKEUP) {
             dev->remote_wakeup = 1;
@@ -282,6 +288,11 @@
         case USB_DT_CONFIG:
             memcpy(data, qemu_hub_config_descriptor, 
                    sizeof(qemu_hub_config_descriptor));
+
+            /* status change endpoint size based on number
+             * of ports */
+            data[22] = (s->nb_ports + 1 + 7) / 8;
+
             ret = sizeof(qemu_hub_config_descriptor);
             break;
         case USB_DT_STRING:
@@ -427,11 +438,29 @@
         }
         break;
     case GetHubDescriptor:
-        memcpy(data, qemu_hub_hub_descriptor, 
-               sizeof(qemu_hub_hub_descriptor));
-        data[2] = s->nb_ports;
-        ret = sizeof(qemu_hub_hub_descriptor);
-        break;
+        {
+            unsigned int n, limit, var_hub_size = 0;
+            memcpy(data, qemu_hub_hub_descriptor, 
+                   sizeof(qemu_hub_hub_descriptor));
+            data[2] = s->nb_ports;
+
+            /* fill DeviceRemovable bits */
+            limit = ((s->nb_ports + 1 + 7) / 8) + 7;
+            for (n = 7; n < limit; n++) {
+                data[n] = 0x00;
+                var_hub_size++;
+            }
+
+            /* fill PortPwrCtrlMask bits */
+            limit = limit + ((s->nb_ports + 7) / 8);
+            for (;n < limit; n++) {
+                data[n] = 0xff;
+                var_hub_size++;
+            }
+
+            ret = sizeof(qemu_hub_hub_descriptor) + var_hub_size;
+            break;
+        }
     default:
     fail:
         ret = USB_RET_STALL;
@@ -453,8 +482,11 @@
             unsigned int status;
             int i, n;
             n = (s->nb_ports + 1 + 7) / 8;
-            if (n > len)
+            if (len == 1) { /* FreeBSD uhub workaround */
+                n = 1;
+            } else if (n > len) {
                 return USB_RET_BABBLE;
+            }
             status = 0;
             for(i = 0; i < s->nb_ports; i++) {
                 port = &s->ports[i];
@@ -467,7 +499,7 @@
                 }
                 ret = n;
             } else {
-                ret = 0;
+                ret = USB_RET_NAK; /* usb_20 11.12.1 */
             }
         } else {
             goto fail;
@@ -541,6 +573,7 @@
         return NULL;
     dev->opaque=                s;
     dev->speed=                 USB_SPEED_FULL;
+    dev->handle_msg=            usb_generic_handle_msg;
     dev->handle_packet=         usb_hub_handle_packet;
     dev->handle_attach=         usb_hub_attach;
     dev->handle_reset=          usb_hub_handle_reset;
@@ -558,5 +591,5 @@
 
 void usb_hub_info(void) {
     term_printf("  Device usbhub, Manufacturer QEMU, Product QEMU USB Hub\n" );
-    term_printf ("     VendorID:ProductID 0000:0000, USB-Standard: 01.01\n");
+    term_printf ("     VendorID:ProductID 0000:0000, USB-Standard: 01.10\n");
 }
--- a/qemu/hw/usb-hid.c 2006-04-21 11:15:40.000000000 -0500
+++ b/qemu/hw/usb-hid.c 2006-04-21 15:31:55.000000000 -0500
@@ -515,6 +515,7 @@
         return NULL;
     dev->opaque=            s;
     dev->speed=             USB_SPEED_FULL;
+    dev->handle_msg=        usb_generic_handle_msg;
     dev->handle_packet=     usb_generic_handle_packet;
 
     dev->handle_reset=      usb_mouse_handle_reset;
@@ -536,6 +539,7 @@
         return NULL;
     dev->opaque=            s;
     dev->speed=             USB_SPEED_FULL;
+    dev->handle_msg=        usb_generic_handle_msg;
     dev->handle_packet=     usb_generic_handle_packet;
 
     dev->handle_reset=      usb_mouse_handle_reset;
@@ -549,5 +553,10 @@
 
 void usb_mouse_info() {
     term_printf("  Device mouse, Manufacturer QEMU, Product QEMU USB Mouse\n" 
);
-    term_printf ("     VendorID:ProductID 2706:0001, USB-Standard: 01.00\n");
+    term_printf ("     VendorID:ProductID 0627:0001, USB-Standard: 01.00\n");
+}
+
+void usb_tablet_info() {
+    term_printf("  Device tablet, Manufacturer QEMU, Product QEMU USB 
Tablet\n");
+    term_printf ("     VendorID:ProductID 0627:0001, USB-Standard: 01.00\n");
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]