[PATCH] compat USB ioctl take II was Re: compat ioctl for submiting URB

2005-01-29 Thread Christopher Li
On Sat, Jan 29, 2005 at 07:33:31AM +0100, Andi Kleen wrote:
> Issues:
> - Should use CONFIG_COMPAT, not x86-64 specific symbols
Fixed.

> - Why can't you set URB_COMPAT transparently in the emulation
> layer?  Then existing applications would hopefully work without
> changes, right?

Now I see it. That is not what I intent. I must misplace it.
I remove the USB_COMPAT in the new patch any way. It looks
cleaner.

> You may also want to preserve the __user casts, otherwise

Not sure where it is. But I need to verify this patch on Monday.
I don't have an AMD 64 at home.

Thanks.

Chris

Index: linux-2.5/include/linux/compat_ioctl.h
===
--- linux-2.5.orig/include/linux/compat_ioctl.h 2005-01-26 17:23:57.0 
-0800
+++ linux-2.5/include/linux/compat_ioctl.h  2005-01-29 00:57:16.0 
-0800
@@ -692,6 +692,9 @@
 COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
 COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
 COMPATIBLE_IOCTL(USBDEVFS_RESET)
+COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
+COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
+COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
 COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
 /* MTD */
 COMPATIBLE_IOCTL(MEMGETINFO)
Index: linux-2.5/include/linux/usbdevice_fs.h
===
--- linux-2.5.orig/include/linux/usbdevice_fs.h 2005-01-25 12:08:02.0 
-0800
+++ linux-2.5/include/linux/usbdevice_fs.h  2005-01-29 00:59:10.0 
-0800
@@ -32,6 +32,7 @@
 #define _LINUX_USBDEVICE_FS_H
 
 #include 
+#include 
 
 /* - */
 
@@ -123,6 +124,22 @@
char port [127];/* e.g. port 3 connects to device 27 */
 };
 
+struct usbdevfs_urb32 {
+   unsigned char type;
+   unsigned char endpoint;
+   compat_int_t status;
+   compat_uint_t flags;
+   compat_caddr_t buffer;
+   compat_int_t buffer_length;
+   compat_int_t actual_length;
+   compat_int_t start_frame;
+   compat_int_t number_of_packets;
+   compat_int_t error_count;
+   compat_uint_t signr;
+   compat_caddr_t usercontext; /* unused */
+   struct usbdevfs_iso_packet_desc iso_frame_desc[0];
+};
+
 #define USBDEVFS_CONTROL   _IOWR('U', 0, struct usbdevfs_ctrltransfer)
 #define USBDEVFS_BULK  _IOWR('U', 2, struct usbdevfs_bulktransfer)
 #define USBDEVFS_RESETEP   _IOR('U', 3, unsigned int)
@@ -130,9 +147,12 @@
 #define USBDEVFS_SETCONFIGURATION  _IOR('U', 5, unsigned int)
 #define USBDEVFS_GETDRIVER _IOW('U', 8, struct usbdevfs_getdriver)
 #define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
+#define USBDEVFS_SUBMITURB32   _IOR('U', 10, struct usbdevfs_urb32)
 #define USBDEVFS_DISCARDURB_IO('U', 11)
 #define USBDEVFS_REAPURB   _IOW('U', 12, void *)
+#define USBDEVFS_REAPURB32 _IOW('U', 12, u32)
 #define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
+#define USBDEVFS_REAPURBdø©NDELAY32   _IOW('U', 13, u32)
 #define USBDEVFS_DISCSIGNAL_IOR('U', 14, struct 
usbdevfs_disconnectsignal)
 #define USBDEVFS_CLAIMINTERFACE_IOR('U', 15, unsigned int)
 #define USBDEVFS_RELEASEINTERFACE  _IOR('U', 16, unsigned int)
@@ -143,5 +163,4 @@
 #define USBDEVFS_CLEAR_HALT_IOR('U', 21, unsigned int)
 #define USBDEVFS_DISCONNECT_IO('U', 22)
 #define USBDEVFS_CONNECT   _IO('U', 23)
-
 #endif /* _LINUX_USBDEVICE_FS_H */
Index: linux-2.5/fs/compat_ioctl.c
===
--- linux-2.5.orig/fs/compat_ioctl.c2005-01-25 12:08:12.0 -0800
+++ linux-2.5/fs/compat_ioctl.c 2005-01-29 00:59:27.0 -0800
@@ -2570,229 +2570,11 @@
 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
 }
 
