Skip to contentSkip to conversation

[5780] Native BSD host USB support (Juergen Lock, Lonnie Mendez)

Qemu-devel Blue Swirl 5 participants 10 messages Nov 22, 2008 – Nov 25, 2008 Kbuild

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

Revision: 5780

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5780
Author:   blueswir1
Date:     2008-11-22 21:03:55 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
Native BSD host USB support (Juergen Lock, Lonnie Mendez)

Modified Paths:
--------------
trunk/Makefile
trunk/configure
trunk/usb-linux.c

Added Paths:
-----------
trunk/usb-bsd.c
trunk/usb-stub.c

Modified: trunk/Makefile
===================================================================

Makefile +1 -1
@@ -74,7 +74,7 @@
 OBJS+=tmp105.o lm832x.o
 OBJS+=scsi-disk.o cdrom.o
 OBJS+=scsi-generic.o
-OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o
+OBJS+=usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
 OBJS+=usb-serial.o usb-net.o
 OBJS+=sd.o ssi-sd.o
 OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o

Modified: trunk/configure
===================================================================

configure +15 -0
@@ -221,6 +221,7 @@
 audio_possible_drivers="oss alsa sdl esd pa"
 linux="yes"
 linux_user="yes"
+usb="linux"
 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
     kqemu="yes"
     audio_possible_drivers="$audio_possible_drivers fmod"
@@ -231,6 +232,7 @@
 if [ "$bsd" = "yes" ] ; then
   if [ "$darwin" != "yes" ] ; then
     make="gmake"
+    usb="bsd"
   fi
   bsd_user="yes"
 fi
@@ -1365,6 +1367,19 @@
 
 echo "#define CONFIG_UNAME_RELEASE \"$uname_release\"" >> $config_h
 
+# USB host support
+case "$usb" in
+linux)
+  echo "HOST_USB=linux" >> $config_mak
+;;
+bsd)
+  echo "HOST_USB=bsd" >> $config_mak
+;;
+*)
+  echo "HOST_USB=stub" >> $config_mak
+;;
+esac
+
 tools=
 if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then
   tools="qemu-img\$(EXESUF) $tools"

Added: trunk/usb-bsd.c
===================================================================

usb-bsd.c +608 -0

608 lines not on this page · raw message

Modified: trunk/usb-linux.c
===================================================================

usb-linux.c +0 -23
@@ -34,7 +34,6 @@
 #include "qemu-timer.h"
 #include "console.h"
 
-#if defined(__linux__)
 #include <dirent.h>
 #include <sys/ioctl.h>
 #include <signal.h>
@@ -1697,25 +1696,3 @@
     	term_printf("    Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
     }
 }
-
-#else
-
-#include "hw/usb.h"
-
-void usb_host_info(void)
-{
-    term_printf("USB host devices not supported\n");
-}
-
-/* XXX: modify configure to compile the right host driver */
-USBDevice *usb_host_device_open(const char *devname)
-{
-    return NULL;
-}
-
-int usb_host_device_close(const char *devname)
-{
-    return 0;
-}
-
-#endif

Added: trunk/usb-stub.c
===================================================================

usb-stub.c +49 -0

49 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Blue Swirl

Revision: 5780

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5780
Author:   blueswir1
Date:     2008-11-22 21:03:55 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
Native BSD host USB support (Juergen Lock, Lonnie Mendez)

This broke the Windows build and cross compiling. Was this patch posted to the list or did you pull it from the URL that Juergen's been posting?

I would have given the patch a run if it had been posted first and we could have avoided the breakage.

Quoted 14 lines

Modified: trunk/configure
===================================================================

configure +1 -0
@@ -221,6 +221,7 @@
 audio_possible_drivers="oss alsa sdl esd pa"
 linux="yes"
 linux_user="yes"
+usb="linux"
 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
     kqemu="yes"
     audio_possible_drivers="$audio_possible_drivers fmod"

configure line 238

Quoted 7 lines
configure +1 -0
@@ -231,6 +232,7 @@
 if [ "$bsd" = "yes" ] ; then
   if [ "$darwin" != "yes" ] ; then
     make="gmake"
+    usb="bsd"
   fi
   bsd_user="yes"
 fi

This whole set of checks is horribly broken because it relies on uname -s. Such a thing doesn't exist on Windows but more importantly, when cross compiling, uname is meaningless.

What we really should do, is compile a small test program that checks for:

#ifndef __linux__
#error Not linux
#endif

And then try compiling that to see if we're on Linux or not. The same with FreeBSD et al.

Quoted 2 lines

Added: trunk/usb-stub.c

This stub doesn't build at all. The copyright is a little bogus too because I don't think Fabrice, Max, or TJ have ever contributed to this file.

Quoted 28 lines

===================================================================

usb-stub.c +23 -0
@@ -0,0 +1,49 @@
+/*
+ * Stub host USB redirector
+ *
+ * Copyright (c) 2005 Fabrice Bellard
+ *
+ * Copyright (c) 2008 Max Krasnyansky
+ *      Support for host device auto connect & disconnect
+ *      Major rewrite to support fully async operation
+ *
+ * Copyright 2008 TJ <[email protected]>
+ *      Added flexible support for /dev/bus/usb /sys/bus/usb/devices in addition
+ *      to the legacy /proc/bus/usb USB device discovery and handling
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *

usb-stub.c line 33

Quoted 10 lines
usb-stub.c +10 -0
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/usb.h"

This is not enough includes to produce something buildable.

Quoted 8 lines
usb-stub.c +6 -0
+
+void usb_host_info(void)
+{
+    term_printf("USB host devices not supported\n");
+}
+

usb-stub.c line 49

Quoted 10 lines
usb-stub.c +10 -0
+/* XXX: modify configure to compile the right host driver */
+USBDevice *usb_host_device_open(const char *devname)
+{
+    return NULL;
+}
+
+int usb_host_device_close(const char *devname)
+{
+    return 0;
+}

Regards,

Anthony Liguori

Quoted 2 lines
#8 lore raw
In reply to Blue Swirl

This patch breaks Win32 build.
Btw, how is it supposed to work, as hw/usb.h uses NICInfo structure, and
usb-stub.c doesn't include net.h to define it?

Attached patch fixes the problem.

Hervé

Quoted 15 lines · Blue Swirl

Revision: 5780

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5780
Author:   blueswir1
Date:     2008-11-22 21:03:55 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
Native BSD host USB support (Juergen Lock, Lonnie Mendez)

Modified Paths:
--------------
trunk/Makefile
trunk/configure
trunk/usb-linux.c

Quoted 5 lines

Added Paths:
-----------
trunk/usb-bsd.c
trunk/usb-stub.c

usb-stub.c +3 -0
Index: usb-stub.c
===================================================================
@@ -30,6 +30,9 @@
  * THE SOFTWARE.
  */
 
+#include "qemu-common.h"
+#include "console.h"
+#include "net.h"
 #include "hw/usb.h"
 
 void usb_host_info(void)
#2 lore raw
In reply to Anthony Liguori

Anthony Liguori wrote:
[snip]

Quoted 18 lines

configure line 238

Quoted 13 lines
configure +2 -0
+usb="linux"
 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
     kqemu="yes"
     audio_possible_drivers="$audio_possible_drivers fmod"
@@ -231,6 +232,7 @@
 if [ "$bsd" = "yes" ] ; then
   if [ "$darwin" != "yes" ] ; then
     make="gmake"
+    usb="bsd"
   fi
   bsd_user="yes"
 fi

This whole set of checks is horribly broken because it relies on uname -s. Such a thing doesn't exist on Windows but more importantly, when cross compiling, uname is meaningless.

Quoted 8 lines

What we really should do, is compile a small test program that checks for:

#ifndef __linux__
#error Not linux
#endif

And then try compiling that to see if we're on Linux or not. The same with FreeBSD et al.

It shouldn't try to compile, for the sake of cross portability. Rather something like

gcc -E -dM -xc /dev/null |grep __linux__

This checks if the compiler in use is a Linux compiler.

Thiemo

#3 lore raw
Quoted 7 lines · Thiemo Seufer

It shouldn't try to compile, for the sake of cross portability. Rather something like

gcc -E -dM -xc /dev/null |grep __linux__

This checks if the compiler in use is a Linux compiler.

Good enough, but I wonder why you think it shouldn't compile for the sake of cross portability?

The cross compiler should be able to create an executable. You don't have to run it, you just have to rely on #error causing compilation to fail.

Regards,

Anthony Liguori

Quoted 2 lines

Thiemo

author
#7 lore raw
In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 2 lines · Blue Swirl

Revision: 5780

http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5780

Quoted 3 lines
Author:   blueswir1
Date:     2008-11-22 21:03:55 +0000 (Sat, 22 Nov 2008)
Quoted 8 lines
Quoted 5 lines

Log Message:
-----------
Native BSD host USB support (Juergen Lock, Lonnie Mendez)

This broke the Windows build and cross compiling. Was this patch posted to
the list or did you pull it from the URL that Juergen's been posting?

Yes, but maybe you missed it because it was inside a shar package.

Quoted 32 lines

I would have given the patch a run if it had been posted first and we could
have avoided the breakage.

Quoted 2 lines

Modified: trunk/configure

===================================================================

Quoted 13 lines
configure 2008-11-22 21:03:55 UTC (rev 5780) renamed from configure 2008-11-22 20:49:12 UTC (rev 5779) +1 -0
@@ -221,6 +221,7 @@
 audio_possible_drivers="oss alsa sdl esd pa"
 linux="yes"
 linux_user="yes"
+usb="linux"
 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
    kqemu="yes"
    audio_possible_drivers="$audio_possible_drivers fmod"

configure 2008-11-22 21:03:55 UTC (rev 5780) line 238

Quoted 7 lines
configure 2008-11-22 21:03:55 UTC (rev 5780) renamed from configure 2008-11-22 20:49:12 UTC (rev 5779) +1 -0
@@ -231,6 +232,7 @@
 if [ "$bsd" = "yes" ] ; then
  if [ "$darwin" != "yes" ] ; then
    make="gmake"
+    usb="bsd"
  fi
  bsd_user="yes"
 fi

This whole set of checks is horribly broken because it relies on uname -s.
Such a thing doesn't exist on Windows but more importantly, when cross compiling, uname is meaningless.

Quoted 8 lines

What we really should do, is compile a small test program that checks for:

#ifndef __linux__
#error Not linux
#endif

And then try compiling that to see if we're on Linux or not. The same with
FreeBSD et al.

In this case we could also check if Linux USB headers or BSD USB headers are available.

Quoted 7 lines
Quoted 3 lines

Added: trunk/usb-stub.c

This stub doesn't build at all. The copyright is a little bogus too
because I don't think Fabrice, Max, or TJ have ever contributed to this file.

Well, before the commit, this code was located at the end of usb-linux.c which carries this preamble.

Quoted 6 lines

configure 2008-11-22 21:03:55 UTC (rev 5780)

Quoted 4 lines
configure 2008-11-22 21:03:55 UTC (rev 5780) renamed from configure 2008-11-22 20:49:12 UTC (rev 5779) +2 -0
+
+#include "hw/usb.h"

This is not enough includes to produce something buildable.

Sorry, I missed the headers before #ifdef __linux__.

#4 lore raw
In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 7 lines · Thiemo Seufer

It shouldn't try to compile, for the sake of cross portability. Rather something like

gcc -E -dM -xc /dev/null |grep __linux__

This checks if the compiler in use is a Linux compiler.

Quoted 6 lines

Good enough, but I wonder why you think it shouldn't compile for the sake of cross portability?

The cross compiler should be able to create an executable. You don't have to run it, you just have to rely on #error causing compilation to fail.

You are right, disregard my comment on that. :-)

Thiemo

#9 lore raw
In reply to Hervé Poussineau

Am 24.11.2008 um 21:42 schrieb Hervé Poussineau:

Quoted 4 lines

This patch breaks Win32 build.
Btw, how is it supposed to work, as hw/usb.h uses NICInfo structure, and usb-stub.c doesn't include net.h to define it?

Attached patch fixes the problem.

Please compare my recent patch for OSX. qemu-common.h was enough, no net.h was needed for NICInfo.

Andreas

Quoted 23 lines

Hervé

Quoted 4 lines · Blue Swirl

Revision: 5780

         http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5780
Author:   blueswir1
Date:     2008-11-22 21:03:55 +0000 (Sat, 22 Nov 2008)
Quoted 12 lines

Log Message:
-----------
Native BSD host USB support (Juergen Lock, Lonnie Mendez) Modified Paths:
--------------
trunk/Makefile
trunk/configure
trunk/usb-linux.c
Added Paths:
-----------
trunk/usb-bsd.c
trunk/usb-stub.c

<fix_win32_build.diff>

author
#5 lore raw
In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Thiemo Seufer

It shouldn't try to compile, for the sake of cross portability. Rather something like

gcc -E -dM -xc /dev/null |grep __linux__

This checks if the compiler in use is a Linux compiler.

Quoted 5 lines

Good enough, but I wonder why you think it shouldn't compile for the sake
of cross portability?

The cross compiler should be able to create an executable. You don't have
to run it, you just have to rely on #error causing compilation to fail.

There is a small problem: in configure, we want to parse the command line options for things like cpu, compiler flags etc. So the OS or CPU detection should be after that.

Currently the CPU from uname is used to modify the OS flags even before command line options are handled, this seems to be broken.

#6 lore raw
Quoted 9 lines · Blue Swirl

On 11/25/08, Anthony Liguori <[email protected]> wrote:

There is a small problem: in configure, we want to parse the command line options for things like cpu, compiler flags etc. So the OS or CPU detection should be after that.

Currently the CPU from uname is used to modify the OS flags even before command line options are handled, this seems to be broken.

Yeah, I'd agree that this is broken.

Regards,

Anthony Liguori