usb4bsd: Add usb_quirk module.
authorSascha Wildner <saw@online.de>
Sun, 14 Oct 2012 20:10:30 +0000 (22:10 +0200)
committerSascha Wildner <saw@online.de>
Sun, 14 Oct 2012 20:10:30 +0000 (22:10 +0200)
Makefile_upgrade.inc
sys/bus/u4b/Makefile
sys/bus/u4b/quirk/Makefile [new file with mode: 0644]
sys/bus/u4b/quirk/usb_quirk.c
sys/conf/files

index 535bb98..838e709 100644 (file)
@@ -2151,6 +2151,7 @@ TO_REMOVE+=/boot/kernel/uaudio.ko
 TO_REMOVE+=/boot/kernel/uep.ko
 TO_REMOVE+=/boot/kernel/uether.ko
 TO_REMOVE+=/boot/kernel/uhci.ko
+TO_REMOVE+=/boot/kernel/usb_quirk.ko
 TO_REMOVE+=/boot/kernel/usfs.ko
 TO_REMOVE+=/boot/kernel/xhci.ko
 TO_REMOVE+=/usr/lib/libusb.a
index fd55599..62ddf74 100644 (file)
@@ -1,5 +1,5 @@
 #SUBDIR=       controller input misc net quirk serial storage template
 
-SUBDIR=        usb audio controller input net storage
+SUBDIR=        usb audio controller input net quirk storage
 
 .include <bsd.subdir.mk>
diff --git a/sys/bus/u4b/quirk/Makefile b/sys/bus/u4b/quirk/Makefile
new file mode 100644 (file)
index 0000000..23990ff
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# $FreeBSD: src/sys/modules/usb/quirk/Makefile,v 1.1 2009/02/23 18:32:59 thompsa Exp $
+#
+# Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+
+KMOD=  usb_quirk
+SRCS=  bus_if.h device_if.h usb_if.h opt_bus.h opt_usb.h \
+       usb_quirk.c
+
+.include <bsd.kmod.mk>
index e07aa2d..23b343f 100644 (file)
@@ -27,7 +27,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
+#include <sys/thread2.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbdi.h>
-#include "usbdevs.h"
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdevs.h>
 
 #define        USB_DEBUG_VAR usb_debug
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_dynamic.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_dynamic.h>
 
-#include <dev/usb/quirk/usb_quirk.h>
+#include <bus/u4b/quirk/usb_quirk.h>
 
 MODULE_DEPEND(usb_quirk, usb, 1, 1, 1);
 MODULE_VERSION(usb_quirk, 1);
@@ -70,7 +68,7 @@ struct usb_quirk_entry {
        uint16_t quirks[USB_SUB_QUIRKS_MAX];
 };
 
-static struct mtx usb_quirk_mtx;
+static struct lock usb_quirk_lock;
 
 #define        USB_QUIRK_VP(v,p,l,h,...) \
   { .vid = (v), .pid = (p), .lo_rev = (l), .hi_rev = (h), \
@@ -561,7 +559,7 @@ usb_test_quirk_by_info(const struct usbd_lookup_info *info, uint16_t quirk)
        if (quirk == UQ_NONE)
                goto done;
 
-       mtx_lock(&usb_quirk_mtx);
+       lockmgr(&usb_quirk_lock, LK_EXCLUSIVE);
 
        for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
                /* see if quirk information does not match */
@@ -585,7 +583,7 @@ usb_test_quirk_by_info(const struct usbd_lookup_info *info, uint16_t quirk)
                /* lookup quirk */
                for (y = 0; y != USB_SUB_QUIRKS_MAX; y++) {
                        if (usb_quirks[x].quirks[y] == quirk) {
-                               mtx_unlock(&usb_quirk_mtx);
+                               lockmgr(&usb_quirk_lock, LK_RELEASE);
                                DPRINTF("Found quirk '%s'.\n", usb_quirkstr(quirk));
                                return (1);
                        }
@@ -593,7 +591,7 @@ usb_test_quirk_by_info(const struct usbd_lookup_info *info, uint16_t quirk)
                /* no quirk found */
                break;
        }
-       mtx_unlock(&usb_quirk_mtx);
+       lockmgr(&usb_quirk_lock, LK_RELEASE);
 done:
        return (0);                     /* no quirk match */
 }
