r1898 - trunk/src/host/qemu-neo1973

andrew at sita.openmoko.org andrew at sita.openmoko.org
Thu May 3 04:46:04 CEST 2007


Author: andrew
Date: 2007-05-03 04:46:03 +0200 (Thu, 03 May 2007)
New Revision: 1898

Modified:
   trunk/src/host/qemu-neo1973/usb-linux-gadget.c
   trunk/src/host/qemu-neo1973/vl.c
   trunk/src/host/qemu-neo1973/vl.h
Log:
Monitor commands to handle the USB gadget functionality, various gadgetfs usage fixes.


Modified: trunk/src/host/qemu-neo1973/usb-linux-gadget.c
===================================================================
--- trunk/src/host/qemu-neo1973/usb-linux-gadget.c	2007-05-02 16:13:04 UTC (rev 1897)
+++ trunk/src/host/qemu-neo1973/usb-linux-gadget.c	2007-05-03 02:46:03 UTC (rev 1898)
@@ -361,6 +361,8 @@
     if (src->bDescriptorType != USB_DT_CONFIG)
         goto fail;
     cfg = (struct usb_config_descriptor *) src;
+    if (packet->len < cfg->wTotalLength)
+        goto fail;
     if (dl + cfg->wTotalLength > sizeof(buffer))
         goto fail;
     cfg->bMaxPower = 0x00;
@@ -376,6 +378,8 @@
     if (dl + hci->desc_len > sizeof(buffer))
         goto fail;
     memcpy(dst, hci->dev_desc, hci->desc_len);
+    /* HACK: report always only a single Configuration */
+    ((struct usb_device_descriptor *) dst)->bNumConfigurations = 1;
     dl += hci->desc_len;
     dst += hci->desc_len;
 
@@ -491,13 +495,13 @@
     struct usb_gadgetfs_event event;
     int ret, len;
 
-    if (!s->addr)
+    if (!s->connected)
         return;
 
     ret = read(s->ep0fd, &event, sizeof(event));
     if (ret < 0 && errno != EAGAIN)
         fprintf(stderr, "%s: event error: %i\n", __FUNCTION__, errno);
-    if (ret < sizeof(event))
+    if (ret < (int) sizeof(event))
         return;
 
     switch (event.type) {
@@ -712,6 +716,8 @@
         return ret;
     atexit(gadget_done);
 
+    hci->addr = 0;
+
     qemu_register_usb_port(&hci->port, hci, USB_INDEX_HOST, gadget_attach);
 
     return ret;

Modified: trunk/src/host/qemu-neo1973/vl.c
===================================================================
--- trunk/src/host/qemu-neo1973/vl.c	2007-05-02 16:13:04 UTC (rev 1897)
+++ trunk/src/host/qemu-neo1973/vl.c	2007-05-03 02:46:03 UTC (rev 1898)
@@ -3955,6 +3955,8 @@
 
 static USBPort *used_usb_ports;
 static USBPort *free_usb_ports;
+static USBPort *host_usb_ports;
+static USBDevice *usb_gadget;
 
 /* ??? Maybe change this to register a hub to keep track of the topology.  */
 void qemu_register_usb_port(USBPort *port, void *opaque, int index,
@@ -3963,10 +3965,20 @@
     port->opaque = opaque;
     port->index = index;
     port->attach = attach;
-    port->next = free_usb_ports;
-    free_usb_ports = port;
+    if (index == USB_INDEX_HOST) {
+        port->next = host_usb_ports;
+        host_usb_ports = port;
+    } else {
+        port->next = free_usb_ports;
+        free_usb_ports = port;
+    }
 }
 
+void qemu_register_usb_gadget(USBDevice *device)
+{
+    usb_gadget = device;
+}
+
 static int usb_device_add(const char *devname)
 {
     const char *p;
@@ -3989,8 +4001,14 @@
 	if (nr >= (unsigned int)nb_nics || strcmp(nd_table[nr].model, "usb"))
 		return -1;
         dev = usb_net_init(&nd_table[nr]);
+    } else if (!strcmp(devname, "gadget")) {
+        dev = usb_gadget;
+        port = host_usb_ports;
+        if (!dev || !port)
+            return -1;
+        goto attach;
     } else {
-        return -1;
+        return 0;
     }
     if (!dev)
         return -1;
@@ -4013,6 +4031,7 @@
     free_usb_ports = port->next;
     port->next = used_usb_ports;
     used_usb_ports = port;
+attach:
     usb_attach(port, dev);
     return 0;
 }
@@ -4025,6 +4044,14 @@
     int bus_num, addr;
     const char *p;
 
+    if (!strcmp(devname, "gadget")) {
+        port = host_usb_ports;
+        if (!port)
+            return -1;
+        usb_attach(port, NULL);
+        return 0;
+    }
+
     if (!used_usb_ports)
         return -1;
 

Modified: trunk/src/host/qemu-neo1973/vl.h
===================================================================
--- trunk/src/host/qemu-neo1973/vl.h	2007-05-02 16:13:04 UTC (rev 1897)
+++ trunk/src/host/qemu-neo1973/vl.h	2007-05-03 02:46:03 UTC (rev 1898)
@@ -1229,8 +1229,10 @@
 
 /* usb ports of the VM */
 
+#define USB_INDEX_HOST  -1
 void qemu_register_usb_port(USBPort *port, void *opaque, int index,
                             usb_attachfn attach);
+void qemu_register_usb_gadget(USBDevice *device);
 
 #define VM_USB_HUB_SIZE 8
 
@@ -1457,6 +1459,8 @@
 
 #include "hw/i2c.h"
 
+#define unlikely(cond)	__builtin_expect(cond, 0)
+
 #ifdef TARGET_ARM
 #include "hw/pxa.h"
 #include "hw/s3c.h"





More information about the commitlog mailing list