Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/subr_bus.c
Show First 20 Lines • Show All 2,536 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Most drivers do not need to use this since the softc is allocated | * Most drivers do not need to use this since the softc is allocated | ||||
* automatically when the driver is attached. | * automatically when the driver is attached. | ||||
*/ | */ | ||||
void | void | ||||
device_set_softc(device_t dev, void *softc) | device_set_softc(device_t dev, void *softc) | ||||
{ | { | ||||
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) | if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) | ||||
free_domain(dev->softc, M_BUS_SC); | free(dev->softc, M_BUS_SC); | ||||
dev->softc = softc; | dev->softc = softc; | ||||
if (dev->softc) | if (dev->softc) | ||||
dev->flags |= DF_EXTERNALSOFTC; | dev->flags |= DF_EXTERNALSOFTC; | ||||
else | else | ||||
dev->flags &= ~DF_EXTERNALSOFTC; | dev->flags &= ~DF_EXTERNALSOFTC; | ||||
} | } | ||||
/** | /** | ||||
* @brief Free claimed softc | * @brief Free claimed softc | ||||
* | * | ||||
* Most drivers do not need to use this since the softc is freed | * Most drivers do not need to use this since the softc is freed | ||||
* automatically when the driver is detached. | * automatically when the driver is detached. | ||||
*/ | */ | ||||
void | void | ||||
device_free_softc(void *softc) | device_free_softc(void *softc) | ||||
{ | { | ||||
free_domain(softc, M_BUS_SC); | free(softc, M_BUS_SC); | ||||
} | } | ||||
/** | /** | ||||
* @brief Claim softc | * @brief Claim softc | ||||
* | * | ||||
* This function can be used to let the driver free the automatically | * This function can be used to let the driver free the automatically | ||||
* allocated softc using "device_free_softc()". This function is | * allocated softc using "device_free_softc()". This function is | ||||
* useful when the driver is refcounting the softc and the softc | * useful when the driver is refcounting the softc and the softc | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | device_set_driver(device_t dev, driver_t *driver) | ||||
if (dev->state >= DS_ATTACHED) | if (dev->state >= DS_ATTACHED) | ||||
return (EBUSY); | return (EBUSY); | ||||
if (dev->driver == driver) | if (dev->driver == driver) | ||||
return (0); | return (0); | ||||
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) { | if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) { | ||||
free_domain(dev->softc, M_BUS_SC); | free(dev->softc, M_BUS_SC); | ||||
dev->softc = NULL; | dev->softc = NULL; | ||||
} | } | ||||
device_set_desc(dev, NULL); | device_set_desc(dev, NULL); | ||||
kobj_delete((kobj_t) dev, NULL); | kobj_delete((kobj_t) dev, NULL); | ||||
dev->driver = driver; | dev->driver = driver; | ||||
if (driver) { | if (driver) { | ||||
kobj_init((kobj_t) dev, (kobj_class_t) driver); | kobj_init((kobj_t) dev, (kobj_class_t) driver); | ||||
if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) { | if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) { | ||||
▲ Show 20 Lines • Show All 3,163 Lines • Show Last 20 Lines |