svn commit: r213852 - in head: lib/libusb sys/dev/usb

Hans Petter Selasky hselasky at FreeBSD.org
Thu Oct 14 20:38:19 UTC 2010


Author: hselasky
Date: Thu Oct 14 20:38:18 2010
New Revision: 213852
URL: http://svn.freebsd.org/changeset/base/213852

Log:
  - Add support for LibUSB in 32-bit compatibility mode.
  
  Approved by:    thompsa (mentor)

Modified:
  head/lib/libusb/Makefile
  head/lib/libusb/libusb20.c
  head/lib/libusb/libusb20_int.h
  head/lib/libusb/libusb20_ugen20.c
  head/sys/dev/usb/usb_ioctl.h

Modified: head/lib/libusb/Makefile
==============================================================================
--- head/lib/libusb/Makefile	Thu Oct 14 20:31:07 2010	(r213851)
+++ head/lib/libusb/Makefile	Thu Oct 14 20:38:18 2010	(r213852)
@@ -30,5 +30,9 @@ SRCS+=		libusb10.c
 SRCS+=		libusb10_desc.c
 SRCS+=		libusb10_io.c
 
+.if defined(COMPAT_32BIT)
+CFLAGS+=	-DCOMPAT_32BIT
+.endif
+
 .include <bsd.lib.mk>
 

