summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2010-10-14 20:38:18 +0000
committerhselasky <hselasky@FreeBSD.org>2010-10-14 20:38:18 +0000
commit1c90ef127420e8aa353a34eb7fcf3d20ec303c46 (patch)
treed4dbe756b857cc1d5d92c6a6cbe7950dc7456747
parentd82c33e9e33482e03f46031fd3c98d3967ce094e (diff)
downloadFreeBSD-src-1c90ef127420e8aa353a34eb7fcf3d20ec303c46.zip
FreeBSD-src-1c90ef127420e8aa353a34eb7fcf3d20ec303c46.tar.gz
- Add support for LibUSB in 32-bit compatibility mode.
Approved by: thompsa (mentor)
-rw-r--r--lib/libusb/Makefile4
-rw-r--r--lib/libusb/libusb20.c14
-rw-r--r--lib/libusb/libusb20_int.h10
-rw-r--r--lib/libusb/libusb20_ugen20.c18
-rw-r--r--sys/dev/usb/usb_ioctl.h21
5 files changed, 51 insertions, 16 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 7405ef3..10e590e 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -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>
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index 3efa9c7..f8edfc3 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -320,7 +320,7 @@ libusb20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
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 libusb20_transfer *xfer, uint32_t nFrames)
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 libusb20_transfer *xfer, void *psetup, void *pB
{
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 libusb20_transfer *xfer, void *psetup, void *pB
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 libusb20_transfer *xfer, void *psetup, void *pB
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_transfer *xfer, void *pBuf, uint32_t leng
/* 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;
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index b0e0e2d..64885f2 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -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:
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index 73daa40..5b7d5e8 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -226,7 +226,7 @@ ugen20_readdir(struct ugen20_urd_state *st)
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 *pdev)
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 libusb20_device *pdev,
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 libusb20_device *pdev,
/* 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_device *pdev,
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, uint32_t MaxBufSize,
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 libusb20_device *pdev,
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;
diff --git a/sys/dev/usb/usb_ioctl.h b/sys/dev/usb/usb_ioctl.h
index f9018e2..8fe55e1 100644
--- a/sys/dev/usb/usb_ioctl.h
+++ b/sys/dev/usb/usb_ioctl.h
@@ -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;
};
OpenPOWER on IntegriCloud