@@ -604,7 +602,7 @@ usb_quirk_get_entry(uint16_t vid, uint16_t pid,
 {
        uint16_t x;
 
-       mtx_assert(&usb_quirk_mtx, MA_OWNED);
+       KKASSERT(lockowned(&usb_quirk_lock));
 
        if ((vid | pid | lo_rev | hi_rev) == 0) {
                /* all zero - special case */
@@ -672,7 +670,7 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                if (y >= USB_DEV_QUIRKS_MAX) {
                        return (EINVAL);
                }
-               mtx_lock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_EXCLUSIVE);
                /* copy out data */
                pgq->vid = usb_quirks[y].vid;
                pgq->pid = usb_quirks[y].pid;
@@ -681,7 +679,7 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                strlcpy(pgq->quirkname,
                    usb_quirkstr(usb_quirks[y].quirks[x]),
                    sizeof(pgq->quirkname));
-               mtx_unlock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_RELEASE);
                return (0);             /* success */
 
        case USB_QUIRK_NAME_GET:
@@ -714,11 +712,11 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                if (y == UQ_NONE) {
                        return (EINVAL);
                }
-               mtx_lock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_EXCLUSIVE);
                pqe = usb_quirk_get_entry(pgq->vid, pgq->pid,
                    pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 1);
                if (pqe == NULL) {
-                       mtx_unlock(&usb_quirk_mtx);
+                       lockmgr(&usb_quirk_lock, LK_RELEASE);
                        return (EINVAL);
                }
                for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
@@ -727,7 +725,7 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                                break;
                        }
                }
-               mtx_unlock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_RELEASE);
                if (x == USB_SUB_QUIRKS_MAX) {
                        return (ENOMEM);
                }
@@ -752,11 +750,11 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                if (y == UQ_NONE) {
                        return (EINVAL);
                }
-               mtx_lock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_EXCLUSIVE);
                pqe = usb_quirk_get_entry(pgq->vid, pgq->pid,
                    pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 0);
                if (pqe == NULL) {
-                       mtx_unlock(&usb_quirk_mtx);
+                       lockmgr(&usb_quirk_lock, LK_RELEASE);
                        return (EINVAL);
                }
                for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
@@ -766,7 +764,7 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                        }
                }
                if (x == USB_SUB_QUIRKS_MAX) {
-                       mtx_unlock(&usb_quirk_mtx);
+                       lockmgr(&usb_quirk_lock, LK_RELEASE);
                        return (ENOMEM);
                }
                for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
@@ -778,7 +776,7 @@ usb_quirk_ioctl(unsigned long cmd, caddr_t data,
                        /* all quirk entries are unused - release */
                        memset(pqe, 0, sizeof(pqe));
                }
-               mtx_unlock(&usb_quirk_mtx);
+               lockmgr(&usb_quirk_lock, LK_RELEASE);
                return (0);             /* success */
 
        default:
@@ -791,7 +789,7 @@ static void
 usb_quirk_init(void *arg)
 {
        /* initialize mutex */
-       mtx_init(&usb_quirk_mtx, "USB quirk", NULL, MTX_DEF);
+       lockinit(&usb_quirk_lock, "USB quirk", 0, 0);
 
        /* register our function */
        usb_test_quirk_p = &usb_test_quirk_by_info;
@@ -804,8 +802,8 @@ usb_quirk_uninit(void *arg)
        usb_quirk_unload(arg);
 
        /* destroy mutex */
-       mtx_destroy(&usb_quirk_mtx);
+       lockuninit(&usb_quirk_lock);
 }
 
-SYSINIT(usb_quirk_init, SI_SUB_LOCK, SI_ORDER_FIRST, usb_quirk_init, NULL);
-SYSUNINIT(usb_quirk_uninit, SI_SUB_LOCK, SI_ORDER_ANY, usb_quirk_uninit, NULL);
+SYSINIT(usb_quirk_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, usb_quirk_init, NULL);
+SYSUNINIT(usb_quirk_uninit, SI_SUB_DRIVERS, SI_ORDER_ANY, usb_quirk_uninit, NULL);
index 7874b6a..ba4700d 100644 (file)
@@ -2240,6 +2240,10 @@ bus/u4b/input/ums.c                      optional ums usb4bsd
 bus/u4b/input/uep.c                    optional uep usb4bsd
 bus/u4b/input/uhid.c                   optional uhid usb4bsd
 #
+# USB quirks
+#
+bus/u4b/quirk/usb_quirk.c              optional usb4bsd
+#
 # Other drivers
 #
 bus/u4b/audio/uaudio.c                 optional snd_uaudio usb4bsd