Modified: head/lib/libusb/libusb20.c
==============================================================================
--- head/lib/libusb/libusb20.c	Thu Oct 14 20:31:07 2010	(r213851)
+++ head/lib/libusb/libusb20.c	Thu Oct 14 20:38:18 2010	(r213852)
@@ -320,7 +320,7 @@ libusb20_tr_clear_stall_sync(struct libu
 void
 libusb20_tr_set_buffer(struct libusb20_transfer *xfer, void *buffer, uint16_t frIndex)
 {
-	xfer->ppBuffer[frIndex] = buffer;
+	xfer->ppBuffer[frIndex] = libusb20_pass_ptr(buffer);
 	return;
 }
 
@@ -386,7 +386,7 @@ libusb20_tr_set_total_frames(struct libu
 void
 libusb20_tr_setup_bulk(struct libusb20_transfer *xfer, void *pBuf, uint32_t length, uint32_t timeout)
 {
-	xfer->ppBuffer[0] = pBuf;
+	xfer->ppBuffer[0] = libusb20_pass_ptr(pBuf);
 	xfer->pLength[0] = length;
 	xfer->timeout = timeout;
 	xfer->nFrames = 1;
@@ -398,7 +398,7 @@ libusb20_tr_setup_control(struct libusb2
 {
 	uint16_t len;
 
-	xfer->ppBuffer[0] = psetup;
+	xfer->ppBuffer[0] = libusb20_pass_ptr(psetup);
 	xfer->pLength[0] = 8;		/* fixed */
 	xfer->timeout = timeout;
 
@@ -406,7 +406,7 @@ libusb20_tr_setup_control(struct libusb2
 
 	if (len != 0) {
 		xfer->nFrames = 2;
-		xfer->ppBuffer[1] = pBuf;
+		xfer->ppBuffer[1] = libusb20_pass_ptr(pBuf);
 		xfer->pLength[1] = len;
 	} else {
 		xfer->nFrames = 1;
@@ -417,7 +417,7 @@ libusb20_tr_setup_control(struct libusb2
 void
 libusb20_tr_setup_intr(struct libusb20_transfer *xfer, void *pBuf, uint32_t length, uint32_t timeout)
 {
-	xfer->ppBuffer[0] = pBuf;
+	xfer->ppBuffer[0] = libusb20_pass_ptr(pBuf);
 	xfer->pLength[0] = length;
 	xfer->timeout = timeout;
 	xfer->nFrames = 1;
@@ -431,7 +431,7 @@ libusb20_tr_setup_isoc(struct libusb20_t
 		/* should not happen */
 		return;
 	}
-	xfer->ppBuffer[frIndex] = pBuf;
+	xfer->ppBuffer[frIndex] = libusb20_pass_ptr(pBuf);
 	xfer->pLength[frIndex] = length;
 	return;
 }
@@ -1167,7 +1167,7 @@ libusb20_be_alloc_ugen20(void)
 {
 	struct libusb20_backend *pbe;
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 	pbe = libusb20_be_alloc(&libusb20_ugen20_backend);
 #else
 	pbe = NULL;

Modified: head/lib/libusb/libusb20_int.h
==============================================================================
--- head/lib/libusb/libusb20_int.h	Thu Oct 14 20:31:07 2010	(r213851)
+++ head/lib/libusb/libusb20_int.h	Thu Oct 14 20:38:18 2010	(r213852)
@@ -31,6 +31,12 @@
 #ifndef _LIBUSB20_INT_H_
 #define	_LIBUSB20_INT_H_
 
+#ifdef COMPAT_32BIT
+#define	libusb20_pass_ptr(ptr)	((uint64_t)(uintptr_t)(ptr))
+#else
+#define	libusb20_pass_ptr(ptr)	(ptr)
+#endif
+
 struct libusb20_device;
 struct libusb20_backend;
 struct libusb20_transfer;
@@ -146,7 +152,11 @@ struct libusb20_transfer {
 	/*
 	 * Pointer to a list of buffer pointers:
 	 */
+#ifdef COMPAT_32BIT
+	uint64_t *ppBuffer;
+#else
 	void  **ppBuffer;
+#endif
 	/*
 	 * Pointer to frame lengths, which are updated to actual length
 	 * after the USB transfer completes:

Modified: head/lib/libusb/libusb20_ugen20.c
==============================================================================
--- head/lib/libusb/libusb20_ugen20.c	Thu Oct 14 20:31:07 2010	(r213851)
+++ head/lib/libusb/libusb20_ugen20.c	Thu Oct 14 20:38:18 2010	(r213852)
@@ -226,7 +226,7 @@ ugen20_readdir(struct ugen20_urd_state *
 repeat:
 	if (st->ptr == NULL) {
 		st->urd.urd_startentry += st->nparsed;
-		st->urd.urd_data = st->buf;
+		st->urd.urd_data = libusb20_pass_ptr(st->buf);
 		st->urd.urd_maxlen = sizeof(st->buf);
 		st->nparsed = 0;
 
@@ -339,7 +339,7 @@ ugen20_tr_renew(struct libusb20_device *
 
 	memset(&fs_init, 0, sizeof(fs_init));
 
-	fs_init.pEndpoints = pdev->privBeData;
+	fs_init.pEndpoints = libusb20_pass_ptr(pdev->privBeData);
 	fs_init.ep_index_max = nMaxTransfer;
 
 	if (ioctl(pdev->file, USB_FS_INIT, &fs_init)) {
@@ -453,7 +453,7 @@ ugen20_get_config_desc_full(struct libus
 	memset(&cdesc, 0, sizeof(cdesc));
 	memset(&gen_desc, 0, sizeof(gen_desc));
 
-	gen_desc.ugd_data = &cdesc;
+	gen_desc.ugd_data = libusb20_pass_ptr(&cdesc);
 	gen_desc.ugd_maxlen = sizeof(cdesc);
 	gen_desc.ugd_config_index = cfg_index;
 
@@ -474,7 +474,7 @@ ugen20_get_config_desc_full(struct libus
 	/* make sure memory is initialised */
 	memset(ptr, 0, len);
 
-	gen_desc.ugd_data = ptr;
+	gen_desc.ugd_data = libusb20_pass_ptr(ptr);
 	gen_desc.ugd_maxlen = len;
 
 	error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
@@ -666,7 +666,7 @@ ugen20_do_request_sync(struct libusb20_d
 
 	memset(&req, 0, sizeof(req));
 
-	req.ucr_data = data;
+	req.ucr_data = libusb20_pass_ptr(data);
 	if (!(flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
 		req.ucr_flags |= USB_SHORT_XFER_OK;
 	}
@@ -761,9 +761,9 @@ ugen20_tr_open(struct libusb20_transfer 
 	xfer->maxTotalLength = temp.max_bufsize;
 	xfer->maxPacketLen = temp.max_packet_length;
 
-	/* setup buffer and length lists */
-	fsep->ppBuffer = xfer->ppBuffer;/* zero copy */
-	fsep->pLength = xfer->pLength;	/* zero copy */
+	/* setup buffer and length lists using zero copy */
+	fsep->ppBuffer = libusb20_pass_ptr(xfer->ppBuffer);
+	fsep->pLength = libusb20_pass_ptr(xfer->pLength);
 
 	return (0);			/* success */
 }
@@ -883,7 +883,7 @@ ugen20_dev_get_iface_desc(struct libusb2
 
 	memset(&ugd, 0, sizeof(ugd));
 
-	ugd.ugd_data = buf;
+	ugd.ugd_data = libusb20_pass_ptr(buf);
 	ugd.ugd_maxlen = len;
 	ugd.ugd_iface_index = iface_index;
 

Modified: head/sys/dev/usb/usb_ioctl.h
==============================================================================
--- head/sys/dev/usb/usb_ioctl.h	Thu Oct 14 20:31:07 2010	(r213851)
+++ head/sys/dev/usb/usb_ioctl.h	Thu Oct 14 20:38:18 2010	(r213852)
@@ -41,13 +41,21 @@
 #define	USB_GENERIC_NAME "ugen"
 
 struct usb_read_dir {
+#ifdef COMPAT_32BIT
+	uint64_t urd_data;
+#else
 	void   *urd_data;
+#endif
 	uint32_t urd_startentry;
 	uint32_t urd_maxlen;
 };
 
 struct usb_ctl_request {
+#ifdef COMPAT_32BIT
+	uint64_t ucr_data;
+#else
 	void   *ucr_data;
+#endif
 	uint16_t ucr_flags;
 	uint16_t ucr_actlen;		/* actual length transferred */
 	uint8_t	ucr_addr;		/* zero - currently not used */
@@ -60,7 +68,11 @@ struct usb_alt_interface {
 };
 
 struct usb_gen_descriptor {
+#ifdef COMPAT_32BIT
+	uint64_t ugd_data;
+#else
 	void   *ugd_data;
+#endif
 	uint16_t ugd_lang_id;
 	uint16_t ugd_maxlen;
 	uint16_t ugd_actlen;
@@ -126,9 +138,14 @@ struct usb_fs_endpoint {
 	 * NOTE: isochronous USB transfer only use one buffer, but can have
 	 * multiple frame lengths !
 	 */
+#ifdef COMPAT_32BIT
+	uint64_t ppBuffer;
+	uint64_t pLength;
+#else
 	void  **ppBuffer;		/* pointer to userland buffers */
 	uint32_t *pLength;		/* pointer to frame lengths, updated
 					 * to actual length */
+#endif
 	uint32_t nFrames;		/* number of frames */
 	uint32_t aFrames;		/* actual number of frames */
 	uint16_t flags;
@@ -150,7 +167,11 @@ struct usb_fs_endpoint {
 
 struct usb_fs_init {
 	/* userland pointer to endpoints structure */
+#ifdef COMPAT_32BIT
+	uint64_t pEndpoints;
+#else
 	struct usb_fs_endpoint *pEndpoints;
+#endif
 	/* maximum number of endpoints */
 	uint8_t	ep_index_max;
 };


More information about the svn-src-head mailing list