Commit 70f7d2ec authored by Patrick Mochel's avatar Patrick Mochel

Remove device_root device; replace with global_device_list.

The device_root device was only a placeholder device that provided a head
for the global device list, and a parent directory for root bridge devices.

This removes the device and replaces with an explicit global_device_list 
and a separate root directory. We never used any of the other fields in 
device_root, and we special cased it. So, it's better off dead.
parent dc4c65da
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# define DBG(x...) # define DBG(x...)
#endif #endif
extern struct device device_root; extern struct list_head global_device_list;
extern spinlock_t device_lock; extern spinlock_t device_lock;
extern struct device * get_device_locked(struct device *); extern struct device * get_device_locked(struct device *);
......
...@@ -15,10 +15,7 @@ ...@@ -15,10 +15,7 @@
#include <linux/err.h> #include <linux/err.h>
#include "base.h" #include "base.h"
struct device device_root = { LIST_HEAD(global_device_list);
.bus_id = "root",
.name = "System root",
};
int (*platform_notify)(struct device * dev) = NULL; int (*platform_notify)(struct device * dev) = NULL;
int (*platform_notify_remove)(struct device * dev) = NULL; int (*platform_notify_remove)(struct device * dev) = NULL;
...@@ -178,17 +175,15 @@ int device_register(struct device *dev) ...@@ -178,17 +175,15 @@ int device_register(struct device *dev)
INIT_LIST_HEAD(&dev->bus_list); INIT_LIST_HEAD(&dev->bus_list);
spin_lock_init(&dev->lock); spin_lock_init(&dev->lock);
atomic_set(&dev->refcount,2); atomic_set(&dev->refcount,2);
if (dev != &device_root) { spin_lock(&device_lock);
if (!dev->parent) if (dev->parent) {
dev->parent = &device_root; get_device_locked(dev->parent);
get_device(dev->parent);
spin_lock(&device_lock);
list_add_tail(&dev->g_list,&dev->parent->g_list); list_add_tail(&dev->g_list,&dev->parent->g_list);
list_add_tail(&dev->node,&dev->parent->children); list_add_tail(&dev->node,&dev->parent->children);
spin_unlock(&device_lock); } else
} list_add_tail(&dev->g_list,&global_device_list);
spin_unlock(&device_lock);
pr_debug("DEV: registering device: ID = '%s', name = %s\n", pr_debug("DEV: registering device: ID = '%s', name = %s\n",
dev->bus_id, dev->name); dev->bus_id, dev->name);
...@@ -269,12 +264,8 @@ void put_device(struct device * dev) ...@@ -269,12 +264,8 @@ void put_device(struct device * dev)
if (dev->release) if (dev->release)
dev->release(dev); dev->release(dev);
put_device(dev->parent); if (dev->parent)
} put_device(dev->parent);
static int __init device_init_root(void)
{
return device_register(&device_root);
} }
static int __init device_init(void) static int __init device_init(void)
...@@ -282,14 +273,9 @@ static int __init device_init(void) ...@@ -282,14 +273,9 @@ static int __init device_init(void)
int error; int error;
error = init_driverfs_fs(); error = init_driverfs_fs();
if (error) {
panic("DEV: could not initialize driverfs");
return error;
}
error = device_init_root();
if (error) if (error)
printk(KERN_ERR "%s: device root init failed!\n", __FUNCTION__); panic("DEV: could not initialize driverfs");
return error; return 0;
} }
core_initcall(device_init); core_initcall(device_init);
......
...@@ -10,11 +10,17 @@ ...@@ -10,11 +10,17 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/limits.h> #include <linux/limits.h>
static struct driver_dir_entry device_root_dir = {
.name = "root",
.mode = (S_IRWXU | S_IRUGO | S_IXUGO),
};
extern struct device_attribute * device_default_files[]; extern struct device_attribute * device_default_files[];
#define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr) #define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr)
...@@ -164,7 +170,7 @@ int device_bus_link(struct device * dev) ...@@ -164,7 +170,7 @@ int device_bus_link(struct device * dev)
* one to get to the 'bus' directory, and one to get to the root * one to get to the 'bus' directory, and one to get to the root
* of the fs.) * of the fs.)
*/ */
length += strlen("../../.."); length += strlen("../../../root");
if (length > PATH_MAX) if (length > PATH_MAX)
return -ENAMETOOLONG; return -ENAMETOOLONG;
...@@ -174,7 +180,7 @@ int device_bus_link(struct device * dev) ...@@ -174,7 +180,7 @@ int device_bus_link(struct device * dev)
memset(path,0,length); memset(path,0,length);
/* our relative position */ /* our relative position */
strcpy(path,"../../.."); strcpy(path,"../../../root");
fill_devpath(dev,path,length); fill_devpath(dev,path,length);
error = driverfs_create_symlink(&dev->bus->device_dir,dev->bus_id,path); error = driverfs_create_symlink(&dev->bus->device_dir,dev->bus_id,path);
...@@ -207,13 +213,12 @@ int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * p ...@@ -207,13 +213,12 @@ int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * p
*/ */
int device_make_dir(struct device * dev) int device_make_dir(struct device * dev)
{ {
struct driver_dir_entry * parent = NULL; struct driver_dir_entry * parent;
struct device_attribute * entry; struct device_attribute * entry;
int error; int error;
int i; int i;
if (dev->parent) parent = dev->parent ? &dev->parent->dir : &device_root_dir;
parent = &dev->parent->dir;
dev->dir.name = dev->bus_id; dev->dir.name = dev->bus_id;
dev->dir.ops = &dev_attr_ops; dev->dir.ops = &dev_attr_ops;
...@@ -229,5 +234,12 @@ int device_make_dir(struct device * dev) ...@@ -229,5 +234,12 @@ int device_make_dir(struct device * dev)
return error; return error;
} }
static int device_driverfs_init(void)
{
return driverfs_create_dir(&device_root_dir,NULL);
}
core_initcall(device_driverfs_init);
EXPORT_SYMBOL(device_create_file); EXPORT_SYMBOL(device_create_file);
EXPORT_SYMBOL(device_remove_file); EXPORT_SYMBOL(device_remove_file);
...@@ -34,7 +34,7 @@ int device_suspend(u32 state, u32 level) ...@@ -34,7 +34,7 @@ int device_suspend(u32 state, u32 level)
printk(KERN_EMERG "Suspending Devices\n"); printk(KERN_EMERG "Suspending Devices\n");
spin_lock(&device_lock); spin_lock(&device_lock);
list_for_each(node,&device_root.g_list) { list_for_each(node,&global_device_list) {
struct device * dev = get_device_locked(to_dev(node)); struct device * dev = get_device_locked(to_dev(node));
if (dev) { if (dev) {
spin_unlock(&device_lock); spin_unlock(&device_lock);
...@@ -65,7 +65,7 @@ void device_resume(u32 level) ...@@ -65,7 +65,7 @@ void device_resume(u32 level)
struct device * prev = NULL; struct device * prev = NULL;
spin_lock(&device_lock); spin_lock(&device_lock);
list_for_each_prev(node,&device_root.g_list) { list_for_each_prev(node,&global_device_list) {
struct device * dev = get_device_locked(to_dev(node)); struct device * dev = get_device_locked(to_dev(node));
if (dev) { if (dev) {
spin_unlock(&device_lock); spin_unlock(&device_lock);
...@@ -98,7 +98,7 @@ void device_shutdown(void) ...@@ -98,7 +98,7 @@ void device_shutdown(void)
printk(KERN_EMERG "Shutting down devices\n"); printk(KERN_EMERG "Shutting down devices\n");
spin_lock(&device_lock); spin_lock(&device_lock);
list_for_each(node,&device_root.g_list) { list_for_each(node,&global_device_list) {
struct device * dev = get_device_locked(to_dev(node)); struct device * dev = get_device_locked(to_dev(node));
if (dev) { if (dev) {
spin_unlock(&device_lock); spin_unlock(&device_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment