Add device_set_softc() which does the obvious.

Not objected to by:	dfr
This commit is contained in:
Poul-Henning Kamp 2000-07-03 13:06:29 +00:00
parent 3bc7ba9057
commit 9282307a5d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=62466
3 changed files with 23 additions and 7 deletions

View File

@ -855,6 +855,18 @@ device_get_softc(device_t dev)
return dev->softc;
}
void
device_set_softc(device_t dev, void *softc)
{
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC))
free(dev->softc, M_BUS);
dev->softc = softc;
if (dev->softc)
dev->flags |= DF_EXTERNALSOFTC;
else
dev->flags &= ~DF_EXTERNALSOFTC;
}
void *
device_get_ivars(device_t dev)
{
@ -976,7 +988,7 @@ device_set_driver(device_t dev, driver_t *driver)
if (dev->driver == driver)
return 0;
if (dev->softc) {
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
free(dev->softc, M_BUS);
dev->softc = NULL;
}
@ -984,6 +996,7 @@ device_set_driver(device_t dev, driver_t *driver)
dev->driver = driver;
if (driver) {
kobj_init((kobj_t) dev, (kobj_class_t) driver);
if (!(dev->flags & DF_EXTERNALSOFTC)) {
dev->softc = malloc(driver->size, M_BUS, M_NOWAIT);
if (!dev->softc) {
kobj_init((kobj_t) dev, &null_class);
@ -991,6 +1004,7 @@ device_set_driver(device_t dev, driver_t *driver)
return ENOMEM;
}
bzero(dev->softc, driver->size);
}
} else
kobj_init((kobj_t) dev, &null_class);
return 0;

View File

@ -247,6 +247,7 @@ void device_set_desc_copy(device_t dev, const char* desc);
int device_set_devclass(device_t dev, const char *classname);
int device_set_driver(device_t dev, driver_t *driver);
void device_set_flags(device_t dev, u_int32_t flags);
void device_set_softc(device_t dev, void *softc);
int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */
int device_shutdown(device_t dev);
void device_unbusy(device_t dev);

View File

@ -114,6 +114,7 @@ struct device {
#define DF_DESCMALLOCED 8 /* description was malloced */
#define DF_QUIET 16 /* don't print verbose attach message */
#define DF_DONENOMATCH 32 /* don't execute DEVICE_NOMATCH again */
#define DF_EXTERNALSOFTC 64 /* softc not allocated by us */
u_char order; /* order from device_add_child_ordered() */
u_char pad;
#ifdef DEVICE_SYSCTLS