Author: thompsa
Date: Tue Jan 13 19:02:40 2009
New Revision: 187170
URL: http://svn.freebsd.org/changeset/base/187170

Log:
  MFp4: //depot/projects/u...@155820
  
        USB memory usage reduction patch.
  
  Submitted by: Hans Petter Selasky

Modified:
  head/sys/dev/usb2/controller/at91dci.h
  head/sys/dev/usb2/controller/at91dci_atmelarm.c
  head/sys/dev/usb2/controller/ehci2.h
  head/sys/dev/usb2/controller/ehci2_pci.c
  head/sys/dev/usb2/controller/musb2_otg.h
  head/sys/dev/usb2/controller/musb2_otg_atmelarm.c
  head/sys/dev/usb2/controller/ohci2.h
  head/sys/dev/usb2/controller/ohci2_atmelarm.c
  head/sys/dev/usb2/controller/ohci2_pci.c
  head/sys/dev/usb2/controller/uhci2.h
  head/sys/dev/usb2/controller/uhci2_pci.c
  head/sys/dev/usb2/controller/usb2_bus.h
  head/sys/dev/usb2/controller/usb2_controller.c
  head/sys/dev/usb2/controller/uss820dci.h
  head/sys/dev/usb2/controller/uss820dci_atmelarm.c
  head/sys/dev/usb2/core/usb2_device.c
  head/sys/dev/usb2/core/usb2_hub.c
  head/sys/dev/usb2/include/usb2_defs.h

Modified: head/sys/dev/usb2/controller/at91dci.h
==============================================================================
--- head/sys/dev/usb2/controller/at91dci.h      Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/at91dci.h      Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/at91dci_atmelarm.c
==============================================================================
--- head/sys/dev/usb2/controller/at91dci_atmelarm.c     Tue Jan 13 19:02:30 
2009        (r187169)
+++ head/sys/dev/usb2/controller/at91dci_atmelarm.c     Tue Jan 13 19:02:40 
2009        (r187170)
@@ -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);

Modified: head/sys/dev/usb2/controller/ehci2.h
==============================================================================
--- head/sys/dev/usb2/controller/ehci2.h        Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/ehci2.h        Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/ehci2_pci.c
==============================================================================
--- head/sys/dev/usb2/controller/ehci2_pci.c    Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/ehci2_pci.c    Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;
 

Modified: head/sys/dev/usb2/controller/musb2_otg.h
==============================================================================
--- head/sys/dev/usb2/controller/musb2_otg.h    Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/musb2_otg.h    Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/musb2_otg_atmelarm.c
==============================================================================
--- head/sys/dev/usb2/controller/musb2_otg_atmelarm.c   Tue Jan 13 19:02:30 
2009        (r187169)
+++ head/sys/dev/usb2/controller/musb2_otg_atmelarm.c   Tue Jan 13 19:02:40 
2009        (r187170)
@@ -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);

Modified: head/sys/dev/usb2/controller/ohci2.h
==============================================================================
--- head/sys/dev/usb2/controller/ohci2.h        Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/ohci2.h        Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/ohci2_atmelarm.c
==============================================================================
--- head/sys/dev/usb2/controller/ohci2_atmelarm.c       Tue Jan 13 19:02:30 
2009        (r187169)
+++ head/sys/dev/usb2/controller/ohci2_atmelarm.c       Tue Jan 13 19:02:40 
2009        (r187170)
@@ -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");

Modified: head/sys/dev/usb2/controller/ohci2_pci.c
==============================================================================
--- head/sys/dev/usb2/controller/ohci2_pci.c    Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/ohci2_pci.c    Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;
 

Modified: head/sys/dev/usb2/controller/uhci2.h
==============================================================================
--- head/sys/dev/usb2/controller/uhci2.h        Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/uhci2.h        Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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

Modified: head/sys/dev/usb2/controller/uhci2_pci.c
==============================================================================
--- head/sys/dev/usb2/controller/uhci2_pci.c    Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/uhci2_pci.c    Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/usb2_bus.h
==============================================================================
--- head/sys/dev/usb2/controller/usb2_bus.h     Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/usb2_bus.h     Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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];

Modified: head/sys/dev/usb2/controller/usb2_controller.c
==============================================================================
--- head/sys/dev/usb2/controller/usb2_controller.c      Tue Jan 13 19:02:30 
2009        (r187169)
+++ head/sys/dev/usb2/controller/usb2_controller.c      Tue Jan 13 19:02:40 
2009        (r187170)
@@ -493,8 +493,6 @@ usb2_bus_mem_alloc_all(struct usb2_bus *
 {
        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 *
        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);
        }

Modified: head/sys/dev/usb2/controller/uss820dci.h
==============================================================================
--- head/sys/dev/usb2/controller/uss820dci.h    Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/controller/uss820dci.h    Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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;

Modified: head/sys/dev/usb2/controller/uss820dci_atmelarm.c
==============================================================================
--- head/sys/dev/usb2/controller/uss820dci_atmelarm.c   Tue Jan 13 19:02:30 
2009        (r187169)
+++ head/sys/dev/usb2/controller/uss820dci_atmelarm.c   Tue Jan 13 19:02:40 
2009        (r187170)
@@ -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);

Modified: head/sys/dev/usb2/core/usb2_device.c
==============================================================================
--- head/sys/dev/usb2/core/usb2_device.c        Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/core/usb2_device.c        Tue Jan 13 19:02:40 2009        
(r187170)
@@ -1290,19 +1290,23 @@ usb2_alloc_device(device_t parent_dev, s
         * 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");

Modified: head/sys/dev/usb2/core/usb2_hub.c
==============================================================================
--- head/sys/dev/usb2/core/usb2_hub.c   Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/core/usb2_hub.c   Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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)

Modified: head/sys/dev/usb2/include/usb2_defs.h
==============================================================================
--- head/sys/dev/usb2/include/usb2_defs.h       Tue Jan 13 19:02:30 2009        
(r187169)
+++ head/sys/dev/usb2/include/usb2_defs.h       Tue Jan 13 19:02:40 2009        
(r187170)
@@ -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_ */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to