summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2009-03-20 21:48:11 +0000
committerthompsa <thompsa@FreeBSD.org>2009-03-20 21:48:11 +0000
commite14295c787e7990fac7af1c1f196f279396b88a7 (patch)
tree5f5d9b7cd28551f4f3923401f6ffea491e559c3b
parent79aaac6e7b4553e4799500d20a8d63ea337b8925 (diff)
downloadFreeBSD-src-e14295c787e7990fac7af1c1f196f279396b88a7.zip
FreeBSD-src-e14295c787e7990fac7af1c1f196f279396b88a7.tar.gz
MFp4 //depot/projects/usb@159392
Add ifdefs for making parts of usb conditional. Submitted by: Hans Petter Selasky
-rw-r--r--sys/dev/usb/controller/at91dci.c2
-rw-r--r--sys/dev/usb/controller/atmegadci.c2
-rw-r--r--sys/dev/usb/controller/musb_otg.c2
-rw-r--r--sys/dev/usb/controller/usb_controller.c26
-rw-r--r--sys/dev/usb/controller/uss820dci.c2
-rw-r--r--sys/dev/usb/usb_busdma.c52
-rw-r--r--sys/dev/usb/usb_busdma.h30
-rw-r--r--sys/dev/usb/usb_core.h80
-rw-r--r--sys/dev/usb/usb_debug.h5
-rw-r--r--sys/dev/usb/usb_device.c12
-rw-r--r--sys/dev/usb/usb_device.h3
-rw-r--r--sys/dev/usb/usb_request.c22
-rw-r--r--sys/dev/usb/usb_transfer.c37
-rw-r--r--sys/dev/usb/usb_transfer.h12
-rw-r--r--sys/dev/usb/usb_util.c12
-rw-r--r--sys/dev/usb/usb_util.h2
16 files changed, 220 insertions, 81 deletions
diff --git a/sys/dev/usb/controller/at91dci.c b/sys/dev/usb/controller/at91dci.c
index cfb74a3..807f899 100644
--- a/sys/dev/usb/controller/at91dci.c
+++ b/sys/dev/usb/controller/at91dci.c
@@ -69,7 +69,7 @@ __FBSDID("$FreeBSD$");
USB_P2U(&(((struct at91dci_softc *)0)->sc_bus))))
#define AT9100_DCI_PC2SC(pc) \
- AT9100_DCI_BUS2SC((pc)->tag_parent->info->bus)
+ AT9100_DCI_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
static int at91dcidebug = 0;
diff --git a/sys/dev/usb/controller/atmegadci.c b/sys/dev/usb/controller/atmegadci.c
index a052385..425cfbc 100644
--- a/sys/dev/usb/controller/atmegadci.c
+++ b/sys/dev/usb/controller/atmegadci.c
@@ -62,7 +62,7 @@ __FBSDID("$FreeBSD$");
USB_P2U(&(((struct atmegadci_softc *)0)->sc_bus))))
#define ATMEGA_PC2SC(pc) \
- ATMEGA_BUS2SC((pc)->tag_parent->info->bus)
+ ATMEGA_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
static int atmegadci_debug = 0;
diff --git a/sys/dev/usb/controller/musb_otg.c b/sys/dev/usb/controller/musb_otg.c
index be0af93..9ffafa3 100644
--- a/sys/dev/usb/controller/musb_otg.c
+++ b/sys/dev/usb/controller/musb_otg.c
@@ -63,7 +63,7 @@
USB_P2U(&(((struct musbotg_softc *)0)->sc_bus))))
#define MUSBOTG_PC2SC(pc) \
- MUSBOTG_BUS2SC((pc)->tag_parent->info->bus)
+ MUSBOTG_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
static int musbotgdebug = 0;
diff --git a/sys/dev/usb/controller/usb_controller.c b/sys/dev/usb/controller/usb_controller.c
index 70099ef..fc31f15 100644
--- a/sys/dev/usb/controller/usb_controller.c
+++ b/sys/dev/usb/controller/usb_controller.c
@@ -49,15 +49,6 @@ static device_detach_t usb2_detach;
static void usb2_attach_sub(device_t, struct usb2_bus *);
static void usb2_post_init(void *);
-static void usb2_bus_mem_flush_all_cb(struct usb2_bus *,
- struct usb2_page_cache *, struct usb2_page *, uint32_t,
- uint32_t);
-static void usb2_bus_mem_alloc_all_cb(struct usb2_bus *,
- struct usb2_page_cache *, struct usb2_page *, uint32_t,
- uint32_t);
-static void usb2_bus_mem_free_all_cb(struct usb2_bus *,
- struct usb2_page_cache *, struct usb2_page *, uint32_t,
- uint32_t);
static void usb2_bus_roothub(struct usb2_proc_msg *pm);
/* static variables */
@@ -487,16 +478,19 @@ SYSUNINIT(usb2_bus_unload, SI_SUB_KLD, SI_ORDER_ANY, usb2_bus_unload, NULL);
/*------------------------------------------------------------------------*
* usb2_bus_mem_flush_all_cb
*------------------------------------------------------------------------*/
+#if USB_HAVE_BUSDMA
static void
usb2_bus_mem_flush_all_cb(struct usb2_bus *bus, struct usb2_page_cache *pc,
struct usb2_page *pg, uint32_t size, uint32_t align)
{
usb2_pc_cpu_flush(pc);
}
+#endif
/*------------------------------------------------------------------------*
* usb2_bus_mem_flush_all - factored out code
*------------------------------------------------------------------------*/
+#if USB_HAVE_BUSDMA
void
usb2_bus_mem_flush_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb)
{
@@ -504,10 +498,12 @@ usb2_bus_mem_flush_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb)
cb(bus, &usb2_bus_mem_flush_all_cb);
}
}
+#endif
/*------------------------------------------------------------------------*
* usb2_bus_mem_alloc_all_cb
*------------------------------------------------------------------------*/
+#if USB_HAVE_BUSDMA
static void
usb2_bus_mem_alloc_all_cb(struct usb2_bus *bus, struct usb2_page_cache *pc,
struct usb2_page *pg, uint32_t size, uint32_t align)
@@ -519,6 +515,7 @@ usb2_bus_mem_alloc_all_cb(struct usb2_bus *bus, struct usb2_page_cache *pc,
bus->alloc_failed = 1;
}
}
+#endif
/*------------------------------------------------------------------------*
* usb2_bus_mem_alloc_all - factored out code
@@ -541,9 +538,10 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
TAILQ_INIT(&bus->intr_q.head);
+#if USB_HAVE_BUSDMA
usb2_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags,
- dmat, &bus->bus_mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX);
-
+ dmat, &bus->bus_mtx, NULL, 32, USB_BUS_DMA_TAG_MAX);
+#endif
if ((bus->devices_max > USB_MAX_DEVICES) ||
(bus->devices_max < USB_MIN_DEVICES) ||
(bus->devices == NULL)) {
@@ -551,9 +549,11 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
"initialised properly!\n");
bus->alloc_failed = 1; /* failure */
}
+#if USB_HAVE_BUSDMA
if (cb) {
cb(bus, &usb2_bus_mem_alloc_all_cb);
}
+#endif
if (bus->alloc_failed) {
usb2_bus_mem_free_all(bus, cb);
}
@@ -563,12 +563,14 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
/*------------------------------------------------------------------------*
* usb2_bus_mem_free_all_cb
*------------------------------------------------------------------------*/
+#if USB_HAVE_BUSDMA
static void
usb2_bus_mem_free_all_cb(struct usb2_bus *bus, struct usb2_page_cache *pc,
struct usb2_page *pg, uint32_t size, uint32_t align)
{
usb2_pc_free_mem(pc);
}
+#endif
/*------------------------------------------------------------------------*
* usb2_bus_mem_free_all - factored out code
@@ -576,10 +578,12 @@ usb2_bus_mem_free_all_cb(struct usb2_bus *bus, struct usb2_page_cache *pc,
void
usb2_bus_mem_free_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb)
{
+#if USB_HAVE_BUSDMA
if (cb) {
cb(bus, &usb2_bus_mem_free_all_cb);
}
usb2_dma_tag_unsetup(bus->dma_parent_tag);
+#endif
mtx_destroy(&bus->bus_mtx);
}
diff --git a/sys/dev/usb/controller/uss820dci.c b/sys/dev/usb/controller/uss820dci.c
index 8e1e2bc..a5144ca 100644
--- a/sys/dev/usb/controller/uss820dci.c
+++ b/sys/dev/usb/controller/uss820dci.c
@@ -58,7 +58,7 @@
USB_P2U(&(((struct uss820dci_softc *)0)->sc_bus))))
#define USS820_DCI_PC2SC(pc) \
- USS820_DCI_BUS2SC((pc)->tag_parent->info->bus)
+ USS820_DCI_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
static int uss820dcidebug = 0;
diff --git a/sys/dev/usb/usb_busdma.c b/sys/dev/usb/usb_busdma.c
index 86b6921..a4422c6 100644
--- a/sys/dev/usb/usb_busdma.c
+++ b/sys/dev/usb/usb_busdma.c
@@ -41,20 +41,20 @@
#include <dev/usb/usb_controller.h>
#include <dev/usb/usb_bus.h>
+#if USB_HAVE_BUSDMA
static void usb2_dma_tag_create(struct usb2_dma_tag *, uint32_t, uint32_t);
static void usb2_dma_tag_destroy(struct usb2_dma_tag *);
+#endif
-#ifdef __FreeBSD__
+#if USB_HAVE_BUSDMA && defined(__FreeBSD__)
static void usb2_dma_lock_cb(void *, bus_dma_lock_op_t);
-static int32_t usb2_m_copy_in_cb(void *, void *, uint32_t);
static void usb2_pc_alloc_mem_cb(void *, bus_dma_segment_t *, int, int);
static void usb2_pc_load_mem_cb(void *, bus_dma_segment_t *, int, int);
static void usb2_pc_common_mem_cb(void *, bus_dma_segment_t *, int, int,
uint8_t);
#endif
-#ifdef __NetBSD__
-static int32_t usb2_m_copy_in_cb(void *, caddr_t, uint32_t);
+#if USB_HAVE_BUSDMA && defined(__NetBSD__)
static void usb2_pc_common_mem_cb(struct usb2_page_cache *,
bus_dma_segment_t *, int, int, uint8_t);
#endif
@@ -71,6 +71,7 @@ usb2_get_page(struct usb2_page_cache *pc, uint32_t offset,
{
struct usb2_page *page;
+#if USB_HAVE_BUSDMA
if (pc->page_start) {
/* Case 1 - something has been loaded into DMA */
@@ -105,14 +106,16 @@ usb2_get_page(struct usb2_page_cache *pc, uint32_t offset,
res->buffer = USB_ADD_BYTES(page->buffer, offset);
}
- } else {
-
- /* Case 2 - Plain PIO */
-
- res->buffer = USB_ADD_BYTES(pc->buffer, offset);
- res->length = 0 - 1;
- res->physaddr = 0;
+ return;
}
+#endif
+ /* Case 2 - Plain PIO */
+
+ res->buffer = USB_ADD_BYTES(pc->buffer, offset);
+ res->length = 0 - 1;
+#if USB_HAVE_BUSDMA
+ res->physaddr = 0;
+#endif
}
/*------------------------------------------------------------------------*
@@ -146,6 +149,7 @@ usb2_copy_in(struct usb2_page_cache *cache, uint32_t offset,
* 0: Success
* Else: Failure
*------------------------------------------------------------------------*/
+#if USB_HAVE_USER_IO
int
usb2_copy_in_user(struct usb2_page_cache *cache, uint32_t offset,
const void *ptr, uint32_t len)
@@ -170,10 +174,12 @@ usb2_copy_in_user(struct usb2_page_cache *cache, uint32_t offset,
}
return (0); /* success */
}
+#endif
/*------------------------------------------------------------------------*
* usb2_m_copy_in - copy a mbuf chain directly into DMA-able memory
*------------------------------------------------------------------------*/
+#if USB_HAVE_MBUF
struct usb2_m_copy_in_arg {
struct usb2_page_cache *cache;
uint32_t dst_offset;
@@ -202,10 +208,12 @@ usb2_m_copy_in(struct usb2_page_cache *cache, uint32_t dst_offset,
error = m_apply(m, src_offset, src_len, &usb2_m_copy_in_cb, &arg);
}
+#endif
/*------------------------------------------------------------------------*
* usb2_uiomove - factored out code
*------------------------------------------------------------------------*/
+#if USB_HAVE_USER_IO
int
usb2_uiomove(struct usb2_page_cache *pc, struct uio *uio,
uint32_t pc_offset, uint32_t len)
@@ -234,6 +242,7 @@ usb2_uiomove(struct usb2_page_cache *pc, struct uio *uio,
}
return (error);
}
+#endif
/*------------------------------------------------------------------------*
* usb2_copy_out - copy directly from DMA-able memory
@@ -266,6 +275,7 @@ usb2_copy_out(struct usb2_page_cache *cache, uint32_t offset,
* 0: Success
* Else: Failure
*------------------------------------------------------------------------*/
+#if USB_HAVE_USER_IO
int
usb2_copy_out_user(struct usb2_page_cache *cache, uint32_t offset,
void *ptr, uint32_t len)
@@ -290,6 +300,7 @@ usb2_copy_out_user(struct usb2_page_cache *cache, uint32_t offset,
}
return (0); /* success */
}
+#endif
/*------------------------------------------------------------------------*
* usb2_bzero - zero DMA-able memory
@@ -313,8 +324,7 @@ usb2_bzero(struct usb2_page_cache *cache, uint32_t offset, uint32_t len)
}
}
-
-#ifdef __FreeBSD__
+#if USB_HAVE_BUSDMA && defined(__FreeBSD__)
/*------------------------------------------------------------------------*
* usb2_dma_lock_cb - dummy callback
@@ -691,7 +701,7 @@ usb2_pc_dmamap_create(struct usb2_page_cache *pc, uint32_t size)
struct usb2_dma_tag *utag;
/* get info */
- info = pc->tag_parent->info;
+ info = USB_DMATAG_TO_XROOT(pc->tag_parent);
/* sanity check */
if (info == NULL) {
@@ -731,7 +741,7 @@ usb2_pc_dmamap_destroy(struct usb2_page_cache *pc)
#endif
-#ifdef __NetBSD__
+#if USB_HAVE_BUSDMA && defined(__NetBSD__)
/*------------------------------------------------------------------------*
* usb2_dma_tag_create - allocate a DMA tag
@@ -1062,7 +1072,7 @@ usb2_pc_dmamap_create(struct usb2_page_cache *pc, uint32_t size)
struct usb2_dma_tag *utag;
/* get info */
- info = pc->tag_parent->info;
+ info = USB_DMATAG_TO_XROOT(pc->tag_parent);
/* sanity check */
if (info == NULL) {
@@ -1106,6 +1116,8 @@ usb2_pc_dmamap_destroy(struct usb2_page_cache *pc)
#endif
+#if USB_HAVE_BUSDMA
+
/*------------------------------------------------------------------------*
* usb2_dma_tag_find - factored out code
*------------------------------------------------------------------------*/
@@ -1148,8 +1160,7 @@ void
usb2_dma_tag_setup(struct usb2_dma_parent_tag *udpt,
struct usb2_dma_tag *udt, bus_dma_tag_t dmat,
struct mtx *mtx, usb2_dma_callback_t *func,
- struct usb2_xfer_root *info, uint8_t ndmabits,
- uint8_t nudt)
+ uint8_t ndmabits, uint8_t nudt)
{
bzero(udpt, sizeof(*udpt));
@@ -1167,7 +1178,6 @@ usb2_dma_tag_setup(struct usb2_dma_parent_tag *udpt,
/* store some information */
udpt->mtx = mtx;
- udpt->info = info;
udpt->func = func;
udpt->tag = dmat;
udpt->utag_first = udt;
@@ -1349,7 +1359,7 @@ usb2_bdma_done_event(struct usb2_dma_parent_tag *udpt)
{
struct usb2_xfer_root *info;
- info = udpt->info;
+ info = USB_DMATAG_TO_XROOT(udpt);
mtx_assert(info->xfer_mtx, MA_OWNED);
@@ -1423,3 +1433,5 @@ usb2_bdma_post_sync(struct usb2_xfer *xfer)
pc++;
}
}
+
+#endif
diff --git a/sys/dev/usb/usb_busdma.h b/sys/dev/usb/usb_busdma.h
index 3c1600b..48b4d29 100644
--- a/sys/dev/usb/usb_busdma.h
+++ b/sys/dev/usb/usb_busdma.h
@@ -60,8 +60,10 @@ typedef void (usb2_dma_callback_t)(struct usb2_dma_parent_tag *udpt);
* address of a memory page having size USB_PAGE_SIZE.
*/
struct usb2_page {
+#if USB_HAVE_BUSDMA
bus_size_t physaddr;
void *buffer; /* non Kernel Virtual Address */
+#endif
};
/*
@@ -71,7 +73,9 @@ struct usb2_page {
*/
struct usb2_page_search {
void *buffer;
+#if USB_HAVE_BUSDMA
bus_size_t physaddr;
+#endif
uint32_t length;
};
@@ -81,62 +85,67 @@ struct usb2_page_search {
*/
struct usb2_page_cache {
-#ifdef __FreeBSD__
+#if USB_HAVE_BUSDMA && defined(__FreeBSD__)
bus_dma_tag_t tag;
bus_dmamap_t map;
#endif
-#ifdef __NetBSD__
+#if USB_HAVE_BUSDMA && defined(__NetBSD__)
bus_dma_tag_t tag;
bus_dmamap_t map;
bus_dma_segment_t *p_seg;
#endif
+#if USB_HAVE_BUSDMA
struct usb2_page *page_start;
+#endif
struct usb2_dma_parent_tag *tag_parent; /* always set */
void *buffer; /* virtual buffer pointer */
-#ifdef __NetBSD__
+#if USB_HAVE_BUSDMA && defined(_NetBSD__)
int n_seg;
#endif
+#if USB_HAVE_BUSDMA
uint32_t page_offset_buf;
uint32_t page_offset_end;
uint8_t isread:1; /* set if we are currently reading
* from the memory. Else write. */
uint8_t ismultiseg:1; /* set if we can have multiple
* segments */
+#endif
};
/*
* The following structure describes the parent USB DMA tag.
*/
struct usb2_dma_parent_tag {
-#ifdef __FreeBSD__
+#if USB_HAVE_BUSDMA && defined(__FreeBSD__)
struct cv cv[1]; /* internal condition variable */
#endif
-
+#if USB_HAVE_BUSDMA
bus_dma_tag_t tag; /* always set */
struct mtx *mtx; /* private mutex, always set */
- struct usb2_xfer_root *info; /* used by the callback function */
usb2_dma_callback_t *func; /* load complete callback function */
struct usb2_dma_tag *utag_first;/* pointer to first USB DMA tag */
-
uint8_t dma_error; /* set if DMA load operation failed */
uint8_t dma_bits; /* number of DMA address lines */
uint8_t utag_max; /* number of USB DMA tags */
+#endif
};
/*
* The following structure describes an USB DMA tag.
*/
struct usb2_dma_tag {
-#ifdef __NetBSD__
+#if USB_HAVE_BUSDMA && defined(__NetBSD__)
bus_dma_segment_t *p_seg;
#endif
+#if USB_HAVE_BUSDMA
struct usb2_dma_parent_tag *tag_parent;
bus_dma_tag_t tag;
uint32_t align;
uint32_t size;
-#ifdef __NetBSD__
+#endif
+#if USB_HAVE_BUSDMA && defined(__NetBSD__)
uint32_t n_seg;
#endif
};
@@ -168,8 +177,7 @@ int usb2_copy_out_user(struct usb2_page_cache *cache, uint32_t offset,
void *ptr, uint32_t len);
void usb2_dma_tag_setup(struct usb2_dma_parent_tag *udpt,
struct usb2_dma_tag *udt, bus_dma_tag_t dmat, struct mtx *mtx,
- usb2_dma_callback_t *func, struct usb2_xfer_root *info,
- uint8_t ndmabits, uint8_t nudt);
+ usb2_dma_callback_t *func, uint8_t ndmabits, uint8_t nudt);
void usb2_dma_tag_unsetup(struct usb2_dma_parent_tag *udpt);
void usb2_get_page(struct usb2_page_cache *pc, uint32_t offset,
struct usb2_page_search *res);
diff --git a/sys/dev/usb/usb_core.h b/sys/dev/usb/usb_core.h
index f760642..69d3965 100644
--- a/sys/dev/usb/usb_core.h
+++ b/sys/dev/usb/usb_core.h
@@ -32,16 +32,84 @@
#ifndef _USB2_CORE_H_
#define _USB2_CORE_H_
+/* Allow defines in "opt_usb.h" to override configuration */
+
+#include "opt_usb.h"
+#include "opt_bus.h"
+
/* Default USB configuration */
-#ifndef USB_USE_CONDVAR
-#define USB_USE_CONDVAR 0
+/*
+ * The following macro defines if the code shall use cv_xxx() instead
+ * of msleep() and wakeup().
+ */
+#ifndef USB_HAVE_CONDVAR
+#define USB_HAVE_CONDVAR 0
#endif
+/*
+ * The following macro defines if the code shall support
+ * /dev/usb/x.y.z.
+ */
#ifndef USB_HAVE_UGEN
#define USB_HAVE_UGEN 1
#endif
+/*
+ * The following macro defines if the code shall support any forms of
+ * ASCII strings.
+ */
+#ifndef USB_HAVE_STRINGS
+#define USB_HAVE_STRINGS 1
+#endif
+
+/*
+ * The following macro defines if the code shall support BUS-DMA.
+ */
+#ifndef USB_HAVE_BUSDMA
+#define USB_HAVE_BUSDMA 1
+#endif
+
+/*
+ * The following macro defines if the code shall support the Linux
+ * compatibility layer.
+ */
+#ifndef USB_HAVE_COMPAT_LINUX
+#define USB_HAVE_COMPAT_LINUX 1
+#endif
+
+/*
+ * The following macro defines if the code shall support
+ * userland data transfer via copyin() and copyout()
+ */
+#ifndef USB_HAVE_USER_IO
+#define USB_HAVE_USER_IO 1
+#endif
+
+/*
+ * The following macro defines if the code shall support copy in via
+ * bsd-mbufs to USB.
+ */
+#ifndef USB_HAVE_MBUF
+#define USB_HAVE_MBUF 1
+#endif
+
+/*
+ * The following macro defines if the code shall compile a table
+ * describing USB vendor and product IDs.
+ */
+#ifndef USB_VERBOSE
+#define USB_VERBOSE 1
+#endif
+
+/*
+ * The following macro defines if USB debugging support shall be
+ * compiled for the USB core and all drivers.
+ */
+#ifndef USB_DEBUG
+#define USB_DEBUG 1
+#endif
+
#ifndef USB_TD_GET_PROC
#define USB_TD_GET_PROC(td) (td)->td_proc
#endif
@@ -76,8 +144,6 @@
#include <dev/usb/usb_revision.h>
#include "usb_if.h"
-#include "opt_usb.h"
-#include "opt_bus.h"
#define USB_STACK_VERSION 2000 /* 2.0 */
@@ -95,10 +161,6 @@
#define USB_MAX_IPACKET 8 /* maximum size of the initial USB
* data packet */
-#ifndef USB_VERBOSE
-#define USB_VERBOSE 1
-#endif
-
#define USB_HUB_MAX_DEPTH 5
/* USB transfer states */
@@ -256,12 +318,14 @@ struct usb2_xfer_flags_int {
uint8_t short_frames_ok:1; /* filtered version */
uint8_t short_xfer_ok:1; /* filtered version */
+#if USB_HAVE_BUSDMA
uint8_t bdma_enable:1; /* filtered version (only set if
* hardware supports DMA) */
uint8_t bdma_no_post_sync:1; /* set if the USB callback wrapper
* should not do the BUS-DMA post sync
* operation */
uint8_t bdma_setup:1; /* set if BUS-DMA has been setup */
+#endif
uint8_t isochronous_xfr:1; /* set if isochronous transfer */
uint8_t usb2_mode:1; /* shadow copy of "udev->usb2_mode" */
uint8_t curr_dma_set:1; /* used by USB HC/DC driver */
diff --git a/sys/dev/usb/usb_debug.h b/sys/dev/usb/usb_debug.h
index 92dcbd5..3d1f872 100644
--- a/sys/dev/usb/usb_debug.h
+++ b/sys/dev/usb/usb_debug.h
@@ -35,11 +35,6 @@ SYSCTL_DECL(_hw_usb2);
/* Declare global USB debug variable. */
extern int usb2_debug;
-/* Force debugging until further */
-#ifndef USB_DEBUG
-#define USB_DEBUG 1
-#endif
-
/* Check if USB debugging is enabled. */
#ifdef USB_DEBUG_VAR
#if (USB_DEBUG != 0)
diff --git a/sys/dev/usb/usb_device.c b/sys/dev/usb/usb_device.c
index c667eac..4fcac83 100644
--- a/sys/dev/usb/usb_device.c
+++ b/sys/dev/usb/usb_device.c
@@ -44,9 +44,11 @@
#include <dev/usb/usb_hub.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_mbuf.h>
-#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_msctest.h>
+#if USB_HAVE_UGEN
+#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_generic.h>
+#endif
#include <dev/usb/quirk/usb_quirk.h>
@@ -68,7 +70,9 @@ static void usb2_init_attach_arg(struct usb2_device *,
static void usb2_suspend_resume_sub(struct usb2_device *, device_t,
uint8_t);
static void usb2_clear_stall_proc(struct usb2_proc_msg *_pm);
+#if USB_HAVE_STRINGS
static void usb2_check_strings(struct usb2_device *);
+#endif
static usb2_error_t usb2_fill_iface_data(struct usb2_device *, uint8_t,
uint8_t);
static void usb2_notify_addq(const char *type, struct usb2_device *);
@@ -482,11 +486,13 @@ usb2_free_iface_data(struct usb2_device *udev)
/* mtx_assert() */
+#if USB_HAVE_COMPAT_LINUX
/* free Linux compat device, if any */
if (udev->linux_dev) {
usb_linux_free_device(udev->linux_dev);
udev->linux_dev = NULL;
}
+#endif
/* free all pipes, if any */
usb2_free_pipe_data(udev, 0, 0);
@@ -1584,6 +1590,7 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
/* assume 100mA bus powered for now. Changed when configured. */
udev->power = USB_MIN_POWER;
+#if USB_HAVE_STRINGS
/* get serial number string */
err = usb2_req_get_string_any
(udev, NULL, (char *)scratch_ptr,
@@ -1607,6 +1614,7 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
/* finish up all the strings */
usb2_check_strings(udev);
+#endif
if (udev->flags.usb2_mode == USB_MODE_HOST) {
uint8_t config_index;
@@ -2032,6 +2040,7 @@ usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len)
}
}
+#if USB_HAVE_STRINGS
#if USB_VERBOSE
/*
* Descriptions of of known vendors and devices ("products").
@@ -2128,6 +2137,7 @@ usb2_check_strings(struct usb2_device *udev)
sizeof(udev->product), "product 0x%04x", product_id);
}
}
+#endif
/*
* Returns:
diff --git a/sys/dev/usb/usb_device.h b/sys/dev/usb/usb_device.h
index a6a5d79..3ec5ad5 100644
--- a/sys/dev/usb/usb_device.h
+++ b/sys/dev/usb/usb_device.h
@@ -28,6 +28,7 @@
#define _USB2_DEVICE_H_
struct usb2_symlink;
+struct usb_device; /* linux compat */
#define USB_DEFAULT_XFER_MAX 2
@@ -114,7 +115,9 @@ struct usb2_device {
struct usb2_device *parent_hub;
struct usb2_config_descriptor *cdesc; /* full config descr */
struct usb2_hub *hub; /* only if this is a hub */
+#if USB_HAVE_COMPAT_LINUX
struct usb_device *linux_dev;
+#endif
struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX];
struct usb2_temp_data *usb2_template_ptr;
struct usb2_pipe *pipe_curr; /* current clear stall pipe */
diff --git a/sys/dev/usb/usb_request.c b/sys/dev/usb/usb_request.c
index 0c66942..ba9ee61 100644
--- a/sys/dev/usb/usb_request.c
+++ b/sys/dev/usb/usb_request.c
@@ -264,6 +264,10 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
if (actlen) {
*actlen = 0;
}
+#if (USB_HAVE_USER_IO == 0)
+ if (flags & USB_USER_DATA_PTR)
+ return (USB_ERR_INVAL);
+#endif
if (udev->flags.usb2_mode == USB_MODE_DEVICE) {
DPRINTF("USB device mode\n");
(usb2_temp_get_desc_p) (udev, req, &desc, &temp);
@@ -277,13 +281,14 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
*actlen = length;
}
if (length > 0) {
+#if USB_HAVE_USER_IO
if (flags & USB_USER_DATA_PTR) {
if (copyout(desc, data, length)) {
return (USB_ERR_INVAL);
}
- } else {
+ } else
+#endif
bcopy(desc, data, length);
- }
}
return (0); /* success */
}
@@ -339,6 +344,7 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
if (temp > 0) {
if (!(req->bmRequestType & UT_READ)) {
+#if USB_HAVE_USER_IO
if (flags & USB_USER_DATA_PTR) {
USB_XFER_UNLOCK(xfer);
err = usb2_copy_in_user(xfer->frbuffers + 1,
@@ -348,9 +354,10 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
err = USB_ERR_INVAL;
break;
}
- } else {
- usb2_copy_in(xfer->frbuffers + 1, 0, data, temp);
- }
+ } else
+#endif
+ usb2_copy_in(xfer->frbuffers + 1,
+ 0, data, temp);
}
xfer->nframes = 2;
} else {
@@ -408,6 +415,7 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
}
if (temp > 0) {
if (req->bmRequestType & UT_READ) {
+#if USB_HAVE_USER_IO
if (flags & USB_USER_DATA_PTR) {
USB_XFER_UNLOCK(xfer);
err = usb2_copy_out_user(xfer->frbuffers + 1,
@@ -417,10 +425,10 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
err = USB_ERR_INVAL;
break;
}
- } else {
+ } else
+#endif
usb2_copy_out(xfer->frbuffers + 1,
0, data, temp);
- }
}
}
/*
diff --git a/sys/dev/usb/usb_transfer.c b/sys/dev/usb/usb_transfer.c
index 097931e..48463a0 100644
--- a/sys/dev/usb/usb_transfer.c
+++ b/sys/dev/usb/usb_transfer.c
@@ -191,6 +191,7 @@ usb2_get_dma_delay(struct usb2_bus *bus)
* 0: Success
* Else: Failure
*------------------------------------------------------------------------*/
+#if USB_HAVE_BUSDMA
uint8_t
usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm,
struct usb2_page_cache **ppc, uint32_t size, uint32_t align,
@@ -301,6 +302,7 @@ usb2_transfer_setup_sub_malloc(struct usb2_setup_params *parm,
parm->dma_page_ptr = pg;
return (0);
}
+#endif
/*------------------------------------------------------------------------*
* usb2_transfer_setup_sub - transfer setup subroutine
@@ -643,6 +645,7 @@ usb2_transfer_setup_sub(struct usb2_setup_params *parm)
if (parm->bufsize_max < parm->bufsize) {
parm->bufsize_max = parm->bufsize;
}
+#if USB_HAVE_BUSDMA
if (xfer->flags_int.bdma_enable) {
/*
* Setup "dma_page_ptr".
@@ -670,6 +673,7 @@ usb2_transfer_setup_sub(struct usb2_setup_params *parm)
parm->dma_page_ptr += (2 * n_frbuffers);
parm->dma_page_ptr += (parm->bufsize / USB_PAGE_SIZE);
}
+#endif
if (zmps) {
/* correct maximum data length */
xfer->max_data_length = 0;
@@ -694,7 +698,7 @@ usb2_transfer_setup_sub(struct usb2_setup_params *parm)
for (x = 0; x != n_frbuffers; x++) {
xfer->frbuffers[x].tag_parent =
&xfer->xroot->dma_parent_tag;
-
+#if USB_HAVE_BUSDMA
if (xfer->flags_int.bdma_enable &&
(parm->bufsize_max > 0)) {
@@ -705,6 +709,7 @@ usb2_transfer_setup_sub(struct usb2_setup_params *parm)
goto done;
}
}
+#endif
}
}
done:
@@ -815,28 +820,31 @@ usb2_transfer_setup(struct usb2_device *udev,
info->memory_base = buf;
info->memory_size = parm.size[0];
+#if USB_HAVE_BUSDMA
info->dma_page_cache_start = USB_ADD_BYTES(buf, parm.size[4]);
info->dma_page_cache_end = USB_ADD_BYTES(buf, parm.size[5]);
+#endif
info->xfer_page_cache_start = USB_ADD_BYTES(buf, parm.size[5]);
info->xfer_page_cache_end = USB_ADD_BYTES(buf, parm.size[2]);
usb2_cv_init(&info->cv_drain, "WDRAIN");
info->xfer_mtx = xfer_mtx;
-
+#if USB_HAVE_BUSDMA
usb2_dma_tag_setup(&info->dma_parent_tag,
parm.dma_tag_p, udev->bus->dma_parent_tag[0].tag,
- xfer_mtx, &usb2_bdma_done_event, info, 32, parm.dma_tag_max);
+ xfer_mtx, &usb2_bdma_done_event, 32, parm.dma_tag_max);
+#endif
info->bus = udev->bus;
info->udev = udev;
TAILQ_INIT(&info->done_q.head);
info->done_q.command = &usb2_callback_wrapper;
-
+#if USB_HAVE_BUSDMA
TAILQ_INIT(&info->dma_q.head);
info->dma_q.command = &usb2_bdma_work_loop;
-
+#endif
info->done_m[0].hdr.pm_callback = &usb2_callback_proc;
info->done_m[0].xroot = info;
info->done_m[1].hdr.pm_callback = &usb2_callback_proc;
@@ -1084,6 +1092,7 @@ usb2_transfer_unsetup_sub(struct usb2_xfer_root *info, uint8_t needs_delay)
USB_BUS_UNLOCK(info->bus);
+#if USB_HAVE_BUSDMA
/* free DMA'able memory, if any */
pc = info->dma_page_cache_start;
while (pc != info->dma_page_cache_end) {
@@ -1100,6 +1109,7 @@ usb2_transfer_unsetup_sub(struct usb2_xfer_root *info, uint8_t needs_delay)
/* free all DMA tags */
usb2_dma_tag_unsetup(&info->dma_parent_tag);
+#endif
usb2_cv_destroy(&info->cv_drain);
@@ -1161,9 +1171,10 @@ usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup)
usb2_transfer_drain(xfer);
+#if USB_HAVE_BUSDMA
if (xfer->flags_int.bdma_enable)
needs_delay = 1;
-
+#endif
/*
* NOTE: default pipe does not have an
* interface, even if pipe->iface_index == 0
@@ -1412,9 +1423,10 @@ usb2_start_hardware(struct usb2_xfer *xfer)
/* clear "did_close" flag */
xfer->flags_int.did_close = 0;
+#if USB_HAVE_BUSDMA
/* clear "bdma_setup" flag */
xfer->flags_int.bdma_setup = 0;
-
+#endif
/* by default we cannot cancel any USB transfer immediately */
xfer->flags_int.can_cancel_immed = 0;
@@ -1507,11 +1519,13 @@ usb2_start_hardware(struct usb2_xfer *xfer)
* Check if BUS-DMA support is enabled and try to load virtual
* buffers into DMA, if any:
*/
+#if USB_HAVE_BUSDMA
if (xfer->flags_int.bdma_enable) {
/* insert the USB transfer last in the BUS-DMA queue */
usb2_command_wrapper(&xfer->xroot->dma_q, xfer);
return;
}
+#endif
/*
* Enter the USB transfer into the Host Controller or
* Device Controller schedule:
@@ -1923,12 +1937,13 @@ usb2_callback_wrapper(struct usb2_xfer_queue *pq)
} else {
/* set transferred state */
xfer->usb2_state = USB_ST_TRANSFERRED;
-
+#if USB_HAVE_BUSDMA
/* sync DMA memory, if any */
if (xfer->flags_int.bdma_enable &&
(!xfer->flags_int.bdma_no_post_sync)) {
usb2_bdma_post_sync(xfer);
}
+#endif
}
}
@@ -2042,8 +2057,6 @@ usb2_transfer_enqueue(struct usb2_xfer_queue *pq, struct usb2_xfer *xfer)
void
usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error)
{
- struct usb2_xfer_queue *pq;
-
USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
DPRINTF("err=%s\n", usb2_errstr(error));
@@ -2070,7 +2083,10 @@ usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error)
*/
usb2_transfer_dequeue(xfer);
+#if USB_HAVE_BUSDMA
if (mtx_owned(xfer->xroot->xfer_mtx)) {
+ struct usb2_xfer_queue *pq;
+
/*
* If the private USB lock is not locked, then we assume
* that the BUS-DMA load stage has been passed:
@@ -2082,6 +2098,7 @@ usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error)
usb2_command_wrapper(pq, NULL);
}
}
+#endif
/* keep some statistics */
if (xfer->error) {
xfer->xroot->bus->stats_err.uds_requests
diff --git a/sys/dev/usb/usb_transfer.h b/sys/dev/usb/usb_transfer.h
index 34124c5..023a1e3 100644
--- a/sys/dev/usb/usb_transfer.h
+++ b/sys/dev/usb/usb_transfer.h
@@ -36,23 +36,33 @@ struct usb2_done_msg {
struct usb2_xfer_root *xroot;
};
+#define USB_DMATAG_TO_XROOT(dpt) \
+ ((struct usb2_xfer_root *)( \
+ ((uint8_t *)(dpt)) - \
+ ((uint8_t *)&((struct usb2_xfer_root *)0)->dma_parent_tag) + \
+ ((uint8_t *)0)))
+
/*
* The following structure is used to keep information about memory
* that should be automatically freed at the moment all USB transfers
* have been freed.
*/
struct usb2_xfer_root {
+ struct usb2_dma_parent_tag dma_parent_tag;
+#if USB_HAVE_BUSDMA
struct usb2_xfer_queue dma_q;
+#endif
struct usb2_xfer_queue done_q;
struct usb2_done_msg done_m[2];
struct cv cv_drain;
- struct usb2_dma_parent_tag dma_parent_tag;
struct usb2_process *done_p; /* pointer to callback process */
void *memory_base;
struct mtx *xfer_mtx; /* cannot be changed during operation */
+#if USB_HAVE_BUSDMA
struct usb2_page_cache *dma_page_cache_start;
struct usb2_page_cache *dma_page_cache_end;
+#endif
struct usb2_page_cache *xfer_page_cache_start;
struct usb2_page_cache *xfer_page_cache_end;
struct usb2_bus *bus; /* pointer to USB bus (cached) */
diff --git a/sys/dev/usb/usb_util.c b/sys/dev/usb/usb_util.c
index b22e35b..adc486d 100644
--- a/sys/dev/usb/usb_util.c
+++ b/sys/dev/usb/usb_util.c
@@ -39,7 +39,7 @@
#include <dev/usb/usb_bus.h>
/* function prototypes */
-#if (USB_USE_CONDVAR == 0)
+#if (USB_HAVE_CONDVAR == 0)
static int usb2_msleep(void *chan, struct mtx *mtx, int priority, const char *wmesg, int timo);
#endif
@@ -47,6 +47,7 @@ static int usb2_msleep(void *chan, struct mtx *mtx, int priority, const char *wm
/*------------------------------------------------------------------------*
* device_delete_all_children - delete all children of a device
*------------------------------------------------------------------------*/
+#ifndef device_delete_all_children
int
device_delete_all_children(device_t dev)
{
@@ -66,6 +67,7 @@ device_delete_all_children(device_t dev)
}
return (error);
}
+#endif
/*------------------------------------------------------------------------*
* device_set_usb2_desc
@@ -76,6 +78,7 @@ device_delete_all_children(device_t dev)
void
device_set_usb2_desc(device_t dev)
{
+#if USB_HAVE_STRINGS
struct usb2_attach_arg *uaa;
struct usb2_device *udev;
struct usb2_interface *iface;
@@ -118,6 +121,7 @@ device_set_usb2_desc(device_t dev)
device_set_desc_copy(dev, temp_p);
device_printf(dev, "<%s> on %s\n", temp_p,
device_get_nameunit(udev->bus->bdev));
+#endif
}
/*------------------------------------------------------------------------*
@@ -163,6 +167,7 @@ usb2_pause_mtx(struct mtx *mtx, int _ticks)
* pointed to by "p" having a maximum length of "p_len" bytes
* including the terminating zero.
*------------------------------------------------------------------------*/
+#if USB_HAVE_STRINGS
void
usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd)
{
@@ -170,6 +175,7 @@ usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd)
/* ignore any errors */
}
}
+#endif
/*------------------------------------------------------------------------*
* usb2_trim_spaces
@@ -177,6 +183,7 @@ usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd)
* This function removes spaces at the beginning and the end of the string
* pointed to by the "p" argument.
*------------------------------------------------------------------------*/
+#if USB_HAVE_STRINGS
void
usb2_trim_spaces(char *p)
{
@@ -193,6 +200,7 @@ usb2_trim_spaces(char *p)
e = p;
*e = 0; /* kill trailing spaces */
}
+#endif
/*------------------------------------------------------------------------*
* usb2_get_devid
@@ -246,7 +254,7 @@ usb2_make_str_desc(void *ptr, uint16_t max_len, const char *s)
return (totlen);
}
-#if (USB_USE_CONDVAR == 0)
+#if (USB_HAVE_CONDVAR == 0)
/*------------------------------------------------------------------------*
* usb2_cv_init - wrapper function
diff --git a/sys/dev/usb/usb_util.h b/sys/dev/usb/usb_util.h
index e081c31..73097f3 100644
--- a/sys/dev/usb/usb_util.h
+++ b/sys/dev/usb/usb_util.h
@@ -35,7 +35,7 @@ void usb2_pause_mtx(struct mtx *mtx, int _ticks);
void usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd);
void usb2_trim_spaces(char *p);
-#if (USB_USE_CONDVAR == 0)
+#if (USB_HAVE_CONDVAR == 0)
void usb2_cv_init(struct cv *cv, const char *desc);
void usb2_cv_destroy(struct cv *cv);
void usb2_cv_wait(struct cv *cv, struct mtx *mtx);
OpenPOWER on IntegriCloud