1/*- 2 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/sys/dev/usb/controller/xhci_pci.c 251499 2013-06-07 14:30:06Z hselasky $"); |
28 29#include <sys/stdint.h> 30#include <sys/stddef.h> 31#include <sys/param.h> 32#include <sys/queue.h> 33#include <sys/types.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> --- 91 unchanged lines hidden (view full) --- 127 if (desc) { 128 device_set_desc(self, desc); 129 return (0); 130 } else { 131 return (ENXIO); 132 } 133} 134 |
135static void 136xhci_interrupt_poll(void *_sc) 137{ 138 struct xhci_softc *sc = _sc; 139 USB_BUS_UNLOCK(&sc->sc_bus); 140 xhci_interrupt(sc); 141 USB_BUS_LOCK(&sc->sc_bus); 142 usb_callout_reset(&sc->sc_callout, 1, (void *)&xhci_interrupt_poll, sc); 143} 144 |
145static int 146xhci_pci_attach(device_t self) 147{ 148 struct xhci_softc *sc = device_get_softc(self); 149 int err; 150 int rid; 151 152 /* XXX check for 64-bit capability */ --- 11 unchanged lines hidden (view full) --- 164 if (!sc->sc_io_res) { 165 device_printf(self, "Could not map memory\n"); 166 goto error; 167 } 168 sc->sc_io_tag = rman_get_bustag(sc->sc_io_res); 169 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); 170 sc->sc_io_size = rman_get_size(sc->sc_io_res); 171 |
172 usb_callout_init_mtx(&sc->sc_callout, &sc->sc_bus.bus_mtx, 0); 173 |
174 rid = 0; 175 sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid, 176 RF_SHAREABLE | RF_ACTIVE); 177 if (sc->sc_irq_res == NULL) { 178 device_printf(self, "Could not allocate IRQ\n"); |
179 } 180 sc->sc_bus.bdev = device_add_child(self, "usbus", -1); 181 if (sc->sc_bus.bdev == NULL) { 182 device_printf(self, "Could not add USB device\n"); 183 goto error; 184 } 185 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 186 187 sprintf(sc->sc_vendor, "0x%04x", pci_get_vendor(self)); 188 |
189 if (sc->sc_irq_res != NULL) { 190 err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, 191 NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl); 192 if (err != 0) { 193 device_printf(self, "Could not setup IRQ, err=%d\n", err); 194 sc->sc_intr_hdl = NULL; 195 } |
196 } |
197 if (sc->sc_irq_res == NULL || sc->sc_intr_hdl == NULL || 198 xhci_use_polling() != 0) { 199 device_printf(self, "Interrupt polling at %dHz\n", hz); 200 USB_BUS_LOCK(&sc->sc_bus); 201 xhci_interrupt_poll(sc); 202 USB_BUS_UNLOCK(&sc->sc_bus); 203 } 204 |
205 xhci_pci_take_controller(self); 206 207 err = xhci_halt_controller(sc); 208 209 if (err == 0) 210 err = xhci_start_controller(sc); 211 212 if (err == 0) --- 19 unchanged lines hidden (view full) --- 232 if (sc->sc_bus.bdev != NULL) { 233 bdev = sc->sc_bus.bdev; 234 device_detach(bdev); 235 device_delete_child(self, bdev); 236 } 237 /* during module unload there are lots of children leftover */ 238 device_delete_children(self); 239 |
240 if (sc->sc_io_res) { 241 usb_callout_drain(&sc->sc_callout); 242 xhci_halt_controller(sc); 243 } 244 |
245 pci_disable_busmaster(self); 246 247 if (sc->sc_irq_res && sc->sc_intr_hdl) { |
248 bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl); 249 sc->sc_intr_hdl = NULL; 250 } 251 if (sc->sc_irq_res) { 252 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res); 253 sc->sc_irq_res = NULL; 254 } 255 if (sc->sc_io_res) { --- 65 unchanged lines hidden --- |