diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/attribute_container.c | 77 | ||||
-rw-r--r-- | drivers/base/bus.c | 16 | ||||
-rw-r--r-- | drivers/base/class.c | 8 | ||||
-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/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 |
15 files changed, 268 insertions, 258 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 3b43e8a9f87..f57652db0a2 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/bus.c b/drivers/base/bus.c index 2d207ad3033..ef522ae5548 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 9d915376c31..b4901799308 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -175,13 +175,13 @@ 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); + pr_debug("%s called for %s\n", __func__, class_dev->class_id); kfree(class_dev); } @@ -189,7 +189,7 @@ static void class_device_create_release(struct class_device *class_dev) 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); + pr_debug("%s called for %s\n", __func__, class_dev->class_id); return 0; } @@ -415,7 +415,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, struct device *dev = class_dev->dev; int retval = 0; - pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); + pr_debug("%s - name = %s\n", __func__, class_dev->class_id); if (MAJOR(class_dev->devt)) { add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt)); diff --git a/drivers/base/core.c b/drivers/base/core.c index 24198ad0197..be288b5e418 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 499b003f927..6fe41742997 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 a5cde94bb98..3ac443b2ac0 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/firmware_class.c b/drivers/base/firmware_class.c index 4a1b9bfc547..9fd4a853414 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 7ae413fdd5f..8ce6de5a7e2 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 e59861f18ce..39f3d1b3a21 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 d887d5cb5be..7b76fd3b93a 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 e32d3bdb92c..a6894f2a4b9 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 f2ed179cd69..d11f74b038d 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 8e13fd94216..4fbb56bcb1e 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 e1d3ad4db2f..fdf4044d2e7 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 cabd0edf215..84997efdb23 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); } |