diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/Kconfig | 2 | ||||
-rw-r--r-- | drivers/base/base.h | 2 | ||||
-rw-r--r-- | drivers/base/bus.c | 139 | ||||
-rw-r--r-- | drivers/base/class.c | 43 | ||||
-rw-r--r-- | drivers/base/core.c | 261 | ||||
-rw-r--r-- | drivers/base/cpu.c | 28 | ||||
-rw-r--r-- | drivers/base/dd.c | 147 | ||||
-rw-r--r-- | drivers/base/dmapool.c | 3 | ||||
-rw-r--r-- | drivers/base/driver.c | 17 | ||||
-rw-r--r-- | drivers/base/firmware_class.c | 14 | ||||
-rw-r--r-- | drivers/base/hypervisor.c | 3 | ||||
-rw-r--r-- | drivers/base/memory.c | 4 | ||||
-rw-r--r-- | drivers/base/node.c | 135 | ||||
-rw-r--r-- | drivers/base/platform.c | 30 | ||||
-rw-r--r-- | drivers/base/power/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/power/main.c | 1 | ||||
-rw-r--r-- | drivers/base/power/resume.c | 45 | ||||
-rw-r--r-- | drivers/base/power/shutdown.c | 1 | ||||
-rw-r--r-- | drivers/base/power/suspend.c | 99 | ||||
-rw-r--r-- | drivers/base/power/sysfs.c | 35 | ||||
-rw-r--r-- | drivers/base/power/trace.c | 228 | ||||
-rw-r--r-- | drivers/base/sys.c | 1 | ||||
-rw-r--r-- | drivers/base/topology.c | 6 |
23 files changed, 960 insertions, 285 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index 80502dc6ed66..0b4e22436935 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig | |||
@@ -20,7 +20,7 @@ config PREVENT_FIRMWARE_BUILD | |||
20 | 20 | ||
21 | config FW_LOADER | 21 | config FW_LOADER |
22 | tristate "Userspace firmware loading support" | 22 | tristate "Userspace firmware loading support" |
23 | select HOTPLUG | 23 | depends on HOTPLUG |
24 | ---help--- | 24 | ---help--- |
25 | This option is provided for the case where no in-kernel-tree modules | 25 | This option is provided for the case where no in-kernel-tree modules |
26 | require userspace firmware loading support, but a module built outside | 26 | require userspace firmware loading support, but a module built outside |
diff --git a/drivers/base/base.h b/drivers/base/base.h index c3b8dc98b8a7..d26644a59537 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void); | |||
16 | extern int attribute_container_init(void); | 16 | extern int attribute_container_init(void); |
17 | 17 | ||
18 | extern int bus_add_device(struct device * dev); | 18 | extern int bus_add_device(struct device * dev); |
19 | extern void bus_attach_device(struct device * dev); | 19 | extern int bus_attach_device(struct device * dev); |
20 | extern void bus_remove_device(struct device * dev); | 20 | extern void bus_remove_device(struct device * dev); |
21 | extern struct bus_type *get_bus(struct bus_type * bus); | 21 | extern struct bus_type *get_bus(struct bus_type * bus); |
22 | extern void put_bus(struct bus_type * bus); | 22 | extern void put_bus(struct bus_type * bus); |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 050d86d0b872..12173d16bea7 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/device.h> | 11 | #include <linux/device.h> |
13 | #include <linux/module.h> | 12 | #include <linux/module.h> |
14 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
@@ -130,7 +129,7 @@ static struct kobj_type ktype_bus = { | |||
130 | 129 | ||
131 | }; | 130 | }; |
132 | 131 | ||
133 | decl_subsys(bus, &ktype_bus, NULL); | 132 | static decl_subsys(bus, &ktype_bus, NULL); |
134 | 133 | ||
135 | 134 | ||
136 | #ifdef CONFIG_HOTPLUG | 135 | #ifdef CONFIG_HOTPLUG |
@@ -372,12 +371,20 @@ int bus_add_device(struct device * dev) | |||
372 | if (bus) { | 371 | if (bus) { |
373 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); | 372 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); |
374 | error = device_add_attrs(bus, dev); | 373 | error = device_add_attrs(bus, dev); |
375 | if (!error) { | 374 | if (error) |
376 | sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); | 375 | goto out; |
377 | sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); | 376 | error = sysfs_create_link(&bus->devices.kobj, |
378 | sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); | 377 | &dev->kobj, dev->bus_id); |
379 | } | 378 | if (error) |
379 | goto out; | ||
380 | error = sysfs_create_link(&dev->kobj, | ||
381 | &dev->bus->subsys.kset.kobj, "subsystem"); | ||
382 | if (error) | ||
383 | goto out; | ||
384 | error = sysfs_create_link(&dev->kobj, | ||
385 | &dev->bus->subsys.kset.kobj, "bus"); | ||
380 | } | 386 | } |
387 | out: | ||
381 | return error; | 388 | return error; |
382 | } | 389 | } |
383 | 390 | ||
@@ -385,16 +392,24 @@ int bus_add_device(struct device * dev) | |||
385 | * bus_attach_device - add device to bus | 392 | * bus_attach_device - add device to bus |
386 | * @dev: device tried to attach to a driver | 393 | * @dev: device tried to attach to a driver |
387 | * | 394 | * |
395 | * - Add device to bus's list of devices. | ||
388 | * - Try to attach to driver. | 396 | * - Try to attach to driver. |
389 | */ | 397 | */ |
390 | void bus_attach_device(struct device * dev) | 398 | int bus_attach_device(struct device * dev) |
391 | { | 399 | { |
392 | struct bus_type * bus = dev->bus; | 400 | struct bus_type *bus = dev->bus; |
401 | int ret = 0; | ||
393 | 402 | ||
394 | if (bus) { | 403 | if (bus) { |
395 | device_attach(dev); | 404 | dev->is_registered = 1; |
396 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); | 405 | ret = device_attach(dev); |
406 | if (ret >= 0) { | ||
407 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); | ||
408 | ret = 0; | ||
409 | } else | ||
410 | dev->is_registered = 0; | ||
397 | } | 411 | } |
412 | return ret; | ||
398 | } | 413 | } |
399 | 414 | ||
400 | /** | 415 | /** |
@@ -413,7 +428,8 @@ void bus_remove_device(struct device * dev) | |||
413 | sysfs_remove_link(&dev->kobj, "bus"); | 428 | sysfs_remove_link(&dev->kobj, "bus"); |
414 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); | 429 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); |
415 | device_remove_attrs(dev->bus, dev); | 430 | device_remove_attrs(dev->bus, dev); |
416 | klist_remove(&dev->knode_bus); | 431 | dev->is_registered = 0; |
432 | klist_del(&dev->knode_bus); | ||
417 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); | 433 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); |
418 | device_release_driver(dev); | 434 | device_release_driver(dev); |
419 | put_bus(dev->bus); | 435 | put_bus(dev->bus); |
@@ -456,10 +472,17 @@ static void driver_remove_attrs(struct bus_type * bus, struct device_driver * dr | |||
456 | * Thanks to drivers making their tables __devinit, we can't allow manual | 472 | * Thanks to drivers making their tables __devinit, we can't allow manual |
457 | * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. | 473 | * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. |
458 | */ | 474 | */ |
459 | static void add_bind_files(struct device_driver *drv) | 475 | static int __must_check add_bind_files(struct device_driver *drv) |
460 | { | 476 | { |
461 | driver_create_file(drv, &driver_attr_unbind); | 477 | int ret; |
462 | driver_create_file(drv, &driver_attr_bind); | 478 | |
479 | ret = driver_create_file(drv, &driver_attr_unbind); | ||
480 | if (ret == 0) { | ||
481 | ret = driver_create_file(drv, &driver_attr_bind); | ||
482 | if (ret) | ||
483 | driver_remove_file(drv, &driver_attr_unbind); | ||
484 | } | ||
485 | return ret; | ||
463 | } | 486 | } |
464 | 487 | ||
465 | static void remove_bind_files(struct device_driver *drv) | 488 | static void remove_bind_files(struct device_driver *drv) |
@@ -468,7 +491,7 @@ static void remove_bind_files(struct device_driver *drv) | |||
468 | driver_remove_file(drv, &driver_attr_unbind); | 491 | driver_remove_file(drv, &driver_attr_unbind); |
469 | } | 492 | } |
470 | #else | 493 | #else |
471 | static inline void add_bind_files(struct device_driver *drv) {} | 494 | static inline int add_bind_files(struct device_driver *drv) { return 0; } |
472 | static inline void remove_bind_files(struct device_driver *drv) {} | 495 | static inline void remove_bind_files(struct device_driver *drv) {} |
473 | #endif | 496 | #endif |
474 | 497 | ||
@@ -477,7 +500,7 @@ static inline void remove_bind_files(struct device_driver *drv) {} | |||
477 | * @drv: driver. | 500 | * @drv: driver. |
478 | * | 501 | * |
479 | */ | 502 | */ |
480 | int bus_add_driver(struct device_driver * drv) | 503 | int bus_add_driver(struct device_driver *drv) |
481 | { | 504 | { |
482 | struct bus_type * bus = get_bus(drv->bus); | 505 | struct bus_type * bus = get_bus(drv->bus); |
483 | int error = 0; | 506 | int error = 0; |
@@ -485,27 +508,39 @@ int bus_add_driver(struct device_driver * drv) | |||
485 | if (bus) { | 508 | if (bus) { |
486 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); | 509 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); |
487 | error = kobject_set_name(&drv->kobj, "%s", drv->name); | 510 | error = kobject_set_name(&drv->kobj, "%s", drv->name); |
488 | if (error) { | 511 | if (error) |
489 | put_bus(bus); | 512 | goto out_put_bus; |
490 | return error; | ||
491 | } | ||
492 | drv->kobj.kset = &bus->drivers; | 513 | drv->kobj.kset = &bus->drivers; |
493 | if ((error = kobject_register(&drv->kobj))) { | 514 | if ((error = kobject_register(&drv->kobj))) |
494 | put_bus(bus); | 515 | goto out_put_bus; |
495 | return error; | ||
496 | } | ||
497 | 516 | ||
498 | driver_attach(drv); | 517 | error = driver_attach(drv); |
518 | if (error) | ||
519 | goto out_unregister; | ||
499 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | 520 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); |
500 | module_add_driver(drv->owner, drv); | 521 | module_add_driver(drv->owner, drv); |
501 | 522 | ||
502 | driver_add_attrs(bus, drv); | 523 | error = driver_add_attrs(bus, drv); |
503 | add_bind_files(drv); | 524 | if (error) { |
525 | /* How the hell do we get out of this pickle? Give up */ | ||
526 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", | ||
527 | __FUNCTION__, drv->name); | ||
528 | } | ||
529 | error = add_bind_files(drv); | ||
530 | if (error) { | ||
531 | /* Ditto */ | ||
532 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | ||
533 | __FUNCTION__, drv->name); | ||
534 | } | ||
504 | } | 535 | } |
505 | return error; | 536 | return error; |
537 | out_unregister: | ||
538 | kobject_unregister(&drv->kobj); | ||
539 | out_put_bus: | ||
540 | put_bus(bus); | ||
541 | return error; | ||
506 | } | 542 | } |
507 | 543 | ||
508 | |||
509 | /** | 544 | /** |
510 | * bus_remove_driver - delete driver from bus's knowledge. | 545 | * bus_remove_driver - delete driver from bus's knowledge. |
511 | * @drv: driver. | 546 | * @drv: driver. |
@@ -531,16 +566,21 @@ void bus_remove_driver(struct device_driver * drv) | |||
531 | 566 | ||
532 | 567 | ||
533 | /* Helper for bus_rescan_devices's iter */ | 568 | /* Helper for bus_rescan_devices's iter */ |
534 | static int bus_rescan_devices_helper(struct device *dev, void *data) | 569 | static int __must_check bus_rescan_devices_helper(struct device *dev, |
570 | void *data) | ||
535 | { | 571 | { |
572 | int ret = 0; | ||
573 | |||
536 | if (!dev->driver) { | 574 | if (!dev->driver) { |
537 | if (dev->parent) /* Needed for USB */ | 575 | if (dev->parent) /* Needed for USB */ |
538 | down(&dev->parent->sem); | 576 | down(&dev->parent->sem); |
539 | device_attach(dev); | 577 | ret = device_attach(dev); |
540 | if (dev->parent) | 578 | if (dev->parent) |
541 | up(&dev->parent->sem); | 579 | up(&dev->parent->sem); |
580 | if (ret > 0) | ||
581 | ret = 0; | ||
542 | } | 582 | } |
543 | return 0; | 583 | return ret < 0 ? ret : 0; |
544 | } | 584 | } |
545 | 585 | ||
546 | /** | 586 | /** |
@@ -551,9 +591,9 @@ static int bus_rescan_devices_helper(struct device *dev, void *data) | |||
551 | * attached and rescan it against existing drivers to see if it matches | 591 | * attached and rescan it against existing drivers to see if it matches |
552 | * any by calling device_attach() for the unbound devices. | 592 | * any by calling device_attach() for the unbound devices. |
553 | */ | 593 | */ |
554 | void bus_rescan_devices(struct bus_type * bus) | 594 | int bus_rescan_devices(struct bus_type * bus) |
555 | { | 595 | { |
556 | bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); | 596 | return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); |
557 | } | 597 | } |
558 | 598 | ||
559 | /** | 599 | /** |
@@ -565,7 +605,7 @@ void bus_rescan_devices(struct bus_type * bus) | |||
565 | * to use if probing criteria changed during a devices lifetime and | 605 | * to use if probing criteria changed during a devices lifetime and |
566 | * driver attachment should change accordingly. | 606 | * driver attachment should change accordingly. |
567 | */ | 607 | */ |
568 | void device_reprobe(struct device *dev) | 608 | int device_reprobe(struct device *dev) |
569 | { | 609 | { |
570 | if (dev->driver) { | 610 | if (dev->driver) { |
571 | if (dev->parent) /* Needed for USB */ | 611 | if (dev->parent) /* Needed for USB */ |
@@ -574,14 +614,14 @@ void device_reprobe(struct device *dev) | |||
574 | if (dev->parent) | 614 | if (dev->parent) |
575 | up(&dev->parent->sem); | 615 | up(&dev->parent->sem); |
576 | } | 616 | } |
577 | 617 | return bus_rescan_devices_helper(dev, NULL); | |
578 | bus_rescan_devices_helper(dev, NULL); | ||
579 | } | 618 | } |
580 | EXPORT_SYMBOL_GPL(device_reprobe); | 619 | EXPORT_SYMBOL_GPL(device_reprobe); |
581 | 620 | ||
582 | struct bus_type * get_bus(struct bus_type * bus) | 621 | struct bus_type *get_bus(struct bus_type *bus) |
583 | { | 622 | { |
584 | return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL; | 623 | return bus ? container_of(subsys_get(&bus->subsys), |
624 | struct bus_type, subsys) : NULL; | ||
585 | } | 625 | } |
586 | 626 | ||
587 | void put_bus(struct bus_type * bus) | 627 | void put_bus(struct bus_type * bus) |
@@ -599,12 +639,13 @@ void put_bus(struct bus_type * bus) | |||
599 | * | 639 | * |
600 | * Note that kset_find_obj increments bus' reference count. | 640 | * Note that kset_find_obj increments bus' reference count. |
601 | */ | 641 | */ |
602 | 642 | #if 0 | |
603 | struct bus_type * find_bus(char * name) | 643 | struct bus_type * find_bus(char * name) |
604 | { | 644 | { |
605 | struct kobject * k = kset_find_obj(&bus_subsys.kset, name); | 645 | struct kobject * k = kset_find_obj(&bus_subsys.kset, name); |
606 | return k ? to_bus(k) : NULL; | 646 | return k ? to_bus(k) : NULL; |
607 | } | 647 | } |
648 | #endif /* 0 */ | ||
608 | 649 | ||
609 | 650 | ||
610 | /** | 651 | /** |
@@ -655,22 +696,6 @@ static void klist_devices_put(struct klist_node *n) | |||
655 | put_device(dev); | 696 | put_device(dev); |
656 | } | 697 | } |
657 | 698 | ||
658 | static void klist_drivers_get(struct klist_node *n) | ||
659 | { | ||
660 | struct device_driver *drv = container_of(n, struct device_driver, | ||
661 | knode_bus); | ||
662 | |||
663 | get_driver(drv); | ||
664 | } | ||
665 | |||
666 | static void klist_drivers_put(struct klist_node *n) | ||
667 | { | ||
668 | struct device_driver *drv = container_of(n, struct device_driver, | ||
669 | knode_bus); | ||
670 | |||
671 | put_driver(drv); | ||
672 | } | ||
673 | |||
674 | /** | 699 | /** |
675 | * bus_register - register a bus with the system. | 700 | * bus_register - register a bus with the system. |
676 | * @bus: bus. | 701 | * @bus: bus. |
@@ -706,7 +731,7 @@ int bus_register(struct bus_type * bus) | |||
706 | goto bus_drivers_fail; | 731 | goto bus_drivers_fail; |
707 | 732 | ||
708 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); | 733 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); |
709 | klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); | 734 | klist_init(&bus->klist_drivers, NULL, NULL); |
710 | bus_add_attrs(bus); | 735 | bus_add_attrs(bus); |
711 | 736 | ||
712 | pr_debug("bus type '%s' registered\n", bus->name); | 737 | pr_debug("bus type '%s' registered\n", bus->name); |
diff --git a/drivers/base/class.c b/drivers/base/class.c index 9aa127460262..b32b77ff2dcd 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -10,7 +10,6 @@ | |||
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/config.h> | ||
14 | #include <linux/device.h> | 13 | #include <linux/device.h> |
15 | #include <linux/module.h> | 14 | #include <linux/module.h> |
16 | #include <linux/init.h> | 15 | #include <linux/init.h> |
@@ -20,6 +19,8 @@ | |||
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include "base.h" | 20 | #include "base.h" |
22 | 21 | ||
22 | extern struct subsystem devices_subsys; | ||
23 | |||
23 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 24 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
24 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) | 25 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) |
25 | 26 | ||
@@ -198,7 +199,7 @@ static int class_device_create_uevent(struct class_device *class_dev, | |||
198 | * Note, the pointer created here is to be destroyed when finished by | 199 | * Note, the pointer created here is to be destroyed when finished by |
199 | * making a call to class_destroy(). | 200 | * making a call to class_destroy(). |
200 | */ | 201 | */ |
201 | struct class *class_create(struct module *owner, char *name) | 202 | struct class *class_create(struct module *owner, const char *name) |
202 | { | 203 | { |
203 | struct class *cls; | 204 | struct class *cls; |
204 | int retval; | 205 | int retval; |
@@ -227,7 +228,7 @@ error: | |||
227 | 228 | ||
228 | /** | 229 | /** |
229 | * class_destroy - destroys a struct class structure | 230 | * class_destroy - destroys a struct class structure |
230 | * @cs: pointer to the struct class that is to be destroyed | 231 | * @cls: pointer to the struct class that is to be destroyed |
231 | * | 232 | * |
232 | * Note, the pointer to be destroyed must have been created with a call | 233 | * Note, the pointer to be destroyed must have been created with a call |
233 | * to class_create(). | 234 | * to class_create(). |
@@ -362,7 +363,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
362 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); | 363 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); |
363 | 364 | ||
364 | if (class_dev->dev) { | 365 | if (class_dev->dev) { |
365 | /* add physical device, backing this device */ | 366 | /* add device, backing this class device (deprecated) */ |
366 | struct device *dev = class_dev->dev; | 367 | struct device *dev = class_dev->dev; |
367 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); | 368 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); |
368 | 369 | ||
@@ -657,9 +658,9 @@ int class_device_register(struct class_device *class_dev) | |||
657 | 658 | ||
658 | /** | 659 | /** |
659 | * class_device_create - creates a class device and registers it with sysfs | 660 | * class_device_create - creates a class device and registers it with sysfs |
660 | * @cs: pointer to the struct class that this device should be registered to. | 661 | * @cls: pointer to the struct class that this device should be registered to. |
661 | * @parent: pointer to the parent struct class_device of this new device, if any. | 662 | * @parent: pointer to the parent struct class_device of this new device, if any. |
662 | * @dev: the dev_t for the char device to be added. | 663 | * @devt: the dev_t for the char device to be added. |
663 | * @device: a pointer to a struct device that is assiociated with this class device. | 664 | * @device: a pointer to a struct device that is assiociated with this class device. |
664 | * @fmt: string for the class device's name | 665 | * @fmt: string for the class device's name |
665 | * | 666 | * |
@@ -680,7 +681,8 @@ int class_device_register(struct class_device *class_dev) | |||
680 | struct class_device *class_device_create(struct class *cls, | 681 | struct class_device *class_device_create(struct class *cls, |
681 | struct class_device *parent, | 682 | struct class_device *parent, |
682 | dev_t devt, | 683 | dev_t devt, |
683 | struct device *device, char *fmt, ...) | 684 | struct device *device, |
685 | const char *fmt, ...) | ||
684 | { | 686 | { |
685 | va_list args; | 687 | va_list args; |
686 | struct class_device *class_dev = NULL; | 688 | struct class_device *class_dev = NULL; |
@@ -764,7 +766,7 @@ void class_device_unregister(struct class_device *class_dev) | |||
764 | /** | 766 | /** |
765 | * class_device_destroy - removes a class device that was created with class_device_create() | 767 | * class_device_destroy - removes a class device that was created with class_device_create() |
766 | * @cls: the pointer to the struct class that this device was registered * with. | 768 | * @cls: the pointer to the struct class that this device was registered * with. |
767 | * @dev: the dev_t of the device that was previously registered. | 769 | * @devt: the dev_t of the device that was previously registered. |
768 | * | 770 | * |
769 | * This call unregisters and cleans up a class device that was created with a | 771 | * This call unregisters and cleans up a class device that was created with a |
770 | * call to class_device_create() | 772 | * call to class_device_create() |
@@ -840,6 +842,7 @@ int class_interface_register(struct class_interface *class_intf) | |||
840 | { | 842 | { |
841 | struct class *parent; | 843 | struct class *parent; |
842 | struct class_device *class_dev; | 844 | struct class_device *class_dev; |
845 | struct device *dev; | ||
843 | 846 | ||
844 | if (!class_intf || !class_intf->class) | 847 | if (!class_intf || !class_intf->class) |
845 | return -ENODEV; | 848 | return -ENODEV; |
@@ -854,6 +857,10 @@ int class_interface_register(struct class_interface *class_intf) | |||
854 | list_for_each_entry(class_dev, &parent->children, node) | 857 | list_for_each_entry(class_dev, &parent->children, node) |
855 | class_intf->add(class_dev, class_intf); | 858 | class_intf->add(class_dev, class_intf); |
856 | } | 859 | } |
860 | if (class_intf->add_dev) { | ||
861 | list_for_each_entry(dev, &parent->devices, node) | ||
862 | class_intf->add_dev(dev, class_intf); | ||
863 | } | ||
857 | up(&parent->sem); | 864 | up(&parent->sem); |
858 | 865 | ||
859 | return 0; | 866 | return 0; |
@@ -863,6 +870,7 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
863 | { | 870 | { |
864 | struct class * parent = class_intf->class; | 871 | struct class * parent = class_intf->class; |
865 | struct class_device *class_dev; | 872 | struct class_device *class_dev; |
873 | struct device *dev; | ||
866 | 874 | ||
867 | if (!parent) | 875 | if (!parent) |
868 | return; | 876 | return; |
@@ -873,12 +881,31 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
873 | list_for_each_entry(class_dev, &parent->children, node) | 881 | list_for_each_entry(class_dev, &parent->children, node) |
874 | class_intf->remove(class_dev, class_intf); | 882 | class_intf->remove(class_dev, class_intf); |
875 | } | 883 | } |
884 | if (class_intf->remove_dev) { | ||
885 | list_for_each_entry(dev, &parent->devices, node) | ||
886 | class_intf->remove_dev(dev, class_intf); | ||
887 | } | ||
876 | up(&parent->sem); | 888 | up(&parent->sem); |
877 | 889 | ||
878 | class_put(parent); | 890 | class_put(parent); |
879 | } | 891 | } |
880 | 892 | ||
893 | int virtual_device_parent(struct device *dev) | ||
894 | { | ||
895 | if (!dev->class) | ||
896 | return -ENODEV; | ||
897 | |||
898 | if (!dev->class->virtual_dir) { | ||
899 | static struct kobject *virtual_dir = NULL; | ||
900 | |||
901 | if (!virtual_dir) | ||
902 | virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual"); | ||
903 | dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name); | ||
904 | } | ||
881 | 905 | ||
906 | dev->kobj.parent = dev->class->virtual_dir; | ||
907 | return 0; | ||
908 | } | ||
882 | 909 | ||
883 | int __init classes_init(void) | 910 | int __init classes_init(void) |
884 | { | 911 | { |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 27c2176895de..b224bb43ff63 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -3,12 +3,13 @@ | |||
3 | * | 3 | * |
4 | * Copyright (c) 2002-3 Patrick Mochel | 4 | * Copyright (c) 2002-3 Patrick Mochel |
5 | * Copyright (c) 2002-3 Open Source Development Labs | 5 | * Copyright (c) 2002-3 Open Source Development Labs |
6 | * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de> | ||
7 | * Copyright (c) 2006 Novell, Inc. | ||
6 | * | 8 | * |
7 | * This file is released under the GPLv2 | 9 | * This file is released under the GPLv2 |
8 | * | 10 | * |
9 | */ | 11 | */ |
10 | 12 | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/device.h> | 13 | #include <linux/device.h> |
13 | #include <linux/err.h> | 14 | #include <linux/err.h> |
14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
@@ -93,6 +94,8 @@ static void device_release(struct kobject * kobj) | |||
93 | 94 | ||
94 | if (dev->release) | 95 | if (dev->release) |
95 | dev->release(dev); | 96 | dev->release(dev); |
97 | else if (dev->class && dev->class->dev_release) | ||
98 | dev->class->dev_release(dev); | ||
96 | else { | 99 | else { |
97 | printk(KERN_ERR "Device '%s' does not have a release() function, " | 100 | printk(KERN_ERR "Device '%s' does not have a release() function, " |
98 | "it is broken and must be fixed.\n", | 101 | "it is broken and must be fixed.\n", |
@@ -150,17 +153,21 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
150 | "MINOR=%u", MINOR(dev->devt)); | 153 | "MINOR=%u", MINOR(dev->devt)); |
151 | } | 154 | } |
152 | 155 | ||
153 | /* add bus name of physical device */ | 156 | /* add bus name (same as SUBSYSTEM, deprecated) */ |
154 | if (dev->bus) | 157 | if (dev->bus) |
155 | add_uevent_var(envp, num_envp, &i, | 158 | add_uevent_var(envp, num_envp, &i, |
156 | buffer, buffer_size, &length, | 159 | buffer, buffer_size, &length, |
157 | "PHYSDEVBUS=%s", dev->bus->name); | 160 | "PHYSDEVBUS=%s", dev->bus->name); |
158 | 161 | ||
159 | /* add driver name of physical device */ | 162 | /* add driver name (PHYSDEV* values are deprecated)*/ |
160 | if (dev->driver) | 163 | if (dev->driver) { |
164 | add_uevent_var(envp, num_envp, &i, | ||
165 | buffer, buffer_size, &length, | ||
166 | "DRIVER=%s", dev->driver->name); | ||
161 | add_uevent_var(envp, num_envp, &i, | 167 | add_uevent_var(envp, num_envp, &i, |
162 | buffer, buffer_size, &length, | 168 | buffer, buffer_size, &length, |
163 | "PHYSDEVDRIVER=%s", dev->driver->name); | 169 | "PHYSDEVDRIVER=%s", dev->driver->name); |
170 | } | ||
164 | 171 | ||
165 | /* terminate, set to next free slot, shrink available space */ | 172 | /* terminate, set to next free slot, shrink available space */ |
166 | envp[i] = NULL; | 173 | envp[i] = NULL; |
@@ -178,6 +185,15 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
178 | } | 185 | } |
179 | } | 186 | } |
180 | 187 | ||
188 | if (dev->class && dev->class->dev_uevent) { | ||
189 | /* have the class specific function add its stuff */ | ||
190 | retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size); | ||
191 | if (retval) { | ||
192 | pr_debug("%s - dev_uevent() returned %d\n", | ||
193 | __FUNCTION__, retval); | ||
194 | } | ||
195 | } | ||
196 | |||
181 | return retval; | 197 | return retval; |
182 | } | 198 | } |
183 | 199 | ||
@@ -194,6 +210,72 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | |||
194 | return count; | 210 | return count; |
195 | } | 211 | } |
196 | 212 | ||
213 | static int device_add_groups(struct device *dev) | ||
214 | { | ||
215 | int i; | ||
216 | int error = 0; | ||
217 | |||
218 | if (dev->groups) { | ||
219 | for (i = 0; dev->groups[i]; i++) { | ||
220 | error = sysfs_create_group(&dev->kobj, dev->groups[i]); | ||
221 | if (error) { | ||
222 | while (--i >= 0) | ||
223 | sysfs_remove_group(&dev->kobj, dev->groups[i]); | ||
224 | goto out; | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | out: | ||
229 | return error; | ||
230 | } | ||
231 | |||
232 | static void device_remove_groups(struct device *dev) | ||
233 | { | ||
234 | int i; | ||
235 | if (dev->groups) { | ||
236 | for (i = 0; dev->groups[i]; i++) { | ||
237 | sysfs_remove_group(&dev->kobj, dev->groups[i]); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | static int device_add_attrs(struct device *dev) | ||
243 | { | ||
244 | struct class *class = dev->class; | ||
245 | int error = 0; | ||
246 | int i; | ||
247 | |||
248 | if (!class) | ||
249 | return 0; | ||
250 | |||
251 | if (class->dev_attrs) { | ||
252 | for (i = 0; attr_name(class->dev_attrs[i]); i++) { | ||
253 | error = device_create_file(dev, &class->dev_attrs[i]); | ||
254 | if (error) | ||
255 | break; | ||
256 | } | ||
257 | } | ||
258 | if (error) | ||
259 | while (--i >= 0) | ||
260 | device_remove_file(dev, &class->dev_attrs[i]); | ||
261 | return error; | ||
262 | } | ||
263 | |||
264 | static void device_remove_attrs(struct device *dev) | ||
265 | { | ||
266 | struct class *class = dev->class; | ||
267 | int i; | ||
268 | |||
269 | if (!class) | ||
270 | return; | ||
271 | |||
272 | if (class->dev_attrs) { | ||
273 | for (i = 0; attr_name(class->dev_attrs[i]); i++) | ||
274 | device_remove_file(dev, &class->dev_attrs[i]); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | |||
197 | static ssize_t show_dev(struct device *dev, struct device_attribute *attr, | 279 | static ssize_t show_dev(struct device *dev, struct device_attribute *attr, |
198 | char *buf) | 280 | char *buf) |
199 | { | 281 | { |
@@ -237,6 +319,32 @@ void device_remove_file(struct device * dev, struct device_attribute * attr) | |||
237 | } | 319 | } |
238 | } | 320 | } |
239 | 321 | ||
322 | /** | ||
323 | * device_create_bin_file - create sysfs binary attribute file for device. | ||
324 | * @dev: device. | ||
325 | * @attr: device binary attribute descriptor. | ||
326 | */ | ||
327 | int device_create_bin_file(struct device *dev, struct bin_attribute *attr) | ||
328 | { | ||
329 | int error = -EINVAL; | ||
330 | if (dev) | ||
331 | error = sysfs_create_bin_file(&dev->kobj, attr); | ||
332 | return error; | ||
333 | } | ||
334 | EXPORT_SYMBOL_GPL(device_create_bin_file); | ||
335 | |||
336 | /** | ||
337 | * device_remove_bin_file - remove sysfs binary attribute file | ||
338 | * @dev: device. | ||
339 | * @attr: device binary attribute descriptor. | ||
340 | */ | ||
341 | void device_remove_bin_file(struct device *dev, struct bin_attribute *attr) | ||
342 | { | ||
343 | if (dev) | ||
344 | sysfs_remove_bin_file(&dev->kobj, attr); | ||
345 | } | ||
346 | EXPORT_SYMBOL_GPL(device_remove_bin_file); | ||
347 | |||
240 | static void klist_children_get(struct klist_node *n) | 348 | static void klist_children_get(struct klist_node *n) |
241 | { | 349 | { |
242 | struct device *dev = container_of(n, struct device, knode_parent); | 350 | struct device *dev = container_of(n, struct device, knode_parent); |
@@ -290,12 +398,20 @@ int device_add(struct device *dev) | |||
290 | { | 398 | { |
291 | struct device *parent = NULL; | 399 | struct device *parent = NULL; |
292 | char *class_name = NULL; | 400 | char *class_name = NULL; |
401 | struct class_interface *class_intf; | ||
293 | int error = -EINVAL; | 402 | int error = -EINVAL; |
294 | 403 | ||
295 | dev = get_device(dev); | 404 | dev = get_device(dev); |
296 | if (!dev || !strlen(dev->bus_id)) | 405 | if (!dev || !strlen(dev->bus_id)) |
297 | goto Error; | 406 | goto Error; |
298 | 407 | ||
408 | /* if this is a class device, and has no parent, create one */ | ||
409 | if ((dev->class) && (dev->parent == NULL)) { | ||
410 | error = virtual_device_parent(dev); | ||
411 | if (error) | ||
412 | goto Error; | ||
413 | } | ||
414 | |||
299 | parent = get_device(dev->parent); | 415 | parent = get_device(dev->parent); |
300 | 416 | ||
301 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); | 417 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); |
@@ -308,6 +424,10 @@ int device_add(struct device *dev) | |||
308 | if ((error = kobject_add(&dev->kobj))) | 424 | if ((error = kobject_add(&dev->kobj))) |
309 | goto Error; | 425 | goto Error; |
310 | 426 | ||
427 | /* notify platform of device entry */ | ||
428 | if (platform_notify) | ||
429 | platform_notify(dev); | ||
430 | |||
311 | dev->uevent_attr.attr.name = "uevent"; | 431 | dev->uevent_attr.attr.name = "uevent"; |
312 | dev->uevent_attr.attr.mode = S_IWUSR; | 432 | dev->uevent_attr.attr.mode = S_IWUSR; |
313 | if (dev->driver) | 433 | if (dev->driver) |
@@ -341,12 +461,17 @@ int device_add(struct device *dev) | |||
341 | "subsystem"); | 461 | "subsystem"); |
342 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, | 462 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, |
343 | dev->bus_id); | 463 | dev->bus_id); |
344 | 464 | if (parent) { | |
345 | sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); | 465 | sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); |
346 | class_name = make_class_name(dev->class->name, &dev->kobj); | 466 | class_name = make_class_name(dev->class->name, &dev->kobj); |
347 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); | 467 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); |
468 | } | ||
348 | } | 469 | } |
349 | 470 | ||
471 | if ((error = device_add_attrs(dev))) | ||
472 | goto AttrsError; | ||
473 | if ((error = device_add_groups(dev))) | ||
474 | goto GroupError; | ||
350 | if ((error = device_pm_add(dev))) | 475 | if ((error = device_pm_add(dev))) |
351 | goto PMError; | 476 | goto PMError; |
352 | if ((error = bus_add_device(dev))) | 477 | if ((error = bus_add_device(dev))) |
@@ -357,15 +482,16 @@ int device_add(struct device *dev) | |||
357 | klist_add_tail(&dev->knode_parent, &parent->klist_children); | 482 | klist_add_tail(&dev->knode_parent, &parent->klist_children); |
358 | 483 | ||
359 | if (dev->class) { | 484 | if (dev->class) { |
360 | /* tie the class to the device */ | ||
361 | down(&dev->class->sem); | 485 | down(&dev->class->sem); |
486 | /* tie the class to the device */ | ||
362 | list_add_tail(&dev->node, &dev->class->devices); | 487 | list_add_tail(&dev->node, &dev->class->devices); |
488 | |||
489 | /* notify any interfaces that the device is here */ | ||
490 | list_for_each_entry(class_intf, &dev->class->interfaces, node) | ||
491 | if (class_intf->add_dev) | ||
492 | class_intf->add_dev(dev, class_intf); | ||
363 | up(&dev->class->sem); | 493 | up(&dev->class->sem); |
364 | } | 494 | } |
365 | |||
366 | /* notify platform of device entry */ | ||
367 | if (platform_notify) | ||
368 | platform_notify(dev); | ||
369 | Done: | 495 | Done: |
370 | kfree(class_name); | 496 | kfree(class_name); |
371 | put_device(dev); | 497 | put_device(dev); |
@@ -373,6 +499,10 @@ int device_add(struct device *dev) | |||
373 | BusError: | 499 | BusError: |
374 | device_pm_remove(dev); | 500 | device_pm_remove(dev); |
375 | PMError: | 501 | PMError: |
502 | device_remove_groups(dev); | ||
503 | GroupError: | ||
504 | device_remove_attrs(dev); | ||
505 | AttrsError: | ||
376 | if (dev->devt_attr) { | 506 | if (dev->devt_attr) { |
377 | device_remove_file(dev, dev->devt_attr); | 507 | device_remove_file(dev, dev->devt_attr); |
378 | kfree(dev->devt_attr); | 508 | kfree(dev->devt_attr); |
@@ -450,6 +580,7 @@ void device_del(struct device * dev) | |||
450 | { | 580 | { |
451 | struct device * parent = dev->parent; | 581 | struct device * parent = dev->parent; |
452 | char *class_name = NULL; | 582 | char *class_name = NULL; |
583 | struct class_interface *class_intf; | ||
453 | 584 | ||
454 | if (parent) | 585 | if (parent) |
455 | klist_del(&dev->knode_parent); | 586 | klist_del(&dev->knode_parent); |
@@ -459,14 +590,23 @@ void device_del(struct device * dev) | |||
459 | sysfs_remove_link(&dev->kobj, "subsystem"); | 590 | sysfs_remove_link(&dev->kobj, "subsystem"); |
460 | sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); | 591 | sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); |
461 | class_name = make_class_name(dev->class->name, &dev->kobj); | 592 | class_name = make_class_name(dev->class->name, &dev->kobj); |
462 | sysfs_remove_link(&dev->kobj, "device"); | 593 | if (parent) { |
463 | sysfs_remove_link(&dev->parent->kobj, class_name); | 594 | sysfs_remove_link(&dev->kobj, "device"); |
595 | sysfs_remove_link(&dev->parent->kobj, class_name); | ||
596 | } | ||
464 | kfree(class_name); | 597 | kfree(class_name); |
465 | down(&dev->class->sem); | 598 | down(&dev->class->sem); |
599 | /* notify any interfaces that the device is now gone */ | ||
600 | list_for_each_entry(class_intf, &dev->class->interfaces, node) | ||
601 | if (class_intf->remove_dev) | ||
602 | class_intf->remove_dev(dev, class_intf); | ||
603 | /* remove the device from the class list */ | ||
466 | list_del_init(&dev->node); | 604 | list_del_init(&dev->node); |
467 | up(&dev->class->sem); | 605 | up(&dev->class->sem); |
468 | } | 606 | } |
469 | device_remove_file(dev, &dev->uevent_attr); | 607 | device_remove_file(dev, &dev->uevent_attr); |
608 | device_remove_groups(dev); | ||
609 | device_remove_attrs(dev); | ||
470 | 610 | ||
471 | /* Notify the platform of the removal, in case they | 611 | /* Notify the platform of the removal, in case they |
472 | * need to do anything... | 612 | * need to do anything... |
@@ -560,27 +700,27 @@ static void device_create_release(struct device *dev) | |||
560 | 700 | ||
561 | /** | 701 | /** |
562 | * device_create - creates a device and registers it with sysfs | 702 | * device_create - creates a device and registers it with sysfs |
563 | * @cs: pointer to the struct class that this device should be registered to. | 703 | * @class: pointer to the struct class that this device should be registered to |
564 | * @parent: pointer to the parent struct device of this new device, if any. | 704 | * @parent: pointer to the parent struct device of this new device, if any |
565 | * @dev: the dev_t for the char device to be added. | 705 | * @devt: the dev_t for the char device to be added |
566 | * @fmt: string for the class device's name | 706 | * @fmt: string for the device's name |
707 | * | ||
708 | * This function can be used by char device classes. A struct device | ||
709 | * will be created in sysfs, registered to the specified class. | ||
567 | * | 710 | * |
568 | * This function can be used by char device classes. A struct | ||
569 | * device will be created in sysfs, registered to the specified | ||
570 | * class. | ||
571 | * A "dev" file will be created, showing the dev_t for the device, if | 711 | * A "dev" file will be created, showing the dev_t for the device, if |
572 | * the dev_t is not 0,0. | 712 | * the dev_t is not 0,0. |
573 | * If a pointer to a parent struct device is passed in, the newly | 713 | * If a pointer to a parent struct device is passed in, the newly created |
574 | * created struct device will be a child of that device in sysfs. The | 714 | * struct device will be a child of that device in sysfs. |
575 | * pointer to the struct device will be returned from the call. Any | 715 | * The pointer to the struct device will be returned from the call. |
576 | * further sysfs files that might be required can be created using this | 716 | * Any further sysfs files that might be required can be created using this |
577 | * pointer. | 717 | * pointer. |
578 | * | 718 | * |
579 | * Note: the struct class passed to this function must have previously | 719 | * Note: the struct class passed to this function must have previously |
580 | * been created with a call to class_create(). | 720 | * been created with a call to class_create(). |
581 | */ | 721 | */ |
582 | struct device *device_create(struct class *class, struct device *parent, | 722 | struct device *device_create(struct class *class, struct device *parent, |
583 | dev_t devt, char *fmt, ...) | 723 | dev_t devt, const char *fmt, ...) |
584 | { | 724 | { |
585 | va_list args; | 725 | va_list args; |
586 | struct device *dev = NULL; | 726 | struct device *dev = NULL; |
@@ -588,10 +728,6 @@ struct device *device_create(struct class *class, struct device *parent, | |||
588 | 728 | ||
589 | if (class == NULL || IS_ERR(class)) | 729 | if (class == NULL || IS_ERR(class)) |
590 | goto error; | 730 | goto error; |
591 | if (parent == NULL) { | ||
592 | printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__); | ||
593 | goto error; | ||
594 | } | ||
595 | 731 | ||
596 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 732 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
597 | if (!dev) { | 733 | if (!dev) { |
@@ -621,11 +757,11 @@ EXPORT_SYMBOL_GPL(device_create); | |||
621 | 757 | ||
622 | /** | 758 | /** |
623 | * device_destroy - removes a device that was created with device_create() | 759 | * device_destroy - removes a device that was created with device_create() |
624 | * @class: the pointer to the struct class that this device was registered * with. | 760 | * @class: pointer to the struct class that this device was registered with |
625 | * @dev: the dev_t of the device that was previously registered. | 761 | * @devt: the dev_t of the device that was previously registered |
626 | * | 762 | * |
627 | * This call unregisters and cleans up a class device that was created with a | 763 | * This call unregisters and cleans up a device that was created with a |
628 | * call to class_device_create() | 764 | * call to device_create(). |
629 | */ | 765 | */ |
630 | void device_destroy(struct class *class, dev_t devt) | 766 | void device_destroy(struct class *class, dev_t devt) |
631 | { | 767 | { |
@@ -645,3 +781,58 @@ void device_destroy(struct class *class, dev_t devt) | |||
645 | device_unregister(dev); | 781 | device_unregister(dev); |
646 | } | 782 | } |
647 | EXPORT_SYMBOL_GPL(device_destroy); | 783 | EXPORT_SYMBOL_GPL(device_destroy); |
784 | |||
785 | /** | ||
786 | * device_rename - renames a device | ||
787 | * @dev: the pointer to the struct device to be renamed | ||
788 | * @new_name: the new name of the device | ||
789 | */ | ||
790 | int device_rename(struct device *dev, char *new_name) | ||
791 | { | ||
792 | char *old_class_name = NULL; | ||
793 | char *new_class_name = NULL; | ||
794 | char *old_symlink_name = NULL; | ||
795 | int error; | ||
796 | |||
797 | dev = get_device(dev); | ||
798 | if (!dev) | ||
799 | return -EINVAL; | ||
800 | |||
801 | pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name); | ||
802 | |||
803 | if ((dev->class) && (dev->parent)) | ||
804 | old_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
805 | |||
806 | if (dev->class) { | ||
807 | old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL); | ||
808 | if (!old_symlink_name) | ||
809 | return -ENOMEM; | ||
810 | strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE); | ||
811 | } | ||
812 | |||
813 | strlcpy(dev->bus_id, new_name, BUS_ID_SIZE); | ||
814 | |||
815 | error = kobject_rename(&dev->kobj, new_name); | ||
816 | |||
817 | if (old_class_name) { | ||
818 | new_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
819 | if (new_class_name) { | ||
820 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, | ||
821 | new_class_name); | ||
822 | sysfs_remove_link(&dev->parent->kobj, old_class_name); | ||
823 | } | ||
824 | } | ||
825 | if (dev->class) { | ||
826 | sysfs_remove_link(&dev->class->subsys.kset.kobj, | ||
827 | old_symlink_name); | ||
828 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, | ||
829 | dev->bus_id); | ||
830 | } | ||
831 | put_device(dev); | ||
832 | |||
833 | kfree(old_class_name); | ||
834 | kfree(new_class_name); | ||
835 | kfree(old_symlink_name); | ||
836 | |||
837 | return error; | ||
838 | } | ||
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index dd712b24ec91..4bef76a2f3f2 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/cpu.h> | 8 | #include <linux/cpu.h> |
9 | #include <linux/topology.h> | 9 | #include <linux/topology.h> |
10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
11 | #include <linux/node.h> | ||
11 | 12 | ||
12 | #include "base.h" | 13 | #include "base.h" |
13 | 14 | ||
@@ -57,13 +58,12 @@ static void __devinit register_cpu_control(struct cpu *cpu) | |||
57 | { | 58 | { |
58 | sysdev_create_file(&cpu->sysdev, &attr_online); | 59 | sysdev_create_file(&cpu->sysdev, &attr_online); |
59 | } | 60 | } |
60 | void unregister_cpu(struct cpu *cpu, struct node *root) | 61 | void unregister_cpu(struct cpu *cpu) |
61 | { | 62 | { |
62 | int logical_cpu = cpu->sysdev.id; | 63 | int logical_cpu = cpu->sysdev.id; |
63 | 64 | ||
64 | if (root) | 65 | unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu)); |
65 | sysfs_remove_link(&root->sysdev.kobj, | 66 | |
66 | kobject_name(&cpu->sysdev.kobj)); | ||
67 | sysdev_remove_file(&cpu->sysdev, &attr_online); | 67 | sysdev_remove_file(&cpu->sysdev, &attr_online); |
68 | 68 | ||
69 | sysdev_unregister(&cpu->sysdev); | 69 | sysdev_unregister(&cpu->sysdev); |
@@ -109,23 +109,21 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL); | |||
109 | * | 109 | * |
110 | * Initialize and register the CPU device. | 110 | * Initialize and register the CPU device. |
111 | */ | 111 | */ |
112 | int __devinit register_cpu(struct cpu *cpu, int num, struct node *root) | 112 | int __devinit register_cpu(struct cpu *cpu, int num) |
113 | { | 113 | { |
114 | int error; | 114 | int error; |
115 | |||
116 | cpu->node_id = cpu_to_node(num); | 115 | cpu->node_id = cpu_to_node(num); |
117 | cpu->sysdev.id = num; | 116 | cpu->sysdev.id = num; |
118 | cpu->sysdev.cls = &cpu_sysdev_class; | 117 | cpu->sysdev.cls = &cpu_sysdev_class; |
119 | 118 | ||
120 | error = sysdev_register(&cpu->sysdev); | 119 | error = sysdev_register(&cpu->sysdev); |
121 | if (!error && root) | 120 | |
122 | error = sysfs_create_link(&root->sysdev.kobj, | ||
123 | &cpu->sysdev.kobj, | ||
124 | kobject_name(&cpu->sysdev.kobj)); | ||
125 | if (!error && !cpu->no_control) | 121 | if (!error && !cpu->no_control) |
126 | register_cpu_control(cpu); | 122 | register_cpu_control(cpu); |
127 | if (!error) | 123 | if (!error) |
128 | cpu_sys_devices[num] = &cpu->sysdev; | 124 | cpu_sys_devices[num] = &cpu->sysdev; |
125 | if (!error) | ||
126 | register_cpu_under_node(num, cpu_to_node(num)); | ||
129 | 127 | ||
130 | #ifdef CONFIG_KEXEC | 128 | #ifdef CONFIG_KEXEC |
131 | if (!error) | 129 | if (!error) |
@@ -145,5 +143,13 @@ EXPORT_SYMBOL_GPL(get_cpu_sysdev); | |||
145 | 143 | ||
146 | int __init cpu_dev_init(void) | 144 | int __init cpu_dev_init(void) |
147 | { | 145 | { |
148 | return sysdev_class_register(&cpu_sysdev_class); | 146 | int err; |
147 | |||
148 | err = sysdev_class_register(&cpu_sysdev_class); | ||
149 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | ||
150 | if (!err) | ||
151 | err = sched_create_sysfs_power_savings_entries(&cpu_sysdev_class); | ||
152 | #endif | ||
153 | |||
154 | return err; | ||
149 | } | 155 | } |
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 889c71111239..b5f43c3e44fa 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/kthread.h> | ||
20 | 21 | ||
21 | #include "base.h" | 22 | #include "base.h" |
22 | #include "power/power.h" | 23 | #include "power/power.h" |
@@ -38,66 +39,73 @@ | |||
38 | * | 39 | * |
39 | * This function must be called with @dev->sem held. | 40 | * This function must be called with @dev->sem held. |
40 | */ | 41 | */ |
41 | void device_bind_driver(struct device * dev) | 42 | int device_bind_driver(struct device *dev) |
42 | { | 43 | { |
43 | if (klist_node_attached(&dev->knode_driver)) | 44 | int ret; |
44 | return; | 45 | |
46 | if (klist_node_attached(&dev->knode_driver)) { | ||
47 | printk(KERN_WARNING "%s: device %s already bound\n", | ||
48 | __FUNCTION__, kobject_name(&dev->kobj)); | ||
49 | return 0; | ||
50 | } | ||
45 | 51 | ||
46 | pr_debug("bound device '%s' to driver '%s'\n", | 52 | pr_debug("bound device '%s' to driver '%s'\n", |
47 | dev->bus_id, dev->driver->name); | 53 | dev->bus_id, dev->driver->name); |
48 | klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); | 54 | klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); |
49 | sysfs_create_link(&dev->driver->kobj, &dev->kobj, | 55 | ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, |
50 | kobject_name(&dev->kobj)); | 56 | kobject_name(&dev->kobj)); |
51 | sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); | 57 | if (ret == 0) { |
58 | ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, | ||
59 | "driver"); | ||
60 | if (ret) | ||
61 | sysfs_remove_link(&dev->driver->kobj, | ||
62 | kobject_name(&dev->kobj)); | ||
63 | } | ||
64 | return ret; | ||
52 | } | 65 | } |
53 | 66 | ||
54 | /** | 67 | struct stupid_thread_structure { |
55 | * driver_probe_device - attempt to bind device & driver. | 68 | struct device_driver *drv; |
56 | * @drv: driver. | 69 | struct device *dev; |
57 | * @dev: device. | 70 | }; |
58 | * | 71 | |
59 | * First, we call the bus's match function, if one present, which | 72 | static atomic_t probe_count = ATOMIC_INIT(0); |
60 | * should compare the device IDs the driver supports with the | 73 | static int really_probe(void *void_data) |
61 | * device IDs of the device. Note we don't do this ourselves | ||
62 | * because we don't know the format of the ID structures, nor what | ||
63 | * is to be considered a match and what is not. | ||
64 | * | ||
65 | * This function returns 1 if a match is found, an error if one | ||
66 | * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. | ||
67 | * | ||
68 | * This function must be called with @dev->sem held. When called | ||
69 | * for a USB interface, @dev->parent->sem must be held as well. | ||
70 | */ | ||
71 | int driver_probe_device(struct device_driver * drv, struct device * dev) | ||
72 | { | 74 | { |
75 | struct stupid_thread_structure *data = void_data; | ||
76 | struct device_driver *drv = data->drv; | ||
77 | struct device *dev = data->dev; | ||
73 | int ret = 0; | 78 | int ret = 0; |
74 | 79 | ||
75 | if (drv->bus->match && !drv->bus->match(dev, drv)) | 80 | atomic_inc(&probe_count); |
76 | goto Done; | 81 | pr_debug("%s: Probing driver %s with device %s\n", |
82 | drv->bus->name, drv->name, dev->bus_id); | ||
77 | 83 | ||
78 | pr_debug("%s: Matched Device %s with Driver %s\n", | ||
79 | drv->bus->name, dev->bus_id, drv->name); | ||
80 | dev->driver = drv; | 84 | dev->driver = drv; |
81 | if (dev->bus->probe) { | 85 | if (dev->bus->probe) { |
82 | ret = dev->bus->probe(dev); | 86 | ret = dev->bus->probe(dev); |
83 | if (ret) { | 87 | if (ret) { |
84 | dev->driver = NULL; | 88 | dev->driver = NULL; |
85 | goto ProbeFailed; | 89 | goto probe_failed; |
86 | } | 90 | } |
87 | } else if (drv->probe) { | 91 | } else if (drv->probe) { |
88 | ret = drv->probe(dev); | 92 | ret = drv->probe(dev); |
89 | if (ret) { | 93 | if (ret) { |
90 | dev->driver = NULL; | 94 | dev->driver = NULL; |
91 | goto ProbeFailed; | 95 | goto probe_failed; |
92 | } | 96 | } |
93 | } | 97 | } |
94 | device_bind_driver(dev); | 98 | if (device_bind_driver(dev)) { |
99 | printk(KERN_ERR "%s: device_bind_driver(%s) failed\n", | ||
100 | __FUNCTION__, dev->bus_id); | ||
101 | /* How does undo a ->probe? We're screwed. */ | ||
102 | } | ||
95 | ret = 1; | 103 | ret = 1; |
96 | pr_debug("%s: Bound Device %s to Driver %s\n", | 104 | pr_debug("%s: Bound Device %s to Driver %s\n", |
97 | drv->bus->name, dev->bus_id, drv->name); | 105 | drv->bus->name, dev->bus_id, drv->name); |
98 | goto Done; | 106 | goto done; |
99 | 107 | ||
100 | ProbeFailed: | 108 | probe_failed: |
101 | if (ret == -ENODEV || ret == -ENXIO) { | 109 | if (ret == -ENODEV || ret == -ENXIO) { |
102 | /* Driver matched, but didn't support device | 110 | /* Driver matched, but didn't support device |
103 | * or device not found. | 111 | * or device not found. |
@@ -110,7 +118,71 @@ int driver_probe_device(struct device_driver * drv, struct device * dev) | |||
110 | "%s: probe of %s failed with error %d\n", | 118 | "%s: probe of %s failed with error %d\n", |
111 | drv->name, dev->bus_id, ret); | 119 | drv->name, dev->bus_id, ret); |
112 | } | 120 | } |
113 | Done: | 121 | done: |
122 | kfree(data); | ||
123 | atomic_dec(&probe_count); | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * driver_probe_done | ||
129 | * Determine if the probe sequence is finished or not. | ||
130 | * | ||
131 | * Should somehow figure out how to use a semaphore, not an atomic variable... | ||
132 | */ | ||
133 | int driver_probe_done(void) | ||
134 | { | ||
135 | pr_debug("%s: probe_count = %d\n", __FUNCTION__, | ||
136 | atomic_read(&probe_count)); | ||
137 | if (atomic_read(&probe_count)) | ||
138 | return -EBUSY; | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * driver_probe_device - attempt to bind device & driver together | ||
144 | * @drv: driver to bind a device to | ||
145 | * @dev: device to try to bind to the driver | ||
146 | * | ||
147 | * First, we call the bus's match function, if one present, which should | ||
148 | * compare the device IDs the driver supports with the device IDs of the | ||
149 | * device. Note we don't do this ourselves because we don't know the | ||
150 | * format of the ID structures, nor what is to be considered a match and | ||
151 | * what is not. | ||
152 | * | ||
153 | * This function returns 1 if a match is found, an error if one occurs | ||
154 | * (that is not -ENODEV or -ENXIO), and 0 otherwise. | ||
155 | * | ||
156 | * This function must be called with @dev->sem held. When called for a | ||
157 | * USB interface, @dev->parent->sem must be held as well. | ||
158 | */ | ||
159 | int driver_probe_device(struct device_driver * drv, struct device * dev) | ||
160 | { | ||
161 | struct stupid_thread_structure *data; | ||
162 | struct task_struct *probe_task; | ||
163 | int ret = 0; | ||
164 | |||
165 | if (!device_is_registered(dev)) | ||
166 | return -ENODEV; | ||
167 | if (drv->bus->match && !drv->bus->match(dev, drv)) | ||
168 | goto done; | ||
169 | |||
170 | pr_debug("%s: Matched Device %s with Driver %s\n", | ||
171 | drv->bus->name, dev->bus_id, drv->name); | ||
172 | |||
173 | data = kmalloc(sizeof(*data), GFP_KERNEL); | ||
174 | data->drv = drv; | ||
175 | data->dev = dev; | ||
176 | |||
177 | if (drv->multithread_probe) { | ||
178 | probe_task = kthread_run(really_probe, data, | ||
179 | "probe-%s", dev->bus_id); | ||
180 | if (IS_ERR(probe_task)) | ||
181 | ret = PTR_ERR(probe_task); | ||
182 | } else | ||
183 | ret = really_probe(data); | ||
184 | |||
185 | done: | ||
114 | return ret; | 186 | return ret; |
115 | } | 187 | } |
116 | 188 | ||
@@ -139,8 +211,9 @@ int device_attach(struct device * dev) | |||
139 | 211 | ||
140 | down(&dev->sem); | 212 | down(&dev->sem); |
141 | if (dev->driver) { | 213 | if (dev->driver) { |
142 | device_bind_driver(dev); | 214 | ret = device_bind_driver(dev); |
143 | ret = 1; | 215 | if (ret == 0) |
216 | ret = 1; | ||
144 | } else | 217 | } else |
145 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); | 218 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); |
146 | up(&dev->sem); | 219 | up(&dev->sem); |
@@ -182,9 +255,9 @@ static int __driver_attach(struct device * dev, void * data) | |||
182 | * returns 0 and the @dev->driver is set, we've found a | 255 | * returns 0 and the @dev->driver is set, we've found a |
183 | * compatible pair. | 256 | * compatible pair. |
184 | */ | 257 | */ |
185 | void driver_attach(struct device_driver * drv) | 258 | int driver_attach(struct device_driver * drv) |
186 | { | 259 | { |
187 | bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); | 260 | return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); |
188 | } | 261 | } |
189 | 262 | ||
190 | /** | 263 | /** |
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c index e2f64f91ed05..33c5cce1560b 100644 --- a/drivers/base/dmapool.c +++ b/drivers/base/dmapool.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/dmapool.h> | 7 | #include <linux/dmapool.h> |
8 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/poison.h> | ||
10 | 11 | ||
11 | /* | 12 | /* |
12 | * Pool allocator ... wraps the dma_alloc_coherent page allocator, so | 13 | * Pool allocator ... wraps the dma_alloc_coherent page allocator, so |
@@ -35,8 +36,6 @@ struct dma_page { /* cacheable header for 'allocation' bytes */ | |||
35 | }; | 36 | }; |
36 | 37 | ||
37 | #define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000) | 38 | #define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000) |
38 | #define POOL_POISON_FREED 0xa7 /* !inuse */ | ||
39 | #define POOL_POISON_ALLOCATED 0xa9 /* !initted */ | ||
40 | 39 | ||
41 | static DECLARE_MUTEX (pools_lock); | 40 | static DECLARE_MUTEX (pools_lock); |
42 | 41 | ||
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index b400314e1c62..1214cbd17d86 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/device.h> | 11 | #include <linux/device.h> |
13 | #include <linux/module.h> | 12 | #include <linux/module.h> |
14 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
@@ -143,20 +142,6 @@ void put_driver(struct device_driver * drv) | |||
143 | kobject_put(&drv->kobj); | 142 | kobject_put(&drv->kobj); |
144 | } | 143 | } |
145 | 144 | ||
146 | static void klist_devices_get(struct klist_node *n) | ||
147 | { | ||
148 | struct device *dev = container_of(n, struct device, knode_driver); | ||
149 | |||
150 | get_device(dev); | ||
151 | } | ||
152 | |||
153 | static void klist_devices_put(struct klist_node *n) | ||
154 | { | ||
155 | struct device *dev = container_of(n, struct device, knode_driver); | ||
156 | |||
157 | put_device(dev); | ||
158 | } | ||
159 | |||
160 | /** | 145 | /** |
161 | * driver_register - register driver with bus | 146 | * driver_register - register driver with bus |
162 | * @drv: driver to register | 147 | * @drv: driver to register |
@@ -176,7 +161,7 @@ int driver_register(struct device_driver * drv) | |||
176 | (drv->bus->shutdown && drv->shutdown)) { | 161 | (drv->bus->shutdown && drv->shutdown)) { |
177 | printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); | 162 | printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); |
178 | } | 163 | } |
179 | klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put); | 164 | klist_init(&drv->klist_devices, NULL, NULL); |
180 | init_completion(&drv->unloaded); | 165 | init_completion(&drv->unloaded); |
181 | return bus_add_driver(drv); | 166 | return bus_add_driver(drv); |
182 | } | 167 | } |
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 5d6c011183f5..14615694ae9a 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/bitops.h> | 17 | #include <linux/bitops.h> |
18 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
19 | #include <linux/kthread.h> | ||
19 | 20 | ||
20 | #include <linux/firmware.h> | 21 | #include <linux/firmware.h> |
21 | #include "base.h" | 22 | #include "base.h" |
@@ -511,7 +512,6 @@ request_firmware_work_func(void *arg) | |||
511 | WARN_ON(1); | 512 | WARN_ON(1); |
512 | return 0; | 513 | return 0; |
513 | } | 514 | } |
514 | daemonize("%s/%s", "firmware", fw_work->name); | ||
515 | ret = _request_firmware(&fw, fw_work->name, fw_work->device, | 515 | ret = _request_firmware(&fw, fw_work->name, fw_work->device, |
516 | fw_work->uevent); | 516 | fw_work->uevent); |
517 | if (ret < 0) | 517 | if (ret < 0) |
@@ -546,9 +546,9 @@ request_firmware_nowait( | |||
546 | const char *name, struct device *device, void *context, | 546 | const char *name, struct device *device, void *context, |
547 | void (*cont)(const struct firmware *fw, void *context)) | 547 | void (*cont)(const struct firmware *fw, void *context)) |
548 | { | 548 | { |
549 | struct task_struct *task; | ||
549 | struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), | 550 | struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), |
550 | GFP_ATOMIC); | 551 | GFP_ATOMIC); |
551 | int ret; | ||
552 | 552 | ||
553 | if (!fw_work) | 553 | if (!fw_work) |
554 | return -ENOMEM; | 554 | return -ENOMEM; |
@@ -566,14 +566,14 @@ request_firmware_nowait( | |||
566 | .uevent = uevent, | 566 | .uevent = uevent, |
567 | }; | 567 | }; |
568 | 568 | ||
569 | ret = kernel_thread(request_firmware_work_func, fw_work, | 569 | task = kthread_run(request_firmware_work_func, fw_work, |
570 | CLONE_FS | CLONE_FILES); | 570 | "firmware/%s", name); |
571 | 571 | ||
572 | if (ret < 0) { | 572 | if (IS_ERR(task)) { |
573 | fw_work->cont(NULL, fw_work->context); | 573 | fw_work->cont(NULL, fw_work->context); |
574 | module_put(fw_work->module); | 574 | module_put(fw_work->module); |
575 | kfree(fw_work); | 575 | kfree(fw_work); |
576 | return ret; | 576 | return PTR_ERR(task); |
577 | } | 577 | } |
578 | return 0; | 578 | return 0; |
579 | } | 579 | } |
@@ -602,7 +602,7 @@ firmware_class_exit(void) | |||
602 | class_unregister(&firmware_class); | 602 | class_unregister(&firmware_class); |
603 | } | 603 | } |
604 | 604 | ||
605 | module_init(firmware_class_init); | 605 | fs_initcall(firmware_class_init); |
606 | module_exit(firmware_class_exit); | 606 | module_exit(firmware_class_exit); |
607 | 607 | ||
608 | EXPORT_SYMBOL(release_firmware); | 608 | EXPORT_SYMBOL(release_firmware); |
diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c index 0c85e9d6a448..7080b413ddc9 100644 --- a/drivers/base/hypervisor.c +++ b/drivers/base/hypervisor.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * hypervisor.c - /sys/hypervisor subsystem. | 2 | * hypervisor.c - /sys/hypervisor subsystem. |
3 | * | 3 | * |
4 | * This file is released under the GPLv2 | 4 | * Copyright (C) IBM Corp. 2006 |
5 | * | 5 | * |
6 | * This file is released under the GPLv2 | ||
6 | */ | 7 | */ |
7 | 8 | ||
8 | #include <linux/kobject.h> | 9 | #include <linux/kobject.h> |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index dd547af4681a..c6b7d9c4b651 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -306,11 +306,13 @@ static ssize_t | |||
306 | memory_probe_store(struct class *class, const char *buf, size_t count) | 306 | memory_probe_store(struct class *class, const char *buf, size_t count) |
307 | { | 307 | { |
308 | u64 phys_addr; | 308 | u64 phys_addr; |
309 | int nid; | ||
309 | int ret; | 310 | int ret; |
310 | 311 | ||
311 | phys_addr = simple_strtoull(buf, NULL, 0); | 312 | phys_addr = simple_strtoull(buf, NULL, 0); |
312 | 313 | ||
313 | ret = add_memory(phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); | 314 | nid = memory_add_physaddr_to_nid(phys_addr); |
315 | ret = add_memory(nid, phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); | ||
314 | 316 | ||
315 | if (ret) | 317 | if (ret) |
316 | count = ret; | 318 | count = ret; |
diff --git a/drivers/base/node.c b/drivers/base/node.c index c80c3aeed004..001e6f6b9c1b 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/cpumask.h> | 11 | #include <linux/cpumask.h> |
12 | #include <linux/topology.h> | 12 | #include <linux/topology.h> |
13 | #include <linux/nodemask.h> | 13 | #include <linux/nodemask.h> |
14 | #include <linux/cpu.h> | ||
14 | 15 | ||
15 | static struct sysdev_class node_class = { | 16 | static struct sysdev_class node_class = { |
16 | set_kset_name("node"), | 17 | set_kset_name("node"), |
@@ -39,24 +40,13 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) | |||
39 | int n; | 40 | int n; |
40 | int nid = dev->id; | 41 | int nid = dev->id; |
41 | struct sysinfo i; | 42 | struct sysinfo i; |
42 | struct page_state ps; | ||
43 | unsigned long inactive; | 43 | unsigned long inactive; |
44 | unsigned long active; | 44 | unsigned long active; |
45 | unsigned long free; | 45 | unsigned long free; |
46 | 46 | ||
47 | si_meminfo_node(&i, nid); | 47 | si_meminfo_node(&i, nid); |
48 | get_page_state_node(&ps, nid); | ||
49 | __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid)); | 48 | __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid)); |
50 | 49 | ||
51 | /* Check for negative values in these approximate counters */ | ||
52 | if ((long)ps.nr_dirty < 0) | ||
53 | ps.nr_dirty = 0; | ||
54 | if ((long)ps.nr_writeback < 0) | ||
55 | ps.nr_writeback = 0; | ||
56 | if ((long)ps.nr_mapped < 0) | ||
57 | ps.nr_mapped = 0; | ||
58 | if ((long)ps.nr_slab < 0) | ||
59 | ps.nr_slab = 0; | ||
60 | 50 | ||
61 | n = sprintf(buf, "\n" | 51 | n = sprintf(buf, "\n" |
62 | "Node %d MemTotal: %8lu kB\n" | 52 | "Node %d MemTotal: %8lu kB\n" |
@@ -64,27 +54,46 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) | |||
64 | "Node %d MemUsed: %8lu kB\n" | 54 | "Node %d MemUsed: %8lu kB\n" |
65 | "Node %d Active: %8lu kB\n" | 55 | "Node %d Active: %8lu kB\n" |
66 | "Node %d Inactive: %8lu kB\n" | 56 | "Node %d Inactive: %8lu kB\n" |
57 | #ifdef CONFIG_HIGHMEM | ||
67 | "Node %d HighTotal: %8lu kB\n" | 58 | "Node %d HighTotal: %8lu kB\n" |
68 | "Node %d HighFree: %8lu kB\n" | 59 | "Node %d HighFree: %8lu kB\n" |
69 | "Node %d LowTotal: %8lu kB\n" | 60 | "Node %d LowTotal: %8lu kB\n" |
70 | "Node %d LowFree: %8lu kB\n" | 61 | "Node %d LowFree: %8lu kB\n" |
62 | #endif | ||
71 | "Node %d Dirty: %8lu kB\n" | 63 | "Node %d Dirty: %8lu kB\n" |
72 | "Node %d Writeback: %8lu kB\n" | 64 | "Node %d Writeback: %8lu kB\n" |
65 | "Node %d FilePages: %8lu kB\n" | ||
73 | "Node %d Mapped: %8lu kB\n" | 66 | "Node %d Mapped: %8lu kB\n" |
74 | "Node %d Slab: %8lu kB\n", | 67 | "Node %d AnonPages: %8lu kB\n" |
68 | "Node %d PageTables: %8lu kB\n" | ||
69 | "Node %d NFS_Unstable: %8lu kB\n" | ||
70 | "Node %d Bounce: %8lu kB\n" | ||
71 | "Node %d Slab: %8lu kB\n" | ||
72 | "Node %d SReclaimable: %8lu kB\n" | ||
73 | "Node %d SUnreclaim: %8lu kB\n", | ||
75 | nid, K(i.totalram), | 74 | nid, K(i.totalram), |
76 | nid, K(i.freeram), | 75 | nid, K(i.freeram), |
77 | nid, K(i.totalram - i.freeram), | 76 | nid, K(i.totalram - i.freeram), |
78 | nid, K(active), | 77 | nid, K(active), |
79 | nid, K(inactive), | 78 | nid, K(inactive), |
79 | #ifdef CONFIG_HIGHMEM | ||
80 | nid, K(i.totalhigh), | 80 | nid, K(i.totalhigh), |
81 | nid, K(i.freehigh), | 81 | nid, K(i.freehigh), |
82 | nid, K(i.totalram - i.totalhigh), | 82 | nid, K(i.totalram - i.totalhigh), |
83 | nid, K(i.freeram - i.freehigh), | 83 | nid, K(i.freeram - i.freehigh), |
84 | nid, K(ps.nr_dirty), | 84 | #endif |
85 | nid, K(ps.nr_writeback), | 85 | nid, K(node_page_state(nid, NR_FILE_DIRTY)), |
86 | nid, K(ps.nr_mapped), | 86 | nid, K(node_page_state(nid, NR_WRITEBACK)), |
87 | nid, K(ps.nr_slab)); | 87 | nid, K(node_page_state(nid, NR_FILE_PAGES)), |
88 | nid, K(node_page_state(nid, NR_FILE_MAPPED)), | ||
89 | nid, K(node_page_state(nid, NR_ANON_PAGES)), | ||
90 | nid, K(node_page_state(nid, NR_PAGETABLE)), | ||
91 | nid, K(node_page_state(nid, NR_UNSTABLE_NFS)), | ||
92 | nid, K(node_page_state(nid, NR_BOUNCE)), | ||
93 | nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + | ||
94 | node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), | ||
95 | nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), | ||
96 | nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))); | ||
88 | n += hugetlb_report_node_meminfo(nid, buf + n); | 97 | n += hugetlb_report_node_meminfo(nid, buf + n); |
89 | return n; | 98 | return n; |
90 | } | 99 | } |
@@ -94,28 +103,6 @@ static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); | |||
94 | 103 | ||
95 | static ssize_t node_read_numastat(struct sys_device * dev, char * buf) | 104 | static ssize_t node_read_numastat(struct sys_device * dev, char * buf) |
96 | { | 105 | { |
97 | unsigned long numa_hit, numa_miss, interleave_hit, numa_foreign; | ||
98 | unsigned long local_node, other_node; | ||
99 | int i, cpu; | ||
100 | pg_data_t *pg = NODE_DATA(dev->id); | ||
101 | numa_hit = 0; | ||
102 | numa_miss = 0; | ||
103 | interleave_hit = 0; | ||
104 | numa_foreign = 0; | ||
105 | local_node = 0; | ||
106 | other_node = 0; | ||
107 | for (i = 0; i < MAX_NR_ZONES; i++) { | ||
108 | struct zone *z = &pg->node_zones[i]; | ||
109 | for_each_online_cpu(cpu) { | ||
110 | struct per_cpu_pageset *ps = zone_pcp(z,cpu); | ||
111 | numa_hit += ps->numa_hit; | ||
112 | numa_miss += ps->numa_miss; | ||
113 | numa_foreign += ps->numa_foreign; | ||
114 | interleave_hit += ps->interleave_hit; | ||
115 | local_node += ps->local_node; | ||
116 | other_node += ps->other_node; | ||
117 | } | ||
118 | } | ||
119 | return sprintf(buf, | 106 | return sprintf(buf, |
120 | "numa_hit %lu\n" | 107 | "numa_hit %lu\n" |
121 | "numa_miss %lu\n" | 108 | "numa_miss %lu\n" |
@@ -123,12 +110,12 @@ static ssize_t node_read_numastat(struct sys_device * dev, char * buf) | |||
123 | "interleave_hit %lu\n" | 110 | "interleave_hit %lu\n" |
124 | "local_node %lu\n" | 111 | "local_node %lu\n" |
125 | "other_node %lu\n", | 112 | "other_node %lu\n", |
126 | numa_hit, | 113 | node_page_state(dev->id, NUMA_HIT), |
127 | numa_miss, | 114 | node_page_state(dev->id, NUMA_MISS), |
128 | numa_foreign, | 115 | node_page_state(dev->id, NUMA_FOREIGN), |
129 | interleave_hit, | 116 | node_page_state(dev->id, NUMA_INTERLEAVE_HIT), |
130 | local_node, | 117 | node_page_state(dev->id, NUMA_LOCAL), |
131 | other_node); | 118 | node_page_state(dev->id, NUMA_OTHER)); |
132 | } | 119 | } |
133 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); | 120 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); |
134 | 121 | ||
@@ -190,6 +177,66 @@ void unregister_node(struct node *node) | |||
190 | sysdev_unregister(&node->sysdev); | 177 | sysdev_unregister(&node->sysdev); |
191 | } | 178 | } |
192 | 179 | ||
180 | struct node node_devices[MAX_NUMNODES]; | ||
181 | |||
182 | /* | ||
183 | * register cpu under node | ||
184 | */ | ||
185 | int register_cpu_under_node(unsigned int cpu, unsigned int nid) | ||
186 | { | ||
187 | if (node_online(nid)) { | ||
188 | struct sys_device *obj = get_cpu_sysdev(cpu); | ||
189 | if (!obj) | ||
190 | return 0; | ||
191 | return sysfs_create_link(&node_devices[nid].sysdev.kobj, | ||
192 | &obj->kobj, | ||
193 | kobject_name(&obj->kobj)); | ||
194 | } | ||
195 | |||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) | ||
200 | { | ||
201 | if (node_online(nid)) { | ||
202 | struct sys_device *obj = get_cpu_sysdev(cpu); | ||
203 | if (obj) | ||
204 | sysfs_remove_link(&node_devices[nid].sysdev.kobj, | ||
205 | kobject_name(&obj->kobj)); | ||
206 | } | ||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | int register_one_node(int nid) | ||
211 | { | ||
212 | int error = 0; | ||
213 | int cpu; | ||
214 | |||
215 | if (node_online(nid)) { | ||
216 | int p_node = parent_node(nid); | ||
217 | struct node *parent = NULL; | ||
218 | |||
219 | if (p_node != nid) | ||
220 | parent = &node_devices[p_node]; | ||
221 | |||
222 | error = register_node(&node_devices[nid], nid, parent); | ||
223 | |||
224 | /* link cpu under this node */ | ||
225 | for_each_present_cpu(cpu) { | ||
226 | if (cpu_to_node(cpu) == nid) | ||
227 | register_cpu_under_node(cpu, nid); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | return error; | ||
232 | |||
233 | } | ||
234 | |||
235 | void unregister_one_node(int nid) | ||
236 | { | ||
237 | unregister_node(&node_devices[nid]); | ||
238 | } | ||
239 | |||
193 | static int __init register_node_type(void) | 240 | static int __init register_node_type(void) |
194 | { | 241 | { |
195 | return sysdev_class_register(&node_class); | 242 | return sysdev_class_register(&node_class); |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 2b8755db76c6..940ce41f1887 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -505,12 +505,36 @@ static int platform_match(struct device * dev, struct device_driver * drv) | |||
505 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); | 505 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); |
506 | } | 506 | } |
507 | 507 | ||
508 | static int platform_suspend(struct device * dev, pm_message_t state) | 508 | static int platform_suspend(struct device *dev, pm_message_t mesg) |
509 | { | 509 | { |
510 | int ret = 0; | 510 | int ret = 0; |
511 | 511 | ||
512 | if (dev->driver && dev->driver->suspend) | 512 | if (dev->driver && dev->driver->suspend) |
513 | ret = dev->driver->suspend(dev, state); | 513 | ret = dev->driver->suspend(dev, mesg); |
514 | |||
515 | return ret; | ||
516 | } | ||
517 | |||
518 | static int platform_suspend_late(struct device *dev, pm_message_t mesg) | ||
519 | { | ||
520 | struct platform_driver *drv = to_platform_driver(dev->driver); | ||
521 | struct platform_device *pdev = container_of(dev, struct platform_device, dev); | ||
522 | int ret = 0; | ||
523 | |||
524 | if (dev->driver && drv->suspend_late) | ||
525 | ret = drv->suspend_late(pdev, mesg); | ||
526 | |||
527 | return ret; | ||
528 | } | ||
529 | |||
530 | static int platform_resume_early(struct device *dev) | ||
531 | { | ||
532 | struct platform_driver *drv = to_platform_driver(dev->driver); | ||
533 | struct platform_device *pdev = container_of(dev, struct platform_device, dev); | ||
534 | int ret = 0; | ||
535 | |||
536 | if (dev->driver && drv->resume_early) | ||
537 | ret = drv->resume_early(pdev); | ||
514 | 538 | ||
515 | return ret; | 539 | return ret; |
516 | } | 540 | } |
@@ -531,6 +555,8 @@ struct bus_type platform_bus_type = { | |||
531 | .match = platform_match, | 555 | .match = platform_match, |
532 | .uevent = platform_uevent, | 556 | .uevent = platform_uevent, |
533 | .suspend = platform_suspend, | 557 | .suspend = platform_suspend, |
558 | .suspend_late = platform_suspend_late, | ||
559 | .resume_early = platform_resume_early, | ||
534 | .resume = platform_resume, | 560 | .resume = platform_resume, |
535 | }; | 561 | }; |
536 | EXPORT_SYMBOL_GPL(platform_bus_type); | 562 | EXPORT_SYMBOL_GPL(platform_bus_type); |
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index ceeeba2c56c7..91f230939c1e 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile | |||
@@ -1,5 +1,6 @@ | |||
1 | obj-y := shutdown.o | 1 | obj-y := shutdown.o |
2 | obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o sysfs.o | 2 | obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o sysfs.o |
3 | obj-$(CONFIG_PM_TRACE) += trace.o | ||
3 | 4 | ||
4 | ifeq ($(CONFIG_DEBUG_DRIVER),y) | 5 | ifeq ($(CONFIG_DEBUG_DRIVER),y) |
5 | EXTRA_CFLAGS += -DDEBUG | 6 | EXTRA_CFLAGS += -DDEBUG |
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 0d2e101e4f15..fdfa3d0cf6af 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -19,7 +19,6 @@ | |||
19 | * ancestral dependencies that the subsystem list maintains. | 19 | * ancestral dependencies that the subsystem list maintains. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/config.h> | ||
23 | #include <linux/device.h> | 22 | #include <linux/device.h> |
24 | #include "power.h" | 23 | #include "power.h" |
25 | 24 | ||
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c index 317edbf0feca..020be36705a6 100644 --- a/drivers/base/power/resume.c +++ b/drivers/base/power/resume.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/device.h> | 11 | #include <linux/device.h> |
12 | #include <linux/resume-trace.h> | ||
12 | #include "../base.h" | 13 | #include "../base.h" |
13 | #include "power.h" | 14 | #include "power.h" |
14 | 15 | ||
@@ -23,6 +24,8 @@ int resume_device(struct device * dev) | |||
23 | { | 24 | { |
24 | int error = 0; | 25 | int error = 0; |
25 | 26 | ||
27 | TRACE_DEVICE(dev); | ||
28 | TRACE_RESUME(0); | ||
26 | down(&dev->sem); | 29 | down(&dev->sem); |
27 | if (dev->power.pm_parent | 30 | if (dev->power.pm_parent |
28 | && dev->power.pm_parent->power.power_state.event) { | 31 | && dev->power.pm_parent->power.power_state.event) { |
@@ -35,12 +38,35 @@ int resume_device(struct device * dev) | |||
35 | dev_dbg(dev,"resuming\n"); | 38 | dev_dbg(dev,"resuming\n"); |
36 | error = dev->bus->resume(dev); | 39 | error = dev->bus->resume(dev); |
37 | } | 40 | } |
41 | if (dev->class && dev->class->resume) { | ||
42 | dev_dbg(dev,"class resume\n"); | ||
43 | error = dev->class->resume(dev); | ||
44 | } | ||
38 | up(&dev->sem); | 45 | up(&dev->sem); |
46 | TRACE_RESUME(error); | ||
39 | return error; | 47 | return error; |
40 | } | 48 | } |
41 | 49 | ||
42 | 50 | ||
51 | static int resume_device_early(struct device * dev) | ||
52 | { | ||
53 | int error = 0; | ||
43 | 54 | ||
55 | TRACE_DEVICE(dev); | ||
56 | TRACE_RESUME(0); | ||
57 | if (dev->bus && dev->bus->resume_early) { | ||
58 | dev_dbg(dev,"EARLY resume\n"); | ||
59 | error = dev->bus->resume_early(dev); | ||
60 | } | ||
61 | TRACE_RESUME(error); | ||
62 | return error; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Resume the devices that have either not gone through | ||
67 | * the late suspend, or that did go through it but also | ||
68 | * went through the early resume | ||
69 | */ | ||
44 | void dpm_resume(void) | 70 | void dpm_resume(void) |
45 | { | 71 | { |
46 | down(&dpm_list_sem); | 72 | down(&dpm_list_sem); |
@@ -49,8 +75,7 @@ void dpm_resume(void) | |||
49 | struct device * dev = to_device(entry); | 75 | struct device * dev = to_device(entry); |
50 | 76 | ||
51 | get_device(dev); | 77 | get_device(dev); |
52 | list_del_init(entry); | 78 | list_move_tail(entry, &dpm_active); |
53 | list_add_tail(entry, &dpm_active); | ||
54 | 79 | ||
55 | up(&dpm_list_sem); | 80 | up(&dpm_list_sem); |
56 | if (!dev->power.prev_state.event) | 81 | if (!dev->power.prev_state.event) |
@@ -71,6 +96,7 @@ void dpm_resume(void) | |||
71 | 96 | ||
72 | void device_resume(void) | 97 | void device_resume(void) |
73 | { | 98 | { |
99 | might_sleep(); | ||
74 | down(&dpm_sem); | 100 | down(&dpm_sem); |
75 | dpm_resume(); | 101 | dpm_resume(); |
76 | up(&dpm_sem); | 102 | up(&dpm_sem); |
@@ -80,12 +106,12 @@ EXPORT_SYMBOL_GPL(device_resume); | |||
80 | 106 | ||
81 | 107 | ||
82 | /** | 108 | /** |
83 | * device_power_up_irq - Power on some devices. | 109 | * dpm_power_up - Power on some devices. |
84 | * | 110 | * |
85 | * Walk the dpm_off_irq list and power each device up. This | 111 | * Walk the dpm_off_irq list and power each device up. This |
86 | * is used for devices that required they be powered down with | 112 | * is used for devices that required they be powered down with |
87 | * interrupts disabled. As devices are powered on, they are moved to | 113 | * interrupts disabled. As devices are powered on, they are moved |
88 | * the dpm_suspended list. | 114 | * to the dpm_active list. |
89 | * | 115 | * |
90 | * Interrupts must be disabled when calling this. | 116 | * Interrupts must be disabled when calling this. |
91 | */ | 117 | */ |
@@ -96,17 +122,14 @@ void dpm_power_up(void) | |||
96 | struct list_head * entry = dpm_off_irq.next; | 122 | struct list_head * entry = dpm_off_irq.next; |
97 | struct device * dev = to_device(entry); | 123 | struct device * dev = to_device(entry); |
98 | 124 | ||
99 | get_device(dev); | 125 | list_move_tail(entry, &dpm_off); |
100 | list_del_init(entry); | 126 | resume_device_early(dev); |
101 | list_add_tail(entry, &dpm_active); | ||
102 | resume_device(dev); | ||
103 | put_device(dev); | ||
104 | } | 127 | } |
105 | } | 128 | } |
106 | 129 | ||
107 | 130 | ||
108 | /** | 131 | /** |
109 | * device_pm_power_up - Turn on all devices that need special attention. | 132 | * device_power_up - Turn on all devices that need special attention. |
110 | * | 133 | * |
111 | * Power on system devices then devices that required we shut them down | 134 | * Power on system devices then devices that required we shut them down |
112 | * with interrupts disabled. | 135 | * with interrupts disabled. |
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c index 8826a5b6673e..3483ae4d57f5 100644 --- a/drivers/base/power/shutdown.c +++ b/drivers/base/power/shutdown.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/device.h> | 11 | #include <linux/device.h> |
13 | #include <asm/semaphore.h> | 12 | #include <asm/semaphore.h> |
14 | 13 | ||
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c index 1a1fe43a3057..ece136bf97e3 100644 --- a/drivers/base/power/suspend.c +++ b/drivers/base/power/suspend.c | |||
@@ -34,6 +34,7 @@ static inline char *suspend_verb(u32 event) | |||
34 | switch (event) { | 34 | switch (event) { |
35 | case PM_EVENT_SUSPEND: return "suspend"; | 35 | case PM_EVENT_SUSPEND: return "suspend"; |
36 | case PM_EVENT_FREEZE: return "freeze"; | 36 | case PM_EVENT_FREEZE: return "freeze"; |
37 | case PM_EVENT_PRETHAW: return "prethaw"; | ||
37 | default: return "(unknown suspend event)"; | 38 | default: return "(unknown suspend event)"; |
38 | } | 39 | } |
39 | } | 40 | } |
@@ -65,7 +66,19 @@ int suspend_device(struct device * dev, pm_message_t state) | |||
65 | 66 | ||
66 | dev->power.prev_state = dev->power.power_state; | 67 | dev->power.prev_state = dev->power.power_state; |
67 | 68 | ||
68 | if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { | 69 | if (dev->class && dev->class->suspend && !dev->power.power_state.event) { |
70 | dev_dbg(dev, "class %s%s\n", | ||
71 | suspend_verb(state.event), | ||
72 | ((state.event == PM_EVENT_SUSPEND) | ||
73 | && device_may_wakeup(dev)) | ||
74 | ? ", may wakeup" | ||
75 | : "" | ||
76 | ); | ||
77 | error = dev->class->suspend(dev, state); | ||
78 | suspend_report_result(dev->class->suspend, error); | ||
79 | } | ||
80 | |||
81 | if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) { | ||
69 | dev_dbg(dev, "%s%s\n", | 82 | dev_dbg(dev, "%s%s\n", |
70 | suspend_verb(state.event), | 83 | suspend_verb(state.event), |
71 | ((state.event == PM_EVENT_SUSPEND) | 84 | ((state.event == PM_EVENT_SUSPEND) |
@@ -81,15 +94,42 @@ int suspend_device(struct device * dev, pm_message_t state) | |||
81 | } | 94 | } |
82 | 95 | ||
83 | 96 | ||
97 | /* | ||
98 | * This is called with interrupts off, only a single CPU | ||
99 | * running. We can't do down() on a semaphore (and we don't | ||
100 | * need the protection) | ||
101 | */ | ||
102 | static int suspend_device_late(struct device *dev, pm_message_t state) | ||
103 | { | ||
104 | int error = 0; | ||
105 | |||
106 | if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) { | ||
107 | dev_dbg(dev, "LATE %s%s\n", | ||
108 | suspend_verb(state.event), | ||
109 | ((state.event == PM_EVENT_SUSPEND) | ||
110 | && device_may_wakeup(dev)) | ||
111 | ? ", may wakeup" | ||
112 | : "" | ||
113 | ); | ||
114 | error = dev->bus->suspend_late(dev, state); | ||
115 | suspend_report_result(dev->bus->suspend_late, error); | ||
116 | } | ||
117 | return error; | ||
118 | } | ||
119 | |||
84 | /** | 120 | /** |
85 | * device_suspend - Save state and stop all devices in system. | 121 | * device_suspend - Save state and stop all devices in system. |
86 | * @state: Power state to put each device in. | 122 | * @state: Power state to put each device in. |
87 | * | 123 | * |
88 | * Walk the dpm_active list, call ->suspend() for each device, and move | 124 | * Walk the dpm_active list, call ->suspend() for each device, and move |
89 | * it to dpm_off. | 125 | * it to the dpm_off list. |
90 | * Check the return value for each. If it returns 0, then we move the | 126 | * |
91 | * the device to the dpm_off list. If it returns -EAGAIN, we move it to | 127 | * (For historical reasons, if it returns -EAGAIN, that used to mean |
92 | * the dpm_off_irq list. If we get a different error, try and back out. | 128 | * that the device would be called again with interrupts disabled. |
129 | * These days, we use the "suspend_late()" callback for that, so we | ||
130 | * print a warning and consider it an error). | ||
131 | * | ||
132 | * If we get a different error, try and back out. | ||
93 | * | 133 | * |
94 | * If we hit a failure with any of the devices, call device_resume() | 134 | * If we hit a failure with any of the devices, call device_resume() |
95 | * above to bring the suspended devices back to life. | 135 | * above to bring the suspended devices back to life. |
@@ -100,6 +140,7 @@ int device_suspend(pm_message_t state) | |||
100 | { | 140 | { |
101 | int error = 0; | 141 | int error = 0; |
102 | 142 | ||
143 | might_sleep(); | ||
103 | down(&dpm_sem); | 144 | down(&dpm_sem); |
104 | down(&dpm_list_sem); | 145 | down(&dpm_list_sem); |
105 | while (!list_empty(&dpm_active) && error == 0) { | 146 | while (!list_empty(&dpm_active) && error == 0) { |
@@ -115,42 +156,27 @@ int device_suspend(pm_message_t state) | |||
115 | 156 | ||
116 | /* Check if the device got removed */ | 157 | /* Check if the device got removed */ |
117 | if (!list_empty(&dev->power.entry)) { | 158 | if (!list_empty(&dev->power.entry)) { |
118 | /* Move it to the dpm_off or dpm_off_irq list */ | 159 | /* Move it to the dpm_off list */ |
119 | if (!error) { | 160 | if (!error) |
120 | list_del(&dev->power.entry); | 161 | list_move(&dev->power.entry, &dpm_off); |
121 | list_add(&dev->power.entry, &dpm_off); | ||
122 | } else if (error == -EAGAIN) { | ||
123 | list_del(&dev->power.entry); | ||
124 | list_add(&dev->power.entry, &dpm_off_irq); | ||
125 | error = 0; | ||
126 | } | ||
127 | } | 162 | } |
128 | if (error) | 163 | if (error) |
129 | printk(KERN_ERR "Could not suspend device %s: " | 164 | printk(KERN_ERR "Could not suspend device %s: " |
130 | "error %d\n", kobject_name(&dev->kobj), error); | 165 | "error %d%s\n", |
166 | kobject_name(&dev->kobj), error, | ||
167 | error == -EAGAIN ? " (please convert to suspend_late)" : ""); | ||
131 | put_device(dev); | 168 | put_device(dev); |
132 | } | 169 | } |
133 | up(&dpm_list_sem); | 170 | up(&dpm_list_sem); |
134 | if (error) { | 171 | if (error) |
135 | /* we failed... before resuming, bring back devices from | ||
136 | * dpm_off_irq list back to main dpm_off list, we do want | ||
137 | * to call resume() on them, in case they partially suspended | ||
138 | * despite returning -EAGAIN | ||
139 | */ | ||
140 | while (!list_empty(&dpm_off_irq)) { | ||
141 | struct list_head * entry = dpm_off_irq.next; | ||
142 | list_del(entry); | ||
143 | list_add(entry, &dpm_off); | ||
144 | } | ||
145 | dpm_resume(); | 172 | dpm_resume(); |
146 | } | 173 | |
147 | up(&dpm_sem); | 174 | up(&dpm_sem); |
148 | return error; | 175 | return error; |
149 | } | 176 | } |
150 | 177 | ||
151 | EXPORT_SYMBOL_GPL(device_suspend); | 178 | EXPORT_SYMBOL_GPL(device_suspend); |
152 | 179 | ||
153 | |||
154 | /** | 180 | /** |
155 | * device_power_down - Shut down special devices. | 181 | * device_power_down - Shut down special devices. |
156 | * @state: Power state to enter. | 182 | * @state: Power state to enter. |
@@ -165,14 +191,17 @@ int device_power_down(pm_message_t state) | |||
165 | int error = 0; | 191 | int error = 0; |
166 | struct device * dev; | 192 | struct device * dev; |
167 | 193 | ||
168 | list_for_each_entry_reverse(dev, &dpm_off_irq, power.entry) { | 194 | while (!list_empty(&dpm_off)) { |
169 | if ((error = suspend_device(dev, state))) | 195 | struct list_head * entry = dpm_off.prev; |
170 | break; | 196 | |
197 | dev = to_device(entry); | ||
198 | error = suspend_device_late(dev, state); | ||
199 | if (error) | ||
200 | goto Error; | ||
201 | list_move(&dev->power.entry, &dpm_off_irq); | ||
171 | } | 202 | } |
172 | if (error) | 203 | |
173 | goto Error; | 204 | error = sysdev_suspend(state); |
174 | if ((error = sysdev_suspend(state))) | ||
175 | goto Error; | ||
176 | Done: | 205 | Done: |
177 | return error; | 206 | return error; |
178 | Error: | 207 | Error: |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index 40d7242a07c1..2d47517dbe32 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -7,22 +7,29 @@ | |||
7 | #include "power.h" | 7 | #include "power.h" |
8 | 8 | ||
9 | 9 | ||
10 | #ifdef CONFIG_PM_SYSFS_DEPRECATED | ||
11 | |||
10 | /** | 12 | /** |
11 | * state - Control current power state of device | 13 | * state - Control current power state of device |
12 | * | 14 | * |
13 | * show() returns the current power state of the device. '0' indicates | 15 | * show() returns the current power state of the device. '0' indicates |
14 | * the device is on. Other values (1-3) indicate the device is in a low | 16 | * the device is on. Other values (2) indicate the device is in some low |
15 | * power state. | 17 | * power state. |
16 | * | 18 | * |
17 | * store() sets the current power state, which is an integer value | 19 | * store() sets the current power state, which is an integer valued |
18 | * between 0-3. If the device is on ('0'), and the value written is | 20 | * 0, 2, or 3. Devices with bus.suspend_late(), or bus.resume_early() |
19 | * greater than 0, then the device is placed directly into the low-power | 21 | * methods fail this operation; those methods couldn't be called. |
20 | * state (via its driver's ->suspend() method). | 22 | * Otherwise, |
21 | * If the device is currently in a low-power state, and the value is 0, | 23 | * |
22 | * the device is powered back on (via the ->resume() method). | 24 | * - If the recorded dev->power.power_state.event matches the |
23 | * If the device is in a low-power state, and a different low-power state | 25 | * target value, nothing is done. |
24 | * is requested, the device is first resumed, then suspended into the new | 26 | * - If the recorded event code is nonzero, the device is reactivated |
25 | * low-power state. | 27 | * by calling bus.resume() and/or class.resume(). |
28 | * - If the target value is nonzero, the device is suspended by | ||
29 | * calling class.suspend() and/or bus.suspend() with event code | ||
30 | * PM_EVENT_SUSPEND. | ||
31 | * | ||
32 | * This mechanism is DEPRECATED and should only be used for testing. | ||
26 | */ | 33 | */ |
27 | 34 | ||
28 | static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) | 35 | static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) |
@@ -38,6 +45,10 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
38 | pm_message_t state; | 45 | pm_message_t state; |
39 | int error = -EINVAL; | 46 | int error = -EINVAL; |
40 | 47 | ||
48 | /* disallow incomplete suspend sequences */ | ||
49 | if (dev->bus && (dev->bus->suspend_late || dev->bus->resume_early)) | ||
50 | return error; | ||
51 | |||
41 | state.event = PM_EVENT_SUSPEND; | 52 | state.event = PM_EVENT_SUSPEND; |
42 | /* Older apps expected to write "3" here - confused with PCI D3 */ | 53 | /* Older apps expected to write "3" here - confused with PCI D3 */ |
43 | if ((n == 1) && !strcmp(buf, "3")) | 54 | if ((n == 1) && !strcmp(buf, "3")) |
@@ -57,6 +68,8 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
57 | static DEVICE_ATTR(state, 0644, state_show, state_store); | 68 | static DEVICE_ATTR(state, 0644, state_show, state_store); |
58 | 69 | ||
59 | 70 | ||
71 | #endif /* CONFIG_PM_SYSFS_DEPRECATED */ | ||
72 | |||
60 | /* | 73 | /* |
61 | * wakeup - Report/change current wakeup option for device | 74 | * wakeup - Report/change current wakeup option for device |
62 | * | 75 | * |
@@ -130,7 +143,9 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | |||
130 | 143 | ||
131 | 144 | ||
132 | static struct attribute * power_attrs[] = { | 145 | static struct attribute * power_attrs[] = { |
146 | #ifdef CONFIG_PM_SYSFS_DEPRECATED | ||
133 | &dev_attr_state.attr, | 147 | &dev_attr_state.attr, |
148 | #endif | ||
134 | &dev_attr_wakeup.attr, | 149 | &dev_attr_wakeup.attr, |
135 | NULL, | 150 | NULL, |
136 | }; | 151 | }; |
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c new file mode 100644 index 000000000000..a9ab30fefffc --- /dev/null +++ b/drivers/base/power/trace.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /* | ||
2 | * drivers/base/power/trace.c | ||
3 | * | ||
4 | * Copyright (C) 2006 Linus Torvalds | ||
5 | * | ||
6 | * Trace facility for suspend/resume problems, when none of the | ||
7 | * devices may be working. | ||
8 | */ | ||
9 | |||
10 | #include <linux/resume-trace.h> | ||
11 | #include <linux/rtc.h> | ||
12 | |||
13 | #include <asm/rtc.h> | ||
14 | |||
15 | #include "power.h" | ||
16 | |||
17 | /* | ||
18 | * Horrid, horrid, horrid. | ||
19 | * | ||
20 | * It turns out that the _only_ piece of hardware that actually | ||
21 | * keeps its value across a hard boot (and, more importantly, the | ||
22 | * POST init sequence) is literally the realtime clock. | ||
23 | * | ||
24 | * Never mind that an RTC chip has 114 bytes (and often a whole | ||
25 | * other bank of an additional 128 bytes) of nice SRAM that is | ||
26 | * _designed_ to keep data - the POST will clear it. So we literally | ||
27 | * can just use the few bytes of actual time data, which means that | ||
28 | * we're really limited. | ||
29 | * | ||
30 | * It means, for example, that we can't use the seconds at all | ||
31 | * (since the time between the hang and the boot might be more | ||
32 | * than a minute), and we'd better not depend on the low bits of | ||
33 | * the minutes either. | ||
34 | * | ||
35 | * There are the wday fields etc, but I wouldn't guarantee those | ||
36 | * are dependable either. And if the date isn't valid, either the | ||
37 | * hw or POST will do strange things. | ||
38 | * | ||
39 | * So we're left with: | ||
40 | * - year: 0-99 | ||
41 | * - month: 0-11 | ||
42 | * - day-of-month: 1-28 | ||
43 | * - hour: 0-23 | ||
44 | * - min: (0-30)*2 | ||
45 | * | ||
46 | * Giving us a total range of 0-16128000 (0xf61800), ie less | ||
47 | * than 24 bits of actual data we can save across reboots. | ||
48 | * | ||
49 | * And if your box can't boot in less than three minutes, | ||
50 | * you're screwed. | ||
51 | * | ||
52 | * Now, almost 24 bits of data is pitifully small, so we need | ||
53 | * to be pretty dense if we want to use it for anything nice. | ||
54 | * What we do is that instead of saving off nice readable info, | ||
55 | * we save off _hashes_ of information that we can hopefully | ||
56 | * regenerate after the reboot. | ||
57 | * | ||
58 | * In particular, this means that we might be unlucky, and hit | ||
59 | * a case where we have a hash collision, and we end up not | ||
60 | * being able to tell for certain exactly which case happened. | ||
61 | * But that's hopefully unlikely. | ||
62 | * | ||
63 | * What we do is to take the bits we can fit, and split them | ||
64 | * into three parts (16*997*1009 = 16095568), and use the values | ||
65 | * for: | ||
66 | * - 0-15: user-settable | ||
67 | * - 0-996: file + line number | ||
68 | * - 0-1008: device | ||
69 | */ | ||
70 | #define USERHASH (16) | ||
71 | #define FILEHASH (997) | ||
72 | #define DEVHASH (1009) | ||
73 | |||
74 | #define DEVSEED (7919) | ||
75 | |||
76 | static unsigned int dev_hash_value; | ||
77 | |||
78 | static int set_magic_time(unsigned int user, unsigned int file, unsigned int device) | ||
79 | { | ||
80 | unsigned int n = user + USERHASH*(file + FILEHASH*device); | ||
81 | |||
82 | // June 7th, 2006 | ||
83 | static struct rtc_time time = { | ||
84 | .tm_sec = 0, | ||
85 | .tm_min = 0, | ||
86 | .tm_hour = 0, | ||
87 | .tm_mday = 7, | ||
88 | .tm_mon = 5, // June - counting from zero | ||
89 | .tm_year = 106, | ||
90 | .tm_wday = 3, | ||
91 | .tm_yday = 160, | ||
92 | .tm_isdst = 1 | ||
93 | }; | ||
94 | |||
95 | time.tm_year = (n % 100); | ||
96 | n /= 100; | ||
97 | time.tm_mon = (n % 12); | ||
98 | n /= 12; | ||
99 | time.tm_mday = (n % 28) + 1; | ||
100 | n /= 28; | ||
101 | time.tm_hour = (n % 24); | ||
102 | n /= 24; | ||
103 | time.tm_min = (n % 20) * 3; | ||
104 | n /= 20; | ||
105 | set_rtc_time(&time); | ||
106 | return n ? -1 : 0; | ||
107 | } | ||
108 | |||
109 | static unsigned int read_magic_time(void) | ||
110 | { | ||
111 | struct rtc_time time; | ||
112 | unsigned int val; | ||
113 | |||
114 | get_rtc_time(&time); | ||
115 | printk("Time: %2d:%02d:%02d Date: %02d/%02d/%02d\n", | ||
116 | time.tm_hour, time.tm_min, time.tm_sec, | ||
117 | time.tm_mon, time.tm_mday, time.tm_year); | ||
118 | val = time.tm_year; /* 100 years */ | ||
119 | if (val > 100) | ||
120 | val -= 100; | ||
121 | val += time.tm_mon * 100; /* 12 months */ | ||
122 | val += (time.tm_mday-1) * 100 * 12; /* 28 month-days */ | ||
123 | val += time.tm_hour * 100 * 12 * 28; /* 24 hours */ | ||
124 | val += (time.tm_min / 3) * 100 * 12 * 28 * 24; /* 20 3-minute intervals */ | ||
125 | return val; | ||
126 | } | ||
127 | |||
128 | /* | ||
129 | * This is just the sdbm hash function with a user-supplied | ||
130 | * seed and final size parameter. | ||
131 | */ | ||
132 | static unsigned int hash_string(unsigned int seed, const char *data, unsigned int mod) | ||
133 | { | ||
134 | unsigned char c; | ||
135 | while ((c = *data++) != 0) { | ||
136 | seed = (seed << 16) + (seed << 6) - seed + c; | ||
137 | } | ||
138 | return seed % mod; | ||
139 | } | ||
140 | |||
141 | void set_trace_device(struct device *dev) | ||
142 | { | ||
143 | dev_hash_value = hash_string(DEVSEED, dev->bus_id, DEVHASH); | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * We could just take the "tracedata" index into the .tracedata | ||
148 | * section instead. Generating a hash of the data gives us a | ||
149 | * chance to work across kernel versions, and perhaps more | ||
150 | * importantly it also gives us valid/invalid check (ie we will | ||
151 | * likely not give totally bogus reports - if the hash matches, | ||
152 | * it's not any guarantee, but it's a high _likelihood_ that | ||
153 | * the match is valid). | ||
154 | */ | ||
155 | void generate_resume_trace(void *tracedata, unsigned int user) | ||
156 | { | ||
157 | unsigned short lineno = *(unsigned short *)tracedata; | ||
158 | const char *file = *(const char **)(tracedata + 2); | ||
159 | unsigned int user_hash_value, file_hash_value; | ||
160 | |||
161 | user_hash_value = user % USERHASH; | ||
162 | file_hash_value = hash_string(lineno, file, FILEHASH); | ||
163 | set_magic_time(user_hash_value, file_hash_value, dev_hash_value); | ||
164 | } | ||
165 | |||
166 | extern char __tracedata_start, __tracedata_end; | ||
167 | static int show_file_hash(unsigned int value) | ||
168 | { | ||
169 | int match; | ||
170 | char *tracedata; | ||
171 | |||
172 | match = 0; | ||
173 | for (tracedata = &__tracedata_start ; tracedata < &__tracedata_end ; tracedata += 6) { | ||
174 | unsigned short lineno = *(unsigned short *)tracedata; | ||
175 | const char *file = *(const char **)(tracedata + 2); | ||
176 | unsigned int hash = hash_string(lineno, file, FILEHASH); | ||
177 | if (hash != value) | ||
178 | continue; | ||
179 | printk(" hash matches %s:%u\n", file, lineno); | ||
180 | match++; | ||
181 | } | ||
182 | return match; | ||
183 | } | ||
184 | |||
185 | static int show_dev_hash(unsigned int value) | ||
186 | { | ||
187 | int match = 0; | ||
188 | struct list_head * entry = dpm_active.prev; | ||
189 | |||
190 | while (entry != &dpm_active) { | ||
191 | struct device * dev = to_device(entry); | ||
192 | unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); | ||
193 | if (hash == value) { | ||
194 | printk(" hash matches device %s\n", dev->bus_id); | ||
195 | match++; | ||
196 | } | ||
197 | entry = entry->prev; | ||
198 | } | ||
199 | return match; | ||
200 | } | ||
201 | |||
202 | static unsigned int hash_value_early_read; | ||
203 | |||
204 | static int early_resume_init(void) | ||
205 | { | ||
206 | hash_value_early_read = read_magic_time(); | ||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int late_resume_init(void) | ||
211 | { | ||
212 | unsigned int val = hash_value_early_read; | ||
213 | unsigned int user, file, dev; | ||
214 | |||
215 | user = val % USERHASH; | ||
216 | val = val / USERHASH; | ||
217 | file = val % FILEHASH; | ||
218 | val = val / FILEHASH; | ||
219 | dev = val /* % DEVHASH */; | ||
220 | |||
221 | printk(" Magic number: %d:%d:%d\n", user, file, dev); | ||
222 | show_file_hash(file); | ||
223 | show_dev_hash(dev); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | core_initcall(early_resume_init); | ||
228 | late_initcall(late_resume_init); | ||
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 6858178b3aff..04e5db445c74 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -12,7 +12,6 @@ | |||
12 | * add themselves as children of the system bus. | 12 | * add themselves as children of the system bus. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/config.h> | ||
16 | #include <linux/sysdev.h> | 15 | #include <linux/sysdev.h> |
17 | #include <linux/err.h> | 16 | #include <linux/err.h> |
18 | #include <linux/module.h> | 17 | #include <linux/module.h> |
diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 8c52421cbc54..3ef9d514b916 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c | |||
@@ -107,7 +107,7 @@ static int __cpuinit topology_remove_dev(struct sys_device * sys_dev) | |||
107 | return 0; | 107 | return 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | static int topology_cpu_callback(struct notifier_block *nfb, | 110 | static int __cpuinit topology_cpu_callback(struct notifier_block *nfb, |
111 | unsigned long action, void *hcpu) | 111 | unsigned long action, void *hcpu) |
112 | { | 112 | { |
113 | unsigned int cpu = (unsigned long)hcpu; | 113 | unsigned int cpu = (unsigned long)hcpu; |
@@ -125,7 +125,7 @@ static int topology_cpu_callback(struct notifier_block *nfb, | |||
125 | return NOTIFY_OK; | 125 | return NOTIFY_OK; |
126 | } | 126 | } |
127 | 127 | ||
128 | static struct notifier_block topology_cpu_notifier = | 128 | static struct notifier_block __cpuinitdata topology_cpu_notifier = |
129 | { | 129 | { |
130 | .notifier_call = topology_cpu_callback, | 130 | .notifier_call = topology_cpu_callback, |
131 | }; | 131 | }; |
@@ -139,7 +139,7 @@ static int __cpuinit topology_sysfs_init(void) | |||
139 | (void *)(long)i); | 139 | (void *)(long)i); |
140 | } | 140 | } |
141 | 141 | ||
142 | register_cpu_notifier(&topology_cpu_notifier); | 142 | register_hotcpu_notifier(&topology_cpu_notifier); |
143 | 143 | ||
144 | return 0; | 144 | return 0; |
145 | } | 145 | } |