subr_bus.c (239178) | subr_bus.c (239299) |
---|---|
1/*- 2 * Copyright (c) 1997,1998,2003 Doug Rabson 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997,1998,2003 Doug Rabson 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/kern/subr_bus.c 239178 2012-08-10 15:02:49Z hselasky $"); | 28__FBSDID("$FreeBSD: head/sys/kern/subr_bus.c 239299 2012-08-15 15:42:57Z hselasky $"); |
29 30#include "opt_bus.h" 31 32#include <sys/param.h> 33#include <sys/conf.h> 34#include <sys/filio.h> 35#include <sys/lock.h> 36#include <sys/kernel.h> --- 2364 unchanged lines hidden (view full) --- 2401 * @brief Set the device's softc field 2402 * 2403 * Most drivers do not need to use this since the softc is allocated 2404 * automatically when the driver is attached. 2405 */ 2406void 2407device_set_softc(device_t dev, void *softc) 2408{ | 29 30#include "opt_bus.h" 31 32#include <sys/param.h> 33#include <sys/conf.h> 34#include <sys/filio.h> 35#include <sys/lock.h> 36#include <sys/kernel.h> --- 2364 unchanged lines hidden (view full) --- 2401 * @brief Set the device's softc field 2402 * 2403 * Most drivers do not need to use this since the softc is allocated 2404 * automatically when the driver is attached. 2405 */ 2406void 2407device_set_softc(device_t dev, void *softc) 2408{ |
2409 if (dev->softc != NULL && !(dev->flags & DF_EXTERNALSOFTC)) 2410 DEVICE_FREE_SOFTC(dev, dev->softc); | 2409 if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) 2410 free(dev->softc, M_BUS_SC); |
2411 dev->softc = softc; 2412 if (dev->softc) 2413 dev->flags |= DF_EXTERNALSOFTC; 2414 else 2415 dev->flags &= ~DF_EXTERNALSOFTC; 2416} 2417 2418/** | 2411 dev->softc = softc; 2412 if (dev->softc) 2413 dev->flags |= DF_EXTERNALSOFTC; 2414 else 2415 dev->flags &= ~DF_EXTERNALSOFTC; 2416} 2417 2418/** |
2419 * @brief Free claimed softc 2420 * 2421 * Most drivers do not need to use this since the softc is freed 2422 * automatically when the driver is detached. 2423 */ 2424void 2425device_free_softc(void *softc) 2426{ 2427 free(softc, M_BUS_SC); 2428} 2429 2430/** 2431 * @brief Claim softc 2432 * 2433 * This function can be used to let the driver free the automatically 2434 * allocated softc using "device_free_softc()". This function is 2435 * useful when the driver is refcounting the softc and the softc 2436 * cannot be freed when the "device_detach" method is called. 2437 */ 2438void 2439device_claim_softc(device_t dev) 2440{ 2441 if (dev->softc) 2442 dev->flags |= DF_EXTERNALSOFTC; 2443 else 2444 dev->flags &= ~DF_EXTERNALSOFTC; 2445} 2446 2447/** |
|
2419 * @brief Get the device's ivars field 2420 * 2421 * The ivars field is used by the parent device to store per-device 2422 * state (e.g. the physical location of the device or a list of 2423 * resources). 2424 */ 2425void * 2426device_get_ivars(device_t dev) --- 172 unchanged lines hidden (view full) --- 2599device_set_driver(device_t dev, driver_t *driver) 2600{ 2601 if (dev->state >= DS_ATTACHED) 2602 return (EBUSY); 2603 2604 if (dev->driver == driver) 2605 return (0); 2606 | 2448 * @brief Get the device's ivars field 2449 * 2450 * The ivars field is used by the parent device to store per-device 2451 * state (e.g. the physical location of the device or a list of 2452 * resources). 2453 */ 2454void * 2455device_get_ivars(device_t dev) --- 172 unchanged lines hidden (view full) --- 2628device_set_driver(device_t dev, driver_t *driver) 2629{ 2630 if (dev->state >= DS_ATTACHED) 2631 return (EBUSY); 2632 2633 if (dev->driver == driver) 2634 return (0); 2635 |
2607 if (dev->softc != NULL && !(dev->flags & DF_EXTERNALSOFTC)) { 2608 DEVICE_FREE_SOFTC(dev, dev->softc); | 2636 if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) { 2637 free(dev->softc, M_BUS_SC); |
2609 dev->softc = NULL; 2610 } 2611 device_set_desc(dev, NULL); 2612 kobj_delete((kobj_t) dev, NULL); 2613 dev->driver = driver; 2614 if (driver) { 2615 kobj_init((kobj_t) dev, (kobj_class_t) driver); 2616 if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) { --- 2175 unchanged lines hidden (view full) --- 4792 4793int 4794bus_free_resource(device_t dev, int type, struct resource *r) 4795{ 4796 if (r == NULL) 4797 return (0); 4798 return (bus_release_resource(dev, type, rman_get_rid(r), r)); 4799} | 2638 dev->softc = NULL; 2639 } 2640 device_set_desc(dev, NULL); 2641 kobj_delete((kobj_t) dev, NULL); 2642 dev->driver = driver; 2643 if (driver) { 2644 kobj_init((kobj_t) dev, (kobj_class_t) driver); 2645 if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) { --- 2175 unchanged lines hidden (view full) --- 4821 4822int 4823bus_free_resource(device_t dev, int type, struct resource *r) 4824{ 4825 if (r == NULL) 4826 return (0); 4827 return (bus_release_resource(dev, type, rman_get_rid(r), r)); 4828} |
4800 4801/* 4802 * The "dev" argument passed to "device_free_softc()" is allowed to be 4803 * NULL, if the device freeing the soft is not available. 4804 */ 4805void 4806device_free_softc(device_t dev, void *softc) 4807{ 4808 free(softc, M_BUS_SC); 4809} | |