usb_controller.c (184610) | usb_controller.c (184824) |
---|---|
1/* $FreeBSD: head/sys/dev/usb2/controller/usb2_controller.c 184610 2008-11-04 02:31:03Z alfred $ */ | 1/* $FreeBSD: head/sys/dev/usb2/controller/usb2_controller.c 184824 2008-11-10 20:54:31Z thompsa $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 129 unchanged lines hidden (view full) --- 139 DPRINTF("\n"); 140 141 if (bus == NULL) { 142 /* was never setup properly */ 143 return (0); 144 } 145 /* Let the USB explore process detach all devices. */ 146 | 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 129 unchanged lines hidden (view full) --- 139 DPRINTF("\n"); 140 141 if (bus == NULL) { 142 /* was never setup properly */ 143 return (0); 144 } 145 /* Let the USB explore process detach all devices. */ 146 |
147 mtx_lock(&bus->mtx); | 147 USB_BUS_LOCK(bus); |
148 if (usb2_proc_msignal(&bus->explore_proc, 149 &bus->detach_msg[0], &bus->detach_msg[1])) { 150 /* ignore */ 151 } 152 /* Wait for detach to complete */ 153 154 usb2_proc_mwait(&bus->explore_proc, 155 &bus->detach_msg[0], &bus->detach_msg[1]); 156 | 148 if (usb2_proc_msignal(&bus->explore_proc, 149 &bus->detach_msg[0], &bus->detach_msg[1])) { 150 /* ignore */ 151 } 152 /* Wait for detach to complete */ 153 154 usb2_proc_mwait(&bus->explore_proc, 155 &bus->detach_msg[0], &bus->detach_msg[1]); 156 |
157 mtx_unlock(&bus->mtx); | 157 USB_BUS_UNLOCK(bus); |
158 159 /* Get rid of USB explore process */ 160 161 usb2_proc_unsetup(&bus->explore_proc); 162 163 return (0); 164} 165 --- 16 unchanged lines hidden (view full) --- 182 if (bus->do_probe) { 183 bus->do_probe = 0; 184 bus->driver_added_refcount++; 185 } 186 if (bus->driver_added_refcount == 0) { 187 /* avoid zero, hence that is memory default */ 188 bus->driver_added_refcount = 1; 189 } | 158 159 /* Get rid of USB explore process */ 160 161 usb2_proc_unsetup(&bus->explore_proc); 162 163 return (0); 164} 165 --- 16 unchanged lines hidden (view full) --- 182 if (bus->do_probe) { 183 bus->do_probe = 0; 184 bus->driver_added_refcount++; 185 } 186 if (bus->driver_added_refcount == 0) { 187 /* avoid zero, hence that is memory default */ 188 bus->driver_added_refcount = 1; 189 } |
190 mtx_unlock(&bus->mtx); | 190 USB_BUS_UNLOCK(bus); |
191 192 mtx_lock(&Giant); 193 194 /* 195 * Explore the Root USB HUB. This call can sleep, 196 * exiting Giant, which is actually Giant. 197 */ 198 (udev->hub->explore) (udev); 199 200 mtx_unlock(&Giant); 201 | 191 192 mtx_lock(&Giant); 193 194 /* 195 * Explore the Root USB HUB. This call can sleep, 196 * exiting Giant, which is actually Giant. 197 */ 198 (udev->hub->explore) (udev); 199 200 mtx_unlock(&Giant); 201 |
202 mtx_lock(&bus->mtx); | 202 USB_BUS_LOCK(bus); |
203 } 204 return; 205} 206 207/*------------------------------------------------------------------------* 208 * usb2_bus_detach 209 * 210 * This function is used to detach the device tree from the root. --- 5 unchanged lines hidden (view full) --- 216 struct usb2_device *udev; 217 device_t dev; 218 219 bus = ((struct usb2_bus_msg *)pm)->bus; 220 udev = bus->devices[USB_ROOT_HUB_ADDR]; 221 dev = bus->bdev; 222 /* clear the softc */ 223 device_set_softc(dev, NULL); | 203 } 204 return; 205} 206 207/*------------------------------------------------------------------------* 208 * usb2_bus_detach 209 * 210 * This function is used to detach the device tree from the root. --- 5 unchanged lines hidden (view full) --- 216 struct usb2_device *udev; 217 device_t dev; 218 219 bus = ((struct usb2_bus_msg *)pm)->bus; 220 udev = bus->devices[USB_ROOT_HUB_ADDR]; 221 dev = bus->bdev; 222 /* clear the softc */ 223 device_set_softc(dev, NULL); |
224 mtx_unlock(&bus->mtx); | 224 USB_BUS_UNLOCK(bus); |
225 226 mtx_lock(&Giant); 227 228 /* detach children first */ 229 bus_generic_detach(dev); 230 231 /* 232 * Free USB Root device, but not any sub-devices, hence they 233 * are freed by the caller of this function: 234 */ 235 usb2_detach_device(udev, USB_IFACE_INDEX_ANY, 0); 236 usb2_free_device(udev); 237 238 mtx_unlock(&Giant); | 225 226 mtx_lock(&Giant); 227 228 /* detach children first */ 229 bus_generic_detach(dev); 230 231 /* 232 * Free USB Root device, but not any sub-devices, hence they 233 * are freed by the caller of this function: 234 */ 235 usb2_detach_device(udev, USB_IFACE_INDEX_ANY, 0); 236 usb2_free_device(udev); 237 238 mtx_unlock(&Giant); |
239 mtx_lock(&bus->mtx); | 239 USB_BUS_LOCK(bus); |
240 /* clear bdev variable last */ 241 bus->bdev = NULL; 242 return; 243} 244 245/*------------------------------------------------------------------------* 246 * usb2_attach_sub 247 * --- 67 unchanged lines hidden (view full) --- 315 316 bus->detach_msg[0].hdr.pm_callback = &usb2_bus_detach; 317 bus->detach_msg[0].bus = bus; 318 bus->detach_msg[1].hdr.pm_callback = &usb2_bus_detach; 319 bus->detach_msg[1].bus = bus; 320 321 /* Create a new USB process */ 322 if (usb2_proc_setup(&bus->explore_proc, | 240 /* clear bdev variable last */ 241 bus->bdev = NULL; 242 return; 243} 244 245/*------------------------------------------------------------------------* 246 * usb2_attach_sub 247 * --- 67 unchanged lines hidden (view full) --- 315 316 bus->detach_msg[0].hdr.pm_callback = &usb2_bus_detach; 317 bus->detach_msg[0].bus = bus; 318 bus->detach_msg[1].hdr.pm_callback = &usb2_bus_detach; 319 bus->detach_msg[1].bus = bus; 320 321 /* Create a new USB process */ 322 if (usb2_proc_setup(&bus->explore_proc, |
323 &bus->mtx, USB_PRI_MED)) { | 323 &bus->bus_mtx, USB_PRI_MED)) { |
324 printf("WARNING: Creation of USB explore process failed.\n"); 325 } 326 /* set softc - we are ready */ 327 device_set_softc(dev, bus); 328 return; 329} 330 331/*------------------------------------------------------------------------* --- 95 unchanged lines hidden (view full) --- 427uint8_t 428usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat, 429 usb2_bus_mem_cb_t *cb) 430{ 431 bus->alloc_failed = 0; 432 433 bus->devices_max = USB_MAX_DEVICES; 434 | 324 printf("WARNING: Creation of USB explore process failed.\n"); 325 } 326 /* set softc - we are ready */ 327 device_set_softc(dev, bus); 328 return; 329} 330 331/*------------------------------------------------------------------------* --- 95 unchanged lines hidden (view full) --- 427uint8_t 428usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat, 429 usb2_bus_mem_cb_t *cb) 430{ 431 bus->alloc_failed = 0; 432 433 bus->devices_max = USB_MAX_DEVICES; 434 |
435 mtx_init(&bus->mtx, "USB lock", | 435 mtx_init(&bus->bus_mtx, "USB bus lock", |
436 NULL, MTX_DEF | MTX_RECURSE); 437 438 TAILQ_INIT(&bus->intr_q.head); 439 440 usb2_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags, | 436 NULL, MTX_DEF | MTX_RECURSE); 437 438 TAILQ_INIT(&bus->intr_q.head); 439 440 usb2_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags, |
441 dmat, &bus->mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX); | 441 dmat, &bus->bus_mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX); |
442 443 if (cb) { 444 cb(bus, &usb2_bus_mem_alloc_all_cb); 445 } 446 if (bus->alloc_failed) { 447 usb2_bus_mem_free_all(bus, cb); 448 } 449 return (bus->alloc_failed); --- 16 unchanged lines hidden (view full) --- 466void 467usb2_bus_mem_free_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb) 468{ 469 if (cb) { 470 cb(bus, &usb2_bus_mem_free_all_cb); 471 } 472 usb2_dma_tag_unsetup(bus->dma_parent_tag); 473 | 442 443 if (cb) { 444 cb(bus, &usb2_bus_mem_alloc_all_cb); 445 } 446 if (bus->alloc_failed) { 447 usb2_bus_mem_free_all(bus, cb); 448 } 449 return (bus->alloc_failed); --- 16 unchanged lines hidden (view full) --- 466void 467usb2_bus_mem_free_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb) 468{ 469 if (cb) { 470 cb(bus, &usb2_bus_mem_free_all_cb); 471 } 472 usb2_dma_tag_unsetup(bus->dma_parent_tag); 473 |
474 mtx_destroy(&bus->mtx); | 474 mtx_destroy(&bus->bus_mtx); |
475 476 return; 477} | 475 476 return; 477} |