diff options
| author | Patrick Mochel <mochel@osdl.org> | 2002-10-16 22:07:11 -0700 |
|---|---|---|
| committer | Patrick Mochel <mochel@osdl.org> | 2002-10-16 22:07:11 -0700 |
| commit | be0b9c71e35ebee75fc694daa9f2a268b504ca50 (patch) | |
| tree | 8d5b8f6576758f593b91beb236cd8c1f0034c6e5 | |
| parent | 6b1febf70889295545f50cc0d05312eaf6daa0a2 (diff) | |
driver model: change struct device::present to enumerated value with multiple states.
Adapted from Greg KH:
- add multiple possible enumerated states a device can be in: UNINITIALIZED, INITIALIZED,
REGISTERED, and GONE.
- Check whether device is INITIALIZED or REGISTERED in device_present().
- Change struct device::current_state to ::power_state to better reflect what it is.
| -rw-r--r-- | drivers/base/core.c | 9 | ||||
| -rw-r--r-- | drivers/base/interface.c | 2 | ||||
| -rw-r--r-- | include/linux/device.h | 13 |
3 files changed, 16 insertions, 8 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index c7f2fcfd480c..bd82a792d877 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -33,7 +33,7 @@ int device_add(struct device *dev) return -EINVAL; down(&device_sem); - dev->present = 1; + dev->state = DEVICE_REGISTERED; if (dev->parent) { list_add_tail(&dev->g_list,&dev->parent->g_list); list_add_tail(&dev->node,&dev->parent->children); @@ -77,6 +77,7 @@ void device_initialize(struct device *dev) INIT_LIST_HEAD(&dev->intf_list); spin_lock_init(&dev->lock); atomic_set(&dev->refcount,1); + dev->state = DEVICE_INITIALIZED; if (dev->parent) get_device(dev->parent); } @@ -112,7 +113,7 @@ struct device * get_device(struct device * dev) { struct device * ret = dev; down(&device_sem); - if (dev && dev->present && atomic_read(&dev->refcount) > 0) + if (device_present(dev) && atomic_read(&dev->refcount) > 0) atomic_inc(&dev->refcount); else ret = NULL; @@ -135,7 +136,7 @@ void put_device(struct device * dev) list_del_init(&dev->g_list); up(&device_sem); - BUG_ON(dev->present); + BUG_ON((dev->state != DEVICE_GONE)); device_del(dev); } @@ -177,7 +178,7 @@ void device_del(struct device * dev) void device_unregister(struct device * dev) { down(&device_sem); - dev->present = 0; + dev->state = DEVICE_GONE; up(&device_sem); pr_debug("DEV: Unregistering device. ID = '%s', name = '%s'\n", diff --git a/drivers/base/interface.c b/drivers/base/interface.c index a585b729c5c4..8a5c6e6bc226 100644 --- a/drivers/base/interface.c +++ b/drivers/base/interface.c @@ -19,7 +19,7 @@ static DEVICE_ATTR(name,S_IRUGO,device_read_name,NULL); static ssize_t device_read_power(struct device * dev, char * page, size_t count, loff_t off) { - return off ? 0 : sprintf(page,"%d\n",dev->current_state); + return off ? 0 : sprintf(page,"%d\n",dev->power_state); } static ssize_t diff --git a/include/linux/device.h b/include/linux/device.h index d34142925760..3dd9a4081298 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -48,6 +48,13 @@ enum { RESUME_ENABLE, }; +enum device_state { + DEVICE_UNINITIALIZED = 0, + DEVICE_INITIALIZED = 1, + DEVICE_REGISTERED = 2, + DEVICE_GONE = 3, +}; + struct device; struct device_driver; struct device_class; @@ -288,8 +295,8 @@ struct device { void *platform_data; /* Platform specific data (e.g. ACPI, BIOS data relevant to device) */ - u32 present; - u32 current_state; /* Current operating state. In + enum device_state state; + u32 power_state; /* Current operating state. In ACPI-speak, this is D0-D3, D0 being fully functional, and D3 being off. */ @@ -363,7 +370,7 @@ extern int (*platform_notify_remove)(struct device * dev); static inline int device_present(struct device * dev) { - return (dev && dev->present == 1); + return (dev && (dev->state == DEVICE_INITIALIZED || dev->state == DEVICE_REGISTERED)); } /* device and bus locking helpers. |
