Hi all,

Here's a patch against 2.5.8 that adds fine grain minor allocation to
the usb core code.  Now we can ask for only 1 minor number from the USB
core if we want.  I also converted all of the current drivers to work
properly.  With this patch, my /proc/usb/drivers looks like the
following with a few drivers loaded:
                 usbfs
                 hub
          0- 15: usblp
             64: rio500
        240-243: dabusb
             32: mdc800

This shows that the rio500 and mdc800 driver only use 1 minor, while the
dabusb driver uses 4 minors, and the printer driver uses 16.  I've also
updated the list on the linux-usb.org site of minor numbers used by the
USB subsystem to reflect that fact that some drivers do not use all 16
minors previously assigned to them.

thanks,

greg k-h



diff -Nru a/drivers/usb/class/printer.c b/drivers/usb/class/printer.c
--- a/drivers/usb/class/printer.c       Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/class/printer.c       Thu Apr 18 21:57:10 2002
@@ -1090,6 +1090,7 @@
        disconnect:     usblp_disconnect,
        fops:           &usblp_fops,
        minor:          USBLP_MINOR_BASE,
+       num_minors:     USBLP_MINORS,
        id_table:       usblp_ids,
 };
 
diff -Nru a/drivers/usb/core/drivers.c b/drivers/usb/core/drivers.c
--- a/drivers/usb/core/drivers.c        Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/core/drivers.c        Thu Apr 18 21:57:10 2002
@@ -71,8 +71,10 @@
                int minor = driver->fops ? driver->minor : -1;
                if (minor == -1)
                        start += sprintf (start, "         %s\n", driver->name);
+               else if (driver->num_minors == 1)
+                       start += sprintf (start, "    %3d: %s\n", minor, driver->name);
                else
