diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/attribute_container.c | 77 | ||||
-rw-r--r-- | drivers/base/base.h | 11 | ||||
-rw-r--r-- | drivers/base/bus.c | 16 | ||||
-rw-r--r-- | drivers/base/class.c | 640 | ||||
-rw-r--r-- | drivers/base/core.c | 74 | ||||
-rw-r--r-- | drivers/base/cpu.c | 52 | ||||
-rw-r--r-- | drivers/base/dd.c | 14 | ||||
-rw-r--r-- | drivers/base/driver.c | 10 | ||||
-rw-r--r-- | drivers/base/firmware_class.c | 20 | ||||
-rw-r--r-- | drivers/base/memory.c | 33 | ||||
-rw-r--r-- | drivers/base/node.c | 31 | ||||
-rw-r--r-- | drivers/base/power/main.c | 103 | ||||
-rw-r--r-- | drivers/base/power/power.h | 23 | ||||
-rw-r--r-- | drivers/base/power/sysfs.c | 2 | ||||
-rw-r--r-- | drivers/base/sys.c | 18 | ||||
-rw-r--r-- | drivers/base/topology.c | 41 | ||||
-rw-r--r-- | drivers/base/transport_class.c | 14 |
17 files changed, 276 insertions, 903 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 3b43e8a9f87e..f57652db0a2a 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c @@ -27,21 +27,21 @@ struct internal_container { struct klist_node node; struct attribute_container *cont; - struct class_device classdev; + struct device classdev; }; static void internal_container_klist_get(struct klist_node *n) { struct internal_container *ic = container_of(n, struct internal_container, node); - class_device_get(&ic->classdev); + get_device(&ic->classdev); } static void internal_container_klist_put(struct klist_node *n) { struct internal_container *ic = container_of(n, struct internal_container, node); - class_device_put(&ic->classdev); + put_device(&ic->classdev); } @@ -53,7 +53,7 @@ static void internal_container_klist_put(struct klist_node *n) * Returns the container associated with this classdev. */ struct attribute_container * -attribute_container_classdev_to_container(struct class_device *classdev) +attribute_container_classdev_to_container(struct device *classdev) { struct internal_container *ic = container_of(classdev, struct internal_container, classdev); @@ -110,11 +110,11 @@ attribute_container_unregister(struct attribute_container *cont) EXPORT_SYMBOL_GPL(attribute_container_unregister); /* private function used as class release */ -static void attribute_container_release(struct class_device *classdev) +static void attribute_container_release(struct device *classdev) { struct internal_container *ic = container_of(classdev, struct internal_container, classdev); - struct device *dev = classdev->dev; + struct device *dev = classdev->parent; kfree(ic); put_device(dev); @@ -129,12 +129,12 @@ static void attribute_container_release(struct class_device *classdev) * This function allocates storage for the class device(s) to be * attached to dev (one for each matching attribute_container). If no * fn is provided, the code will simply register the class device via - * class_device_add. If a function is provided, it is expected to add + * device_add. If a function is provided, it is expected to add * the class device at the appropriate time. One of the things that * might be necessary is to allocate and initialise the classdev and * then add it a later time. To do this, call this routine for * allocation and initialisation and then use - * attribute_container_device_trigger() to call class_device_add() on + * attribute_container_device_trigger() to call device_add() on * it. Note: after this, the class device contains a reference to dev * which is not relinquished until the release of the classdev. */ @@ -142,7 +142,7 @@ void attribute_container_add_device(struct device *dev, int (*fn)(struct attribute_container *, struct device *, - struct class_device *)) + struct device *)) { struct attribute_container *cont; @@ -163,11 +163,11 @@ attribute_container_add_device(struct device *dev, } ic->cont = cont; - class_device_initialize(&ic->classdev); - ic->classdev.dev = get_device(dev); + device_initialize(&ic->classdev); + ic->classdev.parent = get_device(dev); ic->classdev.class = cont->class; - cont->class->release = attribute_container_release; - strcpy(ic->classdev.class_id, dev->bus_id); + cont->class->dev_release = attribute_container_release; + strcpy(ic->classdev.bus_id, dev->bus_id); if (fn) fn(cont, dev, &ic->classdev); else @@ -195,20 +195,19 @@ attribute_container_add_device(struct device *dev, * @fn: A function to call to remove the device * * This routine triggers device removal. If fn is NULL, then it is - * simply done via class_device_unregister (note that if something + * simply done via device_unregister (note that if something * still has a reference to the classdev, then the memory occupied * will not be freed until the classdev is released). If you want a * two phase release: remove from visibility and then delete the * device, then you should use this routine with a fn that calls - * class_device_del() and then use - * attribute_container_device_trigger() to do the final put on the - * classdev. + * device_del() and then use attribute_container_device_trigger() + * to do the final put on the classdev. */ void attribute_container_remove_device(struct device *dev, void (*fn)(struct attribute_container *, struct device *, - struct class_device *)) + struct device *)) { struct attribute_container *cont; @@ -224,14 +223,14 @@ attribute_container_remove_device(struct device *dev, continue; klist_for_each_entry(ic, &cont->containers, node, &iter) { - if (dev != ic->classdev.dev) + if (dev != ic->classdev.parent) continue; klist_del(&ic->node); if (fn) fn(cont, dev, &ic->classdev); else { attribute_container_remove_attrs(&ic->classdev); - class_device_unregister(&ic->classdev); + device_unregister(&ic->classdev); } } } @@ -252,7 +251,7 @@ void attribute_container_device_trigger(struct device *dev, int (*fn)(struct attribute_container *, struct device *, - struct class_device *)) + struct device *)) { struct attribute_container *cont; @@ -270,7 +269,7 @@ attribute_container_device_trigger(struct device *dev, } klist_for_each_entry(ic, &cont->containers, node, &iter) { - if (dev == ic->classdev.dev) + if (dev == ic->classdev.parent) fn(cont, dev, &ic->classdev); } } @@ -313,11 +312,11 @@ attribute_container_trigger(struct device *dev, * attributes listed in the container */ int -attribute_container_add_attrs(struct class_device *classdev) +attribute_container_add_attrs(struct device *classdev) { struct attribute_container *cont = attribute_container_classdev_to_container(classdev); - struct class_device_attribute **attrs = cont->attrs; + struct device_attribute **attrs = cont->attrs; int i, error; BUG_ON(attrs && cont->grp); @@ -329,7 +328,7 @@ attribute_container_add_attrs(struct class_device *classdev) return sysfs_create_group(&classdev->kobj, cont->grp); for (i = 0; attrs[i]; i++) { - error = class_device_create_file(classdev, attrs[i]); + error = device_create_file(classdev, attrs[i]); if (error) return error; } @@ -338,18 +337,18 @@ attribute_container_add_attrs(struct class_device *classdev) } /** - * attribute_container_add_class_device - same function as class_device_add + * attribute_container_add_class_device - same function as device_add * * @classdev: the class device to add * - * This performs essentially the same function as class_device_add except for + * This performs essentially the same function as device_add except for * attribute containers, namely add the classdev to the system and then * create the attribute files */ int -attribute_container_add_class_device(struct class_device *classdev) +attribute_container_add_class_device(struct device *classdev) { - int error = class_device_add(classdev); + int error = device_add(classdev); if (error) return error; return attribute_container_add_attrs(classdev); @@ -364,7 +363,7 @@ attribute_container_add_class_device(struct class_device *classdev) int attribute_container_add_class_device_adapter(struct attribute_container *cont, struct device *dev, - struct class_device *classdev) + struct device *classdev) { return attribute_container_add_class_device(classdev); } @@ -376,11 +375,11 @@ attribute_container_add_class_device_adapter(struct attribute_container *cont, * */ void -attribute_container_remove_attrs(struct class_device *classdev) +attribute_container_remove_attrs(struct device *classdev) { struct attribute_container *cont = attribute_container_classdev_to_container(classdev); - struct class_device_attribute **attrs = cont->attrs; + struct device_attribute **attrs = cont->attrs; int i; if (!attrs && !cont->grp) @@ -392,7 +391,7 @@ attribute_container_remove_attrs(struct class_device *classdev) } for (i = 0; attrs[i]; i++) - class_device_remove_file(classdev, attrs[i]); + device_remove_file(classdev, attrs[i]); } /** @@ -401,13 +400,13 @@ attribute_container_remove_attrs(struct class_device *classdev) * @classdev: the class device * * This function simply removes all the attribute files and then calls - * class_device_del. + * device_del. */ void -attribute_container_class_device_del(struct class_device *classdev) +attribute_container_class_device_del(struct device *classdev) { attribute_container_remove_attrs(classdev); - class_device_del(classdev); + device_del(classdev); } /** @@ -419,16 +418,16 @@ attribute_container_class_device_del(struct class_device *classdev) * Looks up the device in the container's list of class devices and returns * the corresponding class_device. */ -struct class_device * +struct device * attribute_container_find_class_device(struct attribute_container *cont, struct device *dev) { - struct class_device *cdev = NULL; + struct device *cdev = NULL; struct internal_container *ic; struct klist_iter iter; klist_for_each_entry(ic, &cont->containers, node, &iter) { - if (ic->classdev.dev == dev) { + if (ic->classdev.parent == dev) { cdev = &ic->classdev; /* FIXME: must exit iterator then break */ klist_iter_exit(&iter); diff --git a/drivers/base/base.h b/drivers/base/base.h index c0444146c09a..2c9ae43e2219 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -64,17 +64,6 @@ extern void sysdev_shutdown(void); extern int sysdev_suspend(pm_message_t state); extern int sysdev_resume(void); -static inline struct class_device *to_class_dev(struct kobject *obj) -{ - return container_of(obj, struct class_device, kobj); -} - -static inline -struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) -{ - return container_of(_attr, struct class_device_attribute, attr); -} - extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 2d207ad30336..ef522ae55480 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -79,7 +79,7 @@ static void driver_release(struct kobject *kobj) { struct driver_private *drv_priv = to_driver(kobj); - pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__); + pr_debug("driver: '%s': %s\n", kobject_name(kobj), __func__); kfree(drv_priv); } @@ -505,14 +505,11 @@ void bus_attach_device(struct device *dev) int ret = 0; if (bus) { - dev->is_registered = 1; if (bus->p->drivers_autoprobe) ret = device_attach(dev); WARN_ON(ret < 0); if (ret >= 0) klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); - else - dev->is_registered = 0; } } @@ -533,10 +530,9 @@ void bus_remove_device(struct device *dev) sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id); device_remove_attrs(dev->bus, dev); - if (dev->is_registered) { - dev->is_registered = 0; + if (klist_node_attached(&dev->knode_bus)) klist_del(&dev->knode_bus); - } + pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id); device_release_driver(dev); @@ -682,19 +678,19 @@ int bus_add_driver(struct device_driver *drv) error = driver_create_file(drv, &driver_attr_uevent); if (error) { printk(KERN_ERR "%s: uevent attr (%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } error = driver_add_attrs(bus, drv); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } error = add_bind_files(drv); if (error) { /* Ditto */ printk(KERN_ERR "%s: add_bind_files(%s) failed\n", - __FUNCTION__, drv->name); + __func__, drv->name); } kobject_uevent(&priv->kobj, KOBJ_ADD); diff --git a/drivers/base/class.c b/drivers/base/class.c index 9d915376c313..0ef00e8d4153 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -175,31 +175,17 @@ void class_unregister(struct class *cls) static void class_create_release(struct class *cls) { - pr_debug("%s called for %s\n", __FUNCTION__, cls->name); + pr_debug("%s called for %s\n", __func__, cls->name); kfree(cls); } -static void class_device_create_release(struct class_device *class_dev) -{ - pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); - kfree(class_dev); -} - -/* needed to allow these devices to have parent class devices */ -static int class_device_create_uevent(struct class_device *class_dev, - struct kobj_uevent_env *env) -{ - pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); - return 0; -} - /** * class_create - create a struct class structure * @owner: pointer to the module that is to "own" this struct class * @name: pointer to a string for the name of this class. * * This is used to create a struct class pointer that can then be used - * in calls to class_device_create(). + * in calls to device_create(). * * Note, the pointer created here is to be destroyed when finished by * making a call to class_destroy(). @@ -218,7 +204,6 @@ struct class *class_create(struct module *owner, const char *name) cls->name = name; cls->owner = owner; cls->class_release = class_create_release; - cls->release = class_device_create_release; retval = class_register(cls); if (retval) @@ -246,113 +231,6 @@ void class_destroy(struct class *cls) class_unregister(cls); } -/* Class Device Stuff */ - -int class_device_create_file(struct class_device *class_dev, - const struct class_device_attribute *attr) -{ - int error = -EINVAL; - if (class_dev) - error = sysfs_create_file(&class_dev->kobj, &attr->attr); - return error; -} - -void class_device_remove_file(struct class_device *class_dev, - const struct class_device_attribute *attr) -{ - if (class_dev) - sysfs_remove_file(&class_dev->kobj, &attr->attr); -} - -int class_device_create_bin_file(struct class_device *class_dev, - struct bin_attribute *attr) -{ - int error = -EINVAL; - if (class_dev) - error = sysfs_create_bin_file(&class_dev->kobj, attr); - return error; -} - -void class_device_remove_bin_file(struct class_device *class_dev, - struct bin_attribute *attr) -{ - if (class_dev) - sysfs_remove_bin_file(&class_dev->kobj, attr); -} - -static ssize_t class_device_attr_show(struct kobject *kobj, - struct attribute *attr, char *buf) -{ - struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); - struct class_device *cd = to_class_dev(kobj); - ssize_t ret = 0; - - if (class_dev_attr->show) - ret = class_dev_attr->show(cd, buf); - return ret; -} - -static ssize_t class_device_attr_store(struct kobject *kobj, - struct attribute *attr, - const char *buf, size_t count) -{ - struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); - struct class_device *cd = to_class_dev(kobj); - ssize_t ret = 0; - - if (class_dev_attr->store) - ret = class_dev_attr->store(cd, buf, count); - return ret; -} - -static struct sysfs_ops class_dev_sysfs_ops = { - .show = class_device_attr_show, - .store = class_device_attr_store, -}; - -static void class_dev_release(struct kobject *kobj) -{ - struct class_device *cd = to_class_dev(kobj); - struct class *cls = cd->class; - - pr_debug("device class '%s': release.\n", cd->class_id); - - if (cd->release) - cd->release(cd); - else if (cls->release) - cls->release(cd); - else { - printk(KERN_ERR "Class Device '%s' does not have a release() " - "function, it is broken and must be fixed.\n", - cd->class_id); - WARN_ON(1); - } -} - -static struct kobj_type class_device_ktype = { - .sysfs_ops = &class_dev_sysfs_ops, - .release = class_dev_release, -}; - -static int class_uevent_filter(struct kset *kset, struct kobject *kobj) -{ - struct kobj_type *ktype = get_ktype(kobj); - - if (ktype == &class_device_ktype) { - struct class_device *class_dev = to_class_dev(kobj); - if (class_dev->class) - return 1; - } - return 0; -} - -static const char *class_uevent_name(struct kset *kset, struct kobject *kobj) -{ - struct class_device *class_dev = to_class_dev(kobj); - - return class_dev->class->name; -} - #ifdef CONFIG_SYSFS_DEPRECATED char *make_class_name(const char *name, struct kobject *kobj) { @@ -370,445 +248,8 @@ char *make_class_name(const char *name, struct kobject *kobj) strcat(class_name, kobject_name(kobj)); return class_name; } - -static int make_deprecated_class_device_links(struct class_device *class_dev) -{ - char *class_name; - int error; - - if (!class_dev->dev) - return 0; - - class_name = make_class_name(class_dev->class->name, &class_dev->kobj); - if (class_name) - error = sysfs_create_link(&class_dev->dev->kobj, - &class_dev->kobj, class_name); - else - error = -ENOMEM; - kfree(class_name); - return error; -} - -static void remove_deprecated_class_device_links(struct class_device *class_dev) -{ - char *class_name; - - if (!class_dev->dev) - return; - - class_name = make_class_name(class_dev->class->name, &class_dev->kobj); - if (class_name) - sysfs_remove_link(&class_dev->dev->kobj, class_name); - kfree(class_name); -} -#else -static inline int make_deprecated_class_device_links(struct class_device *cd) -{ return 0; } -static void remove_deprecated_class_device_links(struct class_device *cd) -{ } #endif -static int class_uevent(struct kset *kset, struct kobject *kobj, - struct kobj_uevent_env *env) -{ - struct class_device *class_dev = to_class_dev(kobj); - struct device *dev = class_dev->dev; - int retval = 0; - - pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); - - if (MAJOR(class_dev->devt)) { - add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt)); - - add_uevent_var(env, "MINOR=%u", MINOR(class_dev->devt)); - } - - if (dev) { - const char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); - if (path) { - add_uevent_var(env, "PHYSDEVPATH=%s", path); - kfree(path); - } - - if (dev->bus) - add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); - - if (dev->driver) - add_uevent_var(env, "PHYSDEVDRIVER=%s", - dev->driver->name); - } - - if (class_dev->uevent) { - /* have the class device specific function add its stuff */ - retval = class_dev->uevent(class_dev, env); - if (retval) - pr_debug("class_dev->uevent() returned %d\n", retval); - } else if (class_dev->class->uevent) { - /* have the class specific function add its stuff */ - retval = class_dev->class->uevent(class_dev, env); - if (retval) - pr_debug("class->uevent() returned %d\n", retval); - } - - return retval; -} - -static struct kset_uevent_ops class_uevent_ops = { - .filter = class_uevent_filter, - .name = class_uevent_name, - .uevent = class_uevent, -}; - -/* - * DO NOT copy how this is created, kset_create_and_add() should be - * called, but this is a hold-over from the old-way and will be deleted - * entirely soon. - */ -static struct kset class_obj_subsys = { - .uevent_ops = &class_uevent_ops, -}; - -static int class_device_add_attrs(struct class_device *cd) -{ - int i; - int error = 0; - struct class *cls = cd->class; - - if (cls->class_dev_attrs) { - for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { - error = class_device_create_file(cd, - &cls->class_dev_attrs[i]); - if (error) - goto err; - } - } -done: - return error; -err: - while (--i >= 0) - class_device_remove_file(cd, &cls->class_dev_attrs[i]); - goto done; -} - -static void class_device_remove_attrs(struct class_device *cd) -{ - int i; - struct class *cls = cd->class; - - if (cls->class_dev_attrs) { - for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) - class_device_remove_file(cd, &cls->class_dev_attrs[i]); - } -} - -static int class_device_add_groups(struct class_device *cd) -{ - int i; - int error = 0; - - if (cd->groups) { - for (i = 0; cd->groups[i]; i++) { - error = sysfs_create_group(&cd->kobj, cd->groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&cd->kobj, - cd->groups[i]); - goto out; - } - } - } -out: - return error; -} - -static void class_device_remove_groups(struct class_device *cd) -{ - int i; - if (cd->groups) - for (i = 0; cd->groups[i]; i++) - sysfs_remove_group(&cd->kobj, cd->groups[i]); -} - -static ssize_t show_dev(struct class_device *class_dev, char *buf) -{ - return print_dev_t(buf, class_dev->devt); -} - -static struct class_device_attribute class_devt_attr = - __ATTR(dev, S_IRUGO, show_dev, NULL); - -static ssize_t store_uevent(struct class_device *class_dev, - const char *buf, size_t count) -{ - kobject_uevent(&class_dev->kobj, KOBJ_ADD); - return count; -} - -static struct class_device_attribute class_uevent_attr = - __ATTR(uevent, S_IWUSR, NULL, store_uevent); - -void class_device_initialize(struct class_device *class_dev) -{ - class_dev->kobj.kset = &class_obj_subsys; - kobject_init(&class_dev->kobj, &class_device_ktype); - INIT_LIST_HEAD(&class_dev->node); -} - -int class_device_add(struct class_device *class_dev) -{ - struct class *parent_class = NULL; - struct class_device *parent_class_dev = NULL; - struct class_interface *class_intf; - int error = -EINVAL; - - class_dev = class_device_get(class_dev); - if (!class_dev) - return -EINVAL; - - if (!strlen(class_dev->class_id)) - goto out1; - - parent_class = class_get(class_dev->class); - if (!parent_class) - goto out1; - - parent_class_dev = class_device_get(class_dev->parent); - - pr_debug("CLASS: registering class device: ID = '%s'\n", - class_dev->class_id); - - /* first, register with generic layer. */ - if (parent_class_dev) - class_dev->kobj.parent = &parent_class_dev->kobj; - else - class_dev->kobj.parent = &parent_class->subsys.kobj; - - error = kobject_add(&class_dev->kobj, class_dev->kobj.parent, - "%s", class_dev->class_id); - if (error) - goto out2; - - /* add the needed attributes to this device */ - error = sysfs_create_link(&class_dev->kobj, - &parent_class->subsys.kobj, "subsystem"); - if (error) - goto out3; - - error = class_device_create_file(class_dev, &class_uevent_attr); - if (error) - goto out3; - - if (MAJOR(class_dev->devt)) { - error = class_device_create_file(class_dev, &class_devt_attr); - if (error) - goto out4; - } - - error = class_device_add_attrs(class_dev); - if (error) - goto out5; - - if (class_dev->dev) { - error = sysfs_create_link(&class_dev->kobj, - &class_dev->dev->kobj, "device"); - if (error) - goto out6; - } - - error = class_device_add_groups(class_dev); - if (error) - goto out7; - - error = make_deprecated_class_device_links(class_dev); - if (error) - goto out8; - - kobject_uevent(&class_dev->kobj, KOBJ_ADD); - - /* notify any interfaces this device is now here */ - down(&parent_class->sem); - list_add_tail(&class_dev->node, &parent_class->children); - list_for_each_entry(class_intf, &parent_class->interfaces, node) { - if (class_intf->add) - class_intf->add(class_dev, class_intf); - } - up(&parent_class->sem); - - goto out1; - - out8: - class_device_remove_groups(class_dev); - out7: - if (class_dev->dev) - sysfs_remove_link(&class_dev->kobj, "device"); - out6: - class_device_remove_attrs(class_dev); - out5: - if (MAJOR(class_dev->devt)) - class_device_remove_file(class_dev, &class_devt_attr); - out4: - class_device_remove_file(class_dev, &class_uevent_attr); - out3: - kobject_del(&class_dev->kobj); - out2: - if (parent_class_dev) - class_device_put(parent_class_dev); - class_put(parent_class); - out1: - class_device_put(class_dev); - return error; -} - -int class_device_register(struct class_device *class_dev) -{ - class_device_initialize(class_dev); - return class_device_add(class_dev); -} - -/** - * class_device_create - creates a class device and registers it with sysfs - * @cls: pointer to the struct class that this device should be registered to. - * @parent: pointer to the parent struct class_device of this new device, if - * any. - * @devt: the dev_t for the char device to be added. - * @device: a pointer to a struct device that is assiociated with this class - * device. - * @fmt: string for the class device's name - * - * This function can be used by char device classes. A struct - * class_device will be created in sysfs, registered to the specified - * class. - * A "dev" file will be created, showing the dev_t for the device, if - * the dev_t is not 0,0. - * If a pointer to a parent struct class_device is passed in, the newly - * created struct class_device will be a child of that device in sysfs. - * The pointer to the struct class_device will be returned from the - * call. Any further sysfs files that might be required can be created - * using this pointer. - * - * Note: the struct class passed to this function must have previously - * been created with a call to class_create(). - */ -struct class_device *class_device_create(struct class *cls, - struct class_device *parent, - dev_t devt, - struct device *device, - const char *fmt, ...) -{ - va_list args; - struct class_device *class_dev = NULL; - int retval = -ENODEV; - - if (cls == NULL || IS_ERR(cls)) - goto error; - - class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL); - if (!class_dev) { - retval = -ENOMEM; - goto error; - } - - class_dev->devt = devt; - class_dev->dev = device; - class_dev->class = cls; - class_dev->parent = parent; - class_dev->release = class_device_create_release; - class_dev->uevent = class_device_create_uevent; - - va_start(args, fmt); - vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args); - va_end(args); - retval = class_device_register(class_dev); - if (retval) - goto error; - - return class_dev; - -error: - kfree(class_dev); - return ERR_PTR(retval); -} - -void class_device_del(struct class_device *class_dev) -{ - struct class *parent_class = class_dev->class; - struct class_device *parent_device = class_dev->parent; - struct class_interface *class_intf; - - if (parent_class) { - down(&parent_class->sem); - list_del_init(&class_dev->node); - list_for_each_entry(class_intf, &parent_class->interfaces, node) - if (class_intf->remove) - class_intf->remove(class_dev, class_intf); - up(&parent_class->sem); - } - - if (class_dev->dev) { - remove_deprecated_class_device_links(class_dev); - sysfs_remove_link(&class_dev->kobj, "device"); - } - sysfs_remove_link(&class_dev->kobj, "subsystem"); - class_device_remove_file(class_dev, &class_uevent_attr); - if (MAJOR(class_dev->devt)) - class_device_remove_file(class_dev, &class_devt_attr); - class_device_remove_attrs(class_dev); - class_device_remove_groups(class_dev); - - kobject_uevent(&class_dev->kobj, KOBJ_REMOVE); - kobject_del(&class_dev->kobj); - - class_device_put(parent_device); - class_put(parent_class); -} - -void class_device_unregister(struct class_device *class_dev) -{ - pr_debug("CLASS: Unregistering class device. ID = '%s'\n", - class_dev->class_id); - class_device_del(class_dev); - class_device_put(class_dev); -} - -/** - * class_device_destroy - removes a class device that was created with class_device_create() - * @cls: the pointer to the struct class that this device was registered * with. - * @devt: the dev_t of the device that was previously registered. - * - * This call unregisters and cleans up a class device that was created with a - * call to class_device_create() - */ -void class_device_destroy(struct class *cls, dev_t devt) -{ - struct class_device *class_dev = NULL; - struct class_device *class_dev_tmp; - - down(&cls->sem); - list_for_each_entry(class_dev_tmp, &cls->children, node) { - if (class_dev_tmp->devt == devt) { - class_dev = class_dev_tmp; - break; - } - } - up(&cls->sem); - - if (class_dev) - class_device_unregister(class_dev); -} - -struct class_device *class_device_get(struct class_device *class_dev) -{ - if (class_dev) - return to_class_dev(kobject_get(&class_dev->kobj)); - return NULL; -} - -void class_device_put(struct class_device *class_dev) -{ - if (class_dev) - kobject_put(&class_dev->kobj); -} - /** * class_for_each_device - device iterator * @class: the class we're iterating @@ -897,56 +338,9 @@ struct device *class_find_device(struct class *class, void *data, } EXPORT_SYMBOL_GPL(class_find_device); -/** - * class_find_child - device iterator for locating a particular class_device - * @class: the class we're iterating - * @data: data for the match function - * @match: function to check class_device - * - * This function returns a reference to a class_device that is 'found' for - * later use, as determined by the @match callback. - * - * The callback should return 0 if the class_device doesn't match and non-zero - * if it does. If the callback returns non-zero, this function will - * return to the caller and not iterate over any more class_devices. - * - * Note, you will need to drop the reference with class_device_put() after use. - * - * We hold class->sem in this function, so it can not be - * re-acquired in @match, otherwise it will self-deadlocking. For - * example, calls to add or remove class members would be verboten. - */ -struct class_device *class_find_child(struct class *class, void *data, - int (*match)(struct class_device *, void *)) -{ - struct class_device *dev; - int found = 0; - - if (!class) - return NULL; - - down(&class->sem); - list_for_each_entry(dev, &class->children, node) { - dev = class_device_get(dev); - if (dev) { - if (match(dev, data)) { - found = 1; - break; - } else - class_device_put(dev); - } else - break; - } - up(&class->sem); - - return found ? dev : NULL; -} -EXPORT_SYMBOL_GPL(class_find_child); - int class_interface_register(struct class_interface *class_intf) { struct class *parent; - struct class_device *class_dev; struct device *dev; if (!class_intf || !class_intf->class) @@ -958,10 +352,6 @@ int class_interface_register(struct class_interface *class_intf) down(&parent->sem); list_add_tail(&class_intf->node, &parent->interfaces); - if (class_intf->add) { - list_for_each_entry(class_dev, &parent->children, node) - class_intf->add(class_dev, class_intf); - } if (class_intf->add_dev) { list_for_each_entry(dev, &parent->devices, node) class_intf->add_dev(dev, class_intf); @@ -974,7 +364,6 @@ int class_interface_register(struct class_interface *class_intf) void class_interface_unregister(struct class_interface *class_intf) { struct class *parent = class_intf->class; - struct class_device *class_dev; struct device *dev; if (!parent) @@ -982,10 +371,6 @@ void class_interface_unregister(struct class_interface *class_intf) down(&parent->sem); list_del_init(&class_intf->node); - if (class_intf->remove) { - list_for_each_entry(class_dev, &parent->children, node) - class_intf->remove(class_dev, class_intf); - } if (class_intf->remove_dev) { list_for_each_entry(dev, &parent->devices, node) class_intf->remove_dev(dev, class_intf); @@ -1000,13 +385,6 @@ int __init classes_init(void) class_kset = kset_create_and_add("class", NULL, NULL); if (!class_kset) return -ENOMEM; - - /* ick, this is ugly, the things we go through to keep from showing up - * in sysfs... */ - kset_init(&class_obj_subsys); - kobject_set_name(&class_obj_subsys.kobj, "class_obj"); - if (!class_obj_subsys.kobj.parent) - class_obj_subsys.kobj.parent = &class_obj_subsys.kobj; return 0; } @@ -1017,19 +395,5 @@ EXPORT_SYMBOL_GPL(class_unregister); EXPORT_SYMBOL_GPL(class_create); EXPORT_SYMBOL_GPL(class_destroy); -EXPORT_SYMBOL_GPL(class_device_register); -EXPORT_SYMBOL_GPL(class_device_unregister); -EXPORT_SYMBOL_GPL(class_device_initialize); -EXPORT_SYMBOL_GPL(class_device_add); -EXPORT_SYMBOL_GPL(class_device_del); -EXPORT_SYMBOL_GPL(class_device_get); -EXPORT_SYMBOL_GPL(class_device_put); -EXPORT_SYMBOL_GPL(class_device_create); -EXPORT_SYMBOL_GPL(class_device_destroy); -EXPORT_SYMBOL_GPL(class_device_create_file); -EXPORT_SYMBOL_GPL(class_device_remove_file); -EXPORT_SYMBOL_GPL(class_device_create_bin_file); -EXPORT_SYMBOL_GPL(class_device_remove_bin_file); - EXPORT_SYMBOL_GPL(class_interface_register); EXPORT_SYMBOL_GPL(class_interface_unregister); diff --git a/drivers/base/core.c b/drivers/base/core.c index 24198ad01976..be288b5e4180 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -20,7 +20,7 @@ #include <linux/notifier.h> #include <linux/genhd.h> #include <linux/kallsyms.h> -#include <asm/semaphore.h> +#include <linux/semaphore.h> #include "base.h" #include "power/power.h" @@ -207,7 +207,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, retval = dev->bus->uevent(dev, env); if (retval) pr_debug("device: '%s': %s: bus uevent() returned %d\n", - dev->bus_id, __FUNCTION__, retval); + dev->bus_id, __func__, retval); } /* have the class specific function add its stuff */ @@ -216,7 +216,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, if (retval) pr_debug("device: '%s': %s: class uevent() " "returned %d\n", dev->bus_id, - __FUNCTION__, retval); + __func__, retval); } /* have the device type specific fuction add its stuff */ @@ -225,7 +225,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, if (retval) pr_debug("device: '%s': %s: dev_type uevent() " "returned %d\n", dev->bus_id, - __FUNCTION__, retval); + __func__, retval); } return retval; @@ -782,11 +782,15 @@ int device_add(struct device *dev) goto Done; } - pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); + pr_debug("device: '%s': %s\n", dev->bus_id, __func__); parent = get_device(dev->parent); setup_parent(dev, parent); + /* use parent numa_node */ + if (parent) + set_dev_node(dev, dev_to_node(parent)); + /* first, register with generic layer. */ error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); if (error) @@ -817,13 +821,12 @@ int device_add(struct device *dev) error = device_add_attrs(dev); if (error) goto AttrsError; - error = dpm_sysfs_add(dev); - if (error) - goto PMError; - device_pm_add(dev); error = bus_add_device(dev); if (error) goto BusError; + error = device_pm_add(dev); + if (error) + goto PMError; kobject_uevent(&dev->kobj, KOBJ_ADD); bus_attach_device(dev); if (parent) @@ -843,9 +846,9 @@ int device_add(struct device *dev) Done: put_device(dev); return error; - BusError: - device_pm_remove(dev); PMError: + bus_remove_device(dev); + BusError: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); @@ -981,7 +984,7 @@ void device_del(struct device *dev) */ void device_unregister(struct device *dev) { - pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); + pr_debug("device: '%s': %s\n", dev->bus_id, __func__); device_del(dev); put_device(dev); } @@ -1076,7 +1079,7 @@ EXPORT_SYMBOL_GPL(device_remove_file); static void device_create_release(struct device *dev) { - pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); + pr_debug("device: '%s': %s\n", dev->bus_id, __func__); kfree(dev); } @@ -1164,35 +1167,6 @@ void device_destroy(struct class *class, dev_t devt) } EXPORT_SYMBOL_GPL(device_destroy); -#ifdef CONFIG_PM_SLEEP -/** - * destroy_suspended_device - asks the PM core to remove a suspended device - * @class: pointer to the struct class that this device was registered with - * @devt: the dev_t of the device that was previously registered - * - * This call notifies the PM core of the necessity to unregister a suspended - * device created with a call to device_create() (devices cannot be - * unregistered directly while suspended, since the PM core holds their - * semaphores at that time). - * - * It can only be called within the scope of a system sleep transition. In - * practice this means it has to be directly or indirectly invoked either by - * a suspend or resume method, or by the PM core (e.g. via - * disable_nonboot_cpus() or enable_nonboot_cpus()). - */ -void destroy_suspended_device(struct class *class, dev_t devt) -{ - struct device *dev; - - dev = class_find_device(class, &devt, __match_devt); - if (dev) { - device_pm_schedule_removal(dev); - put_device(dev); - } -} -EXPORT_SYMBOL_GPL(destroy_suspended_device); -#endif /* CONFIG_PM_SLEEP */ - /** * device_rename - renames a device * @dev: the pointer to the struct device to be renamed @@ -1210,7 +1184,7 @@ int device_rename(struct device *dev, char *new_name) return -EINVAL; pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id, - __FUNCTION__, new_name); + __func__, new_name); #ifdef CONFIG_SYSFS_DEPRECATED if ((dev->class) && (dev->parent)) @@ -1249,7 +1223,7 @@ int device_rename(struct device *dev, char *new_name) dev->bus_id); if (error) { dev_err(dev, "%s: sysfs_create_symlink failed (%d)\n", - __FUNCTION__, error); + __func__, error); } } #endif @@ -1325,7 +1299,7 @@ int device_move(struct device *dev, struct device *new_parent) new_parent_kobj = get_device_parent(dev, new_parent); pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, - __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>"); + __func__, new_parent ? new_parent->bus_id : "<NULL>"); error = kobject_move(&dev->kobj, new_parent_kobj); if (error) { cleanup_glue_dir(dev, new_parent_kobj); @@ -1336,8 +1310,11 @@ int device_move(struct device *dev, struct device *new_parent) dev->parent = new_parent; if (old_parent) klist_remove(&dev->knode_parent); - if (new_parent) + if (new_parent) { klist_add_tail(&dev->knode_parent, &new_parent->klist_children); + set_dev_node(dev, dev_to_node(new_parent)); + } + if (!dev->class) goto out_put; error = device_move_class_links(dev, old_parent, new_parent); @@ -1347,9 +1324,12 @@ int device_move(struct device *dev, struct device *new_parent) if (!kobject_move(&dev->kobj, &old_parent->kobj)) { if (new_parent) klist_remove(&dev->knode_parent); - if (old_parent) + dev->parent = old_parent; + if (old_parent) { klist_add_tail(&dev->knode_parent, &old_parent->klist_children); + set_dev_node(dev, dev_to_node(old_parent)); + } } cleanup_glue_dir(dev, new_parent_kobj); put_device(new_parent); diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 499b003f9278..6fe417429977 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -28,7 +28,7 @@ static ssize_t show_online(struct sys_device *dev, char *buf) return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id)); } -static ssize_t store_online(struct sys_device *dev, const char *buf, +static ssize_t __ref store_online(struct sys_device *dev, const char *buf, size_t count) { struct cpu *cpu = container_of(dev, struct cpu, sysdev); @@ -55,7 +55,7 @@ static ssize_t store_online(struct sys_device *dev, const char *buf, } static SYSDEV_ATTR(online, 0644, show_online, store_online); -static void __devinit register_cpu_control(struct cpu *cpu) +static void __cpuinit register_cpu_control(struct cpu *cpu) { sysdev_create_file(&cpu->sysdev, &attr_online); } @@ -103,6 +103,51 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL); #endif /* + * Print cpu online, possible, present, and system maps + */ +static ssize_t print_cpus_map(char *buf, cpumask_t *map) +{ + int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *map); + + buf[n++] = '\n'; + buf[n] = '\0'; + return n; +} + +#define print_cpus_func(type) \ +static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \ +{ \ + return print_cpus_map(buf, &cpu_##type##_map); \ +} \ +struct sysdev_class_attribute attr_##type##_map = \ + _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL) + +print_cpus_func(online); +print_cpus_func(possible); +print_cpus_func(present); + +struct sysdev_class_attribute *cpu_state_attr[] = { + &attr_online_map, + &attr_possible_map, + &attr_present_map, +}; + +static int cpu_states_init(void) +{ + int i; + int err = 0; + + for (i = 0; i < ARRAY_SIZE(cpu_state_attr); i++) { + int ret; + ret = sysdev_class_create_file(&cpu_sysdev_class, + cpu_state_attr[i]); + if (!err) + err = ret; + } + return err; +} + +/* * register_cpu - Setup a sysfs device for a CPU. * @cpu - cpu->hotpluggable field set to 1 will generate a control file in * sysfs for this CPU. @@ -147,6 +192,9 @@ int __init cpu_dev_init(void) int err; err = sysdev_class_register(&cpu_sysdev_class); + if (!err) + err = cpu_states_init(); + #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) if (!err) err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a5cde94bb982..3ac443b2ac08 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -30,12 +30,12 @@ static void driver_bound(struct device *dev) { if (klist_node_attached(&dev->knode_driver)) { printk(KERN_WARNING "%s: device %s already bound\n", - __FUNCTION__, kobject_name(&dev->kobj)); + __func__, kobject_name(&dev->kobj)); return; } pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id, - __FUNCTION__, dev->driver->name); + __func__, dev->driver->name); if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -104,13 +104,13 @@ static int really_probe(struct device *dev, struct device_driver *drv) atomic_inc(&probe_count); pr_debug("bus: '%s': %s: probing driver %s with device %s\n", - drv->bus->name, __FUNCTION__, drv->name, dev->bus_id); + drv->bus->name, __func__, drv->name, dev->bus_id); WARN_ON(!list_empty(&dev->devres_head)); dev->driver = drv; if (driver_sysfs_add(dev)) { printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", - __FUNCTION__, dev->bus_id); + __func__, dev->bus_id); goto probe_failed; } @@ -127,7 +127,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) driver_bound(dev); ret = 1; pr_debug("bus: '%s': %s: bound device %s to driver %s\n", - drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); + drv->bus->name, __func__, dev->bus_id, drv->name); goto done; probe_failed: @@ -160,7 +160,7 @@ done: */ int driver_probe_done(void) { - pr_debug("%s: probe_count = %d\n", __FUNCTION__, + pr_debug("%s: probe_count = %d\n", __func__, atomic_read(&probe_count)); if (atomic_read(&probe_count)) return -EBUSY; @@ -194,7 +194,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) goto done; pr_debug("bus: '%s': %s: matched device %s with driver %s\n", - drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); + drv->bus->name, __func__, dev->bus_id, drv->name); ret = really_probe(dev, drv); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 9a6537f14401..2ef5acf4368b 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -217,12 +217,22 @@ static void driver_remove_groups(struct device_driver *drv, int driver_register(struct device_driver *drv) { int ret; + struct device_driver *other; if ((drv->bus->probe && drv->probe) || (drv->bus->remove && drv->remove) || (drv->bus->shutdown && drv->shutdown)) printk(KERN_WARNING "Driver '%s' needs updating - please use " "bus_type methods\n", drv->name); + + other = driver_find(drv->name, drv->bus); + if (other) { + put_driver(other); + printk(KERN_ERR "Error: Driver '%s' is already registered, " + "aborting...\n", drv->name); + return -EEXIST; + } + ret = bus_add_driver(drv); if (ret) return ret; diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 4a1b9bfc5471..9fd4a8534146 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -156,7 +156,7 @@ static ssize_t firmware_loading_store(struct device *dev, } /* fallthrough */ default: - printk(KERN_ERR "%s: unexpected value (%d)\n", __FUNCTION__, + printk(KERN_ERR "%s: unexpected value (%d)\n", __func__, loading); /* fallthrough */ case -1: @@ -209,7 +209,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) new_size = ALIGN(min_size, PAGE_SIZE); new_data = vmalloc(new_size); if (!new_data) { - printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__); + printk(KERN_ERR "%s: unable to alloc buffer\n", __func__); /* Make sure that we don't keep incomplete data */ fw_load_abort(fw_priv); return -ENOMEM; @@ -307,7 +307,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name, *dev_p = NULL; if (!fw_priv || !f_dev) { - printk(KERN_ERR "%s: kmalloc failed\n", __FUNCTION__); + printk(KERN_ERR "%s: kmalloc failed\n", __func__); retval = -ENOMEM; goto error_kfree; } @@ -328,7 +328,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name, retval = device_register(f_dev); if (retval) { printk(KERN_ERR "%s: device_register failed\n", - __FUNCTION__); + __func__); goto error_kfree; } *dev_p = f_dev; @@ -362,14 +362,14 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p, retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); if (retval) { printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", - __FUNCTION__); + __func__); goto error_unreg; } retval = device_create_file(f_dev, &dev_attr_loading); if (retval) { printk(KERN_ERR "%s: device_create_file failed\n", - __FUNCTION__); + __func__); goto error_unreg; } @@ -396,10 +396,12 @@ _request_firmware(const struct firmware **firmware_p, const char *name, if (!firmware_p) return -EINVAL; + printk(KERN_INFO "firmware: requesting %s\n", name); + *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); if (!firmware) { printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", - __FUNCTION__); + __func__); retval = -ENOMEM; goto out; } @@ -570,13 +572,13 @@ firmware_class_init(void) int error; error = class_register(&firmware_class); if (error) { - printk(KERN_ERR "%s: class_register failed\n", __FUNCTION__); + printk(KERN_ERR "%s: class_register failed\n", __func__); return error; } error = class_create_file(&firmware_class, &class_attr_timeout); if (error) { printk(KERN_ERR "%s: class_create_file failed\n", - __FUNCTION__); + __func__); class_unregister(&firmware_class); } return error; diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 7ae413fdd5fc..8ce6de5a7e28 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -20,6 +20,7 @@ #include <linux/kobject.h> #include <linux/memory_hotplug.h> #include <linux/mm.h> +#include <linux/mutex.h> #include <asm/atomic.h> #include <asm/uaccess.h> @@ -61,8 +62,8 @@ void unregister_memory_notifier(struct notifier_block *nb) /* * register_memory - Setup a sysfs device for a memory block */ -int register_memory(struct memory_block *memory, struct mem_section *section, - struct node *root) +static +int register_memory(struct memory_block *memory, struct mem_section *section) { int error; @@ -70,26 +71,18 @@ int register_memory(struct memory_block *memory, struct mem_section *section, memory->sysdev.id = __section_nr(section); error = sysdev_register(&memory->sysdev); - - if (root && !error) - error = sysfs_create_link(&root->sysdev.kobj, - &memory->sysdev.kobj, - kobject_name(&memory->sysdev.kobj)); - return error; } static void -unregister_memory(struct memory_block *memory, struct mem_section *section, - struct node *root) +unregister_memory(struct memory_block *memory, struct mem_section *section) { BUG_ON(memory->sysdev.cls != &memory_sysdev_class); BUG_ON(memory->sysdev.id != __section_nr(section)); + /* drop the ref. we got in remove_memory_block() */ + kobject_put(&memory->sysdev.kobj); sysdev_unregister(&memory->sysdev); - if (root) - sysfs_remove_link(&root->sysdev.kobj, - kobject_name(&memory->sysdev.kobj)); } /* @@ -193,7 +186,7 @@ memory_block_action(struct memory_block *mem, unsigned long action) break; default: printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", - __FUNCTION__, mem, action, action); + __func__, mem, action, action); WARN_ON(1); ret = -EINVAL; } @@ -205,7 +198,7 @@ static int memory_block_change_state(struct memory_block *mem, unsigned long to_state, unsigned long from_state_req) { int ret = 0; - down(&mem->state_sem); + mutex_lock(&mem->state_mutex); if (mem->state != from_state_req) { ret = -EINVAL; @@ -217,7 +210,7 @@ static int memory_block_change_state(struct memory_block *mem, mem->state = to_state; out: - up(&mem->state_sem); + mutex_unlock(&mem->state_mutex); return ret; } @@ -341,10 +334,10 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section, mem->phys_index = __section_nr(section); mem->state = state; - init_MUTEX(&mem->state_sem); + mutex_init(&mem->state_mutex); mem->phys_device = phys_device; - ret = register_memory(mem, section, NULL); + ret = register_memory(mem, section); if (!ret) ret = mem_create_simple_file(mem, phys_index); if (!ret) @@ -395,7 +388,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, mem_remove_simple_file(mem, phys_index); mem_remove_simple_file(mem, state); mem_remove_simple_file(mem, phys_device); - unregister_memory(mem, section, NULL); + unregister_memory(mem, section); return 0; } @@ -451,6 +444,6 @@ int __init memory_dev_init(void) ret = err; out: if (ret) - printk(KERN_ERR "%s() failed: %d\n", __FUNCTION__, ret); + printk(KERN_ERR "%s() failed: %d\n", __func__, ret); return ret; } diff --git a/drivers/base/node.c b/drivers/base/node.c index e59861f18ce5..39f3d1b3a213 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -19,21 +19,34 @@ static struct sysdev_class node_class = { }; -static ssize_t node_read_cpumap(struct sys_device * dev, char * buf) +static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) { struct node *node_dev = to_node(dev); - cpumask_t mask = node_to_cpumask(node_dev->sysdev.id); + node_to_cpumask_ptr(mask, node_dev->sysdev.id); int len; - /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */ - BUILD_BUG_ON(MAX_NUMNODES/4 > PAGE_SIZE/2); + /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ + BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); - len = cpumask_scnprintf(buf, PAGE_SIZE-1, mask); - len += sprintf(buf + len, "\n"); + len = type? + cpulist_scnprintf(buf, PAGE_SIZE-2, *mask): + cpumask_scnprintf(buf, PAGE_SIZE-2, *mask); + buf[len++] = '\n'; + buf[len] = '\0'; return len; } -static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL); +static inline ssize_t node_read_cpumask(struct sys_device *dev, char *buf) +{ + return node_read_cpumap(dev, 0, buf); +} +static inline ssize_t node_read_cpulist(struct sys_device *dev, char *buf) +{ + return node_read_cpumap(dev, 1, buf); +} + +static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); +static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); #define K(x) ((x) << (PAGE_SHIFT - 10)) static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) @@ -64,6 +77,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) "Node %d PageTables: %8lu kB\n" "Node %d NFS_Unstable: %8lu kB\n" "Node %d Bounce: %8lu kB\n" + "Node %d WritebackTmp: %8lu kB\n" "Node %d Slab: %8lu kB\n" "Node %d SReclaimable: %8lu kB\n" "Node %d SUnreclaim: %8lu kB\n", @@ -86,6 +100,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) nid, K(node_page_state(nid, NR_PAGETABLE)), nid, K(node_page_state(nid, NR_UNSTABLE_NFS)), nid, K(node_page_state(nid, NR_BOUNCE)), + nid, K(node_page_state(nid, NR_WRITEBACK_TEMP)), nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), @@ -149,6 +164,7 @@ int register_node(struct node *node, int num, struct node *parent) if (!error){ sysdev_create_file(&node->sysdev, &attr_cpumap); + sysdev_create_file(&node->sysdev, &attr_cpulist); sysdev_create_file(&node->sysdev, &attr_meminfo); sysdev_create_file(&node->sysdev, &attr_numastat); sysdev_create_file(&node->sysdev, &attr_distance); @@ -166,6 +182,7 @@ int register_node(struct node *node, int num, struct node *parent) void unregister_node(struct node *node) { sysdev_remove_file(&node->sysdev, &attr_cpumap); + sysdev_remove_file(&node->sysdev, &attr_cpulist); sysdev_remove_file(&node->sysdev, &attr_meminfo); sysdev_remove_file(&node->sysdev, &attr_numastat); sysdev_remove_file(&node->sysdev, &attr_distance); diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index d887d5cb5bef..7b76fd3b93a4 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -50,26 +50,37 @@ LIST_HEAD(dpm_active); static LIST_HEAD(dpm_off); static LIST_HEAD(dpm_off_irq); -static LIST_HEAD(dpm_destroy); static DEFINE_MUTEX(dpm_list_mtx); -static DECLARE_RWSEM(pm_sleep_rwsem); - -int (*platform_enable_wakeup)(struct device *dev, int is_on); +/* 'true' if all devices have been suspended, protected by dpm_list_mtx */ +static bool all_sleeping; /** * device_pm_add - add a device to the list of active devices * @dev: Device to be added to the list */ -void device_pm_add(struct device *dev) +int device_pm_add(struct device *dev) { + int error; + pr_debug("PM: Adding info for %s:%s\n", dev->bus ? dev->bus->name : "No Bus", kobject_name(&dev->kobj)); mutex_lock(&dpm_list_mtx); - list_add_tail(&dev->power.entry, &dpm_active); + if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) { + if (dev->parent->power.sleeping) + dev_warn(dev, "parent %s is sleeping\n", + dev->parent->bus_id); + else + dev_warn(dev, "all devices are sleeping\n"); + WARN_ON(true); + } + error = dpm_sysfs_add(dev); + if (!error) + list_add_tail(&dev->power.entry, &dpm_active); mutex_unlock(&dpm_list_mtx); + return error; } /** @@ -89,50 +100,6 @@ void device_pm_remove(struct device *dev) mutex_unlock(&dpm_list_mtx); } -/** - * device_pm_schedule_removal - schedule the removal of a suspended device - * @dev: Device to destroy - * - * Moves the device to the dpm_destroy list for further processing by - * unregister_dropped_devices(). - */ -void device_pm_schedule_removal(struct device *dev) -{ - pr_debug("PM: Preparing for removal: %s:%s\n", - dev->bus ? dev->bus->name : "No Bus", - kobject_name(&dev->kobj)); - mutex_lock(&dpm_list_mtx); - list_move_tail(&dev->power.entry, &dpm_destroy); - mutex_unlock(&dpm_list_mtx); -} -EXPORT_SYMBOL_GPL(device_pm_schedule_removal); - -/** - * pm_sleep_lock - mutual exclusion for registration and suspend - * - * Returns 0 if no suspend is underway and device registration - * may proceed, otherwise -EBUSY. - */ -int pm_sleep_lock(void) -{ - if (down_read_trylock(&pm_sleep_rwsem)) - return 0; - - return -EBUSY; -} - -/** - * pm_sleep_unlock - mutual exclusion for registration and suspend - * - * This routine undoes the effect of device_pm_add_lock - * when a device's registration is complete. - */ -void pm_sleep_unlock(void) -{ - up_read(&pm_sleep_rwsem); -} - - /*------------------------- Resume routines -------------------------*/ /** @@ -242,11 +209,13 @@ static int resume_device(struct device *dev) static void dpm_resume(void) { mutex_lock(&dpm_list_mtx); + all_sleeping = false; while(!list_empty(&dpm_off)) { struct list_head *entry = dpm_off.next; struct device *dev = to_device(entry); list_move_tail(entry, &dpm_active); + dev->power.sleeping = false; mutex_unlock(&dpm_list_mtx); resume_device(dev); mutex_lock(&dpm_list_mtx); @@ -255,26 +224,6 @@ static void dpm_resume(void) } /** - * unregister_dropped_devices - Unregister devices scheduled for removal - * - * Unregister all devices on the dpm_destroy list. - */ -static void unregister_dropped_devices(void) -{ - mutex_lock(&dpm_list_mtx); - while (!list_empty(&dpm_destroy)) { - struct list_head *entry = dpm_destroy.next; - struct device *dev = to_device(entry); - - mutex_unlock(&dpm_list_mtx); - /* This also removes the device from the list */ - device_unregister(dev); - mutex_lock(&dpm_list_mtx); - } - mutex_unlock(&dpm_list_mtx); -} - -/** * device_resume - Restore state of each device in system. * * Resume all the devices, unlock them all, and allow new @@ -284,8 +233,6 @@ void device_resume(void) { might_sleep(); dpm_resume(); - unregister_dropped_devices(); - up_write(&pm_sleep_rwsem); } EXPORT_SYMBOL_GPL(device_resume); @@ -377,11 +324,6 @@ static int suspend_device(struct device *dev, pm_message_t state) down(&dev->sem); - if (dev->power.power_state.event) { - dev_dbg(dev, "PM: suspend %d-->%d\n", - dev->power.power_state.event, state.event); - } - if (dev->class && dev->class->suspend) { suspend_device_dbg(dev, state, "class "); error = dev->class->suspend(dev, state); @@ -426,6 +368,9 @@ static int dpm_suspend(pm_message_t state) struct list_head *entry = dpm_active.prev; struct device *dev = to_device(entry); + WARN_ON(dev->parent && dev->parent->power.sleeping); + + dev->power.sleeping = true; mutex_unlock(&dpm_list_mtx); error = suspend_device(dev, state); mutex_lock(&dpm_list_mtx); @@ -437,11 +382,14 @@ static int dpm_suspend(pm_message_t state) (error == -EAGAIN ? " (please convert to suspend_late)" : "")); + dev->power.sleeping = false; break; } if (!list_empty(&dev->power.entry)) list_move(&dev->power.entry, &dpm_off); } + if (!error) + all_sleeping = true; mutex_unlock(&dpm_list_mtx); return error; @@ -459,7 +407,6 @@ int device_suspend(pm_message_t state) int error; might_sleep(); - down_write(&pm_sleep_rwsem); error = dpm_suspend(state); if (error) device_resume(); diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index e32d3bdb92c1..a6894f2a4b99 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -11,30 +11,13 @@ static inline struct device *to_device(struct list_head *entry) return container_of(entry, struct device, power.entry); } -extern void device_pm_add(struct device *); +extern int device_pm_add(struct device *); extern void device_pm_remove(struct device *); -extern int pm_sleep_lock(void); -extern void pm_sleep_unlock(void); #else /* CONFIG_PM_SLEEP */ - -static inline void device_pm_add(struct device *dev) -{ -} - -static inline void device_pm_remove(struct device *dev) -{ -} - -static inline int pm_sleep_lock(void) -{ - return 0; -} - -static inline void pm_sleep_unlock(void) -{ -} +static inline int device_pm_add(struct device *dev) { return 0; } +static inline void device_pm_remove(struct device *dev) {} #endif diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index f2ed179cd695..d11f74b038db 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -6,6 +6,8 @@ #include <linux/string.h> #include "power.h" +int (*platform_enable_wakeup)(struct device *dev, int is_on); + /* * wakeup - Report/change current wakeup option for device diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 8e13fd942163..4fbb56bcb1ee 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -167,6 +167,22 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) { int err = 0; + if (!cls) { + printk(KERN_WARNING "sysdev: invalid class passed to " + "sysdev_driver_register!\n"); + WARN_ON(1); + return -EINVAL; + } + + /* Check whether this driver has already been added to a class. */ + if ((drv->entry.next != drv->entry.prev) || + (drv->entry.next != NULL)) { + printk(KERN_WARNING "sysdev: class %s: driver (%p) has already" + " been registered to a class, something is wrong, but " + "will forge on!\n", cls->name, drv); + WARN_ON(1); + } + mutex_lock(&sysdev_drivers_lock); if (cls && kset_get(&cls->kset)) { list_add_tail(&drv->entry, &cls->drivers); @@ -179,7 +195,7 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) } } else { err = -EINVAL; - printk(KERN_ERR "%s: invalid device class\n", __FUNCTION__); + printk(KERN_ERR "%s: invalid device class\n", __func__); WARN_ON(1); } mutex_unlock(&sysdev_drivers_lock); diff --git a/drivers/base/topology.c b/drivers/base/topology.c index e1d3ad4db2f0..fdf4044d2e74 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -40,15 +40,38 @@ static ssize_t show_##name(struct sys_device *dev, char *buf) \ return sprintf(buf, "%d\n", topology_##name(cpu)); \ } -#define define_siblings_show_func(name) \ -static ssize_t show_##name(struct sys_device *dev, char *buf) \ +static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf) +{ + ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; + int n = 0; + + if (len > 1) { + n = type? + cpulist_scnprintf(buf, len-2, *mask): + cpumask_scnprintf(buf, len-2, *mask); + buf[n++] = '\n'; + buf[n] = '\0'; + } + return n; +} + +#define define_siblings_show_map(name) \ +static inline ssize_t show_##name(struct sys_device *dev, char *buf) \ { \ - ssize_t len = -1; \ unsigned int cpu = dev->id; \ - len = cpumask_scnprintf(buf, NR_CPUS+1, topology_##name(cpu)); \ - return (len + sprintf(buf + len, "\n")); \ + return show_cpumap(0, &(topology_##name(cpu)), buf); \ } +#define define_siblings_show_list(name) \ +static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ +{ \ + unsigned int cpu = dev->id; \ + return show_cpumap(1, &(topology_##name(cpu)), buf); \ +} + +#define define_siblings_show_func(name) \ + define_siblings_show_map(name); define_siblings_show_list(name) + #ifdef topology_physical_package_id define_id_show_func(physical_package_id); define_one_ro(physical_package_id); @@ -68,7 +91,9 @@ define_one_ro(core_id); #ifdef topology_thread_siblings define_siblings_show_func(thread_siblings); define_one_ro(thread_siblings); -#define ref_thread_siblings_attr &attr_thread_siblings.attr, +define_one_ro(thread_siblings_list); +#define ref_thread_siblings_attr \ + &attr_thread_siblings.attr, &attr_thread_siblings_list.attr, #else #define ref_thread_siblings_attr #endif @@ -76,7 +101,9 @@ define_one_ro(thread_siblings); #ifdef topology_core_siblings define_siblings_show_func(core_siblings); define_one_ro(core_siblings); -#define ref_core_siblings_attr &attr_core_siblings.attr, +define_one_ro(core_siblings_list); +#define ref_core_siblings_attr \ + &attr_core_siblings.attr, &attr_core_siblings_list.attr, #else #define ref_core_siblings_attr #endif diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c index cabd0edf2156..84997efdb23d 100644 --- a/drivers/base/transport_class.c +++ b/drivers/base/transport_class.c @@ -66,7 +66,7 @@ EXPORT_SYMBOL_GPL(transport_class_unregister); static int anon_transport_dummy_function(struct transport_container *tc, struct device *dev, - struct class_device *cdev) + struct device *cdev) { /* do nothing */ return 0; @@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(anon_transport_class_unregister); static int transport_setup_classdev(struct attribute_container *cont, struct device *dev, - struct class_device *classdev) + struct device *classdev) { struct transport_class *tclass = class_to_transport_class(cont->class); struct transport_container *tcont = attribute_container_to_transport_container(cont); @@ -149,7 +149,7 @@ EXPORT_SYMBOL_GPL(transport_setup_device); static int transport_add_class_device(struct attribute_container *cont, struct device *dev, - struct class_device *classdev) + struct device *classdev) { int error = attribute_container_add_class_device(classdev); struct transport_container *tcont = @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(transport_add_device); static int transport_configure(struct attribute_container *cont, struct device *dev, - struct class_device *cdev) + struct device *cdev) { struct transport_class *tclass = class_to_transport_class(cont->class); struct transport_container *tcont = attribute_container_to_transport_container(cont); @@ -212,7 +212,7 @@ EXPORT_SYMBOL_GPL(transport_configure_device); static int transport_remove_classdev(struct attribute_container *cont, struct device *dev, - struct class_device *classdev) + struct device *classdev) { struct transport_container *tcont = attribute_container_to_transport_container(cont); @@ -251,12 +251,12 @@ EXPORT_SYMBOL_GPL(transport_remove_device); static void transport_destroy_classdev(struct attribute_container *cont, struct device *dev, - struct class_device *classdev) + struct device *classdev) { struct transport_class *tclass = class_to_transport_class(cont->class); if (tclass->remove != anon_transport_dummy_function) - class_device_put(classdev); + put_device(classdev); } |