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]>
---
The patch currently creates a minor for each physical endpoint (rather
than logical endpoint). I'm not sure which way is easier/better, I just
picked one.
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.
I diffed against Linus' current git tree. Let me know if I should diff
against another tree.
drivers/usb/core/endpoint.c | 10 +++++++---
drivers/usb/core/file.c | 24 ++++++++++++++++++++++++
drivers/usb/core/hcd.c | 2 --
drivers/usb/core/hcd.h | 2 ++
drivers/usb/core/usb.c | 6 ++++++
drivers/usb/core/usb.h | 4 ++++
6 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 3b2d137..eb5649e 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -226,12 +226,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;
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index f794f07..b1562e1 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -21,10 +21,13 @@ #include <linux/errno.h>
#include <linux/usb.h>
#include "usb.h"
+#include "hcd.h"
#define MAX_USB_MINORS 256
+#define MAX_ENDPOINT_MINORS (USB_MAXBUS*128*32)
static const struct file_operations *usb_minors[MAX_USB_MINORS];
static DEFINE_SPINLOCK(minor_lock);
+int usb_endpoints_major;
static int usb_open(struct inode * inode, struct file * file)
{
@@ -123,6 +126,27 @@ void usb_major_cleanup(void)
unregister_chrdev(USB_MAJOR, "usb");
}
+int 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 endpoints_major_cleanup(void)
+{
+ unregister_chrdev_region(MKDEV(usb_endpoints_major, 0),
MAX_ENDPOINT_MINORS);
+}
+
/**
* usb_register_dev - register a USB device, and ask for a minor number
* @intf: pointer to the usb_interface that is being registered
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index afa2dd2..cb44d99 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -86,8 +86,6 @@ #include "hub.h"
LIST_HEAD (usb_bus_list);
EXPORT_SYMBOL_GPL (usb_bus_list);
-/* used when allocating bus numbers */
-#define USB_MAXBUS 64
struct usb_busmap {
unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))];
};
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 8f8df0d..87548c9 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -466,6 +466,8 @@ #define bitmap DeviceRemovable
#define RUN_CONTEXT (in_irq () ? "in_irq" \
: (in_interrupt () ? "in_interrupt" : "can sleep"))
+/* used when allocating bus numbers */
+#define USB_MAXBUS 64
#endif /* __KERNEL__ */
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 467cb02..f6218cf 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1018,6 +1018,9 @@ static int __init usb_init(void)
retval = usb_major_init();
if (retval)
goto major_init_failed;
+ retval = endpoints_major_init();
+ if (retval)
+ goto endpoints_major_init_failed;
retval = usb_register(&usbfs_driver);
if (retval)
goto driver_register_failed;
@@ -1042,6 +1045,8 @@ fs_init_failed:
usbdevice_init_failed:
usb_deregister(&usbfs_driver);
driver_register_failed:
+ endpoints_major_cleanup();
+endpoints_major_init_failed:
usb_major_cleanup();
major_init_failed:
usb_host_cleanup();
@@ -1063,6 +1068,7 @@ static void __exit usb_exit(void)
return;
usb_deregister_device_driver(&usb_generic_driver);
+ endpoints_major_cleanup();
usb_major_cleanup();
usbfs_cleanup();
usb_deregister(&usbfs_driver);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 13322e3..23f95b1 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -26,6 +26,8 @@ extern int usb_hub_init(void);
extern void usb_hub_cleanup(void);
extern int usb_major_init(void);
extern void usb_major_cleanup(void);
+extern int endpoints_major_init(void);
+extern void endpoints_major_cleanup(void);
extern int usb_host_init(void);
extern void usb_host_cleanup(void);
@@ -152,3 +154,5 @@ extern void usb_notify_remove_device(str
extern void usb_notify_add_bus(struct usb_bus *ubus);
extern void usb_notify_remove_bus(struct usb_bus *ubus);
+/* usbfs2 stuff */
+extern int usb_endpoints_major;
--
1.4.3.2
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel