Date: Thu, 8 Jan 2009 15:32:25 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 155820 for review Message-ID: <200901081532.n08FWPDx031982@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=155820 Change 155820 by hselasky@hselasky_laptop001 on 2009/01/08 15:32:01 USB memory usage reduction patch. Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/controller/at91dci.h#6 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/at91dci_atmelarm.c#15 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/ehci2.h#11 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/ehci2_pci.c#18 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg.h#10 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg_atmelarm.c#12 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2.h#7 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_atmelarm.c#14 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_pci.c#15 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/uhci2.h#9 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/uhci2_pci.c#16 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/usb2_bus.h#10 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/usb2_controller.c#21 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci.h#6 edit .. //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci_atmelarm.c#7 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#45 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#28 edit .. //depot/projects/usb/src/sys/dev/usb2/include/usb2_defs.h#7 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/controller/at91dci.h#6 (text+ko) ==== @@ -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 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/at91dci_atmelarm.c#15 (text+ko) ==== @@ -145,9 +145,12 @@ sc->sc_dci.sc_pull_down = &at91_udp_pull_down; sc->sc_dci.sc_pull_arg = sc; + /* 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 */ - - sc->sc_dci.sc_bus.parent = dev; if (usb2_bus_mem_alloc_all(&sc->sc_dci.sc_bus, USB_GET_DMA_TAG(dev), NULL)) { return (ENOMEM); ==== //depot/projects/usb/src/sys/dev/usb2/controller/ehci2.h#11 (text+ko) ==== @@ -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 @@ 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/ehci2_pci.c#18 (text+ko) ==== @@ -232,12 +232,15 @@ device_printf(self, "Could not allocate sc\n"); return (ENXIO); } + /* 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 */ - - sc->sc_bus.parent = self; 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg.h#10 (text+ko) ==== @@ -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 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg_atmelarm.c#12 (text+ko) ==== @@ -102,9 +102,12 @@ sc->sc_otg.sc_clocks_off = &musbotg_clocks_off; sc->sc_otg.sc_clocks_arg = sc; + /* 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 */ - - sc->sc_otg.sc_bus.parent = dev; if (usb2_bus_mem_alloc_all(&sc->sc_otg.sc_bus, USB_GET_DMA_TAG(dev), NULL)) { return (ENOMEM); ==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2.h#7 (text+ko) ==== @@ -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 @@ 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_atmelarm.c#14 (text) ==== @@ -73,12 +73,15 @@ if (sc == NULL) { return (ENXIO); } + /* 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 */ - - sc->sc_ohci.sc_bus.parent = dev; 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"); ==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_pci.c#15 (text+ko) ==== @@ -200,12 +200,15 @@ device_printf(self, "Could not allocate sc\n"); return (ENXIO); } + /* 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 */ - - sc->sc_bus.parent = self; 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/uhci2.h#9 (text+ko) ==== @@ -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 @@ 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 ==== //depot/projects/usb/src/sys/dev/usb2/controller/uhci2_pci.c#16 (text+ko) ==== @@ -251,9 +251,12 @@ device_printf(self, "Could not allocate sc\n"); return (ENXIO); } + /* 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 */ - - sc->sc_bus.parent = self; if (usb2_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self), &uhci_iterate_hw_softc)) { return ENOMEM; ==== //depot/projects/usb/src/sys/dev/usb2/controller/usb2_bus.h#10 (text+ko) ==== @@ -70,7 +70,7 @@ 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]; ==== //depot/projects/usb/src/sys/dev/usb2/controller/usb2_controller.c#21 (text+ko) ==== @@ -493,8 +493,6 @@ { 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_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); } ==== //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci.h#6 (text+ko) ==== @@ -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 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; ==== //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci_atmelarm.c#7 (text+ko) ==== @@ -138,9 +138,13 @@ 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); ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#45 (text+ko) ==== @@ -1290,19 +1290,23 @@ * 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"); ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#28 (text+ko) ==== @@ -1520,8 +1520,12 @@ * 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 @@ /* 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) ==== //depot/projects/usb/src/sys/dev/usb2/include/usb2_defs.h#7 (text+ko) ==== @@ -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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901081532.n08FWPDx031982>