aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/Kconfig2
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/attribute_container.c2
-rw-r--r--drivers/base/bus.c12
-rw-r--r--drivers/base/core.c152
-rw-r--r--drivers/base/cpu.c46
-rw-r--r--drivers/base/dd.c13
-rw-r--r--drivers/base/firmware_class.c8
-rw-r--r--drivers/base/iommu.c100
-rw-r--r--drivers/base/isa.c7
-rw-r--r--drivers/base/memory.c19
-rw-r--r--drivers/base/node.c107
-rw-r--r--drivers/base/platform.c130
-rw-r--r--drivers/base/power/main.c21
-rw-r--r--drivers/base/power/trace.c4
-rw-r--r--drivers/base/topology.c5
16 files changed, 488 insertions, 141 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d8e8c49c0cbd..8f006f96ff53 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -54,7 +54,7 @@ config FIRMWARE_IN_KERNEL
54 such firmware, and do not wish to use an initrd. 54 such firmware, and do not wish to use an initrd.
55 55
56 This single option controls the inclusion of firmware for 56 This single option controls the inclusion of firmware for
57 every driver which uses request_firmare() and ships its 57 every driver which uses request_firmware() and ships its
58 firmware in the kernel source tree, to avoid a proliferation 58 firmware in the kernel source tree, to avoid a proliferation
59 of 'Include firmware for xxx device' options. 59 of 'Include firmware for xxx device' options.
60 60
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index c66637392bbc..b5b8ba512b28 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o
11obj-$(CONFIG_NUMA) += node.o 11obj-$(CONFIG_NUMA) += node.o
12obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o 12obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o
13obj-$(CONFIG_SMP) += topology.o 13obj-$(CONFIG_SMP) += topology.o
14obj-$(CONFIG_IOMMU_API) += iommu.o
14ifeq ($(CONFIG_SYSFS),y) 15ifeq ($(CONFIG_SYSFS),y)
15obj-$(CONFIG_MODULES) += module.o 16obj-$(CONFIG_MODULES) += module.o
16endif 17endif
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index f57652db0a2a..b9cda053d3c0 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
167 ic->classdev.parent = get_device(dev); 167 ic->classdev.parent = get_device(dev);
168 ic->classdev.class = cont->class; 168 ic->classdev.class = cont->class;
169 cont->class->dev_release = attribute_container_release; 169 cont->class->dev_release = attribute_container_release;
170 strcpy(ic->classdev.bus_id, dev->bus_id); 170 dev_set_name(&ic->classdev, dev_name(dev));
171 if (fn) 171 if (fn)
172 fn(cont, dev, &ic->classdev); 172 fn(cont, dev, &ic->classdev);
173 else 173 else
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 5aee1c0169ea..83f32b891fa9 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -333,7 +333,7 @@ static int match_name(struct device *dev, void *data)
333{ 333{
334 const char *name = data; 334 const char *name = data;
335 335
336 return sysfs_streq(name, dev->bus_id); 336 return sysfs_streq(name, dev_name(dev));
337} 337}
338 338
339/** 339/**
@@ -461,12 +461,12 @@ int bus_add_device(struct device *dev)
461 int error = 0; 461 int error = 0;
462 462
463 if (bus) { 463 if (bus) {
464 pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id); 464 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev));
465 error = device_add_attrs(bus, dev); 465 error = device_add_attrs(bus, dev);
466 if (error) 466 if (error)
467 goto out_put; 467 goto out_put;
468 error = sysfs_create_link(&bus->p->devices_kset->kobj, 468 error = sysfs_create_link(&bus->p->devices_kset->kobj,
469 &dev->kobj, dev->bus_id); 469 &dev->kobj, dev_name(dev));
470 if (error) 470 if (error)
471 goto out_id; 471 goto out_id;
472 error = sysfs_create_link(&dev->kobj, 472 error = sysfs_create_link(&dev->kobj,
@@ -482,7 +482,7 @@ int bus_add_device(struct device *dev)
482out_deprecated: 482out_deprecated:
483 sysfs_remove_link(&dev->kobj, "subsystem"); 483 sysfs_remove_link(&dev->kobj, "subsystem");
484out_subsys: 484out_subsys:
485 sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id); 485 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev));
486out_id: 486out_id:
487 device_remove_attrs(bus, dev); 487 device_remove_attrs(bus, dev);
488out_put: 488out_put:
@@ -526,13 +526,13 @@ void bus_remove_device(struct device *dev)
526 sysfs_remove_link(&dev->kobj, "subsystem"); 526 sysfs_remove_link(&dev->kobj, "subsystem");
527 remove_deprecated_bus_links(dev); 527 remove_deprecated_bus_links(dev);
528 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 528 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
529 dev->bus_id); 529 dev_name(dev));
530 device_remove_attrs(dev->bus, dev); 530 device_remove_attrs(dev->bus, dev);
531 if (klist_node_attached(&dev->knode_bus)) 531 if (klist_node_attached(&dev->knode_bus))
532 klist_del(&dev->knode_bus); 532 klist_del(&dev->knode_bus);
533 533
534 pr_debug("bus: '%s': remove device %s\n", 534 pr_debug("bus: '%s': remove device %s\n",
535 dev->bus->name, dev->bus_id); 535 dev->bus->name, dev_name(dev));
536 device_release_driver(dev); 536 device_release_driver(dev);
537 bus_put(dev->bus); 537 bus_put(dev->bus);
538 } 538 }
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8c2cc2648f5a..8079afca4972 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -119,7 +119,7 @@ static void device_release(struct kobject *kobj)
119 else 119 else
120 WARN(1, KERN_ERR "Device '%s' does not have a release() " 120 WARN(1, KERN_ERR "Device '%s' does not have a release() "
121 "function, it is broken and must be fixed.\n", 121 "function, it is broken and must be fixed.\n",
122 dev->bus_id); 122 dev_name(dev));
123} 123}
124 124
125static struct kobj_type device_ktype = { 125static struct kobj_type device_ktype = {
@@ -209,7 +209,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
209 retval = dev->bus->uevent(dev, env); 209 retval = dev->bus->uevent(dev, env);
210 if (retval) 210 if (retval)
211 pr_debug("device: '%s': %s: bus uevent() returned %d\n", 211 pr_debug("device: '%s': %s: bus uevent() returned %d\n",
212 dev->bus_id, __func__, retval); 212 dev_name(dev), __func__, retval);
213 } 213 }
214 214
215 /* have the class specific function add its stuff */ 215 /* have the class specific function add its stuff */
@@ -217,7 +217,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
217 retval = dev->class->dev_uevent(dev, env); 217 retval = dev->class->dev_uevent(dev, env);
218 if (retval) 218 if (retval)
219 pr_debug("device: '%s': %s: class uevent() " 219 pr_debug("device: '%s': %s: class uevent() "
220 "returned %d\n", dev->bus_id, 220 "returned %d\n", dev_name(dev),
221 __func__, retval); 221 __func__, retval);
222 } 222 }
223 223
@@ -226,7 +226,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
226 retval = dev->type->uevent(dev, env); 226 retval = dev->type->uevent(dev, env);
227 if (retval) 227 if (retval)
228 pr_debug("device: '%s': %s: dev_type uevent() " 228 pr_debug("device: '%s': %s: dev_type uevent() "
229 "returned %d\n", dev->bus_id, 229 "returned %d\n", dev_name(dev),
230 __func__, retval); 230 __func__, retval);
231 } 231 }
232 232
@@ -672,7 +672,7 @@ static int device_add_class_symlinks(struct device *dev)
672 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 672 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
673 device_is_not_partition(dev)) { 673 device_is_not_partition(dev)) {
674 error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 674 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
675 &dev->kobj, dev->bus_id); 675 &dev->kobj, dev_name(dev));
676 if (error) 676 if (error)
677 goto out_subsys; 677 goto out_subsys;
678 } 678 }
@@ -712,11 +712,11 @@ out_busid:
712 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 712 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
713 device_is_not_partition(dev)) 713 device_is_not_partition(dev))
714 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 714 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
715 dev->bus_id); 715 dev_name(dev));
716#else 716#else
717 /* link in the class directory pointing to the device */ 717 /* link in the class directory pointing to the device */
718 error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 718 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
719 &dev->kobj, dev->bus_id); 719 &dev->kobj, dev_name(dev));
720 if (error) 720 if (error)
721 goto out_subsys; 721 goto out_subsys;
722 722
@@ -729,7 +729,7 @@ out_busid:
729 return 0; 729 return 0;
730 730
731out_busid: 731out_busid:
732 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id); 732 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
733#endif 733#endif
734 734
735out_subsys: 735out_subsys:
@@ -758,12 +758,12 @@ static void device_remove_class_symlinks(struct device *dev)
758 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 758 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
759 device_is_not_partition(dev)) 759 device_is_not_partition(dev))
760 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 760 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
761 dev->bus_id); 761 dev_name(dev));
762#else 762#else
763 if (dev->parent && device_is_not_partition(dev)) 763 if (dev->parent && device_is_not_partition(dev))
764 sysfs_remove_link(&dev->kobj, "device"); 764 sysfs_remove_link(&dev->kobj, "device");
765 765
766 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id); 766 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
767#endif 767#endif
768 768
769 sysfs_remove_link(&dev->kobj, "subsystem"); 769 sysfs_remove_link(&dev->kobj, "subsystem");
@@ -866,7 +866,7 @@ int device_add(struct device *dev)
866 if (!strlen(dev->bus_id)) 866 if (!strlen(dev->bus_id))
867 goto done; 867 goto done;
868 868
869 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 869 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
870 870
871 parent = get_device(dev->parent); 871 parent = get_device(dev->parent);
872 setup_parent(dev, parent); 872 setup_parent(dev, parent);
@@ -876,7 +876,7 @@ int device_add(struct device *dev)
876 set_dev_node(dev, dev_to_node(parent)); 876 set_dev_node(dev, dev_to_node(parent));
877 877
878 /* first, register with generic layer. */ 878 /* first, register with generic layer. */
879 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); 879 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev_name(dev));
880 if (error) 880 if (error)
881 goto Error; 881 goto Error;
882 882
@@ -884,11 +884,6 @@ int device_add(struct device *dev)
884 if (platform_notify) 884 if (platform_notify)
885 platform_notify(dev); 885 platform_notify(dev);
886 886
887 /* notify clients of device entry (new way) */
888 if (dev->bus)
889 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
890 BUS_NOTIFY_ADD_DEVICE, dev);
891
892 error = device_create_file(dev, &uevent_attr); 887 error = device_create_file(dev, &uevent_attr);
893 if (error) 888 if (error)
894 goto attrError; 889 goto attrError;
@@ -916,6 +911,14 @@ int device_add(struct device *dev)
916 if (error) 911 if (error)
917 goto DPMError; 912 goto DPMError;
918 device_pm_add(dev); 913 device_pm_add(dev);
914
915 /* Notify clients of device addition. This call must come
916 * after dpm_sysf_add() and before kobject_uevent().
917 */
918 if (dev->bus)
919 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
920 BUS_NOTIFY_ADD_DEVICE, dev);
921
919 kobject_uevent(&dev->kobj, KOBJ_ADD); 922 kobject_uevent(&dev->kobj, KOBJ_ADD);
920 bus_attach_device(dev); 923 bus_attach_device(dev);
921 if (parent) 924 if (parent)
@@ -940,9 +943,6 @@ done:
940 DPMError: 943 DPMError:
941 bus_remove_device(dev); 944 bus_remove_device(dev);
942 BusError: 945 BusError:
943 if (dev->bus)
944 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
945 BUS_NOTIFY_DEL_DEVICE, dev);
946 device_remove_attrs(dev); 946 device_remove_attrs(dev);
947 AttrsError: 947 AttrsError:
948 device_remove_class_symlinks(dev); 948 device_remove_class_symlinks(dev);
@@ -1027,6 +1027,12 @@ void device_del(struct device *dev)
1027 struct device *parent = dev->parent; 1027 struct device *parent = dev->parent;
1028 struct class_interface *class_intf; 1028 struct class_interface *class_intf;
1029 1029
1030 /* Notify clients of device removal. This call must come
1031 * before dpm_sysfs_remove().
1032 */
1033 if (dev->bus)
1034 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1035 BUS_NOTIFY_DEL_DEVICE, dev);
1030 device_pm_remove(dev); 1036 device_pm_remove(dev);
1031 dpm_sysfs_remove(dev); 1037 dpm_sysfs_remove(dev);
1032 if (parent) 1038 if (parent)
@@ -1064,9 +1070,6 @@ void device_del(struct device *dev)
1064 */ 1070 */
1065 if (platform_notify_remove) 1071 if (platform_notify_remove)
1066 platform_notify_remove(dev); 1072 platform_notify_remove(dev);
1067 if (dev->bus)
1068 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1069 BUS_NOTIFY_DEL_DEVICE, dev);
1070 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 1073 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
1071 cleanup_device_parent(dev); 1074 cleanup_device_parent(dev);
1072 kobject_del(&dev->kobj); 1075 kobject_del(&dev->kobj);
@@ -1086,7 +1089,7 @@ void device_del(struct device *dev)
1086 */ 1089 */
1087void device_unregister(struct device *dev) 1090void device_unregister(struct device *dev)
1088{ 1091{
1089 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 1092 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
1090 device_del(dev); 1093 device_del(dev);
1091 put_device(dev); 1094 put_device(dev);
1092} 1095}
@@ -1196,10 +1199,101 @@ EXPORT_SYMBOL_GPL(put_device);
1196EXPORT_SYMBOL_GPL(device_create_file); 1199EXPORT_SYMBOL_GPL(device_create_file);
1197EXPORT_SYMBOL_GPL(device_remove_file); 1200EXPORT_SYMBOL_GPL(device_remove_file);
1198 1201
1202struct root_device
1203{
1204 struct device dev;
1205 struct module *owner;
1206};
1207
1208#define to_root_device(dev) container_of(dev, struct root_device, dev)
1209
1210static void root_device_release(struct device *dev)
1211{
1212 kfree(to_root_device(dev));
1213}
1214
1215/**
1216 * __root_device_register - allocate and register a root device
1217 * @name: root device name
1218 * @owner: owner module of the root device, usually THIS_MODULE
1219 *
1220 * This function allocates a root device and registers it
1221 * using device_register(). In order to free the returned
1222 * device, use root_device_unregister().
1223 *
1224 * Root devices are dummy devices which allow other devices
1225 * to be grouped under /sys/devices. Use this function to
1226 * allocate a root device and then use it as the parent of
1227 * any device which should appear under /sys/devices/{name}
1228 *
1229 * The /sys/devices/{name} directory will also contain a
1230 * 'module' symlink which points to the @owner directory
1231 * in sysfs.
1232 *
1233 * Note: You probably want to use root_device_register().
1234 */
1235struct device *__root_device_register(const char *name, struct module *owner)
1236{
1237 struct root_device *root;
1238 int err = -ENOMEM;
1239
1240 root = kzalloc(sizeof(struct root_device), GFP_KERNEL);
1241 if (!root)
1242 return ERR_PTR(err);
1243
1244 err = dev_set_name(&root->dev, name);
1245 if (err) {
1246 kfree(root);
1247 return ERR_PTR(err);
1248 }
1249
1250 root->dev.release = root_device_release;
1251
1252 err = device_register(&root->dev);
1253 if (err) {
1254 put_device(&root->dev);
1255 return ERR_PTR(err);
1256 }
1257
1258#ifdef CONFIG_MODULE /* gotta find a "cleaner" way to do this */
1259 if (owner) {
1260 struct module_kobject *mk = &owner->mkobj;
1261
1262 err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module");
1263 if (err) {
1264 device_unregister(&root->dev);
1265 return ERR_PTR(err);
1266 }
1267 root->owner = owner;
1268 }
1269#endif
1270
1271 return &root->dev;
1272}
1273EXPORT_SYMBOL_GPL(__root_device_register);
1274
1275/**
1276 * root_device_unregister - unregister and free a root device
1277 * @root: device going away.
1278 *
1279 * This function unregisters and cleans up a device that was created by
1280 * root_device_register().
1281 */
1282void root_device_unregister(struct device *dev)
1283{
1284 struct root_device *root = to_root_device(dev);
1285
1286 if (root->owner)
1287 sysfs_remove_link(&root->dev.kobj, "module");
1288
1289 device_unregister(dev);
1290}
1291EXPORT_SYMBOL_GPL(root_device_unregister);
1292
1199 1293
1200static void device_create_release(struct device *dev) 1294static void device_create_release(struct device *dev)
1201{ 1295{
1202 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 1296 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
1203 kfree(dev); 1297 kfree(dev);
1204} 1298}
1205 1299
@@ -1344,7 +1438,7 @@ int device_rename(struct device *dev, char *new_name)
1344 if (!dev) 1438 if (!dev)
1345 return -EINVAL; 1439 return -EINVAL;
1346 1440
1347 pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id, 1441 pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev),
1348 __func__, new_name); 1442 __func__, new_name);
1349 1443
1350#ifdef CONFIG_SYSFS_DEPRECATED 1444#ifdef CONFIG_SYSFS_DEPRECATED
@@ -1381,7 +1475,7 @@ int device_rename(struct device *dev, char *new_name)
1381#else 1475#else
1382 if (dev->class) { 1476 if (dev->class) {
1383 error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj, 1477 error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj,
1384 &dev->kobj, dev->bus_id); 1478 &dev->kobj, dev_name(dev));
1385 if (error) 1479 if (error)
1386 goto out; 1480 goto out;
1387 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 1481 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
@@ -1459,8 +1553,8 @@ int device_move(struct device *dev, struct device *new_parent)
1459 new_parent = get_device(new_parent); 1553 new_parent = get_device(new_parent);
1460 new_parent_kobj = get_device_parent(dev, new_parent); 1554 new_parent_kobj = get_device_parent(dev, new_parent);
1461 1555
1462 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, 1556 pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev),
1463 __func__, new_parent ? new_parent->bus_id : "<NULL>"); 1557 __func__, new_parent ? dev_name(new_parent) : "<NULL>");
1464 error = kobject_move(&dev->kobj, new_parent_kobj); 1558 error = kobject_move(&dev->kobj, new_parent_kobj);
1465 if (error) { 1559 if (error) {
1466 cleanup_glue_dir(dev, new_parent_kobj); 1560 cleanup_glue_dir(dev, new_parent_kobj);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 64f5d54f7edc..719ee5c1c8d9 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -109,7 +109,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
109 */ 109 */
110static ssize_t print_cpus_map(char *buf, cpumask_t *map) 110static ssize_t print_cpus_map(char *buf, cpumask_t *map)
111{ 111{
112 int n = cpulist_scnprintf(buf, PAGE_SIZE-2, *map); 112 int n = cpulist_scnprintf(buf, PAGE_SIZE-2, map);
113 113
114 buf[n++] = '\n'; 114 buf[n++] = '\n';
115 buf[n] = '\0'; 115 buf[n] = '\0';
@@ -128,10 +128,54 @@ print_cpus_func(online);
128print_cpus_func(possible); 128print_cpus_func(possible);
129print_cpus_func(present); 129print_cpus_func(present);
130 130
131/*
132 * Print values for NR_CPUS and offlined cpus
133 */
134static ssize_t print_cpus_kernel_max(struct sysdev_class *class, char *buf)
135{
136 int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1);
137 return n;
138}
139static SYSDEV_CLASS_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
140
141/* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */
142unsigned int total_cpus;
143
144static ssize_t print_cpus_offline(struct sysdev_class *class, char *buf)
145{
146 int n = 0, len = PAGE_SIZE-2;
147 cpumask_var_t offline;
148
149 /* display offline cpus < nr_cpu_ids */
150 if (!alloc_cpumask_var(&offline, GFP_KERNEL))
151 return -ENOMEM;
152 cpumask_complement(offline, cpu_online_mask);
153 n = cpulist_scnprintf(buf, len, offline);
154 free_cpumask_var(offline);
155
156 /* display offline cpus >= nr_cpu_ids */
157 if (total_cpus && nr_cpu_ids < total_cpus) {
158 if (n && n < len)
159 buf[n++] = ',';
160
161 if (nr_cpu_ids == total_cpus-1)
162 n += snprintf(&buf[n], len - n, "%d", nr_cpu_ids);
163 else
164 n += snprintf(&buf[n], len - n, "%d-%d",
165 nr_cpu_ids, total_cpus-1);
166 }
167
168 n += snprintf(&buf[n], len - n, "\n");
169 return n;
170}
171static SYSDEV_CLASS_ATTR(offline, 0444, print_cpus_offline, NULL);
172
131static struct sysdev_class_attribute *cpu_state_attr[] = { 173static struct sysdev_class_attribute *cpu_state_attr[] = {
132 &attr_online_map, 174 &attr_online_map,
133 &attr_possible_map, 175 &attr_possible_map,
134 &attr_present_map, 176 &attr_present_map,
177 &attr_kernel_max,
178 &attr_offline,
135}; 179};
136 180
137static int cpu_states_init(void) 181static int cpu_states_init(void)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 20febc00a525..315bed8d5e7f 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -34,7 +34,7 @@ static void driver_bound(struct device *dev)
34 return; 34 return;
35 } 35 }
36 36
37 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id, 37 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev_name(dev),
38 __func__, dev->driver->name); 38 __func__, dev->driver->name);
39 39
40 if (dev->bus) 40 if (dev->bus)
@@ -104,13 +104,13 @@ static int really_probe(struct device *dev, struct device_driver *drv)
104 104
105 atomic_inc(&probe_count); 105 atomic_inc(&probe_count);
106 pr_debug("bus: '%s': %s: probing driver %s with device %s\n", 106 pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
107 drv->bus->name, __func__, drv->name, dev->bus_id); 107 drv->bus->name, __func__, drv->name, dev_name(dev));
108 WARN_ON(!list_empty(&dev->devres_head)); 108 WARN_ON(!list_empty(&dev->devres_head));
109 109
110 dev->driver = drv; 110 dev->driver = drv;
111 if (driver_sysfs_add(dev)) { 111 if (driver_sysfs_add(dev)) {
112 printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", 112 printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",
113 __func__, dev->bus_id); 113 __func__, dev_name(dev));
114 goto probe_failed; 114 goto probe_failed;
115 } 115 }
116 116
@@ -127,7 +127,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
127 driver_bound(dev); 127 driver_bound(dev);
128 ret = 1; 128 ret = 1;
129 pr_debug("bus: '%s': %s: bound device %s to driver %s\n", 129 pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
130 drv->bus->name, __func__, dev->bus_id, drv->name); 130 drv->bus->name, __func__, dev_name(dev), drv->name);
131 goto done; 131 goto done;
132 132
133probe_failed: 133probe_failed:
@@ -139,7 +139,7 @@ probe_failed:
139 /* driver matched but the probe failed */ 139 /* driver matched but the probe failed */
140 printk(KERN_WARNING 140 printk(KERN_WARNING
141 "%s: probe of %s failed with error %d\n", 141 "%s: probe of %s failed with error %d\n",
142 drv->name, dev->bus_id, ret); 142 drv->name, dev_name(dev), ret);
143 } 143 }
144 /* 144 /*
145 * Ignore errors returned by ->probe so that the next driver can try 145 * Ignore errors returned by ->probe so that the next driver can try
@@ -194,7 +194,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
194 goto done; 194 goto done;
195 195
196 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 196 pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
197 drv->bus->name, __func__, dev->bus_id, drv->name); 197 drv->bus->name, __func__, dev_name(dev), drv->name);
198 198
199 ret = really_probe(dev, drv); 199 ret = really_probe(dev, drv);
200 200
@@ -298,7 +298,6 @@ static void __device_release_driver(struct device *dev)
298 drv = dev->driver; 298 drv = dev->driver;
299 if (drv) { 299 if (drv) {
300 driver_sysfs_remove(dev); 300 driver_sysfs_remove(dev);
301 sysfs_remove_link(&dev->kobj, "driver");
302 301
303 if (dev->bus) 302 if (dev->bus)
304 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 303 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b7e571031ecd..44699d9dd85c 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -291,12 +291,6 @@ firmware_class_timeout(u_long data)
291 fw_load_abort(fw_priv); 291 fw_load_abort(fw_priv);
292} 292}
293 293
294static inline void fw_setup_device_id(struct device *f_dev, struct device *dev)
295{
296 /* XXX warning we should watch out for name collisions */
297 strlcpy(f_dev->bus_id, dev->bus_id, BUS_ID_SIZE);
298}
299
300static int fw_register_device(struct device **dev_p, const char *fw_name, 294static int fw_register_device(struct device **dev_p, const char *fw_name,
301 struct device *device) 295 struct device *device)
302{ 296{
@@ -321,7 +315,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
321 fw_priv->timeout.data = (u_long) fw_priv; 315 fw_priv->timeout.data = (u_long) fw_priv;
322 init_timer(&fw_priv->timeout); 316 init_timer(&fw_priv->timeout);
323 317
324 fw_setup_device_id(f_dev, device); 318 dev_set_name(f_dev, dev_name(device));
325 f_dev->parent = device; 319 f_dev->parent = device;
326 f_dev->class = &firmware_class; 320 f_dev->class = &firmware_class;
327 dev_set_drvdata(f_dev, fw_priv); 321 dev_set_drvdata(f_dev, fw_priv);
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
new file mode 100644
index 000000000000..5e039d4f877c
--- /dev/null
+++ b/drivers/base/iommu.c
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
3 * Author: Joerg Roedel <joerg.roedel@amd.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <linux/bug.h>
20#include <linux/types.h>
21#include <linux/errno.h>
22#include <linux/iommu.h>
23
24static struct iommu_ops *iommu_ops;
25
26void register_iommu(struct iommu_ops *ops)
27{
28 if (iommu_ops)
29 BUG();
30
31 iommu_ops = ops;
32}
33
34bool iommu_found()
35{
36 return iommu_ops != NULL;
37}
38EXPORT_SYMBOL_GPL(iommu_found);
39
40struct iommu_domain *iommu_domain_alloc(void)
41{
42 struct iommu_domain *domain;
43 int ret;
44
45 domain = kmalloc(sizeof(*domain), GFP_KERNEL);
46 if (!domain)
47 return NULL;
48
49 ret = iommu_ops->domain_init(domain);
50 if (ret)
51 goto out_free;
52
53 return domain;
54
55out_free:
56 kfree(domain);
57
58 return NULL;
59}
60EXPORT_SYMBOL_GPL(iommu_domain_alloc);
61
62void iommu_domain_free(struct iommu_domain *domain)
63{
64 iommu_ops->domain_destroy(domain);
65 kfree(domain);
66}
67EXPORT_SYMBOL_GPL(iommu_domain_free);
68
69int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
70{
71 return iommu_ops->attach_dev(domain, dev);
72}
73EXPORT_SYMBOL_GPL(iommu_attach_device);
74
75void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
76{
77 iommu_ops->detach_dev(domain, dev);
78}
79EXPORT_SYMBOL_GPL(iommu_detach_device);
80
81int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
82 phys_addr_t paddr, size_t size, int prot)
83{
84 return iommu_ops->map(domain, iova, paddr, size, prot);
85}
86EXPORT_SYMBOL_GPL(iommu_map_range);
87
88void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
89 size_t size)
90{
91 iommu_ops->unmap(domain, iova, size);
92}
93EXPORT_SYMBOL_GPL(iommu_unmap_range);
94
95phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
96 unsigned long iova)
97{
98 return iommu_ops->iova_to_phys(domain, iova);
99}
100EXPORT_SYMBOL_GPL(iommu_iova_to_phys);
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index efd577574948..479694b6cbe3 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -11,7 +11,7 @@
11#include <linux/isa.h> 11#include <linux/isa.h>
12 12
13static struct device isa_bus = { 13static struct device isa_bus = {
14 .bus_id = "isa" 14 .init_name = "isa"
15}; 15};
16 16
17struct isa_dev { 17struct isa_dev {
@@ -135,9 +135,8 @@ int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
135 isa_dev->dev.parent = &isa_bus; 135 isa_dev->dev.parent = &isa_bus;
136 isa_dev->dev.bus = &isa_bus_type; 136 isa_dev->dev.bus = &isa_bus_type;
137 137
138 snprintf(isa_dev->dev.bus_id, BUS_ID_SIZE, "%s.%u", 138 dev_set_name(&isa_dev->dev, "%s.%u",
139 isa_driver->driver.name, id); 139 isa_driver->driver.name, id);
140
141 isa_dev->dev.platform_data = isa_driver; 140 isa_dev->dev.platform_data = isa_driver;
142 isa_dev->dev.release = isa_dev_release; 141 isa_dev->dev.release = isa_dev_release;
143 isa_dev->id = id; 142 isa_dev->id = id;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 5260e9e0df48..989429cfed88 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -347,8 +347,9 @@ static inline int memory_probe_init(void)
347 * section belongs to... 347 * section belongs to...
348 */ 348 */
349 349
350static int add_memory_block(unsigned long node_id, struct mem_section *section, 350static int add_memory_block(int nid, struct mem_section *section,
351 unsigned long state, int phys_device) 351 unsigned long state, int phys_device,
352 enum mem_add_context context)
352{ 353{
353 struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); 354 struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL);
354 int ret = 0; 355 int ret = 0;
@@ -370,6 +371,10 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
370 ret = mem_create_simple_file(mem, phys_device); 371 ret = mem_create_simple_file(mem, phys_device);
371 if (!ret) 372 if (!ret)
372 ret = mem_create_simple_file(mem, removable); 373 ret = mem_create_simple_file(mem, removable);
374 if (!ret) {
375 if (context == HOTPLUG)
376 ret = register_mem_sect_under_node(mem, nid);
377 }
373 378
374 return ret; 379 return ret;
375} 380}
@@ -382,7 +387,7 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
382 * 387 *
383 * This could be made generic for all sysdev classes. 388 * This could be made generic for all sysdev classes.
384 */ 389 */
385static struct memory_block *find_memory_block(struct mem_section *section) 390struct memory_block *find_memory_block(struct mem_section *section)
386{ 391{
387 struct kobject *kobj; 392 struct kobject *kobj;
388 struct sys_device *sysdev; 393 struct sys_device *sysdev;
@@ -411,6 +416,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
411 struct memory_block *mem; 416 struct memory_block *mem;
412 417
413 mem = find_memory_block(section); 418 mem = find_memory_block(section);
419 unregister_mem_sect_under_nodes(mem);
414 mem_remove_simple_file(mem, phys_index); 420 mem_remove_simple_file(mem, phys_index);
415 mem_remove_simple_file(mem, state); 421 mem_remove_simple_file(mem, state);
416 mem_remove_simple_file(mem, phys_device); 422 mem_remove_simple_file(mem, phys_device);
@@ -424,9 +430,9 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
424 * need an interface for the VM to add new memory regions, 430 * need an interface for the VM to add new memory regions,
425 * but without onlining it. 431 * but without onlining it.
426 */ 432 */
427int register_new_memory(struct mem_section *section) 433int register_new_memory(int nid, struct mem_section *section)
428{ 434{
429 return add_memory_block(0, section, MEM_OFFLINE, 0); 435 return add_memory_block(nid, section, MEM_OFFLINE, 0, HOTPLUG);
430} 436}
431 437
432int unregister_memory_section(struct mem_section *section) 438int unregister_memory_section(struct mem_section *section)
@@ -458,7 +464,8 @@ int __init memory_dev_init(void)
458 for (i = 0; i < NR_MEM_SECTIONS; i++) { 464 for (i = 0; i < NR_MEM_SECTIONS; i++) {
459 if (!present_section_nr(i)) 465 if (!present_section_nr(i))
460 continue; 466 continue;
461 err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 0); 467 err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE,
468 0, BOOT);
462 if (!ret) 469 if (!ret)
463 ret = err; 470 ret = err;
464 } 471 }
diff --git a/drivers/base/node.c b/drivers/base/node.c
index f5207090885a..43fa90b837ee 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -6,6 +6,7 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/memory.h>
9#include <linux/node.h> 10#include <linux/node.h>
10#include <linux/hugetlb.h> 11#include <linux/hugetlb.h>
11#include <linux/cpumask.h> 12#include <linux/cpumask.h>
@@ -30,8 +31,8 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
30 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); 31 BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
31 32
32 len = type? 33 len = type?
33 cpulist_scnprintf(buf, PAGE_SIZE-2, *mask): 34 cpulist_scnprintf(buf, PAGE_SIZE-2, mask) :
34 cpumask_scnprintf(buf, PAGE_SIZE-2, *mask); 35 cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
35 buf[len++] = '\n'; 36 buf[len++] = '\n';
36 buf[len] = '\0'; 37 buf[len] = '\0';
37 return len; 38 return len;
@@ -248,6 +249,105 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
248 return 0; 249 return 0;
249} 250}
250 251
252#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
253#define page_initialized(page) (page->lru.next)
254
255static int get_nid_for_pfn(unsigned long pfn)
256{
257 struct page *page;
258
259 if (!pfn_valid_within(pfn))
260 return -1;
261 page = pfn_to_page(pfn);
262 if (!page_initialized(page))
263 return -1;
264 return pfn_to_nid(pfn);
265}
266
267/* register memory section under specified node if it spans that node */
268int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
269{
270 unsigned long pfn, sect_start_pfn, sect_end_pfn;
271
272 if (!mem_blk)
273 return -EFAULT;
274 if (!node_online(nid))
275 return 0;
276 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
277 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
278 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
279 int page_nid;
280
281 page_nid = get_nid_for_pfn(pfn);
282 if (page_nid < 0)
283 continue;
284 if (page_nid != nid)
285 continue;
286 return sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj,
287 &mem_blk->sysdev.kobj,
288 kobject_name(&mem_blk->sysdev.kobj));
289 }
290 /* mem section does not span the specified node */
291 return 0;
292}
293
294/* unregister memory section under all nodes that it spans */
295int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
296{
297 nodemask_t unlinked_nodes;
298 unsigned long pfn, sect_start_pfn, sect_end_pfn;
299
300 if (!mem_blk)
301 return -EFAULT;
302 nodes_clear(unlinked_nodes);
303 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
304 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
305 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
306 unsigned int nid;
307
308 nid = get_nid_for_pfn(pfn);
309 if (nid < 0)
310 continue;
311 if (!node_online(nid))
312 continue;
313 if (node_test_and_set(nid, unlinked_nodes))
314 continue;
315 sysfs_remove_link(&node_devices[nid].sysdev.kobj,
316 kobject_name(&mem_blk->sysdev.kobj));
317 }
318 return 0;
319}
320
321static int link_mem_sections(int nid)
322{
323 unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
324 unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
325 unsigned long pfn;
326 int err = 0;
327
328 for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
329 unsigned long section_nr = pfn_to_section_nr(pfn);
330 struct mem_section *mem_sect;
331 struct memory_block *mem_blk;
332 int ret;
333
334 if (!present_section_nr(section_nr))
335 continue;
336 mem_sect = __nr_to_section(section_nr);
337 mem_blk = find_memory_block(mem_sect);
338 ret = register_mem_sect_under_node(mem_blk, nid);
339 if (!err)
340 err = ret;
341
342 /* discard ref obtained in find_memory_block() */
343 kobject_put(&mem_blk->sysdev.kobj);
344 }
345 return err;
346}
347#else
348static int link_mem_sections(int nid) { return 0; }
349#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
350
251int register_one_node(int nid) 351int register_one_node(int nid)
252{ 352{
253 int error = 0; 353 int error = 0;
@@ -267,6 +367,9 @@ int register_one_node(int nid)
267 if (cpu_to_node(cpu) == nid) 367 if (cpu_to_node(cpu) == nid)
268 register_cpu_under_node(cpu, nid); 368 register_cpu_under_node(cpu, nid);
269 } 369 }
370
371 /* link memory sections under this node */
372 error = link_mem_sections(nid);
270 } 373 }
271 374
272 return error; 375 return error;
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dfcbfe504867..349a1013603f 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -24,7 +24,7 @@
24 driver)) 24 driver))
25 25
26struct device platform_bus = { 26struct device platform_bus = {
27 .bus_id = "platform", 27 .init_name = "platform",
28}; 28};
29EXPORT_SYMBOL_GPL(platform_bus); 29EXPORT_SYMBOL_GPL(platform_bus);
30 30
@@ -242,16 +242,15 @@ int platform_device_add(struct platform_device *pdev)
242 pdev->dev.bus = &platform_bus_type; 242 pdev->dev.bus = &platform_bus_type;
243 243
244 if (pdev->id != -1) 244 if (pdev->id != -1)
245 snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%d", pdev->name, 245 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
246 pdev->id);
247 else 246 else
248 strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE); 247 dev_set_name(&pdev->dev, pdev->name);
249 248
250 for (i = 0; i < pdev->num_resources; i++) { 249 for (i = 0; i < pdev->num_resources; i++) {
251 struct resource *p, *r = &pdev->resource[i]; 250 struct resource *p, *r = &pdev->resource[i];
252 251
253 if (r->name == NULL) 252 if (r->name == NULL)
254 r->name = pdev->dev.bus_id; 253 r->name = dev_name(&pdev->dev);
255 254
256 p = r->parent; 255 p = r->parent;
257 if (!p) { 256 if (!p) {
@@ -264,14 +263,14 @@ int platform_device_add(struct platform_device *pdev)
264 if (p && insert_resource(p, r)) { 263 if (p && insert_resource(p, r)) {
265 printk(KERN_ERR 264 printk(KERN_ERR
266 "%s: failed to claim resource %d\n", 265 "%s: failed to claim resource %d\n",
267 pdev->dev.bus_id, i); 266 dev_name(&pdev->dev), i);
268 ret = -EBUSY; 267 ret = -EBUSY;
269 goto failed; 268 goto failed;
270 } 269 }
271 } 270 }
272 271
273 pr_debug("Registering platform device '%s'. Parent at %s\n", 272 pr_debug("Registering platform device '%s'. Parent at %s\n",
274 pdev->dev.bus_id, pdev->dev.parent->bus_id); 273 dev_name(&pdev->dev), dev_name(pdev->dev.parent));
275 274
276 ret = device_add(&pdev->dev); 275 ret = device_add(&pdev->dev);
277 if (ret == 0) 276 if (ret == 0)
@@ -503,8 +502,6 @@ int platform_driver_register(struct platform_driver *drv)
503 drv->driver.suspend = platform_drv_suspend; 502 drv->driver.suspend = platform_drv_suspend;
504 if (drv->resume) 503 if (drv->resume)
505 drv->driver.resume = platform_drv_resume; 504 drv->driver.resume = platform_drv_resume;
506 if (drv->pm)
507 drv->driver.pm = &drv->pm->base;
508 return driver_register(&drv->driver); 505 return driver_register(&drv->driver);
509} 506}
510EXPORT_SYMBOL_GPL(platform_driver_register); 507EXPORT_SYMBOL_GPL(platform_driver_register);
@@ -609,7 +606,7 @@ static int platform_match(struct device *dev, struct device_driver *drv)
609 struct platform_device *pdev; 606 struct platform_device *pdev;
610 607
611 pdev = container_of(dev, struct platform_device, dev); 608 pdev = container_of(dev, struct platform_device, dev);
612 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 609 return (strcmp(pdev->name, drv->name) == 0);
613} 610}
614 611
615#ifdef CONFIG_PM_SLEEP 612#ifdef CONFIG_PM_SLEEP
@@ -686,7 +683,10 @@ static int platform_pm_suspend(struct device *dev)
686 struct device_driver *drv = dev->driver; 683 struct device_driver *drv = dev->driver;
687 int ret = 0; 684 int ret = 0;
688 685
689 if (drv && drv->pm) { 686 if (!drv)
687 return 0;
688
689 if (drv->pm) {
690 if (drv->pm->suspend) 690 if (drv->pm->suspend)
691 ret = drv->pm->suspend(dev); 691 ret = drv->pm->suspend(dev);
692 } else { 692 } else {
@@ -698,16 +698,15 @@ static int platform_pm_suspend(struct device *dev)
698 698
699static int platform_pm_suspend_noirq(struct device *dev) 699static int platform_pm_suspend_noirq(struct device *dev)
700{ 700{
701 struct platform_driver *pdrv; 701 struct device_driver *drv = dev->driver;
702 int ret = 0; 702 int ret = 0;
703 703
704 if (!dev->driver) 704 if (!drv)
705 return 0; 705 return 0;
706 706
707 pdrv = to_platform_driver(dev->driver); 707 if (drv->pm) {
708 if (pdrv->pm) { 708 if (drv->pm->suspend_noirq)
709 if (pdrv->pm->suspend_noirq) 709 ret = drv->pm->suspend_noirq(dev);
710 ret = pdrv->pm->suspend_noirq(dev);
711 } else { 710 } else {
712 ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND); 711 ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND);
713 } 712 }
@@ -720,7 +719,10 @@ static int platform_pm_resume(struct device *dev)
720 struct device_driver *drv = dev->driver; 719 struct device_driver *drv = dev->driver;
721 int ret = 0; 720 int ret = 0;
722 721
723 if (drv && drv->pm) { 722 if (!drv)
723 return 0;
724
725 if (drv->pm) {
724 if (drv->pm->resume) 726 if (drv->pm->resume)
725 ret = drv->pm->resume(dev); 727 ret = drv->pm->resume(dev);
726 } else { 728 } else {
@@ -732,16 +734,15 @@ static int platform_pm_resume(struct device *dev)
732 734
733static int platform_pm_resume_noirq(struct device *dev) 735static int platform_pm_resume_noirq(struct device *dev)
734{ 736{
735 struct platform_driver *pdrv; 737 struct device_driver *drv = dev->driver;
736 int ret = 0; 738 int ret = 0;
737 739
738 if (!dev->driver) 740 if (!drv)
739 return 0; 741 return 0;
740 742
741 pdrv = to_platform_driver(dev->driver); 743 if (drv->pm) {
742 if (pdrv->pm) { 744 if (drv->pm->resume_noirq)
743 if (pdrv->pm->resume_noirq) 745 ret = drv->pm->resume_noirq(dev);
744 ret = pdrv->pm->resume_noirq(dev);
745 } else { 746 } else {
746 ret = platform_legacy_resume_early(dev); 747 ret = platform_legacy_resume_early(dev);
747 } 748 }
@@ -780,16 +781,15 @@ static int platform_pm_freeze(struct device *dev)
780 781
781static int platform_pm_freeze_noirq(struct device *dev) 782static int platform_pm_freeze_noirq(struct device *dev)
782{ 783{
783 struct platform_driver *pdrv; 784 struct device_driver *drv = dev->driver;
784 int ret = 0; 785 int ret = 0;
785 786
786 if (!dev->driver) 787 if (!drv)
787 return 0; 788 return 0;
788 789
789 pdrv = to_platform_driver(dev->driver); 790 if (drv->pm) {
790 if (pdrv->pm) { 791 if (drv->pm->freeze_noirq)
791 if (pdrv->pm->freeze_noirq) 792 ret = drv->pm->freeze_noirq(dev);
792 ret = pdrv->pm->freeze_noirq(dev);
793 } else { 793 } else {
794 ret = platform_legacy_suspend_late(dev, PMSG_FREEZE); 794 ret = platform_legacy_suspend_late(dev, PMSG_FREEZE);
795 } 795 }
@@ -802,7 +802,10 @@ static int platform_pm_thaw(struct device *dev)
802 struct device_driver *drv = dev->driver; 802 struct device_driver *drv = dev->driver;
803 int ret = 0; 803 int ret = 0;
804 804
805 if (drv && drv->pm) { 805 if (!drv)
806 return 0;
807
808 if (drv->pm) {
806 if (drv->pm->thaw) 809 if (drv->pm->thaw)
807 ret = drv->pm->thaw(dev); 810 ret = drv->pm->thaw(dev);
808 } else { 811 } else {
@@ -814,16 +817,15 @@ static int platform_pm_thaw(struct device *dev)
814 817
815static int platform_pm_thaw_noirq(struct device *dev) 818static int platform_pm_thaw_noirq(struct device *dev)
816{ 819{
817 struct platform_driver *pdrv; 820 struct device_driver *drv = dev->driver;
818 int ret = 0; 821 int ret = 0;
819 822
820 if (!dev->driver) 823 if (!drv)
821 return 0; 824 return 0;
822 825
823 pdrv = to_platform_driver(dev->driver); 826 if (drv->pm) {
824 if (pdrv->pm) { 827 if (drv->pm->thaw_noirq)
825 if (pdrv->pm->thaw_noirq) 828 ret = drv->pm->thaw_noirq(dev);
826 ret = pdrv->pm->thaw_noirq(dev);
827 } else { 829 } else {
828 ret = platform_legacy_resume_early(dev); 830 ret = platform_legacy_resume_early(dev);
829 } 831 }
@@ -836,7 +838,10 @@ static int platform_pm_poweroff(struct device *dev)
836 struct device_driver *drv = dev->driver; 838 struct device_driver *drv = dev->driver;
837 int ret = 0; 839 int ret = 0;
838 840
839 if (drv && drv->pm) { 841 if (!drv)
842 return 0;
843
844 if (drv->pm) {
840 if (drv->pm->poweroff) 845 if (drv->pm->poweroff)
841 ret = drv->pm->poweroff(dev); 846 ret = drv->pm->poweroff(dev);
842 } else { 847 } else {
@@ -848,16 +853,15 @@ static int platform_pm_poweroff(struct device *dev)
848 853
849static int platform_pm_poweroff_noirq(struct device *dev) 854static int platform_pm_poweroff_noirq(struct device *dev)
850{ 855{
851 struct platform_driver *pdrv; 856 struct device_driver *drv = dev->driver;
852 int ret = 0; 857 int ret = 0;
853 858
854 if (!dev->driver) 859 if (!drv)
855 return 0; 860 return 0;
856 861
857 pdrv = to_platform_driver(dev->driver); 862 if (drv->pm) {
858 if (pdrv->pm) { 863 if (drv->pm->poweroff_noirq)
859 if (pdrv->pm->poweroff_noirq) 864 ret = drv->pm->poweroff_noirq(dev);
860 ret = pdrv->pm->poweroff_noirq(dev);
861 } else { 865 } else {
862 ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE); 866 ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE);
863 } 867 }
@@ -870,7 +874,10 @@ static int platform_pm_restore(struct device *dev)
870 struct device_driver *drv = dev->driver; 874 struct device_driver *drv = dev->driver;
871 int ret = 0; 875 int ret = 0;
872 876
873 if (drv && drv->pm) { 877 if (!drv)
878 return 0;
879
880 if (drv->pm) {
874 if (drv->pm->restore) 881 if (drv->pm->restore)
875 ret = drv->pm->restore(dev); 882 ret = drv->pm->restore(dev);
876 } else { 883 } else {
@@ -882,16 +889,15 @@ static int platform_pm_restore(struct device *dev)
882 889
883static int platform_pm_restore_noirq(struct device *dev) 890static int platform_pm_restore_noirq(struct device *dev)
884{ 891{
885 struct platform_driver *pdrv; 892 struct device_driver *drv = dev->driver;
886 int ret = 0; 893 int ret = 0;
887 894
888 if (!dev->driver) 895 if (!drv)
889 return 0; 896 return 0;
890 897
891 pdrv = to_platform_driver(dev->driver); 898 if (drv->pm) {
892 if (pdrv->pm) { 899 if (drv->pm->restore_noirq)
893 if (pdrv->pm->restore_noirq) 900 ret = drv->pm->restore_noirq(dev);
894 ret = pdrv->pm->restore_noirq(dev);
895 } else { 901 } else {
896 ret = platform_legacy_resume_early(dev); 902 ret = platform_legacy_resume_early(dev);
897 } 903 }
@@ -912,17 +918,15 @@ static int platform_pm_restore_noirq(struct device *dev)
912 918
913#endif /* !CONFIG_HIBERNATION */ 919#endif /* !CONFIG_HIBERNATION */
914 920
915static struct pm_ext_ops platform_pm_ops = { 921static struct dev_pm_ops platform_dev_pm_ops = {
916 .base = { 922 .prepare = platform_pm_prepare,
917 .prepare = platform_pm_prepare, 923 .complete = platform_pm_complete,
918 .complete = platform_pm_complete, 924 .suspend = platform_pm_suspend,
919 .suspend = platform_pm_suspend, 925 .resume = platform_pm_resume,
920 .resume = platform_pm_resume, 926 .freeze = platform_pm_freeze,
921 .freeze = platform_pm_freeze, 927 .thaw = platform_pm_thaw,
922 .thaw = platform_pm_thaw, 928 .poweroff = platform_pm_poweroff,
923 .poweroff = platform_pm_poweroff, 929 .restore = platform_pm_restore,
924 .restore = platform_pm_restore,
925 },
926 .suspend_noirq = platform_pm_suspend_noirq, 930 .suspend_noirq = platform_pm_suspend_noirq,
927 .resume_noirq = platform_pm_resume_noirq, 931 .resume_noirq = platform_pm_resume_noirq,
928 .freeze_noirq = platform_pm_freeze_noirq, 932 .freeze_noirq = platform_pm_freeze_noirq,
@@ -931,7 +935,7 @@ static struct pm_ext_ops platform_pm_ops = {
931 .restore_noirq = platform_pm_restore_noirq, 935 .restore_noirq = platform_pm_restore_noirq,
932}; 936};
933 937
934#define PLATFORM_PM_OPS_PTR &platform_pm_ops 938#define PLATFORM_PM_OPS_PTR (&platform_dev_pm_ops)
935 939
936#else /* !CONFIG_PM_SLEEP */ 940#else /* !CONFIG_PM_SLEEP */
937 941
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 692c20ba5144..670c9d6c1407 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -76,7 +76,7 @@ void device_pm_add(struct device *dev)
76 if (dev->parent) { 76 if (dev->parent) {
77 if (dev->parent->power.status >= DPM_SUSPENDING) 77 if (dev->parent->power.status >= DPM_SUSPENDING)
78 dev_warn(dev, "parent %s should not be sleeping\n", 78 dev_warn(dev, "parent %s should not be sleeping\n",
79 dev->parent->bus_id); 79 dev_name(dev->parent));
80 } else if (transition_started) { 80 } else if (transition_started) {
81 /* 81 /*
82 * We refuse to register parentless devices while a PM 82 * We refuse to register parentless devices while a PM
@@ -112,7 +112,8 @@ void device_pm_remove(struct device *dev)
112 * @ops: PM operations to choose from. 112 * @ops: PM operations to choose from.
113 * @state: PM transition of the system being carried out. 113 * @state: PM transition of the system being carried out.
114 */ 114 */
115static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state) 115static int pm_op(struct device *dev, struct dev_pm_ops *ops,
116 pm_message_t state)
116{ 117{
117 int error = 0; 118 int error = 0;
118 119
@@ -174,7 +175,7 @@ static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state)
174 * The operation is executed with interrupts disabled by the only remaining 175 * The operation is executed with interrupts disabled by the only remaining
175 * functional CPU in the system. 176 * functional CPU in the system.
176 */ 177 */
177static int pm_noirq_op(struct device *dev, struct pm_ext_ops *ops, 178static int pm_noirq_op(struct device *dev, struct dev_pm_ops *ops,
178 pm_message_t state) 179 pm_message_t state)
179{ 180{
180 int error = 0; 181 int error = 0;
@@ -354,7 +355,7 @@ static int resume_device(struct device *dev, pm_message_t state)
354 if (dev->bus) { 355 if (dev->bus) {
355 if (dev->bus->pm) { 356 if (dev->bus->pm) {
356 pm_dev_dbg(dev, state, ""); 357 pm_dev_dbg(dev, state, "");
357 error = pm_op(dev, &dev->bus->pm->base, state); 358 error = pm_op(dev, dev->bus->pm, state);
358 } else if (dev->bus->resume) { 359 } else if (dev->bus->resume) {
359 pm_dev_dbg(dev, state, "legacy "); 360 pm_dev_dbg(dev, state, "legacy ");
360 error = dev->bus->resume(dev); 361 error = dev->bus->resume(dev);
@@ -451,9 +452,9 @@ static void complete_device(struct device *dev, pm_message_t state)
451 dev->type->pm->complete(dev); 452 dev->type->pm->complete(dev);
452 } 453 }
453 454
454 if (dev->bus && dev->bus->pm && dev->bus->pm->base.complete) { 455 if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
455 pm_dev_dbg(dev, state, "completing "); 456 pm_dev_dbg(dev, state, "completing ");
456 dev->bus->pm->base.complete(dev); 457 dev->bus->pm->complete(dev);
457 } 458 }
458 459
459 up(&dev->sem); 460 up(&dev->sem);
@@ -624,7 +625,7 @@ static int suspend_device(struct device *dev, pm_message_t state)
624 if (dev->bus) { 625 if (dev->bus) {
625 if (dev->bus->pm) { 626 if (dev->bus->pm) {
626 pm_dev_dbg(dev, state, ""); 627 pm_dev_dbg(dev, state, "");
627 error = pm_op(dev, &dev->bus->pm->base, state); 628 error = pm_op(dev, dev->bus->pm, state);
628 } else if (dev->bus->suspend) { 629 } else if (dev->bus->suspend) {
629 pm_dev_dbg(dev, state, "legacy "); 630 pm_dev_dbg(dev, state, "legacy ");
630 error = dev->bus->suspend(dev, state); 631 error = dev->bus->suspend(dev, state);
@@ -685,10 +686,10 @@ static int prepare_device(struct device *dev, pm_message_t state)
685 686
686 down(&dev->sem); 687 down(&dev->sem);
687 688
688 if (dev->bus && dev->bus->pm && dev->bus->pm->base.prepare) { 689 if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
689 pm_dev_dbg(dev, state, "preparing "); 690 pm_dev_dbg(dev, state, "preparing ");
690 error = dev->bus->pm->base.prepare(dev); 691 error = dev->bus->pm->prepare(dev);
691 suspend_report_result(dev->bus->pm->base.prepare, error); 692 suspend_report_result(dev->bus->pm->prepare, error);
692 if (error) 693 if (error)
693 goto End; 694 goto End;
694 } 695 }
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index 2aa6e8fc4def..0a1a2c4dbc6e 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -140,7 +140,7 @@ static unsigned int hash_string(unsigned int seed, const char *data, unsigned in
140 140
141void set_trace_device(struct device *dev) 141void set_trace_device(struct device *dev)
142{ 142{
143 dev_hash_value = hash_string(DEVSEED, dev->bus_id, DEVHASH); 143 dev_hash_value = hash_string(DEVSEED, dev_name(dev), DEVHASH);
144} 144}
145EXPORT_SYMBOL(set_trace_device); 145EXPORT_SYMBOL(set_trace_device);
146 146
@@ -192,7 +192,7 @@ static int show_dev_hash(unsigned int value)
192 192
193 while (entry != &dpm_list) { 193 while (entry != &dpm_list) {
194 struct device * dev = to_device(entry); 194 struct device * dev = to_device(entry);
195 unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); 195 unsigned int hash = hash_string(DEVSEED, dev_name(dev), DEVHASH);
196 if (hash == value) { 196 if (hash == value) {
197 dev_info(dev, "hash matches\n"); 197 dev_info(dev, "hash matches\n");
198 match++; 198 match++;
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index 199cd97e32e6..a778fb52b11f 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -28,6 +28,7 @@
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/cpu.h> 29#include <linux/cpu.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/hardirq.h>
31#include <linux/topology.h> 32#include <linux/topology.h>
32 33
33#define define_one_ro(_name) \ 34#define define_one_ro(_name) \
@@ -49,8 +50,8 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
49 50
50 if (len > 1) { 51 if (len > 1) {
51 n = type? 52 n = type?
52 cpulist_scnprintf(buf, len-2, *mask): 53 cpulist_scnprintf(buf, len-2, mask) :
53 cpumask_scnprintf(buf, len-2, *mask); 54 cpumask_scnprintf(buf, len-2, mask);
54 buf[n++] = '\n'; 55 buf[n++] = '\n';
55 buf[n] = '\0'; 56 buf[n] = '\0';
56 } 57 }