diff options
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/Kconfig | 51 | ||||
| -rw-r--r-- | drivers/base/attribute_container.c | 1 | ||||
| -rw-r--r-- | drivers/base/bus.c | 27 | ||||
| -rw-r--r-- | drivers/base/class.c | 18 | ||||
| -rw-r--r-- | drivers/base/core.c | 52 | ||||
| -rw-r--r-- | drivers/base/cpu.c | 106 | ||||
| -rw-r--r-- | drivers/base/dd.c | 38 | ||||
| -rw-r--r-- | drivers/base/devres.c | 1 | ||||
| -rw-r--r-- | drivers/base/devtmpfs.c | 14 | ||||
| -rw-r--r-- | drivers/base/dma-coherent.c | 1 | ||||
| -rw-r--r-- | drivers/base/dma-mapping.c | 1 | ||||
| -rw-r--r-- | drivers/base/driver.c | 1 | ||||
| -rw-r--r-- | drivers/base/firmware_class.c | 14 | ||||
| -rw-r--r-- | drivers/base/memory.c | 38 | ||||
| -rw-r--r-- | drivers/base/module.c | 1 | ||||
| -rw-r--r-- | drivers/base/node.c | 89 | ||||
| -rw-r--r-- | drivers/base/platform.c | 109 | ||||
| -rw-r--r-- | drivers/base/power/Makefile | 1 | ||||
| -rw-r--r-- | drivers/base/power/generic_ops.c | 233 | ||||
| -rw-r--r-- | drivers/base/power/main.c | 51 | ||||
| -rw-r--r-- | drivers/base/sys.c | 18 |
21 files changed, 628 insertions, 237 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index ee377270beb9..fd52c48ee762 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig | |||
| @@ -3,35 +3,50 @@ menu "Generic Driver Options" | |||
| 3 | config UEVENT_HELPER_PATH | 3 | config UEVENT_HELPER_PATH |
| 4 | string "path to uevent helper" | 4 | string "path to uevent helper" |
| 5 | depends on HOTPLUG | 5 | depends on HOTPLUG |
| 6 | default "/sbin/hotplug" | 6 | default "" |
| 7 | help | 7 | help |
| 8 | Path to uevent helper program forked by the kernel for | 8 | Path to uevent helper program forked by the kernel for |
| 9 | every uevent. | 9 | every uevent. |
| 10 | Before the switch to the netlink-based uevent source, this was | ||
| 11 | used to hook hotplug scripts into kernel device events. It | ||
| 12 | usually pointed to a shell script at /sbin/hotplug. | ||
| 13 | This should not be used today, because usual systems create | ||
| 14 | many events at bootup or device discovery in a very short time | ||
| 15 | frame. One forked process per event can create so many processes | ||
| 16 | that it creates a high system load, or on smaller systems | ||
| 17 | it is known to create out-of-memory situations during bootup. | ||
| 10 | 18 | ||
| 11 | config DEVTMPFS | 19 | config DEVTMPFS |
| 12 | bool "Create a kernel maintained /dev tmpfs (EXPERIMENTAL)" | 20 | bool "Maintain a devtmpfs filesystem to mount at /dev" |
| 13 | depends on HOTPLUG && SHMEM && TMPFS | 21 | depends on HOTPLUG && SHMEM && TMPFS |
| 14 | help | 22 | help |
| 15 | This creates a tmpfs filesystem, and mounts it at bootup | 23 | This creates a tmpfs filesystem instance early at bootup. |
| 16 | and mounts it at /dev. The kernel driver core creates device | 24 | In this filesystem, the kernel driver core maintains device |
| 17 | nodes for all registered devices in that filesystem. All device | 25 | nodes with their default names and permissions for all |
| 18 | nodes are owned by root and have the default mode of 0600. | 26 | registered devices with an assigned major/minor number. |
| 19 | Userspace can add and delete the nodes as needed. This is | 27 | Userspace can modify the filesystem content as needed, add |
| 20 | intended to simplify bootup, and make it possible to delay | 28 | symlinks, and apply needed permissions. |
| 21 | the initial coldplug at bootup done by udev in userspace. | 29 | It provides a fully functional /dev directory, where usually |
| 22 | It should also provide a simpler way for rescue systems | 30 | udev runs on top, managing permissions and adding meaningful |
| 23 | to bring up a kernel with dynamic major/minor numbers. | 31 | symlinks. |
| 24 | Meaningful symlinks, permissions and device ownership must | 32 | In very limited environments, it may provide a sufficient |
| 25 | still be handled by userspace. | 33 | functional /dev without any further help. It also allows simple |
| 26 | If unsure, say N here. | 34 | rescue systems, and reliably handles dynamic major/minor numbers. |
| 27 | 35 | ||
| 28 | config DEVTMPFS_MOUNT | 36 | config DEVTMPFS_MOUNT |
| 29 | bool "Automount devtmpfs at /dev" | 37 | bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs" |
| 30 | depends on DEVTMPFS | 38 | depends on DEVTMPFS |
| 31 | help | 39 | help |
| 32 | This will mount devtmpfs at /dev if the kernel mounts the root | 40 | This will instruct the kernel to automatically mount the |
| 33 | filesystem. It will not affect initramfs based mounting. | 41 | devtmpfs filesystem at /dev, directly after the kernel has |
| 34 | If unsure, say N here. | 42 | mounted the root filesystem. The behavior can be overridden |
| 43 | with the commandline parameter: devtmpfs.mount=0|1. | ||
| 44 | This option does not affect initramfs based booting, here | ||
| 45 | the devtmpfs filesystem always needs to be mounted manually | ||
| 46 | after the roots is mounted. | ||
| 47 | With this option enabled, it allows to bring up a system in | ||
| 48 | rescue mode with init=/bin/sh, even when the /dev directory | ||
| 49 | on the rootfs is completely empty. | ||
| 35 | 50 | ||
| 36 | config STANDALONE | 51 | config STANDALONE |
| 37 | bool "Select only drivers that don't need compile-time external firmware" if EXPERIMENTAL | 52 | bool "Select only drivers that don't need compile-time external firmware" if EXPERIMENTAL |
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index b9cda053d3c0..8fc200b2e2c0 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c | |||
| @@ -328,6 +328,7 @@ attribute_container_add_attrs(struct device *classdev) | |||
| 328 | return sysfs_create_group(&classdev->kobj, cont->grp); | 328 | return sysfs_create_group(&classdev->kobj, cont->grp); |
| 329 | 329 | ||
| 330 | for (i = 0; attrs[i]; i++) { | 330 | for (i = 0; attrs[i]; i++) { |
| 331 | sysfs_attr_init(&attrs[i]->attr); | ||
| 331 | error = device_create_file(classdev, attrs[i]); | 332 | error = device_create_file(classdev, attrs[i]); |
| 332 | if (error) | 333 | if (error) |
| 333 | return error; | 334 | return error; |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index c0c5a43d9fb3..12eec3f633b1 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/device.h> | 13 | #include <linux/device.h> |
| 14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> | ||
| 16 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 17 | #include <linux/string.h> | 18 | #include <linux/string.h> |
| 18 | #include "base.h" | 19 | #include "base.h" |
| @@ -70,7 +71,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr, | |||
| 70 | return ret; | 71 | return ret; |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | static struct sysfs_ops driver_sysfs_ops = { | 74 | static const struct sysfs_ops driver_sysfs_ops = { |
| 74 | .show = drv_attr_show, | 75 | .show = drv_attr_show, |
| 75 | .store = drv_attr_store, | 76 | .store = drv_attr_store, |
| 76 | }; | 77 | }; |
| @@ -115,7 +116,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr, | |||
| 115 | return ret; | 116 | return ret; |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | static struct sysfs_ops bus_sysfs_ops = { | 119 | static const struct sysfs_ops bus_sysfs_ops = { |
| 119 | .show = bus_attr_show, | 120 | .show = bus_attr_show, |
| 120 | .store = bus_attr_store, | 121 | .store = bus_attr_store, |
| 121 | }; | 122 | }; |
| @@ -154,7 +155,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj) | |||
| 154 | return 0; | 155 | return 0; |
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | static struct kset_uevent_ops bus_uevent_ops = { | 158 | static const struct kset_uevent_ops bus_uevent_ops = { |
| 158 | .filter = bus_uevent_filter, | 159 | .filter = bus_uevent_filter, |
| 159 | }; | 160 | }; |
| 160 | 161 | ||
| @@ -173,10 +174,10 @@ static ssize_t driver_unbind(struct device_driver *drv, | |||
| 173 | dev = bus_find_device_by_name(bus, NULL, buf); | 174 | dev = bus_find_device_by_name(bus, NULL, buf); |
| 174 | if (dev && dev->driver == drv) { | 175 | if (dev && dev->driver == drv) { |
| 175 | if (dev->parent) /* Needed for USB */ | 176 | if (dev->parent) /* Needed for USB */ |
| 176 | down(&dev->parent->sem); | 177 | device_lock(dev->parent); |
| 177 | device_release_driver(dev); | 178 | device_release_driver(dev); |
| 178 | if (dev->parent) | 179 | if (dev->parent) |
| 179 | up(&dev->parent->sem); | 180 | device_unlock(dev->parent); |
| 180 | err = count; | 181 | err = count; |
| 181 | } | 182 | } |
| 182 | put_device(dev); | 183 | put_device(dev); |
| @@ -200,12 +201,12 @@ static ssize_t driver_bind(struct device_driver *drv, | |||
| 200 | dev = bus_find_device_by_name(bus, NULL, buf); | 201 | dev = bus_find_device_by_name(bus, NULL, buf); |
| 201 | if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { | 202 | if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { |
| 202 | if (dev->parent) /* Needed for USB */ | 203 | if (dev->parent) /* Needed for USB */ |
| 203 | down(&dev->parent->sem); | 204 | device_lock(dev->parent); |
| 204 | down(&dev->sem); | 205 | device_lock(dev); |
| 205 | err = driver_probe_device(drv, dev); | 206 | err = driver_probe_device(drv, dev); |
| 206 | up(&dev->sem); | 207 | device_unlock(dev); |
| 207 | if (dev->parent) | 208 | if (dev->parent) |
| 208 | up(&dev->parent->sem); | 209 | device_unlock(dev->parent); |
| 209 | 210 | ||
| 210 | if (err > 0) { | 211 | if (err > 0) { |
| 211 | /* success */ | 212 | /* success */ |
| @@ -744,10 +745,10 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, | |||
| 744 | 745 | ||
| 745 | if (!dev->driver) { | 746 | if (!dev->driver) { |
| 746 | if (dev->parent) /* Needed for USB */ | 747 | if (dev->parent) /* Needed for USB */ |
| 747 | down(&dev->parent->sem); | 748 | device_lock(dev->parent); |
| 748 | ret = device_attach(dev); | 749 | ret = device_attach(dev); |
| 749 | if (dev->parent) | 750 | if (dev->parent) |
| 750 | up(&dev->parent->sem); | 751 | device_unlock(dev->parent); |
| 751 | } | 752 | } |
| 752 | return ret < 0 ? ret : 0; | 753 | return ret < 0 ? ret : 0; |
| 753 | } | 754 | } |
| @@ -779,10 +780,10 @@ int device_reprobe(struct device *dev) | |||
| 779 | { | 780 | { |
| 780 | if (dev->driver) { | 781 | if (dev->driver) { |
| 781 | if (dev->parent) /* Needed for USB */ | 782 | if (dev->parent) /* Needed for USB */ |
| 782 | down(&dev->parent->sem); | 783 | device_lock(dev->parent); |
| 783 | device_release_driver(dev); | 784 | device_release_driver(dev); |
| 784 | if (dev->parent) | 785 | if (dev->parent) |
| 785 | up(&dev->parent->sem); | 786 | device_unlock(dev->parent); |
| 786 | } | 787 | } |
| 787 | return bus_rescan_devices_helper(dev, NULL); | 788 | return bus_rescan_devices_helper(dev, NULL); |
| 788 | } | 789 | } |
diff --git a/drivers/base/class.c b/drivers/base/class.c index 6e2c3b064f53..9c6a0d6408e7 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
| @@ -31,7 +31,7 @@ static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr, | |||
| 31 | ssize_t ret = -EIO; | 31 | ssize_t ret = -EIO; |
| 32 | 32 | ||
| 33 | if (class_attr->show) | 33 | if (class_attr->show) |
| 34 | ret = class_attr->show(cp->class, buf); | 34 | ret = class_attr->show(cp->class, class_attr, buf); |
| 35 | return ret; | 35 | return ret; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -43,7 +43,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr, | |||
| 43 | ssize_t ret = -EIO; | 43 | ssize_t ret = -EIO; |
| 44 | 44 | ||
| 45 | if (class_attr->store) | 45 | if (class_attr->store) |
| 46 | ret = class_attr->store(cp->class, buf, count); | 46 | ret = class_attr->store(cp->class, class_attr, buf, count); |
| 47 | return ret; | 47 | return ret; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| @@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj) | |||
| 63 | kfree(cp); | 63 | kfree(cp); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | static struct sysfs_ops class_sysfs_ops = { | 66 | static const struct sysfs_ops class_sysfs_ops = { |
| 67 | .show = class_attr_show, | 67 | .show = class_attr_show, |
| 68 | .store = class_attr_store, | 68 | .store = class_attr_store, |
| 69 | }; | 69 | }; |
| @@ -219,6 +219,8 @@ static void class_create_release(struct class *cls) | |||
| 219 | * This is used to create a struct class pointer that can then be used | 219 | * This is used to create a struct class pointer that can then be used |
| 220 | * in calls to device_create(). | 220 | * in calls to device_create(). |
| 221 | * | 221 | * |
| 222 | * Returns &struct class pointer on success, or ERR_PTR() on error. | ||
| 223 | * | ||
| 222 | * Note, the pointer created here is to be destroyed when finished by | 224 | * Note, the pointer created here is to be destroyed when finished by |
| 223 | * making a call to class_destroy(). | 225 | * making a call to class_destroy(). |
| 224 | */ | 226 | */ |
| @@ -490,6 +492,16 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
| 490 | class_put(parent); | 492 | class_put(parent); |
| 491 | } | 493 | } |
| 492 | 494 | ||
| 495 | ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, | ||
| 496 | char *buf) | ||
| 497 | { | ||
| 498 | struct class_attribute_string *cs; | ||
| 499 | cs = container_of(attr, struct class_attribute_string, attr); | ||
| 500 | return snprintf(buf, PAGE_SIZE, "%s\n", cs->str); | ||
| 501 | } | ||
| 502 | |||
| 503 | EXPORT_SYMBOL_GPL(show_class_attr_string); | ||
| 504 | |||
| 493 | struct class_compat { | 505 | struct class_compat { |
| 494 | struct kobject *kobj; | 506 | struct kobject *kobj; |
| 495 | }; | 507 | }; |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 282025770429..b56a0ba31d4a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
| @@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr, | |||
| 100 | return ret; | 100 | return ret; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | static struct sysfs_ops dev_sysfs_ops = { | 103 | static const struct sysfs_ops dev_sysfs_ops = { |
| 104 | .show = dev_attr_show, | 104 | .show = dev_attr_show, |
| 105 | .store = dev_attr_store, | 105 | .store = dev_attr_store, |
| 106 | }; | 106 | }; |
| @@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, | |||
| 252 | return retval; | 252 | return retval; |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | static struct kset_uevent_ops device_uevent_ops = { | 255 | static const struct kset_uevent_ops device_uevent_ops = { |
| 256 | .filter = dev_uevent_filter, | 256 | .filter = dev_uevent_filter, |
| 257 | .name = dev_uevent_name, | 257 | .name = dev_uevent_name, |
| 258 | .uevent = dev_uevent, | 258 | .uevent = dev_uevent, |
| @@ -306,15 +306,10 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | |||
| 306 | { | 306 | { |
| 307 | enum kobject_action action; | 307 | enum kobject_action action; |
| 308 | 308 | ||
| 309 | if (kobject_action_type(buf, count, &action) == 0) { | 309 | if (kobject_action_type(buf, count, &action) == 0) |
| 310 | kobject_uevent(&dev->kobj, action); | 310 | kobject_uevent(&dev->kobj, action); |
| 311 | goto out; | 311 | else |
| 312 | } | 312 | dev_err(dev, "uevent: unknown action-string\n"); |
| 313 | |||
| 314 | dev_err(dev, "uevent: unsupported action-string; this will " | ||
| 315 | "be ignored in a future kernel version\n"); | ||
| 316 | kobject_uevent(&dev->kobj, KOBJ_ADD); | ||
| 317 | out: | ||
| 318 | return count; | 313 | return count; |
| 319 | } | 314 | } |
| 320 | 315 | ||
| @@ -607,6 +602,7 @@ static struct kobject *get_device_parent(struct device *dev, | |||
| 607 | int retval; | 602 | int retval; |
| 608 | 603 | ||
| 609 | if (dev->class) { | 604 | if (dev->class) { |
| 605 | static DEFINE_MUTEX(gdp_mutex); | ||
| 610 | struct kobject *kobj = NULL; | 606 | struct kobject *kobj = NULL; |
| 611 | struct kobject *parent_kobj; | 607 | struct kobject *parent_kobj; |
| 612 | struct kobject *k; | 608 | struct kobject *k; |
| @@ -623,6 +619,8 @@ static struct kobject *get_device_parent(struct device *dev, | |||
| 623 | else | 619 | else |
| 624 | parent_kobj = &parent->kobj; | 620 | parent_kobj = &parent->kobj; |
| 625 | 621 | ||
| 622 | mutex_lock(&gdp_mutex); | ||
| 623 | |||
| 626 | /* find our class-directory at the parent and reference it */ | 624 | /* find our class-directory at the parent and reference it */ |
| 627 | spin_lock(&dev->class->p->class_dirs.list_lock); | 625 | spin_lock(&dev->class->p->class_dirs.list_lock); |
| 628 | list_for_each_entry(k, &dev->class->p->class_dirs.list, entry) | 626 | list_for_each_entry(k, &dev->class->p->class_dirs.list, entry) |
| @@ -631,20 +629,26 @@ static struct kobject *get_device_parent(struct device *dev, | |||
| 631 | break; | 629 | break; |
| 632 | } | 630 | } |
| 633 | spin_unlock(&dev->class->p->class_dirs.list_lock); | 631 | spin_unlock(&dev->class->p->class_dirs.list_lock); |
| 634 | if (kobj) | 632 | if (kobj) { |
| 633 | mutex_unlock(&gdp_mutex); | ||
| 635 | return kobj; | 634 | return kobj; |
| 635 | } | ||
| 636 | 636 | ||
| 637 | /* or create a new class-directory at the parent device */ | 637 | /* or create a new class-directory at the parent device */ |
| 638 | k = kobject_create(); | 638 | k = kobject_create(); |
| 639 | if (!k) | 639 | if (!k) { |
| 640 | mutex_unlock(&gdp_mutex); | ||
| 640 | return NULL; | 641 | return NULL; |
| 642 | } | ||
| 641 | k->kset = &dev->class->p->class_dirs; | 643 | k->kset = &dev->class->p->class_dirs; |
| 642 | retval = kobject_add(k, parent_kobj, "%s", dev->class->name); | 644 | retval = kobject_add(k, parent_kobj, "%s", dev->class->name); |
| 643 | if (retval < 0) { | 645 | if (retval < 0) { |
| 646 | mutex_unlock(&gdp_mutex); | ||
| 644 | kobject_put(k); | 647 | kobject_put(k); |
| 645 | return NULL; | 648 | return NULL; |
| 646 | } | 649 | } |
| 647 | /* do not emit an uevent for this simple "glue" directory */ | 650 | /* do not emit an uevent for this simple "glue" directory */ |
| 651 | mutex_unlock(&gdp_mutex); | ||
| 648 | return k; | 652 | return k; |
| 649 | } | 653 | } |
| 650 | 654 | ||
| @@ -1341,6 +1345,8 @@ static void root_device_release(struct device *dev) | |||
| 1341 | * 'module' symlink which points to the @owner directory | 1345 | * 'module' symlink which points to the @owner directory |
| 1342 | * in sysfs. | 1346 | * in sysfs. |
| 1343 | * | 1347 | * |
| 1348 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1349 | * | ||
| 1344 | * Note: You probably want to use root_device_register(). | 1350 | * Note: You probably want to use root_device_register(). |
| 1345 | */ | 1351 | */ |
| 1346 | struct device *__root_device_register(const char *name, struct module *owner) | 1352 | struct device *__root_device_register(const char *name, struct module *owner) |
| @@ -1428,6 +1434,8 @@ static void device_create_release(struct device *dev) | |||
| 1428 | * Any further sysfs files that might be required can be created using this | 1434 | * Any further sysfs files that might be required can be created using this |
| 1429 | * pointer. | 1435 | * pointer. |
| 1430 | * | 1436 | * |
| 1437 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1438 | * | ||
| 1431 | * Note: the struct class passed to this function must have previously | 1439 | * Note: the struct class passed to this function must have previously |
| 1432 | * been created with a call to class_create(). | 1440 | * been created with a call to class_create(). |
| 1433 | */ | 1441 | */ |
| @@ -1488,6 +1496,8 @@ EXPORT_SYMBOL_GPL(device_create_vargs); | |||
| 1488 | * Any further sysfs files that might be required can be created using this | 1496 | * Any further sysfs files that might be required can be created using this |
| 1489 | * pointer. | 1497 | * pointer. |
| 1490 | * | 1498 | * |
| 1499 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1500 | * | ||
| 1491 | * Note: the struct class passed to this function must have previously | 1501 | * Note: the struct class passed to this function must have previously |
| 1492 | * been created with a call to class_create(). | 1502 | * been created with a call to class_create(). |
| 1493 | */ | 1503 | */ |
| @@ -1574,22 +1584,16 @@ int device_rename(struct device *dev, char *new_name) | |||
| 1574 | if (old_class_name) { | 1584 | if (old_class_name) { |
| 1575 | new_class_name = make_class_name(dev->class->name, &dev->kobj); | 1585 | new_class_name = make_class_name(dev->class->name, &dev->kobj); |
| 1576 | if (new_class_name) { | 1586 | if (new_class_name) { |
| 1577 | error = sysfs_create_link_nowarn(&dev->parent->kobj, | 1587 | error = sysfs_rename_link(&dev->parent->kobj, |
| 1578 | &dev->kobj, | 1588 | &dev->kobj, |
| 1579 | new_class_name); | 1589 | old_class_name, |
| 1580 | if (error) | 1590 | new_class_name); |
| 1581 | goto out; | ||
| 1582 | sysfs_remove_link(&dev->parent->kobj, old_class_name); | ||
| 1583 | } | 1591 | } |
| 1584 | } | 1592 | } |
| 1585 | #else | 1593 | #else |
| 1586 | if (dev->class) { | 1594 | if (dev->class) { |
| 1587 | error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj, | 1595 | error = sysfs_rename_link(&dev->class->p->class_subsys.kobj, |
| 1588 | &dev->kobj, dev_name(dev)); | 1596 | &dev->kobj, old_device_name, new_name); |
| 1589 | if (error) | ||
| 1590 | goto out; | ||
| 1591 | sysfs_remove_link(&dev->class->p->class_subsys.kobj, | ||
| 1592 | old_device_name); | ||
| 1593 | } | 1597 | } |
| 1594 | #endif | 1598 | #endif |
| 1595 | 1599 | ||
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 958bd1540c30..f35719aab3c1 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
| @@ -10,11 +10,15 @@ | |||
| 10 | #include <linux/topology.h> | 10 | #include <linux/topology.h> |
| 11 | #include <linux/device.h> | 11 | #include <linux/device.h> |
| 12 | #include <linux/node.h> | 12 | #include <linux/node.h> |
| 13 | #include <linux/gfp.h> | ||
| 13 | 14 | ||
| 14 | #include "base.h" | 15 | #include "base.h" |
| 15 | 16 | ||
| 17 | static struct sysdev_class_attribute *cpu_sysdev_class_attrs[]; | ||
| 18 | |||
| 16 | struct sysdev_class cpu_sysdev_class = { | 19 | struct sysdev_class cpu_sysdev_class = { |
| 17 | .name = "cpu", | 20 | .name = "cpu", |
| 21 | .attrs = cpu_sysdev_class_attrs, | ||
| 18 | }; | 22 | }; |
| 19 | EXPORT_SYMBOL(cpu_sysdev_class); | 23 | EXPORT_SYMBOL(cpu_sysdev_class); |
| 20 | 24 | ||
| @@ -76,34 +80,24 @@ void unregister_cpu(struct cpu *cpu) | |||
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE | 82 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE |
| 79 | static ssize_t cpu_probe_store(struct class *class, const char *buf, | 83 | static ssize_t cpu_probe_store(struct sysdev_class *class, |
| 84 | struct sysdev_class_attribute *attr, | ||
| 85 | const char *buf, | ||
| 80 | size_t count) | 86 | size_t count) |
| 81 | { | 87 | { |
| 82 | return arch_cpu_probe(buf, count); | 88 | return arch_cpu_probe(buf, count); |
| 83 | } | 89 | } |
| 84 | 90 | ||
| 85 | static ssize_t cpu_release_store(struct class *class, const char *buf, | 91 | static ssize_t cpu_release_store(struct sysdev_class *class, |
| 92 | struct sysdev_class_attribute *attr, | ||
| 93 | const char *buf, | ||
| 86 | size_t count) | 94 | size_t count) |
| 87 | { | 95 | { |
| 88 | return arch_cpu_release(buf, count); | 96 | return arch_cpu_release(buf, count); |
| 89 | } | 97 | } |
| 90 | 98 | ||
| 91 | static CLASS_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); | 99 | static SYSDEV_CLASS_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); |
| 92 | static CLASS_ATTR(release, S_IWUSR, NULL, cpu_release_store); | 100 | static SYSDEV_CLASS_ATTR(release, S_IWUSR, NULL, cpu_release_store); |
| 93 | |||
| 94 | int __init cpu_probe_release_init(void) | ||
| 95 | { | ||
| 96 | int rc; | ||
| 97 | |||
| 98 | rc = sysfs_create_file(&cpu_sysdev_class.kset.kobj, | ||
| 99 | &class_attr_probe.attr); | ||
| 100 | if (!rc) | ||
| 101 | rc = sysfs_create_file(&cpu_sysdev_class.kset.kobj, | ||
| 102 | &class_attr_release.attr); | ||
| 103 | |||
| 104 | return rc; | ||
| 105 | } | ||
| 106 | device_initcall(cpu_probe_release_init); | ||
| 107 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ | 101 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ |
| 108 | 102 | ||
| 109 | #else /* ... !CONFIG_HOTPLUG_CPU */ | 103 | #else /* ... !CONFIG_HOTPLUG_CPU */ |
| @@ -141,31 +135,39 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL); | |||
| 141 | /* | 135 | /* |
| 142 | * Print cpu online, possible, present, and system maps | 136 | * Print cpu online, possible, present, and system maps |
| 143 | */ | 137 | */ |
| 144 | static ssize_t print_cpus_map(char *buf, const struct cpumask *map) | 138 | |
| 139 | struct cpu_attr { | ||
| 140 | struct sysdev_class_attribute attr; | ||
| 141 | const struct cpumask *const * const map; | ||
| 142 | }; | ||
| 143 | |||
| 144 | static ssize_t show_cpus_attr(struct sysdev_class *class, | ||
| 145 | struct sysdev_class_attribute *attr, | ||
| 146 | char *buf) | ||
| 145 | { | 147 | { |
| 146 | int n = cpulist_scnprintf(buf, PAGE_SIZE-2, map); | 148 | struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr); |
| 149 | int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *(ca->map)); | ||
| 147 | 150 | ||
| 148 | buf[n++] = '\n'; | 151 | buf[n++] = '\n'; |
| 149 | buf[n] = '\0'; | 152 | buf[n] = '\0'; |
| 150 | return n; | 153 | return n; |
| 151 | } | 154 | } |
| 152 | 155 | ||
| 153 | #define print_cpus_func(type) \ | 156 | #define _CPU_ATTR(name, map) \ |
| 154 | static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \ | 157 | { _SYSDEV_CLASS_ATTR(name, 0444, show_cpus_attr, NULL), map } |
| 155 | { \ | ||
| 156 | return print_cpus_map(buf, cpu_##type##_mask); \ | ||
| 157 | } \ | ||
| 158 | static struct sysdev_class_attribute attr_##type##_map = \ | ||
| 159 | _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL) | ||
| 160 | 158 | ||
| 161 | print_cpus_func(online); | 159 | /* Keep in sync with cpu_sysdev_class_attrs */ |
| 162 | print_cpus_func(possible); | 160 | static struct cpu_attr cpu_attrs[] = { |
| 163 | print_cpus_func(present); | 161 | _CPU_ATTR(online, &cpu_online_mask), |
| 162 | _CPU_ATTR(possible, &cpu_possible_mask), | ||
| 163 | _CPU_ATTR(present, &cpu_present_mask), | ||
| 164 | }; | ||
| 164 | 165 | ||
| 165 | /* | 166 | /* |
| 166 | * Print values for NR_CPUS and offlined cpus | 167 | * Print values for NR_CPUS and offlined cpus |
| 167 | */ | 168 | */ |
| 168 | static ssize_t print_cpus_kernel_max(struct sysdev_class *class, char *buf) | 169 | static ssize_t print_cpus_kernel_max(struct sysdev_class *class, |
| 170 | struct sysdev_class_attribute *attr, char *buf) | ||
| 169 | { | 171 | { |
| 170 | int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1); | 172 | int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1); |
| 171 | return n; | 173 | return n; |
| @@ -175,7 +177,8 @@ static SYSDEV_CLASS_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL); | |||
| 175 | /* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */ | 177 | /* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */ |
| 176 | unsigned int total_cpus; | 178 | unsigned int total_cpus; |
| 177 | 179 | ||
| 178 | static ssize_t print_cpus_offline(struct sysdev_class *class, char *buf) | 180 | static ssize_t print_cpus_offline(struct sysdev_class *class, |
| 181 | struct sysdev_class_attribute *attr, char *buf) | ||
| 179 | { | 182 | { |
| 180 | int n = 0, len = PAGE_SIZE-2; | 183 | int n = 0, len = PAGE_SIZE-2; |
| 181 | cpumask_var_t offline; | 184 | cpumask_var_t offline; |
| @@ -204,29 +207,6 @@ static ssize_t print_cpus_offline(struct sysdev_class *class, char *buf) | |||
| 204 | } | 207 | } |
| 205 | static SYSDEV_CLASS_ATTR(offline, 0444, print_cpus_offline, NULL); | 208 | static SYSDEV_CLASS_ATTR(offline, 0444, print_cpus_offline, NULL); |
| 206 | 209 | ||
| 207 | static struct sysdev_class_attribute *cpu_state_attr[] = { | ||
| 208 | &attr_online_map, | ||
| 209 | &attr_possible_map, | ||
| 210 | &attr_present_map, | ||
| 211 | &attr_kernel_max, | ||
| 212 | &attr_offline, | ||
| 213 | }; | ||
| 214 | |||
| 215 | static int cpu_states_init(void) | ||
| 216 | { | ||
| 217 | int i; | ||
| 218 | int err = 0; | ||
| 219 | |||
| 220 | for (i = 0; i < ARRAY_SIZE(cpu_state_attr); i++) { | ||
| 221 | int ret; | ||
| 222 | ret = sysdev_class_create_file(&cpu_sysdev_class, | ||
| 223 | cpu_state_attr[i]); | ||
| 224 | if (!err) | ||
| 225 | err = ret; | ||
| 226 | } | ||
| 227 | return err; | ||
| 228 | } | ||
| 229 | |||
| 230 | /* | 210 | /* |
| 231 | * register_cpu - Setup a sysfs device for a CPU. | 211 | * register_cpu - Setup a sysfs device for a CPU. |
| 232 | * @cpu - cpu->hotpluggable field set to 1 will generate a control file in | 212 | * @cpu - cpu->hotpluggable field set to 1 will generate a control file in |
| @@ -272,9 +252,6 @@ int __init cpu_dev_init(void) | |||
| 272 | int err; | 252 | int err; |
| 273 | 253 | ||
| 274 | err = sysdev_class_register(&cpu_sysdev_class); | 254 | err = sysdev_class_register(&cpu_sysdev_class); |
| 275 | if (!err) | ||
| 276 | err = cpu_states_init(); | ||
| 277 | |||
| 278 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | 255 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) |
| 279 | if (!err) | 256 | if (!err) |
| 280 | err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); | 257 | err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); |
| @@ -282,3 +259,16 @@ int __init cpu_dev_init(void) | |||
| 282 | 259 | ||
| 283 | return err; | 260 | return err; |
| 284 | } | 261 | } |
| 262 | |||
| 263 | static struct sysdev_class_attribute *cpu_sysdev_class_attrs[] = { | ||
| 264 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE | ||
| 265 | &attr_probe, | ||
| 266 | &attr_release, | ||
| 267 | #endif | ||
| 268 | &cpu_attrs[0].attr, | ||
| 269 | &cpu_attrs[1].attr, | ||
| 270 | &cpu_attrs[2].attr, | ||
| 271 | &attr_kernel_max, | ||
| 272 | &attr_offline, | ||
| 273 | NULL | ||
| 274 | }; | ||
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index ee95c76bfd3d..c89291f8a16b 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
| @@ -85,7 +85,7 @@ static void driver_sysfs_remove(struct device *dev) | |||
| 85 | * for before calling this. (It is ok to call with no other effort | 85 | * for before calling this. (It is ok to call with no other effort |
| 86 | * from a driver's probe() method.) | 86 | * from a driver's probe() method.) |
| 87 | * | 87 | * |
| 88 | * This function must be called with @dev->sem held. | 88 | * This function must be called with the device lock held. |
| 89 | */ | 89 | */ |
| 90 | int device_bind_driver(struct device *dev) | 90 | int device_bind_driver(struct device *dev) |
| 91 | { | 91 | { |
| @@ -190,8 +190,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe); | |||
| 190 | * This function returns -ENODEV if the device is not registered, | 190 | * This function returns -ENODEV if the device is not registered, |
| 191 | * 1 if the device is bound successfully and 0 otherwise. | 191 | * 1 if the device is bound successfully and 0 otherwise. |
| 192 | * | 192 | * |
| 193 | * This function must be called with @dev->sem held. When called for a | 193 | * This function must be called with @dev lock held. When called for a |
| 194 | * USB interface, @dev->parent->sem must be held as well. | 194 | * USB interface, @dev->parent lock must be held as well. |
| 195 | */ | 195 | */ |
| 196 | int driver_probe_device(struct device_driver *drv, struct device *dev) | 196 | int driver_probe_device(struct device_driver *drv, struct device *dev) |
| 197 | { | 197 | { |
| @@ -233,13 +233,13 @@ static int __device_attach(struct device_driver *drv, void *data) | |||
| 233 | * 0 if no matching driver was found; | 233 | * 0 if no matching driver was found; |
| 234 | * -ENODEV if the device is not registered. | 234 | * -ENODEV if the device is not registered. |
| 235 | * | 235 | * |
| 236 | * When called for a USB interface, @dev->parent->sem must be held. | 236 | * When called for a USB interface, @dev->parent lock must be held. |
| 237 | */ | 237 | */ |
| 238 | int device_attach(struct device *dev) | 238 | int device_attach(struct device *dev) |
| 239 | { | 239 | { |
| 240 | int ret = 0; | 240 | int ret = 0; |
| 241 | 241 | ||
| 242 | down(&dev->sem); | 242 | device_lock(dev); |
| 243 | if (dev->driver) { | 243 | if (dev->driver) { |
| 244 | ret = device_bind_driver(dev); | 244 | ret = device_bind_driver(dev); |
| 245 | if (ret == 0) | 245 | if (ret == 0) |
| @@ -253,7 +253,7 @@ int device_attach(struct device *dev) | |||
| 253 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); | 253 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); |
| 254 | pm_runtime_put_sync(dev); | 254 | pm_runtime_put_sync(dev); |
| 255 | } | 255 | } |
| 256 | up(&dev->sem); | 256 | device_unlock(dev); |
| 257 | return ret; | 257 | return ret; |
| 258 | } | 258 | } |
| 259 | EXPORT_SYMBOL_GPL(device_attach); | 259 | EXPORT_SYMBOL_GPL(device_attach); |
| @@ -276,13 +276,13 @@ static int __driver_attach(struct device *dev, void *data) | |||
| 276 | return 0; | 276 | return 0; |
| 277 | 277 | ||
| 278 | if (dev->parent) /* Needed for USB */ | 278 | if (dev->parent) /* Needed for USB */ |
| 279 | down(&dev->parent->sem); | 279 | device_lock(dev->parent); |
| 280 | down(&dev->sem); | 280 | device_lock(dev); |
| 281 | if (!dev->driver) | 281 | if (!dev->driver) |
| 282 | driver_probe_device(drv, dev); | 282 | driver_probe_device(drv, dev); |
| 283 | up(&dev->sem); | 283 | device_unlock(dev); |
| 284 | if (dev->parent) | 284 | if (dev->parent) |
| 285 | up(&dev->parent->sem); | 285 | device_unlock(dev->parent); |
| 286 | 286 | ||
| 287 | return 0; | 287 | return 0; |
| 288 | } | 288 | } |
| @@ -303,8 +303,8 @@ int driver_attach(struct device_driver *drv) | |||
| 303 | EXPORT_SYMBOL_GPL(driver_attach); | 303 | EXPORT_SYMBOL_GPL(driver_attach); |
| 304 | 304 | ||
| 305 | /* | 305 | /* |
| 306 | * __device_release_driver() must be called with @dev->sem held. | 306 | * __device_release_driver() must be called with @dev lock held. |
| 307 | * When called for a USB interface, @dev->parent->sem must be held as well. | 307 | * When called for a USB interface, @dev->parent lock must be held as well. |
| 308 | */ | 308 | */ |
| 309 | static void __device_release_driver(struct device *dev) | 309 | static void __device_release_driver(struct device *dev) |
| 310 | { | 310 | { |
| @@ -343,7 +343,7 @@ static void __device_release_driver(struct device *dev) | |||
| 343 | * @dev: device. | 343 | * @dev: device. |
| 344 | * | 344 | * |
| 345 | * Manually detach device from driver. | 345 | * Manually detach device from driver. |
| 346 | * When called for a USB interface, @dev->parent->sem must be held. | 346 | * When called for a USB interface, @dev->parent lock must be held. |
| 347 | */ | 347 | */ |
| 348 | void device_release_driver(struct device *dev) | 348 | void device_release_driver(struct device *dev) |
| 349 | { | 349 | { |
| @@ -352,9 +352,9 @@ void device_release_driver(struct device *dev) | |||
| 352 | * within their ->remove callback for the same device, they | 352 | * within their ->remove callback for the same device, they |
| 353 | * will deadlock right here. | 353 | * will deadlock right here. |
| 354 | */ | 354 | */ |
| 355 | down(&dev->sem); | 355 | device_lock(dev); |
| 356 | __device_release_driver(dev); | 356 | __device_release_driver(dev); |
| 357 | up(&dev->sem); | 357 | device_unlock(dev); |
| 358 | } | 358 | } |
| 359 | EXPORT_SYMBOL_GPL(device_release_driver); | 359 | EXPORT_SYMBOL_GPL(device_release_driver); |
| 360 | 360 | ||
| @@ -381,13 +381,13 @@ void driver_detach(struct device_driver *drv) | |||
| 381 | spin_unlock(&drv->p->klist_devices.k_lock); | 381 | spin_unlock(&drv->p->klist_devices.k_lock); |
| 382 | 382 | ||
| 383 | if (dev->parent) /* Needed for USB */ | 383 | if (dev->parent) /* Needed for USB */ |
| 384 | down(&dev->parent->sem); | 384 | device_lock(dev->parent); |
| 385 | down(&dev->sem); | 385 | device_lock(dev); |
| 386 | if (dev->driver == drv) | 386 | if (dev->driver == drv) |
| 387 | __device_release_driver(dev); | 387 | __device_release_driver(dev); |
| 388 | up(&dev->sem); | 388 | device_unlock(dev); |
| 389 | if (dev->parent) | 389 | if (dev->parent) |
| 390 | up(&dev->parent->sem); | 390 | device_unlock(dev->parent); |
| 391 | put_device(dev); | 391 | put_device(dev); |
| 392 | } | 392 | } |
| 393 | } | 393 | } |
diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 05dd307e8f02..cf7a0c788052 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/slab.h> | ||
| 12 | 13 | ||
| 13 | #include "base.h" | 14 | #include "base.h" |
| 14 | 15 | ||
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index 42ae452b36b0..057cf11326bf 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <linux/cred.h> | 23 | #include <linux/cred.h> |
| 24 | #include <linux/sched.h> | 24 | #include <linux/sched.h> |
| 25 | #include <linux/init_task.h> | 25 | #include <linux/init_task.h> |
| 26 | #include <linux/slab.h> | ||
| 26 | 27 | ||
| 27 | static struct vfsmount *dev_mnt; | 28 | static struct vfsmount *dev_mnt; |
| 28 | 29 | ||
| @@ -301,6 +302,19 @@ int devtmpfs_delete_node(struct device *dev) | |||
| 301 | if (dentry->d_inode) { | 302 | if (dentry->d_inode) { |
| 302 | err = vfs_getattr(nd.path.mnt, dentry, &stat); | 303 | err = vfs_getattr(nd.path.mnt, dentry, &stat); |
| 303 | if (!err && dev_mynode(dev, dentry->d_inode, &stat)) { | 304 | if (!err && dev_mynode(dev, dentry->d_inode, &stat)) { |
| 305 | struct iattr newattrs; | ||
| 306 | /* | ||
| 307 | * before unlinking this node, reset permissions | ||
| 308 | * of possible references like hardlinks | ||
| 309 | */ | ||
| 310 | newattrs.ia_uid = 0; | ||
| 311 | newattrs.ia_gid = 0; | ||
| 312 | newattrs.ia_mode = stat.mode & ~0777; | ||
| 313 | newattrs.ia_valid = | ||
| 314 | ATTR_UID|ATTR_GID|ATTR_MODE; | ||
| 315 | mutex_lock(&dentry->d_inode->i_mutex); | ||
| 316 | notify_change(dentry, &newattrs); | ||
| 317 | mutex_unlock(&dentry->d_inode->i_mutex); | ||
| 304 | err = vfs_unlink(nd.path.dentry->d_inode, | 318 | err = vfs_unlink(nd.path.dentry->d_inode, |
| 305 | dentry); | 319 | dentry); |
| 306 | if (!err || err == -ENOENT) | 320 | if (!err || err == -ENOENT) |
diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index 962a3b574f21..d4d8ce53886a 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * Coherent per-device memory handling. | 2 | * Coherent per-device memory handling. |
| 3 | * Borrowed from i386 | 3 | * Borrowed from i386 |
| 4 | */ | 4 | */ |
| 5 | #include <linux/slab.h> | ||
| 5 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
| 6 | #include <linux/dma-mapping.h> | 7 | #include <linux/dma-mapping.h> |
| 7 | 8 | ||
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index ca9186f70a69..763d59c1eb65 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include <linux/dma-mapping.h> | 10 | #include <linux/dma-mapping.h> |
| 11 | #include <linux/gfp.h> | ||
| 11 | 12 | ||
| 12 | /* | 13 | /* |
| 13 | * Managed DMA API | 14 | * Managed DMA API |
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 90c9fff09ead..b631f7c59453 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/device.h> | 13 | #include <linux/device.h> |
| 14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> | ||
| 16 | #include <linux/string.h> | 17 | #include <linux/string.h> |
| 17 | #include "base.h" | 18 | #include "base.h" |
| 18 | 19 | ||
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index a95024166b66..985da11174e7 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/kthread.h> | 19 | #include <linux/kthread.h> |
| 20 | #include <linux/highmem.h> | 20 | #include <linux/highmem.h> |
| 21 | #include <linux/firmware.h> | 21 | #include <linux/firmware.h> |
| 22 | #include "base.h" | 22 | #include <linux/slab.h> |
| 23 | 23 | ||
| 24 | #define to_dev(obj) container_of(obj, struct device, kobj) | 24 | #define to_dev(obj) container_of(obj, struct device, kobj) |
| 25 | 25 | ||
| @@ -69,7 +69,9 @@ fw_load_abort(struct firmware_priv *fw_priv) | |||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | static ssize_t | 71 | static ssize_t |
| 72 | firmware_timeout_show(struct class *class, char *buf) | 72 | firmware_timeout_show(struct class *class, |
| 73 | struct class_attribute *attr, | ||
| 74 | char *buf) | ||
| 73 | { | 75 | { |
| 74 | return sprintf(buf, "%d\n", loading_timeout); | 76 | return sprintf(buf, "%d\n", loading_timeout); |
| 75 | } | 77 | } |
| @@ -77,6 +79,7 @@ firmware_timeout_show(struct class *class, char *buf) | |||
| 77 | /** | 79 | /** |
| 78 | * firmware_timeout_store - set number of seconds to wait for firmware | 80 | * firmware_timeout_store - set number of seconds to wait for firmware |
| 79 | * @class: device class pointer | 81 | * @class: device class pointer |
| 82 | * @attr: device attribute pointer | ||
| 80 | * @buf: buffer to scan for timeout value | 83 | * @buf: buffer to scan for timeout value |
| 81 | * @count: number of bytes in @buf | 84 | * @count: number of bytes in @buf |
| 82 | * | 85 | * |
| @@ -87,7 +90,9 @@ firmware_timeout_show(struct class *class, char *buf) | |||
| 87 | * Note: zero means 'wait forever'. | 90 | * Note: zero means 'wait forever'. |
| 88 | **/ | 91 | **/ |
| 89 | static ssize_t | 92 | static ssize_t |
| 90 | firmware_timeout_store(struct class *class, const char *buf, size_t count) | 93 | firmware_timeout_store(struct class *class, |
| 94 | struct class_attribute *attr, | ||
| 95 | const char *buf, size_t count) | ||
| 91 | { | 96 | { |
| 92 | loading_timeout = simple_strtol(buf, NULL, 10); | 97 | loading_timeout = simple_strtol(buf, NULL, 10); |
| 93 | if (loading_timeout < 0) | 98 | if (loading_timeout < 0) |
| @@ -439,6 +444,7 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p, | |||
| 439 | fw_priv = dev_get_drvdata(f_dev); | 444 | fw_priv = dev_get_drvdata(f_dev); |
| 440 | 445 | ||
| 441 | fw_priv->fw = fw; | 446 | fw_priv->fw = fw; |
| 447 | sysfs_bin_attr_init(&fw_priv->attr_data); | ||
| 442 | retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); | 448 | retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); |
| 443 | if (retval) { | 449 | if (retval) { |
| 444 | dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__); | 450 | dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__); |
| @@ -610,7 +616,7 @@ request_firmware_work_func(void *arg) | |||
| 610 | } | 616 | } |
| 611 | 617 | ||
| 612 | /** | 618 | /** |
| 613 | * request_firmware_nowait: asynchronous version of request_firmware | 619 | * request_firmware_nowait - asynchronous version of request_firmware |
| 614 | * @module: module requesting the firmware | 620 | * @module: module requesting the firmware |
| 615 | * @uevent: sends uevent to copy the firmware image if this flag | 621 | * @uevent: sends uevent to copy the firmware image if this flag |
| 616 | * is non-zero else the firmware copy must be done manually. | 622 | * is non-zero else the firmware copy must be done manually. |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index bd025059711f..933442f40321 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
| 23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
| 24 | #include <linux/stat.h> | 24 | #include <linux/stat.h> |
| 25 | #include <linux/slab.h> | ||
| 25 | 26 | ||
| 26 | #include <asm/atomic.h> | 27 | #include <asm/atomic.h> |
| 27 | #include <asm/uaccess.h> | 28 | #include <asm/uaccess.h> |
| @@ -44,7 +45,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev | |||
| 44 | return retval; | 45 | return retval; |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | static struct kset_uevent_ops memory_uevent_ops = { | 48 | static const struct kset_uevent_ops memory_uevent_ops = { |
| 48 | .name = memory_uevent_name, | 49 | .name = memory_uevent_name, |
| 49 | .uevent = memory_uevent, | 50 | .uevent = memory_uevent, |
| 50 | }; | 51 | }; |
| @@ -309,17 +310,18 @@ static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); | |||
| 309 | * Block size attribute stuff | 310 | * Block size attribute stuff |
| 310 | */ | 311 | */ |
| 311 | static ssize_t | 312 | static ssize_t |
| 312 | print_block_size(struct class *class, char *buf) | 313 | print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, |
| 314 | char *buf) | ||
| 313 | { | 315 | { |
| 314 | return sprintf(buf, "%#lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); | 316 | return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); |
| 315 | } | 317 | } |
| 316 | 318 | ||
| 317 | static CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); | 319 | static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); |
| 318 | 320 | ||
| 319 | static int block_size_init(void) | 321 | static int block_size_init(void) |
| 320 | { | 322 | { |
| 321 | return sysfs_create_file(&memory_sysdev_class.kset.kobj, | 323 | return sysfs_create_file(&memory_sysdev_class.kset.kobj, |
| 322 | &class_attr_block_size_bytes.attr); | 324 | &attr_block_size_bytes.attr); |
| 323 | } | 325 | } |
| 324 | 326 | ||
| 325 | /* | 327 | /* |
| @@ -330,7 +332,8 @@ static int block_size_init(void) | |||
| 330 | */ | 332 | */ |
| 331 | #ifdef CONFIG_ARCH_MEMORY_PROBE | 333 | #ifdef CONFIG_ARCH_MEMORY_PROBE |
| 332 | static ssize_t | 334 | static ssize_t |
| 333 | memory_probe_store(struct class *class, const char *buf, size_t count) | 335 | memory_probe_store(struct class *class, struct class_attribute *attr, |
| 336 | const char *buf, size_t count) | ||
| 334 | { | 337 | { |
| 335 | u64 phys_addr; | 338 | u64 phys_addr; |
| 336 | int nid; | 339 | int nid; |
| @@ -367,7 +370,9 @@ static inline int memory_probe_init(void) | |||
| 367 | 370 | ||
| 368 | /* Soft offline a page */ | 371 | /* Soft offline a page */ |
| 369 | static ssize_t | 372 | static ssize_t |
| 370 | store_soft_offline_page(struct class *class, const char *buf, size_t count) | 373 | store_soft_offline_page(struct class *class, |
| 374 | struct class_attribute *attr, | ||
| 375 | const char *buf, size_t count) | ||
| 371 | { | 376 | { |
| 372 | int ret; | 377 | int ret; |
| 373 | u64 pfn; | 378 | u64 pfn; |
| @@ -384,7 +389,9 @@ store_soft_offline_page(struct class *class, const char *buf, size_t count) | |||
| 384 | 389 | ||
| 385 | /* Forcibly offline a page, including killing processes. */ | 390 | /* Forcibly offline a page, including killing processes. */ |
| 386 | static ssize_t | 391 | static ssize_t |
| 387 | store_hard_offline_page(struct class *class, const char *buf, size_t count) | 392 | store_hard_offline_page(struct class *class, |
| 393 | struct class_attribute *attr, | ||
| 394 | const char *buf, size_t count) | ||
| 388 | { | 395 | { |
| 389 | int ret; | 396 | int ret; |
| 390 | u64 pfn; | 397 | u64 pfn; |
| @@ -423,12 +430,16 @@ static inline int memory_fail_init(void) | |||
| 423 | * differentiation between which *physical* devices each | 430 | * differentiation between which *physical* devices each |
| 424 | * section belongs to... | 431 | * section belongs to... |
| 425 | */ | 432 | */ |
| 433 | int __weak arch_get_memory_phys_device(unsigned long start_pfn) | ||
| 434 | { | ||
| 435 | return 0; | ||
| 436 | } | ||
| 426 | 437 | ||
| 427 | static int add_memory_block(int nid, struct mem_section *section, | 438 | static int add_memory_block(int nid, struct mem_section *section, |
| 428 | unsigned long state, int phys_device, | 439 | unsigned long state, enum mem_add_context context) |
| 429 | enum mem_add_context context) | ||
| 430 | { | 440 | { |
| 431 | struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); | 441 | struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); |
| 442 | unsigned long start_pfn; | ||
| 432 | int ret = 0; | 443 | int ret = 0; |
| 433 | 444 | ||
| 434 | if (!mem) | 445 | if (!mem) |
| @@ -437,7 +448,8 @@ static int add_memory_block(int nid, struct mem_section *section, | |||
| 437 | mem->phys_index = __section_nr(section); | 448 | mem->phys_index = __section_nr(section); |
| 438 | mem->state = state; | 449 | mem->state = state; |
| 439 | mutex_init(&mem->state_mutex); | 450 | mutex_init(&mem->state_mutex); |
| 440 | mem->phys_device = phys_device; | 451 | start_pfn = section_nr_to_pfn(mem->phys_index); |
| 452 | mem->phys_device = arch_get_memory_phys_device(start_pfn); | ||
| 441 | 453 | ||
| 442 | ret = register_memory(mem, section); | 454 | ret = register_memory(mem, section); |
| 443 | if (!ret) | 455 | if (!ret) |
| @@ -509,7 +521,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, | |||
| 509 | */ | 521 | */ |
| 510 | int register_new_memory(int nid, struct mem_section *section) | 522 | int register_new_memory(int nid, struct mem_section *section) |
| 511 | { | 523 | { |
| 512 | return add_memory_block(nid, section, MEM_OFFLINE, 0, HOTPLUG); | 524 | return add_memory_block(nid, section, MEM_OFFLINE, HOTPLUG); |
| 513 | } | 525 | } |
| 514 | 526 | ||
| 515 | int unregister_memory_section(struct mem_section *section) | 527 | int unregister_memory_section(struct mem_section *section) |
| @@ -542,7 +554,7 @@ int __init memory_dev_init(void) | |||
| 542 | if (!present_section_nr(i)) | 554 | if (!present_section_nr(i)) |
| 543 | continue; | 555 | continue; |
| 544 | err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, | 556 | err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, |
| 545 | 0, BOOT); | 557 | BOOT); |
| 546 | if (!ret) | 558 | if (!ret) |
| 547 | ret = err; | 559 | ret = err; |
| 548 | } | 560 | } |
diff --git a/drivers/base/module.c b/drivers/base/module.c index 103be9cacb05..f32f2f9b7be5 100644 --- a/drivers/base/module.c +++ b/drivers/base/module.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <linux/device.h> | 7 | #include <linux/device.h> |
| 8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
| 9 | #include <linux/errno.h> | 9 | #include <linux/errno.h> |
| 10 | #include <linux/slab.h> | ||
| 10 | #include <linux/string.h> | 11 | #include <linux/string.h> |
| 11 | #include "base.h" | 12 | #include "base.h" |
| 12 | 13 | ||
diff --git a/drivers/base/node.c b/drivers/base/node.c index 70122791683d..057979a19eea 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
| @@ -15,9 +15,13 @@ | |||
| 15 | #include <linux/cpu.h> | 15 | #include <linux/cpu.h> |
| 16 | #include <linux/device.h> | 16 | #include <linux/device.h> |
| 17 | #include <linux/swap.h> | 17 | #include <linux/swap.h> |
| 18 | #include <linux/slab.h> | ||
| 19 | |||
| 20 | static struct sysdev_class_attribute *node_state_attrs[]; | ||
| 18 | 21 | ||
| 19 | static struct sysdev_class node_class = { | 22 | static struct sysdev_class node_class = { |
| 20 | .name = "node", | 23 | .name = "node", |
| 24 | .attrs = node_state_attrs, | ||
| 21 | }; | 25 | }; |
| 22 | 26 | ||
| 23 | 27 | ||
| @@ -162,8 +166,11 @@ static ssize_t node_read_distance(struct sys_device * dev, | |||
| 162 | int len = 0; | 166 | int len = 0; |
| 163 | int i; | 167 | int i; |
| 164 | 168 | ||
| 165 | /* buf currently PAGE_SIZE, need ~4 chars per node */ | 169 | /* |
| 166 | BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2); | 170 | * buf is currently PAGE_SIZE in length and each node needs 4 chars |
| 171 | * at the most (distance + space or newline). | ||
| 172 | */ | ||
| 173 | BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE); | ||
| 167 | 174 | ||
| 168 | for_each_online_node(i) | 175 | for_each_online_node(i) |
| 169 | len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i)); | 176 | len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i)); |
| @@ -544,76 +551,52 @@ static ssize_t print_nodes_state(enum node_states state, char *buf) | |||
| 544 | return n; | 551 | return n; |
| 545 | } | 552 | } |
| 546 | 553 | ||
| 547 | static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf) | 554 | struct node_attr { |
| 548 | { | 555 | struct sysdev_class_attribute attr; |
| 549 | return print_nodes_state(N_POSSIBLE, buf); | 556 | enum node_states state; |
| 550 | } | 557 | }; |
| 551 | |||
| 552 | static ssize_t print_nodes_online(struct sysdev_class *class, char *buf) | ||
| 553 | { | ||
| 554 | return print_nodes_state(N_ONLINE, buf); | ||
| 555 | } | ||
| 556 | |||
| 557 | static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class, | ||
| 558 | char *buf) | ||
| 559 | { | ||
| 560 | return print_nodes_state(N_NORMAL_MEMORY, buf); | ||
| 561 | } | ||
| 562 | 558 | ||
| 563 | static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf) | 559 | static ssize_t show_node_state(struct sysdev_class *class, |
| 560 | struct sysdev_class_attribute *attr, char *buf) | ||
| 564 | { | 561 | { |
| 565 | return print_nodes_state(N_CPU, buf); | 562 | struct node_attr *na = container_of(attr, struct node_attr, attr); |
| 563 | return print_nodes_state(na->state, buf); | ||
| 566 | } | 564 | } |
| 567 | 565 | ||
| 568 | static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL); | 566 | #define _NODE_ATTR(name, state) \ |
| 569 | static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL); | 567 | { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } |
| 570 | static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory, | ||
| 571 | NULL); | ||
| 572 | static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL); | ||
| 573 | 568 | ||
| 569 | static struct node_attr node_state_attr[] = { | ||
| 570 | _NODE_ATTR(possible, N_POSSIBLE), | ||
| 571 | _NODE_ATTR(online, N_ONLINE), | ||
| 572 | _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY), | ||
| 573 | _NODE_ATTR(has_cpu, N_CPU), | ||
| 574 | #ifdef CONFIG_HIGHMEM | 574 | #ifdef CONFIG_HIGHMEM |
| 575 | static ssize_t print_nodes_has_high_memory(struct sysdev_class *class, | 575 | _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), |
| 576 | char *buf) | ||
| 577 | { | ||
| 578 | return print_nodes_state(N_HIGH_MEMORY, buf); | ||
| 579 | } | ||
| 580 | |||
| 581 | static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory, | ||
| 582 | NULL); | ||
| 583 | #endif | 576 | #endif |
| 577 | }; | ||
| 584 | 578 | ||
| 585 | struct sysdev_class_attribute *node_state_attr[] = { | 579 | static struct sysdev_class_attribute *node_state_attrs[] = { |
| 586 | &attr_possible, | 580 | &node_state_attr[0].attr, |
| 587 | &attr_online, | 581 | &node_state_attr[1].attr, |
| 588 | &attr_has_normal_memory, | 582 | &node_state_attr[2].attr, |
| 583 | &node_state_attr[3].attr, | ||
| 589 | #ifdef CONFIG_HIGHMEM | 584 | #ifdef CONFIG_HIGHMEM |
| 590 | &attr_has_high_memory, | 585 | &node_state_attr[4].attr, |
| 591 | #endif | 586 | #endif |
| 592 | &attr_has_cpu, | 587 | NULL |
| 593 | }; | 588 | }; |
| 594 | 589 | ||
| 595 | static int node_states_init(void) | ||
| 596 | { | ||
| 597 | int i; | ||
| 598 | int err = 0; | ||
| 599 | |||
| 600 | for (i = 0; i < NR_NODE_STATES; i++) { | ||
| 601 | int ret; | ||
| 602 | ret = sysdev_class_create_file(&node_class, node_state_attr[i]); | ||
| 603 | if (!err) | ||
| 604 | err = ret; | ||
| 605 | } | ||
| 606 | return err; | ||
| 607 | } | ||
| 608 | |||
| 609 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ | 590 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ |
| 610 | static int __init register_node_type(void) | 591 | static int __init register_node_type(void) |
| 611 | { | 592 | { |
| 612 | int ret; | 593 | int ret; |
| 613 | 594 | ||
| 595 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); | ||
| 596 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); | ||
| 597 | |||
| 614 | ret = sysdev_class_register(&node_class); | 598 | ret = sysdev_class_register(&node_class); |
| 615 | if (!ret) { | 599 | if (!ret) { |
| 616 | ret = node_states_init(); | ||
| 617 | hotplug_memory_notifier(node_memory_callback, | 600 | hotplug_memory_notifier(node_memory_callback, |
| 618 | NODE_CALLBACK_PRI); | 601 | NODE_CALLBACK_PRI); |
| 619 | } | 602 | } |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 58efaf2f1259..4b4b565c835f 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
| @@ -128,7 +128,7 @@ struct platform_object { | |||
| 128 | }; | 128 | }; |
| 129 | 129 | ||
| 130 | /** | 130 | /** |
| 131 | * platform_device_put | 131 | * platform_device_put - destroy a platform device |
| 132 | * @pdev: platform device to free | 132 | * @pdev: platform device to free |
| 133 | * | 133 | * |
| 134 | * Free all memory associated with a platform device. This function must | 134 | * Free all memory associated with a platform device. This function must |
| @@ -152,7 +152,7 @@ static void platform_device_release(struct device *dev) | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | /** | 154 | /** |
| 155 | * platform_device_alloc | 155 | * platform_device_alloc - create a platform device |
| 156 | * @name: base name of the device we're adding | 156 | * @name: base name of the device we're adding |
| 157 | * @id: instance id | 157 | * @id: instance id |
| 158 | * | 158 | * |
| @@ -177,7 +177,7 @@ struct platform_device *platform_device_alloc(const char *name, int id) | |||
| 177 | EXPORT_SYMBOL_GPL(platform_device_alloc); | 177 | EXPORT_SYMBOL_GPL(platform_device_alloc); |
| 178 | 178 | ||
| 179 | /** | 179 | /** |
| 180 | * platform_device_add_resources | 180 | * platform_device_add_resources - add resources to a platform device |
| 181 | * @pdev: platform device allocated by platform_device_alloc to add resources to | 181 | * @pdev: platform device allocated by platform_device_alloc to add resources to |
| 182 | * @res: set of resources that needs to be allocated for the device | 182 | * @res: set of resources that needs to be allocated for the device |
| 183 | * @num: number of resources | 183 | * @num: number of resources |
| @@ -202,7 +202,7 @@ int platform_device_add_resources(struct platform_device *pdev, | |||
| 202 | EXPORT_SYMBOL_GPL(platform_device_add_resources); | 202 | EXPORT_SYMBOL_GPL(platform_device_add_resources); |
| 203 | 203 | ||
| 204 | /** | 204 | /** |
| 205 | * platform_device_add_data | 205 | * platform_device_add_data - add platform-specific data to a platform device |
| 206 | * @pdev: platform device allocated by platform_device_alloc to add resources to | 206 | * @pdev: platform device allocated by platform_device_alloc to add resources to |
| 207 | * @data: platform specific data for this platform device | 207 | * @data: platform specific data for this platform device |
| 208 | * @size: size of platform specific data | 208 | * @size: size of platform specific data |
| @@ -344,7 +344,7 @@ void platform_device_unregister(struct platform_device *pdev) | |||
| 344 | EXPORT_SYMBOL_GPL(platform_device_unregister); | 344 | EXPORT_SYMBOL_GPL(platform_device_unregister); |
| 345 | 345 | ||
| 346 | /** | 346 | /** |
| 347 | * platform_device_register_simple | 347 | * platform_device_register_simple - add a platform-level device and its resources |
| 348 | * @name: base name of the device we're adding | 348 | * @name: base name of the device we're adding |
| 349 | * @id: instance id | 349 | * @id: instance id |
| 350 | * @res: set of resources that needs to be allocated for the device | 350 | * @res: set of resources that needs to be allocated for the device |
| @@ -362,6 +362,8 @@ EXPORT_SYMBOL_GPL(platform_device_unregister); | |||
| 362 | * enumeration tasks, they don't fully conform to the Linux driver model. | 362 | * enumeration tasks, they don't fully conform to the Linux driver model. |
| 363 | * In particular, when such drivers are built as modules, they can't be | 363 | * In particular, when such drivers are built as modules, they can't be |
| 364 | * "hotplugged". | 364 | * "hotplugged". |
| 365 | * | ||
| 366 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | ||
| 365 | */ | 367 | */ |
| 366 | struct platform_device *platform_device_register_simple(const char *name, | 368 | struct platform_device *platform_device_register_simple(const char *name, |
| 367 | int id, | 369 | int id, |
| @@ -396,7 +398,7 @@ error: | |||
| 396 | EXPORT_SYMBOL_GPL(platform_device_register_simple); | 398 | EXPORT_SYMBOL_GPL(platform_device_register_simple); |
| 397 | 399 | ||
| 398 | /** | 400 | /** |
| 399 | * platform_device_register_data | 401 | * platform_device_register_data - add a platform-level device with platform-specific data |
| 400 | * @parent: parent device for the device we're adding | 402 | * @parent: parent device for the device we're adding |
| 401 | * @name: base name of the device we're adding | 403 | * @name: base name of the device we're adding |
| 402 | * @id: instance id | 404 | * @id: instance id |
| @@ -408,6 +410,8 @@ EXPORT_SYMBOL_GPL(platform_device_register_simple); | |||
| 408 | * allocated for the device allows drivers using such devices to be | 410 | * allocated for the device allows drivers using such devices to be |
| 409 | * unloaded without waiting for the last reference to the device to be | 411 | * unloaded without waiting for the last reference to the device to be |
| 410 | * dropped. | 412 | * dropped. |
| 413 | * | ||
| 414 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | ||
| 411 | */ | 415 | */ |
| 412 | struct platform_device *platform_device_register_data( | 416 | struct platform_device *platform_device_register_data( |
| 413 | struct device *parent, | 417 | struct device *parent, |
| @@ -473,7 +477,7 @@ static void platform_drv_shutdown(struct device *_dev) | |||
| 473 | } | 477 | } |
| 474 | 478 | ||
| 475 | /** | 479 | /** |
| 476 | * platform_driver_register | 480 | * platform_driver_register - register a driver for platform-level devices |
| 477 | * @drv: platform driver structure | 481 | * @drv: platform driver structure |
| 478 | */ | 482 | */ |
| 479 | int platform_driver_register(struct platform_driver *drv) | 483 | int platform_driver_register(struct platform_driver *drv) |
| @@ -491,7 +495,7 @@ int platform_driver_register(struct platform_driver *drv) | |||
| 491 | EXPORT_SYMBOL_GPL(platform_driver_register); | 495 | EXPORT_SYMBOL_GPL(platform_driver_register); |
| 492 | 496 | ||
| 493 | /** | 497 | /** |
| 494 | * platform_driver_unregister | 498 | * platform_driver_unregister - unregister a driver for platform-level devices |
| 495 | * @drv: platform driver structure | 499 | * @drv: platform driver structure |
| 496 | */ | 500 | */ |
| 497 | void platform_driver_unregister(struct platform_driver *drv) | 501 | void platform_driver_unregister(struct platform_driver *drv) |
| @@ -548,6 +552,66 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv, | |||
| 548 | } | 552 | } |
| 549 | EXPORT_SYMBOL_GPL(platform_driver_probe); | 553 | EXPORT_SYMBOL_GPL(platform_driver_probe); |
| 550 | 554 | ||
| 555 | /** | ||
| 556 | * platform_create_bundle - register driver and create corresponding device | ||
| 557 | * @driver: platform driver structure | ||
| 558 | * @probe: the driver probe routine, probably from an __init section | ||
| 559 | * @res: set of resources that needs to be allocated for the device | ||
| 560 | * @n_res: number of resources | ||
| 561 | * @data: platform specific data for this platform device | ||
| 562 | * @size: size of platform specific data | ||
| 563 | * | ||
| 564 | * Use this in legacy-style modules that probe hardware directly and | ||
| 565 | * register a single platform device and corresponding platform driver. | ||
| 566 | * | ||
| 567 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | ||
| 568 | */ | ||
| 569 | struct platform_device * __init_or_module platform_create_bundle( | ||
| 570 | struct platform_driver *driver, | ||
| 571 | int (*probe)(struct platform_device *), | ||
| 572 | struct resource *res, unsigned int n_res, | ||
| 573 | const void *data, size_t size) | ||
| 574 | { | ||
| 575 | struct platform_device *pdev; | ||
| 576 | int error; | ||
| 577 | |||
| 578 | pdev = platform_device_alloc(driver->driver.name, -1); | ||
| 579 | if (!pdev) { | ||
| 580 | error = -ENOMEM; | ||
| 581 | goto err_out; | ||
| 582 | } | ||
| 583 | |||
| 584 | if (res) { | ||
| 585 | error = platform_device_add_resources(pdev, res, n_res); | ||
| 586 | if (error) | ||
| 587 | goto err_pdev_put; | ||
| 588 | } | ||
| 589 | |||
| 590 | if (data) { | ||
| 591 | error = platform_device_add_data(pdev, data, size); | ||
| 592 | if (error) | ||
| 593 | goto err_pdev_put; | ||
| 594 | } | ||
| 595 | |||
| 596 | error = platform_device_add(pdev); | ||
| 597 | if (error) | ||
| 598 | goto err_pdev_put; | ||
| 599 | |||
| 600 | error = platform_driver_probe(driver, probe); | ||
| 601 | if (error) | ||
| 602 | goto err_pdev_del; | ||
| 603 | |||
| 604 | return pdev; | ||
| 605 | |||
| 606 | err_pdev_del: | ||
| 607 | platform_device_del(pdev); | ||
| 608 | err_pdev_put: | ||
| 609 | platform_device_put(pdev); | ||
| 610 | err_out: | ||
| 611 | return ERR_PTR(error); | ||
| 612 | } | ||
| 613 | EXPORT_SYMBOL_GPL(platform_create_bundle); | ||
| 614 | |||
| 551 | /* modalias support enables more hands-off userspace setup: | 615 | /* modalias support enables more hands-off userspace setup: |
| 552 | * (a) environment variable lets new-style hotplug events work once system is | 616 | * (a) environment variable lets new-style hotplug events work once system is |
| 553 | * fully running: "modprobe $MODALIAS" | 617 | * fully running: "modprobe $MODALIAS" |
| @@ -578,7 +642,7 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
| 578 | } | 642 | } |
| 579 | 643 | ||
| 580 | static const struct platform_device_id *platform_match_id( | 644 | static const struct platform_device_id *platform_match_id( |
| 581 | struct platform_device_id *id, | 645 | const struct platform_device_id *id, |
| 582 | struct platform_device *pdev) | 646 | struct platform_device *pdev) |
| 583 | { | 647 | { |
| 584 | while (id->name[0]) { | 648 | while (id->name[0]) { |
| @@ -994,9 +1058,11 @@ static __initdata LIST_HEAD(early_platform_driver_list); | |||
| 994 | static __initdata LIST_HEAD(early_platform_device_list); | 1058 | static __initdata LIST_HEAD(early_platform_device_list); |
| 995 | 1059 | ||
| 996 | /** | 1060 | /** |
| 997 | * early_platform_driver_register | 1061 | * early_platform_driver_register - register early platform driver |
| 998 | * @epdrv: early_platform driver structure | 1062 | * @epdrv: early_platform driver structure |
| 999 | * @buf: string passed from early_param() | 1063 | * @buf: string passed from early_param() |
| 1064 | * | ||
| 1065 | * Helper function for early_platform_init() / early_platform_init_buffer() | ||
| 1000 | */ | 1066 | */ |
| 1001 | int __init early_platform_driver_register(struct early_platform_driver *epdrv, | 1067 | int __init early_platform_driver_register(struct early_platform_driver *epdrv, |
| 1002 | char *buf) | 1068 | char *buf) |
| @@ -1048,9 +1114,12 @@ int __init early_platform_driver_register(struct early_platform_driver *epdrv, | |||
| 1048 | } | 1114 | } |
| 1049 | 1115 | ||
| 1050 | /** | 1116 | /** |
| 1051 | * early_platform_add_devices - add a numbers of early platform devices | 1117 | * early_platform_add_devices - adds a number of early platform devices |
| 1052 | * @devs: array of early platform devices to add | 1118 | * @devs: array of early platform devices to add |
| 1053 | * @num: number of early platform devices in array | 1119 | * @num: number of early platform devices in array |
| 1120 | * | ||
| 1121 | * Used by early architecture code to register early platform devices and | ||
| 1122 | * their platform data. | ||
| 1054 | */ | 1123 | */ |
| 1055 | void __init early_platform_add_devices(struct platform_device **devs, int num) | 1124 | void __init early_platform_add_devices(struct platform_device **devs, int num) |
| 1056 | { | 1125 | { |
| @@ -1070,8 +1139,12 @@ void __init early_platform_add_devices(struct platform_device **devs, int num) | |||
| 1070 | } | 1139 | } |
| 1071 | 1140 | ||
| 1072 | /** | 1141 | /** |
| 1073 | * early_platform_driver_register_all | 1142 | * early_platform_driver_register_all - register early platform drivers |
| 1074 | * @class_str: string to identify early platform driver class | 1143 | * @class_str: string to identify early platform driver class |
| 1144 | * | ||
| 1145 | * Used by architecture code to register all early platform drivers | ||
| 1146 | * for a certain class. If omitted then only early platform drivers | ||
| 1147 | * with matching kernel command line class parameters will be registered. | ||
| 1075 | */ | 1148 | */ |
| 1076 | void __init early_platform_driver_register_all(char *class_str) | 1149 | void __init early_platform_driver_register_all(char *class_str) |
| 1077 | { | 1150 | { |
| @@ -1093,7 +1166,7 @@ void __init early_platform_driver_register_all(char *class_str) | |||
| 1093 | } | 1166 | } |
| 1094 | 1167 | ||
| 1095 | /** | 1168 | /** |
| 1096 | * early_platform_match | 1169 | * early_platform_match - find early platform device matching driver |
| 1097 | * @epdrv: early platform driver structure | 1170 | * @epdrv: early platform driver structure |
| 1098 | * @id: id to match against | 1171 | * @id: id to match against |
| 1099 | */ | 1172 | */ |
| @@ -1111,7 +1184,7 @@ early_platform_match(struct early_platform_driver *epdrv, int id) | |||
| 1111 | } | 1184 | } |
| 1112 | 1185 | ||
| 1113 | /** | 1186 | /** |
| 1114 | * early_platform_left | 1187 | * early_platform_left - check if early platform driver has matching devices |
| 1115 | * @epdrv: early platform driver structure | 1188 | * @epdrv: early platform driver structure |
| 1116 | * @id: return true if id or above exists | 1189 | * @id: return true if id or above exists |
| 1117 | */ | 1190 | */ |
| @@ -1129,7 +1202,7 @@ static __init int early_platform_left(struct early_platform_driver *epdrv, | |||
| 1129 | } | 1202 | } |
| 1130 | 1203 | ||
| 1131 | /** | 1204 | /** |
| 1132 | * early_platform_driver_probe_id | 1205 | * early_platform_driver_probe_id - probe drivers matching class_str and id |
| 1133 | * @class_str: string to identify early platform driver class | 1206 | * @class_str: string to identify early platform driver class |
| 1134 | * @id: id to match against | 1207 | * @id: id to match against |
| 1135 | * @nr_probe: number of platform devices to successfully probe before exiting | 1208 | * @nr_probe: number of platform devices to successfully probe before exiting |
| @@ -1199,10 +1272,14 @@ static int __init early_platform_driver_probe_id(char *class_str, | |||
| 1199 | } | 1272 | } |
| 1200 | 1273 | ||
| 1201 | /** | 1274 | /** |
| 1202 | * early_platform_driver_probe | 1275 | * early_platform_driver_probe - probe a class of registered drivers |
| 1203 | * @class_str: string to identify early platform driver class | 1276 | * @class_str: string to identify early platform driver class |
| 1204 | * @nr_probe: number of platform devices to successfully probe before exiting | 1277 | * @nr_probe: number of platform devices to successfully probe before exiting |
| 1205 | * @user_only: only probe user specified early platform devices | 1278 | * @user_only: only probe user specified early platform devices |
| 1279 | * | ||
| 1280 | * Used by architecture code to probe registered early platform drivers | ||
| 1281 | * within a certain class. For probe to happen a registered early platform | ||
| 1282 | * device matching a registered early platform driver is needed. | ||
| 1206 | */ | 1283 | */ |
| 1207 | int __init early_platform_driver_probe(char *class_str, | 1284 | int __init early_platform_driver_probe(char *class_str, |
| 1208 | int nr_probe, | 1285 | int nr_probe, |
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 3ce3519e8f30..89de75325cea 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | obj-$(CONFIG_PM) += sysfs.o | 1 | obj-$(CONFIG_PM) += sysfs.o |
| 2 | obj-$(CONFIG_PM_SLEEP) += main.o | 2 | obj-$(CONFIG_PM_SLEEP) += main.o |
| 3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o | 3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o |
| 4 | obj-$(CONFIG_PM_OPS) += generic_ops.o | ||
| 4 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o | 5 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o |
| 5 | 6 | ||
| 6 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG | 7 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG |
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c new file mode 100644 index 000000000000..4b29d4981253 --- /dev/null +++ b/drivers/base/power/generic_ops.c | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | /* | ||
| 2 | * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems | ||
| 3 | * | ||
| 4 | * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | ||
| 5 | * | ||
| 6 | * This file is released under the GPLv2. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/pm.h> | ||
| 10 | #include <linux/pm_runtime.h> | ||
| 11 | |||
| 12 | #ifdef CONFIG_PM_RUNTIME | ||
| 13 | /** | ||
| 14 | * pm_generic_runtime_idle - Generic runtime idle callback for subsystems. | ||
| 15 | * @dev: Device to handle. | ||
| 16 | * | ||
| 17 | * If PM operations are defined for the @dev's driver and they include | ||
| 18 | * ->runtime_idle(), execute it and return its error code, if nonzero. | ||
| 19 | * Otherwise, execute pm_runtime_suspend() for the device and return 0. | ||
| 20 | */ | ||
| 21 | int pm_generic_runtime_idle(struct device *dev) | ||
| 22 | { | ||
| 23 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 24 | |||
| 25 | if (pm && pm->runtime_idle) { | ||
| 26 | int ret = pm->runtime_idle(dev); | ||
| 27 | if (ret) | ||
| 28 | return ret; | ||
| 29 | } | ||
| 30 | |||
| 31 | pm_runtime_suspend(dev); | ||
| 32 | return 0; | ||
| 33 | } | ||
| 34 | EXPORT_SYMBOL_GPL(pm_generic_runtime_idle); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems. | ||
| 38 | * @dev: Device to suspend. | ||
| 39 | * | ||
| 40 | * If PM operations are defined for the @dev's driver and they include | ||
| 41 | * ->runtime_suspend(), execute it and return its error code. Otherwise, | ||
| 42 | * return -EINVAL. | ||
| 43 | */ | ||
| 44 | int pm_generic_runtime_suspend(struct device *dev) | ||
| 45 | { | ||
| 46 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 47 | int ret; | ||
| 48 | |||
| 49 | ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : -EINVAL; | ||
| 50 | |||
| 51 | return ret; | ||
| 52 | } | ||
| 53 | EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * pm_generic_runtime_resume - Generic runtime resume callback for subsystems. | ||
| 57 | * @dev: Device to resume. | ||
| 58 | * | ||
| 59 | * If PM operations are defined for the @dev's driver and they include | ||
| 60 | * ->runtime_resume(), execute it and return its error code. Otherwise, | ||
| 61 | * return -EINVAL. | ||
| 62 | */ | ||
| 63 | int pm_generic_runtime_resume(struct device *dev) | ||
| 64 | { | ||
| 65 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 66 | int ret; | ||
| 67 | |||
| 68 | ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : -EINVAL; | ||
| 69 | |||
| 70 | return ret; | ||
| 71 | } | ||
| 72 | EXPORT_SYMBOL_GPL(pm_generic_runtime_resume); | ||
| 73 | #endif /* CONFIG_PM_RUNTIME */ | ||
| 74 | |||
| 75 | #ifdef CONFIG_PM_SLEEP | ||
| 76 | /** | ||
| 77 | * __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. | ||
| 78 | * @dev: Device to handle. | ||
| 79 | * @event: PM transition of the system under way. | ||
| 80 | * | ||
| 81 | * If the device has not been suspended at run time, execute the | ||
| 82 | * suspend/freeze/poweroff/thaw callback provided by its driver, if defined, and | ||
| 83 | * return its error code. Otherwise, return zero. | ||
| 84 | */ | ||
| 85 | static int __pm_generic_call(struct device *dev, int event) | ||
| 86 | { | ||
| 87 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 88 | int (*callback)(struct device *); | ||
| 89 | |||
| 90 | if (!pm || pm_runtime_suspended(dev)) | ||
| 91 | return 0; | ||
| 92 | |||
| 93 | switch (event) { | ||
| 94 | case PM_EVENT_SUSPEND: | ||
| 95 | callback = pm->suspend; | ||
| 96 | break; | ||
| 97 | case PM_EVENT_FREEZE: | ||
| 98 | callback = pm->freeze; | ||
| 99 | break; | ||
| 100 | case PM_EVENT_HIBERNATE: | ||
| 101 | callback = pm->poweroff; | ||
| 102 | break; | ||
| 103 | case PM_EVENT_THAW: | ||
| 104 | callback = pm->thaw; | ||
| 105 | break; | ||
| 106 | default: | ||
| 107 | callback = NULL; | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | |||
| 111 | return callback ? callback(dev) : 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 115 | * pm_generic_suspend - Generic suspend callback for subsystems. | ||
| 116 | * @dev: Device to suspend. | ||
| 117 | */ | ||
| 118 | int pm_generic_suspend(struct device *dev) | ||
| 119 | { | ||
| 120 | return __pm_generic_call(dev, PM_EVENT_SUSPEND); | ||
| 121 | } | ||
| 122 | EXPORT_SYMBOL_GPL(pm_generic_suspend); | ||
| 123 | |||
| 124 | /** | ||
| 125 | * pm_generic_freeze - Generic freeze callback for subsystems. | ||
| 126 | * @dev: Device to freeze. | ||
| 127 | */ | ||
| 128 | int pm_generic_freeze(struct device *dev) | ||
| 129 | { | ||
| 130 | return __pm_generic_call(dev, PM_EVENT_FREEZE); | ||
| 131 | } | ||
| 132 | EXPORT_SYMBOL_GPL(pm_generic_freeze); | ||
| 133 | |||
| 134 | /** | ||
| 135 | * pm_generic_poweroff - Generic poweroff callback for subsystems. | ||
| 136 | * @dev: Device to handle. | ||
| 137 | */ | ||
| 138 | int pm_generic_poweroff(struct device *dev) | ||
| 139 | { | ||
| 140 | return __pm_generic_call(dev, PM_EVENT_HIBERNATE); | ||
| 141 | } | ||
| 142 | EXPORT_SYMBOL_GPL(pm_generic_poweroff); | ||
| 143 | |||
| 144 | /** | ||
| 145 | * pm_generic_thaw - Generic thaw callback for subsystems. | ||
| 146 | * @dev: Device to thaw. | ||
| 147 | */ | ||
| 148 | int pm_generic_thaw(struct device *dev) | ||
| 149 | { | ||
| 150 | return __pm_generic_call(dev, PM_EVENT_THAW); | ||
| 151 | } | ||
| 152 | EXPORT_SYMBOL_GPL(pm_generic_thaw); | ||
| 153 | |||
| 154 | /** | ||
| 155 | * __pm_generic_resume - Generic resume/restore callback for subsystems. | ||
| 156 | * @dev: Device to handle. | ||
| 157 | * @event: PM transition of the system under way. | ||
| 158 | * | ||
| 159 | * Execute the resume/resotre callback provided by the @dev's driver, if | ||
| 160 | * defined. If it returns 0, change the device's runtime PM status to 'active'. | ||
| 161 | * Return the callback's error code. | ||
| 162 | */ | ||
| 163 | static int __pm_generic_resume(struct device *dev, int event) | ||
| 164 | { | ||
| 165 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 166 | int (*callback)(struct device *); | ||
| 167 | int ret; | ||
| 168 | |||
| 169 | if (!pm) | ||
| 170 | return 0; | ||
| 171 | |||
| 172 | switch (event) { | ||
| 173 | case PM_EVENT_RESUME: | ||
| 174 | callback = pm->resume; | ||
| 175 | break; | ||
| 176 | case PM_EVENT_RESTORE: | ||
| 177 | callback = pm->restore; | ||
| 178 | break; | ||
| 179 | default: | ||
| 180 | callback = NULL; | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | |||
| 184 | if (!callback) | ||
| 185 | return 0; | ||
| 186 | |||
| 187 | ret = callback(dev); | ||
| 188 | if (!ret) { | ||
| 189 | pm_runtime_disable(dev); | ||
| 190 | pm_runtime_set_active(dev); | ||
| 191 | pm_runtime_enable(dev); | ||
| 192 | } | ||
| 193 | |||
| 194 | return ret; | ||
| 195 | } | ||
| 196 | |||
| 197 | /** | ||
| 198 | * pm_generic_resume - Generic resume callback for subsystems. | ||
| 199 | * @dev: Device to resume. | ||
| 200 | */ | ||
| 201 | int pm_generic_resume(struct device *dev) | ||
| 202 | { | ||
| 203 | return __pm_generic_resume(dev, PM_EVENT_RESUME); | ||
| 204 | } | ||
| 205 | EXPORT_SYMBOL_GPL(pm_generic_resume); | ||
| 206 | |||
| 207 | /** | ||
| 208 | * pm_generic_restore - Generic restore callback for subsystems. | ||
| 209 | * @dev: Device to restore. | ||
| 210 | */ | ||
| 211 | int pm_generic_restore(struct device *dev) | ||
| 212 | { | ||
| 213 | return __pm_generic_resume(dev, PM_EVENT_RESTORE); | ||
| 214 | } | ||
| 215 | EXPORT_SYMBOL_GPL(pm_generic_restore); | ||
| 216 | #endif /* CONFIG_PM_SLEEP */ | ||
| 217 | |||
| 218 | struct dev_pm_ops generic_subsys_pm_ops = { | ||
| 219 | #ifdef CONFIG_PM_SLEEP | ||
| 220 | .suspend = pm_generic_suspend, | ||
| 221 | .resume = pm_generic_resume, | ||
| 222 | .freeze = pm_generic_freeze, | ||
| 223 | .thaw = pm_generic_thaw, | ||
| 224 | .poweroff = pm_generic_poweroff, | ||
| 225 | .restore = pm_generic_restore, | ||
| 226 | #endif | ||
| 227 | #ifdef CONFIG_PM_RUNTIME | ||
| 228 | .runtime_suspend = pm_generic_runtime_suspend, | ||
| 229 | .runtime_resume = pm_generic_runtime_resume, | ||
| 230 | .runtime_idle = pm_generic_runtime_idle, | ||
| 231 | #endif | ||
| 232 | }; | ||
| 233 | EXPORT_SYMBOL_GPL(generic_subsys_pm_ops); | ||
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 0e26a6f6fd48..941fcb87e52a 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
| @@ -35,8 +35,8 @@ | |||
| 35 | * because children are guaranteed to be discovered after parents, and | 35 | * because children are guaranteed to be discovered after parents, and |
| 36 | * are inserted at the back of the list on discovery. | 36 | * are inserted at the back of the list on discovery. |
| 37 | * | 37 | * |
| 38 | * Since device_pm_add() may be called with a device semaphore held, | 38 | * Since device_pm_add() may be called with a device lock held, |
| 39 | * we must never try to acquire a device semaphore while holding | 39 | * we must never try to acquire a device lock while holding |
| 40 | * dpm_list_mutex. | 40 | * dpm_list_mutex. |
| 41 | */ | 41 | */ |
| 42 | 42 | ||
| @@ -439,8 +439,23 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) | |||
| 439 | if (dev->bus && dev->bus->pm) { | 439 | if (dev->bus && dev->bus->pm) { |
| 440 | pm_dev_dbg(dev, state, "EARLY "); | 440 | pm_dev_dbg(dev, state, "EARLY "); |
| 441 | error = pm_noirq_op(dev, dev->bus->pm, state); | 441 | error = pm_noirq_op(dev, dev->bus->pm, state); |
| 442 | if (error) | ||
| 443 | goto End; | ||
| 442 | } | 444 | } |
| 443 | 445 | ||
| 446 | if (dev->type && dev->type->pm) { | ||
| 447 | pm_dev_dbg(dev, state, "EARLY type "); | ||
| 448 | error = pm_noirq_op(dev, dev->type->pm, state); | ||
| 449 | if (error) | ||
| 450 | goto End; | ||
| 451 | } | ||
| 452 | |||
| 453 | if (dev->class && dev->class->pm) { | ||
| 454 | pm_dev_dbg(dev, state, "EARLY class "); | ||
| 455 | error = pm_noirq_op(dev, dev->class->pm, state); | ||
| 456 | } | ||
| 457 | |||
| 458 | End: | ||
| 444 | TRACE_RESUME(error); | 459 | TRACE_RESUME(error); |
| 445 | return error; | 460 | return error; |
| 446 | } | 461 | } |
| @@ -508,7 +523,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
| 508 | TRACE_RESUME(0); | 523 | TRACE_RESUME(0); |
| 509 | 524 | ||
| 510 | dpm_wait(dev->parent, async); | 525 | dpm_wait(dev->parent, async); |
| 511 | down(&dev->sem); | 526 | device_lock(dev); |
| 512 | 527 | ||
| 513 | dev->power.status = DPM_RESUMING; | 528 | dev->power.status = DPM_RESUMING; |
| 514 | 529 | ||
| @@ -543,7 +558,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
| 543 | } | 558 | } |
| 544 | } | 559 | } |
| 545 | End: | 560 | End: |
| 546 | up(&dev->sem); | 561 | device_unlock(dev); |
| 547 | complete_all(&dev->power.completion); | 562 | complete_all(&dev->power.completion); |
| 548 | 563 | ||
| 549 | TRACE_RESUME(error); | 564 | TRACE_RESUME(error); |
| @@ -629,7 +644,7 @@ static void dpm_resume(pm_message_t state) | |||
| 629 | */ | 644 | */ |
| 630 | static void device_complete(struct device *dev, pm_message_t state) | 645 | static void device_complete(struct device *dev, pm_message_t state) |
| 631 | { | 646 | { |
| 632 | down(&dev->sem); | 647 | device_lock(dev); |
| 633 | 648 | ||
| 634 | if (dev->class && dev->class->pm && dev->class->pm->complete) { | 649 | if (dev->class && dev->class->pm && dev->class->pm->complete) { |
| 635 | pm_dev_dbg(dev, state, "completing class "); | 650 | pm_dev_dbg(dev, state, "completing class "); |
| @@ -646,7 +661,7 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
| 646 | dev->bus->pm->complete(dev); | 661 | dev->bus->pm->complete(dev); |
| 647 | } | 662 | } |
| 648 | 663 | ||
| 649 | up(&dev->sem); | 664 | device_unlock(dev); |
| 650 | } | 665 | } |
| 651 | 666 | ||
| 652 | /** | 667 | /** |
| @@ -735,10 +750,26 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
| 735 | { | 750 | { |
| 736 | int error = 0; | 751 | int error = 0; |
| 737 | 752 | ||
| 753 | if (dev->class && dev->class->pm) { | ||
| 754 | pm_dev_dbg(dev, state, "LATE class "); | ||
| 755 | error = pm_noirq_op(dev, dev->class->pm, state); | ||
| 756 | if (error) | ||
| 757 | goto End; | ||
| 758 | } | ||
| 759 | |||
| 760 | if (dev->type && dev->type->pm) { | ||
| 761 | pm_dev_dbg(dev, state, "LATE type "); | ||
| 762 | error = pm_noirq_op(dev, dev->type->pm, state); | ||
| 763 | if (error) | ||
| 764 | goto End; | ||
| 765 | } | ||
| 766 | |||
| 738 | if (dev->bus && dev->bus->pm) { | 767 | if (dev->bus && dev->bus->pm) { |
| 739 | pm_dev_dbg(dev, state, "LATE "); | 768 | pm_dev_dbg(dev, state, "LATE "); |
| 740 | error = pm_noirq_op(dev, dev->bus->pm, state); | 769 | error = pm_noirq_op(dev, dev->bus->pm, state); |
| 741 | } | 770 | } |
| 771 | |||
| 772 | End: | ||
| 742 | return error; | 773 | return error; |
| 743 | } | 774 | } |
| 744 | 775 | ||
| @@ -809,7 +840,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
| 809 | int error = 0; | 840 | int error = 0; |
| 810 | 841 | ||
| 811 | dpm_wait_for_children(dev, async); | 842 | dpm_wait_for_children(dev, async); |
| 812 | down(&dev->sem); | 843 | device_lock(dev); |
| 813 | 844 | ||
| 814 | if (async_error) | 845 | if (async_error) |
| 815 | goto End; | 846 | goto End; |
| @@ -849,7 +880,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
| 849 | dev->power.status = DPM_OFF; | 880 | dev->power.status = DPM_OFF; |
| 850 | 881 | ||
| 851 | End: | 882 | End: |
| 852 | up(&dev->sem); | 883 | device_unlock(dev); |
| 853 | complete_all(&dev->power.completion); | 884 | complete_all(&dev->power.completion); |
| 854 | 885 | ||
| 855 | return error; | 886 | return error; |
| @@ -938,7 +969,7 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
| 938 | { | 969 | { |
| 939 | int error = 0; | 970 | int error = 0; |
| 940 | 971 | ||
| 941 | down(&dev->sem); | 972 | device_lock(dev); |
| 942 | 973 | ||
| 943 | if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) { | 974 | if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) { |
| 944 | pm_dev_dbg(dev, state, "preparing "); | 975 | pm_dev_dbg(dev, state, "preparing "); |
| @@ -962,7 +993,7 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
| 962 | suspend_report_result(dev->class->pm->prepare, error); | 993 | suspend_report_result(dev->class->pm->prepare, error); |
| 963 | } | 994 | } |
| 964 | End: | 995 | End: |
| 965 | up(&dev->sem); | 996 | device_unlock(dev); |
| 966 | 997 | ||
| 967 | return error; | 998 | return error; |
| 968 | } | 999 | } |
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 0d903909af7e..9354dc10a363 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
| 20 | #include <linux/slab.h> | ||
| 21 | #include <linux/string.h> | 20 | #include <linux/string.h> |
| 22 | #include <linux/pm.h> | 21 | #include <linux/pm.h> |
| 23 | #include <linux/device.h> | 22 | #include <linux/device.h> |
| @@ -54,7 +53,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr, | |||
| 54 | return -EIO; | 53 | return -EIO; |
| 55 | } | 54 | } |
| 56 | 55 | ||
| 57 | static struct sysfs_ops sysfs_ops = { | 56 | static const struct sysfs_ops sysfs_ops = { |
| 58 | .show = sysdev_show, | 57 | .show = sysdev_show, |
| 59 | .store = sysdev_store, | 58 | .store = sysdev_store, |
| 60 | }; | 59 | }; |
| @@ -89,7 +88,7 @@ static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, | |||
| 89 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); | 88 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); |
| 90 | 89 | ||
| 91 | if (class_attr->show) | 90 | if (class_attr->show) |
| 92 | return class_attr->show(class, buffer); | 91 | return class_attr->show(class, class_attr, buffer); |
| 93 | return -EIO; | 92 | return -EIO; |
| 94 | } | 93 | } |
| 95 | 94 | ||
| @@ -100,11 +99,11 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr, | |||
| 100 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); | 99 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); |
| 101 | 100 | ||
| 102 | if (class_attr->store) | 101 | if (class_attr->store) |
| 103 | return class_attr->store(class, buffer, count); | 102 | return class_attr->store(class, class_attr, buffer, count); |
| 104 | return -EIO; | 103 | return -EIO; |
| 105 | } | 104 | } |
| 106 | 105 | ||
| 107 | static struct sysfs_ops sysfs_class_ops = { | 106 | static const struct sysfs_ops sysfs_class_ops = { |
| 108 | .show = sysdev_class_show, | 107 | .show = sysdev_class_show, |
| 109 | .store = sysdev_class_store, | 108 | .store = sysdev_class_store, |
| 110 | }; | 109 | }; |
| @@ -145,13 +144,20 @@ int sysdev_class_register(struct sysdev_class *cls) | |||
| 145 | if (retval) | 144 | if (retval) |
| 146 | return retval; | 145 | return retval; |
| 147 | 146 | ||
| 148 | return kset_register(&cls->kset); | 147 | retval = kset_register(&cls->kset); |
| 148 | if (!retval && cls->attrs) | ||
| 149 | retval = sysfs_create_files(&cls->kset.kobj, | ||
| 150 | (const struct attribute **)cls->attrs); | ||
| 151 | return retval; | ||
| 149 | } | 152 | } |
| 150 | 153 | ||
| 151 | void sysdev_class_unregister(struct sysdev_class *cls) | 154 | void sysdev_class_unregister(struct sysdev_class *cls) |
| 152 | { | 155 | { |
| 153 | pr_debug("Unregistering sysdev class '%s'\n", | 156 | pr_debug("Unregistering sysdev class '%s'\n", |
| 154 | kobject_name(&cls->kset.kobj)); | 157 | kobject_name(&cls->kset.kobj)); |
| 158 | if (cls->attrs) | ||
| 159 | sysfs_remove_files(&cls->kset.kobj, | ||
| 160 | (const struct attribute **)cls->attrs); | ||
| 155 | kset_unregister(&cls->kset); | 161 | kset_unregister(&cls->kset); |
| 156 | } | 162 | } |
| 157 | 163 | ||
