This patch is an update for Greg K-H's proposed usbfs2:
http://sourceforge.net/mailarchive/message.php?msg_id=19295229

It creates a dynamic major for USB endpoints and fixes
the endpoint minor calculation.

Signed-off-by: Sarah Bailey <[EMAIL PROTECTED]>
---

On Mon, Nov 13, 2006 at 03:44:31PM -0800, Greg KH wrote:
> On Mon, Nov 13, 2006 at 03:22:35PM -0800, Sarah Bailey wrote:
> > Signed-off-by: Sarah Bailey <[EMAIL PROTECTED]>
> 
> This address is different from your "From:" line, should they be the
> same?

Yes, they should be the same.  I had git and mutt configured for two
different addresses, but my git configuration is updated now.

> > The patch uses the newer way of allocating major numbers to allocate as
> > many minor numbers as the system would need.  The host controller file
> > specifies a maximum of 64 USB busses; each one can have 128 devices with
> > 32 physical endpoints.  That results in 262,144 minors.  I thought about
> > adding minors as each new bus was added (perhaps in usb_register_bus in
> > hcd.c or by registering a new function using usb_register_notify in
> > hcd.c).  In the end, I went with the simpler patch.
> 
> Hm, how about just using the code in idr.h to just get an arbitrary
> number.  That interface will handle giving the numbers back when needed,
> and that way you don't have to rely on the fact that we don't have more
> than 64 USB busses in the system at once.
> 
> It should make the code a bit simpler too.

Here's a patch that addresses your other suggestions, but I didn't quite
understand this one.  Are you suggesting that I use the code in idr.h to
dynamically allocate minor numbers?  I thought we have to preallocate
minor numbers, because we can't call register_chrdev_region() more than
once.

I looked for other drivers that use idr.h to handle minor numbers, but I
didn't see any. Can you give me an example?

Sarah Bailey


 drivers/usb/core/endpoint.c |   33 ++++++++++++++++++++++++++++++---
 drivers/usb/core/endpoint.h |    4 ++++
 drivers/usb/core/usb.c      |    7 +++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 3b2d137..9edf4fd 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -12,7 +12,10 @@
 #include <linux/kernel.h>
 #include <linux/usb.h>
 #include "usb.h"
+#include "endpoint.h"
 
+#define MAX_ENDPOINT_MINORS (64*128*32)
+int usb_endpoints_major;
 /* endpoint stuff */
 
 struct ep_device {
@@ -226,12 +229,16 @@ int usb_create_ep_files(struct device *p
                goto error_alloc;
        }
 
-       /* fun calculation to determine the minor of this endpoint */
-       minor = (((udev->bus->busnum - 1) * 128) * 16) + (udev->devnum - 1);
+       /* fun calculation to determine the minor of this endpoint
+        * using the endpoint physical address
+        */
+       minor = (((udev->bus->busnum - 1) * 128 + (udev->devnum - 1))*32) +
+               ((endpoint->desc.bEndpointAddress*0xF) << 1) +
+               ((endpoint->desc.bEndpointAddress*0x80) >> 7);
 
        ep_dev->desc = &endpoint->desc;
        ep_dev->udev = udev;
-       ep_dev->dev.devt = MKDEV(442, minor);   // FIXME fake number...
+       ep_dev->dev.devt = MKDEV(usb_endpoints_major, minor);
        ep_dev->dev.class = ep_class->class;
        ep_dev->dev.parent = parent;
        ep_dev->dev.release = ep_device_release;
@@ -283,3 +290,23 @@ void usb_remove_ep_files(struct usb_host
                destroy_endpoint_class();
        }
 }
+
+int usb_endpoints_major_init(void)
+{
+       dev_t dev;
+       int error;
+
+       error = alloc_chrdev_region(&dev, 0, MAX_ENDPOINT_MINORS, 
"usb_endpoint");
+       if (error) {
+               err("unable to get a dynamic major for usb endpoints");
+               return error;
+       }
+       usb_endpoints_major = MAJOR(dev);
+
+       return error;
+}
+
+void usb_endpoints_major_cleanup(void)
+{
+       unregister_chrdev_region(MKDEV(usb_endpoints_major, 0), 
MAX_ENDPOINT_MINORS);
+}
diff --git a/drivers/usb/core/endpoint.h b/drivers/usb/core/endpoint.h
new file mode 100644
index 0000000..93ec3c5
--- /dev/null
+++ b/drivers/usb/core/endpoint.h
@@ -0,0 +1,4 @@
+/* Endpoint major functions local to drivers/usb/core/ */
+
+extern int usb_endpoints_major_init(void);
+extern void usb_endpoints_major_cleanup(void);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 467cb02..ca285e8 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -42,6 +42,7 @@
 
 #include "hcd.h"
 #include "usb.h"
+#include "endpoint.h"
 
 
 const char *usbcore_name = "usbcore";
@@ -1018,6 +1019,9 @@ static int __init usb_init(void)
        retval = usb_major_init();
        if (retval)
                goto major_init_failed;
+       retval = usb_endpoints_major_init();
+       if (retval)
+               goto endpoints_major_init_failed;
        retval = usb_register(&usbfs_driver);
        if (retval)
                goto driver_register_failed;
@@ -1042,6 +1046,8 @@ fs_init_failed:
 usbdevice_init_failed:
        usb_deregister(&usbfs_driver);
 driver_register_failed:
+       usb_endpoints_major_cleanup();
+endpoints_major_init_failed:
        usb_major_cleanup();
 major_init_failed:
        usb_host_cleanup();
@@ -1063,6 +1069,7 @@ static void __exit usb_exit(void)
                return;
 
        usb_deregister_device_driver(&usb_generic_driver);
+       usb_endpoints_major_cleanup();
        usb_major_cleanup();
        usbfs_cleanup();
        usb_deregister(&usbfs_driver);
-- 
1.4.3.3


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to