-/* This needs more work before we can enable it.  Unfortunately
- * because of the fancy asynchronous way URB status/error is written
- * back to userspace, we'll need to fiddle with USB devio internals
- * and/or reimplement entirely the frontend of it ourselves. -DaveM
- *
- * The issue is:
- *
- * When an URB is submitted via usbdevicefs it is put onto an
- * asynchronous queue.  When the URB completes, it may be reaped
- * via another ioctl.  During this reaping the status is written
- * back to userspace along with the length of the transfer.
- *
- * We must translate into 64-bit kernel types so we pass in a kernel
- * space copy of the usbdevfs_urb structure.  This would mean that we
- * must do something to deal with the async entry reaping.  First we
- * have to deal somehow with this transitory memory we've allocated.
- * This is problematic since there are many call sites from which the
- * async entries can be destroyed (and thus when we'd need to free up
- * this kernel memory).  One of which is the close() op of usbdevicefs.
- * To handle that we'd need to make our own file_operations struct 

[PATCH] compat USB ioctl take II was Re: compat ioctl for submiting URB

2005-01-29 Thread Christopher Li
On Sat, Jan 29, 2005 at 07:33:31AM +0100, Andi Kleen wrote:
 Issues:
 - Should use CONFIG_COMPAT, not x86-64 specific symbols
Fixed.

 - Why can't you set URB_COMPAT transparently in the emulation
 layer?  Then existing applications would hopefully work without
 changes, right?

Now I see it. That is not what I intent. I must misplace it.
I remove the USB_COMPAT in the new patch any way. It looks
cleaner.

 You may also want to preserve the __user casts, otherwise

Not sure where it is. But I need to verify this patch on Monday.
I don't have an AMD 64 at home.

Thanks.

Chris

Index: linux-2.5/include/linux/compat_ioctl.h
===
--- linux-2.5.orig/include/linux/compat_ioctl.h 2005-01-26 17:23:57.0 
-0800
+++ linux-2.5/include/linux/compat_ioctl.h  2005-01-29 00:57:16.0 
-0800
@@ -692,6 +692,9 @@
 COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
 COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
 COMPATIBLE_IOCTL(USBDEVFS_RESET)
+COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
+COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
+COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
 COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
 /* MTD */
 COMPATIBLE_IOCTL(MEMGETINFO)
Index: linux-2.5/include/linux/usbdevice_fs.h
===
--- linux-2.5.orig/include/linux/usbdevice_fs.h 2005-01-25 12:08:02.0 
-0800
+++ linux-2.5/include/linux/usbdevice_fs.h  2005-01-29 00:59:10.0 
-0800
@@ -32,6 +32,7 @@
 #define _LINUX_USBDEVICE_FS_H
 
 #include linux/types.h
+#include linux/compat.h
 
 /* - */
 
@@ -123,6 +124,22 @@
char port [127];/* e.g. port 3 connects to device 27 */
 };
 
+struct usbdevfs_urb32 {
+   unsigned char type;
+   unsigned char endpoint;
+   compat_int_t status;
+   compat_uint_t flags;
+   compat_caddr_t buffer;
+   compat_int_t buffer_length;
+   compat_int_t actual_length;
+   compat_int_t start_frame;
+   compat_int_t number_of_packets;
+   compat_int_t error_count;
+   compat_uint_t signr;
+   compat_caddr_t usercontext; /* unused */
+   struct usbdevfs_iso_packet_desc iso_frame_desc[0];
+};
+
 #define USBDEVFS_CONTROL   _IOWR('U', 0, struct usbdevfs_ctrltransfer)
 #define USBDEVFS_BULK  _IOWR('U', 2, struct usbdevfs_bulktransfer)
 #define USBDEVFS_RESETEP   _IOR('U', 3, unsigned int)
@@ -130,9 +147,12 @@
 #define USBDEVFS_SETCONFIGURATION  _IOR('U', 5, unsigned int)
 #define USBDEVFS_GETDRIVER _IOW('U', 8, struct usbdevfs_getdriver)
 #define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb)
+#define USBDEVFS_SUBMITURB32   _IOR('U', 10, struct usbdevfs_urb32)
 #define USBDEVFS_DISCARDURB_IO('U', 11)
 #define USBDEVFS_REAPURB   _IOW('U', 12, void *)
+#define USBDEVFS_REAPURB32 _IOW('U', 12, u32)
 #define USBDEVFS_REAPURBNDELAY _IOW('U', 13, void *)
+#define USBDEVFS_REAPURBdø©NDELAY32   _IOW('U', 13, u32)
 #define USBDEVFS_DISCSIGNAL_IOR('U', 14, struct 
usbdevfs_disconnectsignal)
 #define USBDEVFS_CLAIMINTERFACE_IOR('U', 15, unsigned int)
 #define USBDEVFS_RELEASEINTERFACE  _IOR('U', 16, unsigned int)
@@ -143,5 +163,4 @@
 #define USBDEVFS_CLEAR_HALT_IOR('U', 21, unsigned int)
 #define USBDEVFS_DISCONNECT_IO('U', 22)
 #define USBDEVFS_CONNECT   _IO('U', 23)
-
 #endif /* _LINUX_USBDEVICE_FS_H */
Index: linux-2.5/fs/compat_ioctl.c
===
--- linux-2.5.orig/fs/compat_ioctl.c2005-01-25 12:08:12.0 -0800
+++ linux-2.5/fs/compat_ioctl.c 2005-01-29 00:59:27.0 -0800
@@ -2570,229 +2570,11 @@
 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
 }
 
-/* This needs more work before we can enable it.  Unfortunately
- * because of the fancy asynchronous way URB status/error is written
- * back to userspace, we'll need to fiddle with USB devio internals
- * and/or reimplement entirely the frontend of it ourselves. -DaveM
- *
- * The issue is:
- *
- * When an URB is submitted via usbdevicefs it is put onto an
- * asynchronous queue.  When the URB completes, it may be reaped
- * via another ioctl.  During this reaping the status is written
- * back to userspace along with the length of the transfer.
- *
- * We must translate into 64-bit kernel types so we pass in a kernel
- * space copy of the usbdevfs_urb structure.  This would mean that we
- * must do something to deal with the async entry reaping.  First we
- * have to deal somehow with this transitory memory we've allocated.
- * This is problematic since there are many call sites from which the
- * async entries can be destroyed (and thus when we'd need to free up
- * this kernel memory).  One of which is the close() op of usbdevicefs.
- * To handle that we'd need to make our own