aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/usb2
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2009-01-13 19:02:40 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2009-01-13 19:02:40 +0000
commitcba1b53d88fced418a087f2db27678b30fdd2ad5 (patch)
tree7750750e9e276700730ce521b39b53136d4f2c76 /sys/dev/usb2
parentf3396b74be0eaf844e6499d8ffb028721b6a3356 (diff)
Notes
Diffstat (limited to 'sys/dev/usb2')
-rw-r--r--sys/dev/usb2/controller/at91dci.h3
-rw-r--r--sys/dev/usb2/controller/at91dci_atmelarm.c7
-rw-r--r--sys/dev/usb2/controller/ehci2.h3
-rw-r--r--sys/dev/usb2/controller/ehci2_pci.c9
-rw-r--r--sys/dev/usb2/controller/musb2_otg.h4
-rw-r--r--sys/dev/usb2/controller/musb2_otg_atmelarm.c7
-rw-r--r--sys/dev/usb2/controller/ohci2.h3
-rw-r--r--sys/dev/usb2/controller/ohci2_atmelarm.c9
-rw-r--r--sys/dev/usb2/controller/ohci2_pci.c9
-rw-r--r--sys/dev/usb2/controller/uhci2.h3
-rw-r--r--sys/dev/usb2/controller/uhci2_pci.c7
-rw-r--r--sys/dev/usb2/controller/usb2_bus.h2
-rw-r--r--sys/dev/usb2/controller/usb2_controller.c9
-rw-r--r--sys/dev/usb2/controller/uss820dci.h3
-rw-r--r--sys/dev/usb2/controller/uss820dci_atmelarm.c6
-rw-r--r--sys/dev/usb2/core/usb2_device.c20
-rw-r--r--sys/dev/usb2/core/usb2_hub.c16
-rw-r--r--sys/dev/usb2/include/usb2_defs.h6
18 files changed, 94 insertions, 32 deletions
diff --git a/sys/dev/usb2/controller/at91dci.h b/sys/dev/usb2/controller/at91dci.h
index bade80a38309..77b195447d1b 100644
--- a/sys/dev/usb2/controller/at91dci.h
+++ b/sys/dev/usb2/controller/at91dci.h
@@ -34,6 +34,8 @@
#ifndef _AT9100_DCI_H_
#define _AT9100_DCI_H_
+#define AT91_MAX_DEVICES (USB_MIN_DEVICES + 1)
+
#define AT91_UDP_FRM 0x00 /* Frame number register */
#define AT91_UDP_FRM_MASK (0x7FF << 0) /* Frame Number as Defined in
* the Packet Field Formats */
@@ -206,6 +208,7 @@ struct at91dci_softc {
struct usb2_sw_transfer sc_root_intr;
struct usb2_config_td sc_config_td;
+ struct usb2_device *sc_devices[AT91_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
void *sc_intr_hdl;
diff --git a/sys/dev/usb2/controller/at91dci_atmelarm.c b/sys/dev/usb2/controller/at91dci_atmelarm.c
index 23de204fc053..fb2f920d8b7b 100644
--- a/sys/dev/usb2/controller/at91dci_atmelarm.c
+++ b/sys/dev/usb2/controller/at91dci_atmelarm.c
@@ -145,9 +145,12 @@ at91_udp_attach(device_t dev)
sc->sc_dci.sc_pull_down = &at91_udp_pull_down;
sc->sc_dci.sc_pull_arg = sc;
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_dci.sc_bus.parent = dev;
+ sc->sc_dci.sc_bus.devices = sc->sc_dci.sc_devices;
+ sc->sc_dci.sc_bus.devices_max = AT91_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_dci.sc_bus,
USB_GET_DMA_TAG(dev), NULL)) {
return (ENOMEM);
diff --git a/sys/dev/usb2/controller/ehci2.h b/sys/dev/usb2/controller/ehci2.h
index 3dee6bd3fa5c..eb377d580511 100644
--- a/sys/dev/usb2/controller/ehci2.h
+++ b/sys/dev/usb2/controller/ehci2.h
@@ -38,6 +38,8 @@
#ifndef _EHCI_H_
#define _EHCI_H_
+#define EHCI_MAX_DEVICES USB_MAX_DEVICES
+
/* PCI config registers */
#define PCI_CBMEM 0x10 /* configuration base MEM */
#define PCI_INTERFACE_EHCI 0x20
@@ -459,6 +461,7 @@ typedef struct ehci_softc {
struct usb2_sw_transfer sc_root_ctrl;
struct usb2_sw_transfer sc_root_intr;
+ struct usb2_device *sc_devices[EHCI_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
struct ehci_qh *sc_async_p_last;
diff --git a/sys/dev/usb2/controller/ehci2_pci.c b/sys/dev/usb2/controller/ehci2_pci.c
index 65e4fcefe6e3..03b225553ce8 100644
--- a/sys/dev/usb2/controller/ehci2_pci.c
+++ b/sys/dev/usb2/controller/ehci2_pci.c
@@ -232,12 +232,15 @@ ehci_pci_attach(device_t self)
device_printf(self, "Could not allocate sc\n");
return (ENXIO);
}
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_bus.parent = self;
+ sc->sc_bus.devices = sc->sc_devices;
+ sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_bus,
USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
- return ENOMEM;
+ return (ENOMEM);
}
sc->sc_dev = self;
diff --git a/sys/dev/usb2/controller/musb2_otg.h b/sys/dev/usb2/controller/musb2_otg.h
index 68193e2ea085..78bc4d6f967d 100644
--- a/sys/dev/usb2/controller/musb2_otg.h
+++ b/sys/dev/usb2/controller/musb2_otg.h
@@ -32,6 +32,8 @@
#ifndef _MUSB2_OTG_H_
#define _MUSB2_OTG_H_
+#define MUSB2_MAX_DEVICES (USB_MIN_DEVICES + 1)
+
/* Common registers */
#define MUSB2_REG_FADDR 0x0000 /* function address register */
@@ -365,6 +367,8 @@ struct musbotg_softc {
struct usb2_sw_transfer sc_root_intr;
struct usb2_config_td sc_config_td;
struct usb2_hw_ep_profile sc_hw_ep_profile[16];
+
+ struct usb2_device *sc_devices[MUSB2_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
void *sc_intr_hdl;
diff --git a/sys/dev/usb2/controller/musb2_otg_atmelarm.c b/sys/dev/usb2/controller/musb2_otg_atmelarm.c
index de4b58b2f640..8464f2b8b321 100644
--- a/sys/dev/usb2/controller/musb2_otg_atmelarm.c
+++ b/sys/dev/usb2/controller/musb2_otg_atmelarm.c
@@ -102,9 +102,12 @@ musbotg_attach(device_t dev)
sc->sc_otg.sc_clocks_off = &musbotg_clocks_off;
sc->sc_otg.sc_clocks_arg = sc;
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_otg.sc_bus.parent = dev;
+ sc->sc_otg.sc_bus.devices = sc->sc_otg.sc_devices;
+ sc->sc_otg.sc_bus.devices_max = MUSB2_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_otg.sc_bus,
USB_GET_DMA_TAG(dev), NULL)) {
return (ENOMEM);
diff --git a/sys/dev/usb2/controller/ohci2.h b/sys/dev/usb2/controller/ohci2.h
index fefde6cf54ca..219b80f5bbdb 100644
--- a/sys/dev/usb2/controller/ohci2.h
+++ b/sys/dev/usb2/controller/ohci2.h
@@ -39,6 +39,8 @@
#ifndef _OHCI_H_
#define _OHCI_H_
+#define OHCI_MAX_DEVICES USB_MAX_DEVICES
+
/* PCI config registers */
#define PCI_CBMEM 0x10 /* configuration base memory */
#define PCI_INTERFACE_OHCI 0x10
@@ -324,6 +326,7 @@ typedef struct ohci_softc {
struct usb2_sw_transfer sc_root_ctrl;
struct usb2_sw_transfer sc_root_intr;
+ struct usb2_device *sc_devices[OHCI_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
struct ohci_hcca *sc_hcca_p;
diff --git a/sys/dev/usb2/controller/ohci2_atmelarm.c b/sys/dev/usb2/controller/ohci2_atmelarm.c
index b440f1490d50..df4006fada81 100644
--- a/sys/dev/usb2/controller/ohci2_atmelarm.c
+++ b/sys/dev/usb2/controller/ohci2_atmelarm.c
@@ -73,12 +73,15 @@ ohci_atmelarm_attach(device_t dev)
if (sc == NULL) {
return (ENXIO);
}
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_ohci.sc_bus.parent = dev;
+ sc->sc_ohci.sc_bus.devices = sc->sc_ohci.sc_devices;
+ sc->sc_ohci.sc_bus.devices_max = OHCI_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_ohci.sc_bus,
USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc)) {
- return ENOMEM;
+ return (ENOMEM);
}
sc->iclk = at91_pmc_clock_ref("ohci_clk");
sc->fclk = at91_pmc_clock_ref("uhpck");
diff --git a/sys/dev/usb2/controller/ohci2_pci.c b/sys/dev/usb2/controller/ohci2_pci.c
index b54ade6da590..f2ca38390d50 100644
--- a/sys/dev/usb2/controller/ohci2_pci.c
+++ b/sys/dev/usb2/controller/ohci2_pci.c
@@ -200,12 +200,15 @@ ohci_pci_attach(device_t self)
device_printf(self, "Could not allocate sc\n");
return (ENXIO);
}
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_bus.parent = self;
+ sc->sc_bus.devices = sc->sc_devices;
+ sc->sc_bus.devices_max = OHCI_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self),
&ohci_iterate_hw_softc)) {
- return ENOMEM;
+ return (ENOMEM);
}
sc->sc_dev = self;
diff --git a/sys/dev/usb2/controller/uhci2.h b/sys/dev/usb2/controller/uhci2.h
index ee0b36dc8bba..802e241e23f6 100644
--- a/sys/dev/usb2/controller/uhci2.h
+++ b/sys/dev/usb2/controller/uhci2.h
@@ -39,6 +39,8 @@
#ifndef _UHCI_H_
#define _UHCI_H_
+#define UHCI_MAX_DEVICES USB_MAX_DEVICES
+
/* PCI config registers */
#define PCI_USBREV 0x60 /* USB protocol revision */
#define PCI_USB_REV_MASK 0xff
@@ -273,6 +275,7 @@ typedef struct uhci_softc {
struct usb2_sw_transfer sc_root_ctrl;
struct usb2_sw_transfer sc_root_intr;
+ struct usb2_device *sc_devices[UHCI_MAX_DEVICES];
struct uhci_td *sc_isoc_p_last[UHCI_VFRAMELIST_COUNT]; /* pointer to last TD
* for isochronous */
struct uhci_qh *sc_intr_p_last[UHCI_IFRAMELIST_COUNT]; /* pointer to last QH
diff --git a/sys/dev/usb2/controller/uhci2_pci.c b/sys/dev/usb2/controller/uhci2_pci.c
index 9baf42bd1c09..a8e92648c20c 100644
--- a/sys/dev/usb2/controller/uhci2_pci.c
+++ b/sys/dev/usb2/controller/uhci2_pci.c
@@ -251,9 +251,12 @@ uhci_pci_attach(device_t self)
device_printf(self, "Could not allocate sc\n");
return (ENXIO);
}
- /* get all DMA memory */
-
+ /* initialise some bus fields */
sc->sc_bus.parent = self;
+ sc->sc_bus.devices = sc->sc_devices;
+ sc->sc_bus.devices_max = UHCI_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self),
&uhci_iterate_hw_softc)) {
return ENOMEM;
diff --git a/sys/dev/usb2/controller/usb2_bus.h b/sys/dev/usb2/controller/usb2_bus.h
index f30d61f5aed3..163ad5af37e7 100644
--- a/sys/dev/usb2/controller/usb2_bus.h
+++ b/sys/dev/usb2/controller/usb2_bus.h
@@ -70,7 +70,7 @@ struct usb2_bus {
struct usb2_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
struct usb2_bus_methods *methods; /* filled by HC driver */
- struct usb2_device *devices[USB_MAX_DEVICES];
+ struct usb2_device **devices;
uint32_t hw_power_state; /* see USB_HW_POWER_XXX */
uint32_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
diff --git a/sys/dev/usb2/controller/usb2_controller.c b/sys/dev/usb2/controller/usb2_controller.c
index ec1aff5a5707..8e407bbaf382 100644
--- a/sys/dev/usb2/controller/usb2_controller.c
+++ b/sys/dev/usb2/controller/usb2_controller.c
@@ -493,8 +493,6 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
{
bus->alloc_failed = 0;
- bus->devices_max = USB_MAX_DEVICES;
-
mtx_init(&bus->bus_mtx, device_get_nameunit(bus->parent),
NULL, MTX_DEF | MTX_RECURSE);
@@ -506,6 +504,13 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
usb2_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags,
dmat, &bus->bus_mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX);
+ if ((bus->devices_max > USB_MAX_DEVICES) ||
+ (bus->devices_max < USB_MIN_DEVICES) ||
+ (bus->devices == NULL)) {
+ DPRINTFN(0, "Devices field has not been "
+ "initialised properly!\n");
+ bus->alloc_failed = 1; /* failure */
+ }
if (cb) {
cb(bus, &usb2_bus_mem_alloc_all_cb);
}
diff --git a/sys/dev/usb2/controller/uss820dci.h b/sys/dev/usb2/controller/uss820dci.h
index aa8b535a9fd5..622b71c9e1f2 100644
--- a/sys/dev/usb2/controller/uss820dci.h
+++ b/sys/dev/usb2/controller/uss820dci.h
@@ -28,6 +28,8 @@
#ifndef _USS820_DCI_H_
#define _USS820_DCI_H_
+#define USS820_MAX_DEVICES (USB_MIN_DEVICES + 1)
+
#define USS820_EP_MAX 8 /* maximum number of endpoints */
#define USS820_TXDAT 0x00 /* Transmit FIFO data */
@@ -347,6 +349,7 @@ struct uss820dci_softc {
struct usb2_sw_transfer sc_root_intr;
struct usb2_config_td sc_config_td;
+ struct usb2_device *sc_devices[USS820_MAX_DEVICES];
struct resource *sc_io_res;
struct resource *sc_irq_res;
void *sc_intr_hdl;
diff --git a/sys/dev/usb2/controller/uss820dci_atmelarm.c b/sys/dev/usb2/controller/uss820dci_atmelarm.c
index 8e92ffb4f9e0..f5056972a7ae 100644
--- a/sys/dev/usb2/controller/uss820dci_atmelarm.c
+++ b/sys/dev/usb2/controller/uss820dci_atmelarm.c
@@ -138,9 +138,13 @@ uss820_atmelarm_attach(device_t dev)
if (sc == NULL) {
return (ENXIO);
}
- /* get all DMA memory */
+ /* initialise some bus fields */
sc->sc_bus.parent = dev;
+ sc->sc_bus.devices = sc->sc_devices;
+ sc->sc_bus.devices_max = USS820_MAX_DEVICES;
+
+ /* get all DMA memory */
if (usb2_bus_mem_alloc_all(&sc->sc_bus,
USB_GET_DMA_TAG(dev), NULL)) {
return (ENOMEM);
diff --git a/sys/dev/usb2/core/usb2_device.c b/sys/dev/usb2/core/usb2_device.c
index 805de0a3cff4..739af1abd090 100644
--- a/sys/dev/usb2/core/usb2_device.c
+++ b/sys/dev/usb2/core/usb2_device.c
@@ -1290,19 +1290,23 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
* Find an unused device index. In USB Host mode this is the
* same as the device address.
*
- * NOTE: Index 1 is reserved for the Root HUB.
+ * Device index zero is not used and device index 1 should
+ * always be the root hub.
*/
- for (device_index = USB_ROOT_HUB_ADDR; device_index !=
- USB_MAX_DEVICES; device_index++) {
+ for (device_index = USB_ROOT_HUB_ADDR;; device_index++) {
+#if (USB_ROOT_HUB_ADDR > USB_MIN_DEVICES)
+#error "Incorrect device limit."
+#endif
+ if (device_index == bus->devices_max) {
+ device_printf(bus->bdev,
+ "No free USB device "
+ "index for new device!\n");
+ return (NULL);
+ }
if (bus->devices[device_index] == NULL)
break;
}
- if (device_index == USB_MAX_DEVICES) {
- device_printf(bus->bdev,
- "No free USB device index for new device!\n");
- return (NULL);
- }
if (depth > 0x10) {
device_printf(bus->bdev,
"Invalid device depth!\n");
diff --git a/sys/dev/usb2/core/usb2_hub.c b/sys/dev/usb2/core/usb2_hub.c
index b58477526806..7756cb6ce4f8 100644
--- a/sys/dev/usb2/core/usb2_hub.c
+++ b/sys/dev/usb2/core/usb2_hub.c
@@ -1520,8 +1520,12 @@ usb2_bus_powerd(struct usb2_bus *bus)
* The root HUB device is never suspended
* and we simply skip it.
*/
- for (x = USB_ROOT_HUB_ADDR + 1;
- x != USB_MAX_DEVICES; x++) {
+ for (x = USB_ROOT_HUB_ADDR + 1;; x++) {
+#if ((USB_ROOT_HUB_ADDR + 1) > USB_MIN_DEVICES)
+#error "Incorrect device limit."
+#endif
+ if (x == bus->devices_max)
+ break;
udev = bus->devices[x];
if (udev == NULL)
@@ -1564,8 +1568,12 @@ usb2_bus_powerd(struct usb2_bus *bus)
/* Re-loop all the devices to get the actual state */
- for (x = USB_ROOT_HUB_ADDR + 1;
- x != USB_MAX_DEVICES; x++) {
+ for (x = USB_ROOT_HUB_ADDR + 1;; x++) {
+#if ((USB_ROOT_HUB_ADDR + 1) > USB_MIN_DEVICES)
+#error "Incorrect device limit."
+#endif
+ if (x == bus->devices_max)
+ break;
udev = bus->devices[x];
if (udev == NULL)
diff --git a/sys/dev/usb2/include/usb2_defs.h b/sys/dev/usb2/include/usb2_defs.h
index d791f4dd84d4..a31a7cda9f34 100644
--- a/sys/dev/usb2/include/usb2_defs.h
+++ b/sys/dev/usb2/include/usb2_defs.h
@@ -35,6 +35,8 @@
#define USB_EP_MAX (2*16) /* hardcoded */
#define USB_FIFO_MAX (4 * USB_EP_MAX)
+#define USB_MIN_DEVICES 2 /* unused + root HUB */
+
#define USB_MAX_DEVICES USB_DEV_MAX /* including virtual root HUB and
* address zero */
#define USB_MAX_ENDPOINTS USB_EP_MAX /* 2 directions on 16 endpoints */
@@ -64,5 +66,7 @@
#if (USB_EP_MAX < (2*16))
#error "Misconfigured limits #3"
#endif
-
+#if (USB_MAX_DEVICES < USB_MIN_DEVICES)
+#error "Misconfigured limits #4"
+#endif
#endif /* _USB2_DEFS_H_ */