-                       start += sprintf (start, "%3d-%3d: %s\n", minor, minor + 15, 
driver->name);
+                       start += sprintf (start, "%3d-%3d: %s\n", minor, minor + 
+driver->num_minors - 1, driver->name);
                if (start > end) {
                        start += sprintf(start, "(truncated)\n");
                        break;
diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c    Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/core/usb.c    Thu Apr 18 21:57:10 2002
@@ -59,7 +59,7 @@
 
 devfs_handle_t usb_devfs_handle;       /* /dev/usb dir. */
 
-static struct usb_driver *usb_minors[16];
+static struct usb_driver *usb_minors[256];
 
 /**
  *     usb_register - register a USB driver
@@ -72,12 +72,17 @@
  */
 int usb_register(struct usb_driver *new_driver)
 {
+       int i;
+
        if (new_driver->fops != NULL) {
-               if (usb_minors[new_driver->minor/16]) {
-                        err("error registering %s driver", new_driver->name);
-                       return -EINVAL;
+               for (i = new_driver->minor; i < new_driver->minor + 
+new_driver->num_minors; ++i) {
+                       if (usb_minors[i]) {
+                               err("error registering %s driver", new_driver->name);
+                               return -EINVAL;
+                       }
                }
-               usb_minors[new_driver->minor/16] = new_driver;
+               for (i = new_driver->minor; i < new_driver->minor + 
+new_driver->num_minors; ++i)
+                       usb_minors[i] = new_driver;
        }
 
        info("registered new driver %s", new_driver->name);
@@ -172,10 +177,12 @@
 void usb_deregister(struct usb_driver *driver)
 {
        struct list_head *tmp;
+       int i;
 
        info("deregistering driver %s", driver->name);
        if (driver->fops != NULL)
-               usb_minors[driver->minor/16] = NULL;
+               for (i = driver->minor; i < driver->minor + driver->num_minors; ++i)
+                       usb_minors[i] = NULL;
 
        /*
         * first we remove the driver, to be sure it doesn't get used by
@@ -2517,7 +2524,7 @@
 static int usb_open(struct inode * inode, struct file * file)
 {
        int minor = minor(inode->i_rdev);
-       struct usb_driver *c = usb_minors[minor/16];
+       struct usb_driver *c = usb_minors[minor];
        int err = -ENODEV;
        struct file_operations *old_fops, *new_fops = NULL;
 
diff -Nru a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
--- a/drivers/usb/image/mdc800.c        Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/image/mdc800.c        Thu Apr 18 21:57:10 2002
@@ -933,6 +933,7 @@
        disconnect:     mdc800_usb_disconnect,
        fops:           &mdc800_device_ops,
        minor:          MDC800_DEVICE_MINOR_BASE,
+       num_minors:     1,
        id_table:       mdc800_table
 };
 
diff -Nru a/drivers/usb/image/scanner.c b/drivers/usb/image/scanner.c
--- a/drivers/usb/image/scanner.c       Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/image/scanner.c       Thu Apr 18 21:57:10 2002
@@ -1100,6 +1100,7 @@
        disconnect:     disconnect_scanner,
        fops:           &usb_scanner_fops,
        minor:          SCN_BASE_MNR,
+       num_minors:     SCN_MAX_MNR,
        id_table:       NULL, /* This would be scanner_device_ids, but we
                                 need to check every USB device, in case
                                 we match a user defined vendor/product ID. */
diff -Nru a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
--- a/drivers/usb/input/hiddev.c        Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/input/hiddev.c        Thu Apr 18 21:57:10 2002
@@ -678,10 +678,11 @@
 
 
 static /* const */ struct usb_driver hiddev_driver = {
-       name:   "hiddev",
-       probe:  hiddev_usbd_probe,
-       fops:   &hiddev_fops,
-       minor:  HIDDEV_MINOR_BASE
+       name:           "hiddev",
+       probe:          hiddev_usbd_probe,
+       fops:           &hiddev_fops,
+       minor:          HIDDEV_MINOR_BASE,
+       num_minors:     HIDDEV_MINORS,
 };
 
 int __init hiddev_init(void)
diff -Nru a/drivers/usb/media/dabusb.c b/drivers/usb/media/dabusb.c
--- a/drivers/usb/media/dabusb.c        Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/media/dabusb.c        Thu Apr 18 21:57:10 2002
@@ -801,6 +801,7 @@
        disconnect:     dabusb_disconnect,
        fops:           &dabusb_fops,
        minor:          DABUSB_MINOR,
+       num_minors:     NRDABUSB,
        id_table:       dabusb_ids,
 };
 
diff -Nru a/drivers/usb/media/dsbr100.c b/drivers/usb/media/dsbr100.c
--- a/drivers/usb/media/dsbr100.c       Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/media/dsbr100.c       Thu Apr 18 21:57:10 2002
@@ -128,8 +128,6 @@
        name:           "dsbr100",
        probe:          usb_dsbr100_probe,
        disconnect:     usb_dsbr100_disconnect,
-       fops:           NULL,
-       minor:          0,
        id_table:       usb_dsbr100_table,
 };
 
diff -Nru a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
--- a/drivers/usb/misc/auerswald.c      Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/misc/auerswald.c      Thu Apr 18 21:57:10 2002
@@ -2138,6 +2138,7 @@
        disconnect:     auerswald_disconnect,
        fops:           &auerswald_fops,
        minor:          AUER_MINOR_BASE,
+       num_minors:     AUER_MAX_DEVICES,
        id_table:       auerswald_ids,
 };
 
diff -Nru a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
--- a/drivers/usb/misc/rio500.c Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/misc/rio500.c Thu Apr 18 21:57:10 2002
@@ -517,6 +517,7 @@
        disconnect:     disconnect_rio,
        fops:           &usb_rio_fops,
        minor:          RIO_MINOR,
+       num_minors:     1,
        id_table:       rio_table,
 };
 
diff -Nru a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
--- a/drivers/usb/usb-skeleton.c        Thu Apr 18 21:57:10 2002
+++ b/drivers/usb/usb-skeleton.c        Thu Apr 18 21:57:10 2002
@@ -187,6 +187,7 @@
        disconnect:     skel_disconnect,
        fops:           &skel_fops,
        minor:          USB_SKEL_MINOR_BASE,
+       num_minors:     MAX_DEVICES,
        id_table:       skel_table,
 };
 
diff -Nru a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h       Thu Apr 18 21:57:10 2002
+++ b/include/linux/usb.h       Thu Apr 18 21:57:10 2002
@@ -493,6 +493,8 @@
  * @minor: Used with fops to simplify creating USB character devices.
  *     Such drivers have sixteen character devices, using the USB
  *     major number and starting with this minor number.
+ * @num_minors: Used with minor to specify how many minors are used by
+ *     this driver.
  * @ioctl: Used for drivers that want to talk to userspace through
  *     the "usbfs" filesystem.  This lets devices provide ways to
  *     expose information to user space regardless of where they
@@ -534,6 +536,7 @@
 
        struct file_operations *fops;
        int minor;
+       int num_minors;
 
        struct semaphore serialize;
 

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to