diff options
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/Makefile | 1 | ||||
| -rw-r--r-- | drivers/base/attribute_container.c | 2 | ||||
| -rw-r--r-- | drivers/base/base.h | 12 | ||||
| -rw-r--r-- | drivers/base/class.c | 150 | ||||
| -rw-r--r-- | drivers/base/core.c | 21 | ||||
| -rw-r--r-- | drivers/base/cpu.c | 1 | ||||
| -rw-r--r-- | drivers/base/driver.c | 3 | ||||
| -rw-r--r-- | drivers/base/firmware.c | 3 | ||||
| -rw-r--r-- | drivers/base/init.c | 12 | ||||
| -rw-r--r-- | drivers/base/memory.c | 452 | ||||
| -rw-r--r-- | drivers/base/platform.c | 22 | ||||
| -rw-r--r-- | drivers/base/power/main.c | 26 | ||||
| -rw-r--r-- | drivers/base/power/power.h | 13 | ||||
| -rw-r--r-- | drivers/base/power/runtime.c | 1 | ||||
| -rw-r--r-- | drivers/base/power/sysfs.c | 73 |
15 files changed, 681 insertions, 111 deletions
diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 66d9c4643fc1..f12898d53078 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile | |||
| @@ -7,6 +7,7 @@ obj-y := core.o sys.o bus.o dd.o \ | |||
| 7 | obj-y += power/ | 7 | obj-y += power/ |
| 8 | obj-$(CONFIG_FW_LOADER) += firmware_class.o | 8 | obj-$(CONFIG_FW_LOADER) += firmware_class.o |
| 9 | obj-$(CONFIG_NUMA) += node.o | 9 | obj-$(CONFIG_NUMA) += node.o |
| 10 | obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o | ||
| 10 | 11 | ||
| 11 | ifeq ($(CONFIG_DEBUG_DRIVER),y) | 12 | ifeq ($(CONFIG_DEBUG_DRIVER),y) |
| 12 | EXTRA_CFLAGS += -DDEBUG | 13 | EXTRA_CFLAGS += -DDEBUG |
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 6b2eb6f39b4d..2a7d7ae83e1e 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c | |||
| @@ -19,6 +19,8 @@ | |||
| 19 | #include <linux/list.h> | 19 | #include <linux/list.h> |
| 20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 21 | 21 | ||
| 22 | #include "base.h" | ||
| 23 | |||
| 22 | /* This is a private structure used to tie the classdev and the | 24 | /* This is a private structure used to tie the classdev and the |
| 23 | * container .. it should never be visible outside this file */ | 25 | * container .. it should never be visible outside this file */ |
| 24 | struct internal_container { | 26 | struct internal_container { |
diff --git a/drivers/base/base.h b/drivers/base/base.h index 783752b68a9a..e3b548d46cff 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | |||
| 2 | /* initialisation functions */ | ||
| 3 | |||
| 4 | extern int devices_init(void); | ||
| 5 | extern int buses_init(void); | ||
| 6 | extern int classes_init(void); | ||
| 7 | extern int firmware_init(void); | ||
| 8 | extern int platform_bus_init(void); | ||
| 9 | extern int system_bus_init(void); | ||
| 10 | extern int cpu_dev_init(void); | ||
| 11 | extern int attribute_container_init(void); | ||
| 12 | |||
| 1 | extern int bus_add_device(struct device * dev); | 13 | extern int bus_add_device(struct device * dev); |
| 2 | extern void bus_remove_device(struct device * dev); | 14 | extern void bus_remove_device(struct device * dev); |
| 3 | 15 | ||
diff --git a/drivers/base/class.c b/drivers/base/class.c index ce23dc8c18c5..c3e569730afe 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
| @@ -99,7 +99,8 @@ struct class * class_get(struct class * cls) | |||
| 99 | 99 | ||
| 100 | void class_put(struct class * cls) | 100 | void class_put(struct class * cls) |
| 101 | { | 101 | { |
| 102 | subsys_put(&cls->subsys); | 102 | if (cls) |
| 103 | subsys_put(&cls->subsys); | ||
| 103 | } | 104 | } |
| 104 | 105 | ||
| 105 | 106 | ||
| @@ -165,14 +166,25 @@ void class_unregister(struct class * cls) | |||
| 165 | 166 | ||
| 166 | static void class_create_release(struct class *cls) | 167 | static void class_create_release(struct class *cls) |
| 167 | { | 168 | { |
| 169 | pr_debug("%s called for %s\n", __FUNCTION__, cls->name); | ||
| 168 | kfree(cls); | 170 | kfree(cls); |
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | static void class_device_create_release(struct class_device *class_dev) | 173 | static void class_device_create_release(struct class_device *class_dev) |
| 172 | { | 174 | { |
| 175 | pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); | ||
| 173 | kfree(class_dev); | 176 | kfree(class_dev); |
| 174 | } | 177 | } |
| 175 | 178 | ||
| 179 | /* needed to allow these devices to have parent class devices */ | ||
| 180 | static int class_device_create_hotplug(struct class_device *class_dev, | ||
| 181 | char **envp, int num_envp, | ||
| 182 | char *buffer, int buffer_size) | ||
| 183 | { | ||
| 184 | pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); | ||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 176 | /** | 188 | /** |
| 177 | * class_create - create a struct class structure | 189 | * class_create - create a struct class structure |
| 178 | * @owner: pointer to the module that is to "own" this struct class | 190 | * @owner: pointer to the module that is to "own" this struct class |
| @@ -301,10 +313,12 @@ static void class_dev_release(struct kobject * kobj) | |||
| 301 | kfree(cd->devt_attr); | 313 | kfree(cd->devt_attr); |
| 302 | cd->devt_attr = NULL; | 314 | cd->devt_attr = NULL; |
| 303 | 315 | ||
| 304 | if (cls->release) | 316 | if (cd->release) |
| 317 | cd->release(cd); | ||
| 318 | else if (cls->release) | ||
| 305 | cls->release(cd); | 319 | cls->release(cd); |
| 306 | else { | 320 | else { |
| 307 | printk(KERN_ERR "Device class '%s' does not have a release() function, " | 321 | printk(KERN_ERR "Class Device '%s' does not have a release() function, " |
| 308 | "it is broken and must be fixed.\n", | 322 | "it is broken and must be fixed.\n", |
| 309 | cd->class_id); | 323 | cd->class_id); |
| 310 | WARN_ON(1); | 324 | WARN_ON(1); |
| @@ -382,14 +396,18 @@ static int class_hotplug(struct kset *kset, struct kobject *kobj, char **envp, | |||
| 382 | buffer = &buffer[length]; | 396 | buffer = &buffer[length]; |
| 383 | buffer_size -= length; | 397 | buffer_size -= length; |
| 384 | 398 | ||
| 385 | if (class_dev->class->hotplug) { | 399 | if (class_dev->hotplug) { |
| 386 | /* have the bus specific function add its stuff */ | 400 | /* have the class device specific function add its stuff */ |
| 387 | retval = class_dev->class->hotplug (class_dev, envp, num_envp, | 401 | retval = class_dev->hotplug(class_dev, envp, num_envp, |
| 388 | buffer, buffer_size); | 402 | buffer, buffer_size); |
| 389 | if (retval) { | 403 | if (retval) |
| 390 | pr_debug ("%s - hotplug() returned %d\n", | 404 | pr_debug("class_dev->hotplug() returned %d\n", retval); |
| 391 | __FUNCTION__, retval); | 405 | } else if (class_dev->class->hotplug) { |
| 392 | } | 406 | /* have the class specific function add its stuff */ |
| 407 | retval = class_dev->class->hotplug(class_dev, envp, num_envp, | ||
| 408 | buffer, buffer_size); | ||
| 409 | if (retval) | ||
| 410 | pr_debug("class->hotplug() returned %d\n", retval); | ||
| 393 | } | 411 | } |
| 394 | 412 | ||
| 395 | return retval; | 413 | return retval; |
| @@ -442,6 +460,13 @@ static ssize_t show_dev(struct class_device *class_dev, char *buf) | |||
| 442 | return print_dev_t(buf, class_dev->devt); | 460 | return print_dev_t(buf, class_dev->devt); |
| 443 | } | 461 | } |
| 444 | 462 | ||
| 463 | static ssize_t store_uevent(struct class_device *class_dev, | ||
| 464 | const char *buf, size_t count) | ||
| 465 | { | ||
| 466 | kobject_hotplug(&class_dev->kobj, KOBJ_ADD); | ||
| 467 | return count; | ||
| 468 | } | ||
| 469 | |||
| 445 | void class_device_initialize(struct class_device *class_dev) | 470 | void class_device_initialize(struct class_device *class_dev) |
| 446 | { | 471 | { |
| 447 | kobj_set_kset_s(class_dev, class_obj_subsys); | 472 | kobj_set_kset_s(class_dev, class_obj_subsys); |
| @@ -469,34 +494,45 @@ static char *make_class_name(struct class_device *class_dev) | |||
| 469 | 494 | ||
| 470 | int class_device_add(struct class_device *class_dev) | 495 | int class_device_add(struct class_device *class_dev) |
| 471 | { | 496 | { |
| 472 | struct class * parent = NULL; | 497 | struct class *parent_class = NULL; |
| 473 | struct class_interface * class_intf; | 498 | struct class_device *parent_class_dev = NULL; |
| 499 | struct class_interface *class_intf; | ||
| 474 | char *class_name = NULL; | 500 | char *class_name = NULL; |
| 475 | int error; | 501 | int error = -EINVAL; |
| 476 | 502 | ||
| 477 | class_dev = class_device_get(class_dev); | 503 | class_dev = class_device_get(class_dev); |
| 478 | if (!class_dev) | 504 | if (!class_dev) |
| 479 | return -EINVAL; | 505 | return -EINVAL; |
| 480 | 506 | ||
| 481 | if (!strlen(class_dev->class_id)) { | 507 | if (!strlen(class_dev->class_id)) |
| 482 | error = -EINVAL; | ||
| 483 | goto register_done; | 508 | goto register_done; |
| 484 | } | ||
| 485 | 509 | ||
| 486 | parent = class_get(class_dev->class); | 510 | parent_class = class_get(class_dev->class); |
| 511 | if (!parent_class) | ||
| 512 | goto register_done; | ||
| 513 | parent_class_dev = class_device_get(class_dev->parent); | ||
| 487 | 514 | ||
| 488 | pr_debug("CLASS: registering class device: ID = '%s'\n", | 515 | pr_debug("CLASS: registering class device: ID = '%s'\n", |
| 489 | class_dev->class_id); | 516 | class_dev->class_id); |
| 490 | 517 | ||
| 491 | /* first, register with generic layer. */ | 518 | /* first, register with generic layer. */ |
| 492 | kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id); | 519 | kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id); |
| 493 | if (parent) | 520 | if (parent_class_dev) |
| 494 | class_dev->kobj.parent = &parent->subsys.kset.kobj; | 521 | class_dev->kobj.parent = &parent_class_dev->kobj; |
| 522 | else | ||
| 523 | class_dev->kobj.parent = &parent_class->subsys.kset.kobj; | ||
| 495 | 524 | ||
| 496 | if ((error = kobject_add(&class_dev->kobj))) | 525 | error = kobject_add(&class_dev->kobj); |
| 526 | if (error) | ||
| 497 | goto register_done; | 527 | goto register_done; |
| 498 | 528 | ||
| 499 | /* add the needed attributes to this device */ | 529 | /* add the needed attributes to this device */ |
| 530 | class_dev->uevent_attr.attr.name = "uevent"; | ||
| 531 | class_dev->uevent_attr.attr.mode = S_IWUSR; | ||
| 532 | class_dev->uevent_attr.attr.owner = parent_class->owner; | ||
| 533 | class_dev->uevent_attr.store = store_uevent; | ||
| 534 | class_device_create_file(class_dev, &class_dev->uevent_attr); | ||
| 535 | |||
| 500 | if (MAJOR(class_dev->devt)) { | 536 | if (MAJOR(class_dev->devt)) { |
| 501 | struct class_device_attribute *attr; | 537 | struct class_device_attribute *attr; |
| 502 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | 538 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
| @@ -505,12 +541,10 @@ int class_device_add(struct class_device *class_dev) | |||
| 505 | kobject_del(&class_dev->kobj); | 541 | kobject_del(&class_dev->kobj); |
| 506 | goto register_done; | 542 | goto register_done; |
| 507 | } | 543 | } |
| 508 | |||
| 509 | attr->attr.name = "dev"; | 544 | attr->attr.name = "dev"; |
| 510 | attr->attr.mode = S_IRUGO; | 545 | attr->attr.mode = S_IRUGO; |
| 511 | attr->attr.owner = parent->owner; | 546 | attr->attr.owner = parent_class->owner; |
| 512 | attr->show = show_dev; | 547 | attr->show = show_dev; |
| 513 | attr->store = NULL; | ||
| 514 | class_device_create_file(class_dev, attr); | 548 | class_device_create_file(class_dev, attr); |
| 515 | class_dev->devt_attr = attr; | 549 | class_dev->devt_attr = attr; |
| 516 | } | 550 | } |
| @@ -524,20 +558,23 @@ int class_device_add(struct class_device *class_dev) | |||
| 524 | class_name); | 558 | class_name); |
| 525 | } | 559 | } |
| 526 | 560 | ||
| 561 | kobject_hotplug(&class_dev->kobj, KOBJ_ADD); | ||
| 562 | |||
| 527 | /* notify any interfaces this device is now here */ | 563 | /* notify any interfaces this device is now here */ |
| 528 | if (parent) { | 564 | if (parent_class) { |
| 529 | down(&parent->sem); | 565 | down(&parent_class->sem); |
| 530 | list_add_tail(&class_dev->node, &parent->children); | 566 | list_add_tail(&class_dev->node, &parent_class->children); |
| 531 | list_for_each_entry(class_intf, &parent->interfaces, node) | 567 | list_for_each_entry(class_intf, &parent_class->interfaces, node) |
| 532 | if (class_intf->add) | 568 | if (class_intf->add) |
| 533 | class_intf->add(class_dev); | 569 | class_intf->add(class_dev, class_intf); |
| 534 | up(&parent->sem); | 570 | up(&parent_class->sem); |
| 535 | } | 571 | } |
| 536 | kobject_hotplug(&class_dev->kobj, KOBJ_ADD); | ||
| 537 | 572 | ||
| 538 | register_done: | 573 | register_done: |
| 539 | if (error && parent) | 574 | if (error) { |
| 540 | class_put(parent); | 575 | class_put(parent_class); |
| 576 | class_device_put(parent_class_dev); | ||
| 577 | } | ||
| 541 | class_device_put(class_dev); | 578 | class_device_put(class_dev); |
| 542 | kfree(class_name); | 579 | kfree(class_name); |
| 543 | return error; | 580 | return error; |
| @@ -552,21 +589,28 @@ int class_device_register(struct class_device *class_dev) | |||
| 552 | /** | 589 | /** |
| 553 | * class_device_create - creates a class device and registers it with sysfs | 590 | * class_device_create - creates a class device and registers it with sysfs |
| 554 | * @cs: pointer to the struct class that this device should be registered to. | 591 | * @cs: pointer to the struct class that this device should be registered to. |
| 592 | * @parent: pointer to the parent struct class_device of this new device, if any. | ||
| 555 | * @dev: the dev_t for the char device to be added. | 593 | * @dev: the dev_t for the char device to be added. |
| 556 | * @device: a pointer to a struct device that is assiociated with this class device. | 594 | * @device: a pointer to a struct device that is assiociated with this class device. |
| 557 | * @fmt: string for the class device's name | 595 | * @fmt: string for the class device's name |
| 558 | * | 596 | * |
| 559 | * This function can be used by char device classes. A struct | 597 | * This function can be used by char device classes. A struct |
| 560 | * class_device will be created in sysfs, registered to the specified | 598 | * class_device will be created in sysfs, registered to the specified |
| 561 | * class. A "dev" file will be created, showing the dev_t for the | 599 | * class. |
| 562 | * device. The pointer to the struct class_device will be returned from | 600 | * A "dev" file will be created, showing the dev_t for the device, if |
| 563 | * the call. Any further sysfs files that might be required can be | 601 | * the dev_t is not 0,0. |
| 564 | * created using this pointer. | 602 | * If a pointer to a parent struct class_device is passed in, the newly |
| 603 | * created struct class_device will be a child of that device in sysfs. | ||
| 604 | * The pointer to the struct class_device will be returned from the | ||
| 605 | * call. Any further sysfs files that might be required can be created | ||
| 606 | * using this pointer. | ||
| 565 | * | 607 | * |
| 566 | * Note: the struct class passed to this function must have previously | 608 | * Note: the struct class passed to this function must have previously |
| 567 | * been created with a call to class_create(). | 609 | * been created with a call to class_create(). |
| 568 | */ | 610 | */ |
| 569 | struct class_device *class_device_create(struct class *cls, dev_t devt, | 611 | struct class_device *class_device_create(struct class *cls, |
| 612 | struct class_device *parent, | ||
| 613 | dev_t devt, | ||
| 570 | struct device *device, char *fmt, ...) | 614 | struct device *device, char *fmt, ...) |
| 571 | { | 615 | { |
| 572 | va_list args; | 616 | va_list args; |
| @@ -585,6 +629,9 @@ struct class_device *class_device_create(struct class *cls, dev_t devt, | |||
| 585 | class_dev->devt = devt; | 629 | class_dev->devt = devt; |
| 586 | class_dev->dev = device; | 630 | class_dev->dev = device; |
| 587 | class_dev->class = cls; | 631 | class_dev->class = cls; |
| 632 | class_dev->parent = parent; | ||
| 633 | class_dev->release = class_device_create_release; | ||
| 634 | class_dev->hotplug = class_device_create_hotplug; | ||
| 588 | 635 | ||
| 589 | va_start(args, fmt); | 636 | va_start(args, fmt); |
| 590 | vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args); | 637 | vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args); |
| @@ -602,17 +649,18 @@ error: | |||
| 602 | 649 | ||
| 603 | void class_device_del(struct class_device *class_dev) | 650 | void class_device_del(struct class_device *class_dev) |
| 604 | { | 651 | { |
| 605 | struct class * parent = class_dev->class; | 652 | struct class *parent_class = class_dev->class; |
| 606 | struct class_interface * class_intf; | 653 | struct class_device *parent_device = class_dev->parent; |
| 654 | struct class_interface *class_intf; | ||
| 607 | char *class_name = NULL; | 655 | char *class_name = NULL; |
| 608 | 656 | ||
| 609 | if (parent) { | 657 | if (parent_class) { |
| 610 | down(&parent->sem); | 658 | down(&parent_class->sem); |
| 611 | list_del_init(&class_dev->node); | 659 | list_del_init(&class_dev->node); |
| 612 | list_for_each_entry(class_intf, &parent->interfaces, node) | 660 | list_for_each_entry(class_intf, &parent_class->interfaces, node) |
| 613 | if (class_intf->remove) | 661 | if (class_intf->remove) |
| 614 | class_intf->remove(class_dev); | 662 | class_intf->remove(class_dev, class_intf); |
| 615 | up(&parent->sem); | 663 | up(&parent_class->sem); |
| 616 | } | 664 | } |
| 617 | 665 | ||
| 618 | if (class_dev->dev) { | 666 | if (class_dev->dev) { |
| @@ -620,6 +668,7 @@ void class_device_del(struct class_device *class_dev) | |||
| 620 | sysfs_remove_link(&class_dev->kobj, "device"); | 668 | sysfs_remove_link(&class_dev->kobj, "device"); |
| 621 | sysfs_remove_link(&class_dev->dev->kobj, class_name); | 669 | sysfs_remove_link(&class_dev->dev->kobj, class_name); |
| 622 | } | 670 | } |
| 671 | class_device_remove_file(class_dev, &class_dev->uevent_attr); | ||
| 623 | if (class_dev->devt_attr) | 672 | if (class_dev->devt_attr) |
| 624 | class_device_remove_file(class_dev, class_dev->devt_attr); | 673 | class_device_remove_file(class_dev, class_dev->devt_attr); |
| 625 | class_device_remove_attrs(class_dev); | 674 | class_device_remove_attrs(class_dev); |
| @@ -627,8 +676,8 @@ void class_device_del(struct class_device *class_dev) | |||
| 627 | kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE); | 676 | kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE); |
| 628 | kobject_del(&class_dev->kobj); | 677 | kobject_del(&class_dev->kobj); |
| 629 | 678 | ||
| 630 | if (parent) | 679 | class_device_put(parent_device); |
| 631 | class_put(parent); | 680 | class_put(parent_class); |
| 632 | kfree(class_name); | 681 | kfree(class_name); |
| 633 | } | 682 | } |
| 634 | 683 | ||
| @@ -708,7 +757,8 @@ struct class_device * class_device_get(struct class_device *class_dev) | |||
| 708 | 757 | ||
| 709 | void class_device_put(struct class_device *class_dev) | 758 | void class_device_put(struct class_device *class_dev) |
| 710 | { | 759 | { |
| 711 | kobject_put(&class_dev->kobj); | 760 | if (class_dev) |
| 761 | kobject_put(&class_dev->kobj); | ||
| 712 | } | 762 | } |
| 713 | 763 | ||
| 714 | 764 | ||
| @@ -728,7 +778,7 @@ int class_interface_register(struct class_interface *class_intf) | |||
| 728 | list_add_tail(&class_intf->node, &parent->interfaces); | 778 | list_add_tail(&class_intf->node, &parent->interfaces); |
| 729 | if (class_intf->add) { | 779 | if (class_intf->add) { |
| 730 | list_for_each_entry(class_dev, &parent->children, node) | 780 | list_for_each_entry(class_dev, &parent->children, node) |
| 731 | class_intf->add(class_dev); | 781 | class_intf->add(class_dev, class_intf); |
| 732 | } | 782 | } |
| 733 | up(&parent->sem); | 783 | up(&parent->sem); |
| 734 | 784 | ||
| @@ -747,7 +797,7 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
| 747 | list_del_init(&class_intf->node); | 797 | list_del_init(&class_intf->node); |
| 748 | if (class_intf->remove) { | 798 | if (class_intf->remove) { |
| 749 | list_for_each_entry(class_dev, &parent->children, node) | 799 | list_for_each_entry(class_dev, &parent->children, node) |
| 750 | class_intf->remove(class_dev); | 800 | class_intf->remove(class_dev, class_intf); |
| 751 | } | 801 | } |
| 752 | up(&parent->sem); | 802 | up(&parent->sem); |
| 753 | 803 | ||
diff --git a/drivers/base/core.c b/drivers/base/core.c index 6ab73f5c799a..8615b42b517a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
| @@ -154,6 +154,13 @@ static struct kset_hotplug_ops device_hotplug_ops = { | |||
| 154 | .hotplug = dev_hotplug, | 154 | .hotplug = dev_hotplug, |
| 155 | }; | 155 | }; |
| 156 | 156 | ||
| 157 | static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | ||
| 158 | const char *buf, size_t count) | ||
| 159 | { | ||
| 160 | kobject_hotplug(&dev->kobj, KOBJ_ADD); | ||
| 161 | return count; | ||
| 162 | } | ||
| 163 | |||
| 157 | /** | 164 | /** |
| 158 | * device_subsys - structure to be registered with kobject core. | 165 | * device_subsys - structure to be registered with kobject core. |
| 159 | */ | 166 | */ |
| @@ -225,6 +232,7 @@ void device_initialize(struct device *dev) | |||
| 225 | klist_children_put); | 232 | klist_children_put); |
| 226 | INIT_LIST_HEAD(&dev->dma_pools); | 233 | INIT_LIST_HEAD(&dev->dma_pools); |
| 227 | init_MUTEX(&dev->sem); | 234 | init_MUTEX(&dev->sem); |
| 235 | device_init_wakeup(dev, 0); | ||
| 228 | } | 236 | } |
| 229 | 237 | ||
| 230 | /** | 238 | /** |
| @@ -258,6 +266,14 @@ int device_add(struct device *dev) | |||
| 258 | 266 | ||
| 259 | if ((error = kobject_add(&dev->kobj))) | 267 | if ((error = kobject_add(&dev->kobj))) |
| 260 | goto Error; | 268 | goto Error; |
| 269 | |||
| 270 | dev->uevent_attr.attr.name = "uevent"; | ||
| 271 | dev->uevent_attr.attr.mode = S_IWUSR; | ||
| 272 | if (dev->driver) | ||
| 273 | dev->uevent_attr.attr.owner = dev->driver->owner; | ||
| 274 | dev->uevent_attr.store = store_uevent; | ||
| 275 | device_create_file(dev, &dev->uevent_attr); | ||
| 276 | |||
| 261 | kobject_hotplug(&dev->kobj, KOBJ_ADD); | 277 | kobject_hotplug(&dev->kobj, KOBJ_ADD); |
| 262 | if ((error = device_pm_add(dev))) | 278 | if ((error = device_pm_add(dev))) |
| 263 | goto PMError; | 279 | goto PMError; |
| @@ -349,6 +365,7 @@ void device_del(struct device * dev) | |||
| 349 | 365 | ||
| 350 | if (parent) | 366 | if (parent) |
| 351 | klist_del(&dev->knode_parent); | 367 | klist_del(&dev->knode_parent); |
| 368 | device_remove_file(dev, &dev->uevent_attr); | ||
| 352 | 369 | ||
| 353 | /* Notify the platform of the removal, in case they | 370 | /* Notify the platform of the removal, in case they |
| 354 | * need to do anything... | 371 | * need to do anything... |
| @@ -390,11 +407,11 @@ static struct device * next_device(struct klist_iter * i) | |||
| 390 | 407 | ||
| 391 | /** | 408 | /** |
| 392 | * device_for_each_child - device child iterator. | 409 | * device_for_each_child - device child iterator. |
| 393 | * @dev: parent struct device. | 410 | * @parent: parent struct device. |
| 394 | * @data: data for the callback. | 411 | * @data: data for the callback. |
| 395 | * @fn: function to be called for each device. | 412 | * @fn: function to be called for each device. |
| 396 | * | 413 | * |
| 397 | * Iterate over @dev's child devices, and call @fn for each, | 414 | * Iterate over @parent's child devices, and call @fn for each, |
| 398 | * passing it @data. | 415 | * passing it @data. |
| 399 | * | 416 | * |
| 400 | * We check the return of @fn each time. If it returns anything | 417 | * We check the return of @fn each time. If it returns anything |
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index b79badd0f158..081c927b1ed8 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/topology.h> | 9 | #include <linux/topology.h> |
| 10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
| 11 | 11 | ||
| 12 | #include "base.h" | ||
| 12 | 13 | ||
| 13 | struct sysdev_class cpu_sysdev_class = { | 14 | struct sysdev_class cpu_sysdev_class = { |
| 14 | set_kset_name("cpu"), | 15 | set_kset_name("cpu"), |
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index ef3fe513e398..161f3a390d90 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
| @@ -28,6 +28,7 @@ static struct device * next_device(struct klist_iter * i) | |||
| 28 | /** | 28 | /** |
| 29 | * driver_for_each_device - Iterator for devices bound to a driver. | 29 | * driver_for_each_device - Iterator for devices bound to a driver. |
| 30 | * @drv: Driver we're iterating. | 30 | * @drv: Driver we're iterating. |
| 31 | * @start: Device to begin with | ||
| 31 | * @data: Data to pass to the callback. | 32 | * @data: Data to pass to the callback. |
| 32 | * @fn: Function to call for each device. | 33 | * @fn: Function to call for each device. |
| 33 | * | 34 | * |
| @@ -57,7 +58,7 @@ EXPORT_SYMBOL_GPL(driver_for_each_device); | |||
| 57 | 58 | ||
| 58 | /** | 59 | /** |
| 59 | * driver_find_device - device iterator for locating a particular device. | 60 | * driver_find_device - device iterator for locating a particular device. |
| 60 | * @driver: The device's driver | 61 | * @drv: The device's driver |
| 61 | * @start: Device to begin with | 62 | * @start: Device to begin with |
| 62 | * @data: Data to pass to match function | 63 | * @data: Data to pass to match function |
| 63 | * @match: Callback function to check device | 64 | * @match: Callback function to check device |
diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index 88ab044932f2..cb1b98ae0d58 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c | |||
| @@ -11,6 +11,9 @@ | |||
| 11 | #include <linux/kobject.h> | 11 | #include <linux/kobject.h> |
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
| 14 | #include <linux/device.h> | ||
| 15 | |||
| 16 | #include "base.h" | ||
| 14 | 17 | ||
| 15 | static decl_subsys(firmware, NULL, NULL); | 18 | static decl_subsys(firmware, NULL, NULL); |
| 16 | 19 | ||
diff --git a/drivers/base/init.c b/drivers/base/init.c index a76ae5a221f3..c648914b9cde 100644 --- a/drivers/base/init.c +++ b/drivers/base/init.c | |||
| @@ -9,15 +9,10 @@ | |||
| 9 | 9 | ||
| 10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
| 11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
| 12 | #include <linux/memory.h> | ||
| 13 | |||
| 14 | #include "base.h" | ||
| 12 | 15 | ||
| 13 | extern int devices_init(void); | ||
| 14 | extern int buses_init(void); | ||
| 15 | extern int classes_init(void); | ||
| 16 | extern int firmware_init(void); | ||
| 17 | extern int platform_bus_init(void); | ||
| 18 | extern int system_bus_init(void); | ||
| 19 | extern int cpu_dev_init(void); | ||
| 20 | extern int attribute_container_init(void); | ||
| 21 | /** | 16 | /** |
| 22 | * driver_init - initialize driver model. | 17 | * driver_init - initialize driver model. |
| 23 | * | 18 | * |
| @@ -39,5 +34,6 @@ void __init driver_init(void) | |||
| 39 | platform_bus_init(); | 34 | platform_bus_init(); |
| 40 | system_bus_init(); | 35 | system_bus_init(); |
| 41 | cpu_dev_init(); | 36 | cpu_dev_init(); |
| 37 | memory_dev_init(); | ||
| 42 | attribute_container_init(); | 38 | attribute_container_init(); |
| 43 | } | 39 | } |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c new file mode 100644 index 000000000000..b7ddd651d664 --- /dev/null +++ b/drivers/base/memory.c | |||
| @@ -0,0 +1,452 @@ | |||
| 1 | /* | ||
| 2 | * drivers/base/memory.c - basic Memory class support | ||
| 3 | * | ||
| 4 | * Written by Matt Tolentino <matthew.e.tolentino@intel.com> | ||
| 5 | * Dave Hansen <haveblue@us.ibm.com> | ||
| 6 | * | ||
| 7 | * This file provides the necessary infrastructure to represent | ||
| 8 | * a SPARSEMEM-memory-model system's physical memory in /sysfs. | ||
| 9 | * All arch-independent code that assumes MEMORY_HOTPLUG requires | ||
| 10 | * SPARSEMEM should be contained here, or in mm/memory_hotplug.c. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/sysdev.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/sched.h> /* capable() */ | ||
| 17 | #include <linux/topology.h> | ||
| 18 | #include <linux/device.h> | ||
| 19 | #include <linux/memory.h> | ||
| 20 | #include <linux/kobject.h> | ||
| 21 | #include <linux/memory_hotplug.h> | ||
| 22 | #include <linux/mm.h> | ||
| 23 | #include <asm/atomic.h> | ||
| 24 | #include <asm/uaccess.h> | ||
| 25 | |||
| 26 | #define MEMORY_CLASS_NAME "memory" | ||
| 27 | |||
| 28 | static struct sysdev_class memory_sysdev_class = { | ||
| 29 | set_kset_name(MEMORY_CLASS_NAME), | ||
| 30 | }; | ||
| 31 | EXPORT_SYMBOL(memory_sysdev_class); | ||
| 32 | |||
| 33 | static char *memory_hotplug_name(struct kset *kset, struct kobject *kobj) | ||
| 34 | { | ||
| 35 | return MEMORY_CLASS_NAME; | ||
| 36 | } | ||
| 37 | |||
| 38 | static int memory_hotplug(struct kset *kset, struct kobject *kobj, char **envp, | ||
| 39 | int num_envp, char *buffer, int buffer_size) | ||
| 40 | { | ||
| 41 | int retval = 0; | ||
| 42 | |||
| 43 | return retval; | ||
| 44 | } | ||
| 45 | |||
| 46 | static struct kset_hotplug_ops memory_hotplug_ops = { | ||
| 47 | .name = memory_hotplug_name, | ||
| 48 | .hotplug = memory_hotplug, | ||
| 49 | }; | ||
| 50 | |||
| 51 | static struct notifier_block *memory_chain; | ||
| 52 | |||
| 53 | static int register_memory_notifier(struct notifier_block *nb) | ||
| 54 | { | ||
| 55 | return notifier_chain_register(&memory_chain, nb); | ||
| 56 | } | ||
| 57 | |||
| 58 | static void unregister_memory_notifier(struct notifier_block *nb) | ||
| 59 | { | ||
| 60 | notifier_chain_unregister(&memory_chain, nb); | ||
| 61 | } | ||
| 62 | |||
| 63 | /* | ||
| 64 | * register_memory - Setup a sysfs device for a memory block | ||
| 65 | */ | ||
| 66 | static int | ||
| 67 | register_memory(struct memory_block *memory, struct mem_section *section, | ||
| 68 | struct node *root) | ||
| 69 | { | ||
| 70 | int error; | ||
| 71 | |||
| 72 | memory->sysdev.cls = &memory_sysdev_class; | ||
| 73 | memory->sysdev.id = __section_nr(section); | ||
| 74 | |||
| 75 | error = sysdev_register(&memory->sysdev); | ||
| 76 | |||
| 77 | if (root && !error) | ||
| 78 | error = sysfs_create_link(&root->sysdev.kobj, | ||
| 79 | &memory->sysdev.kobj, | ||
| 80 | kobject_name(&memory->sysdev.kobj)); | ||
| 81 | |||
| 82 | return error; | ||
| 83 | } | ||
| 84 | |||
| 85 | static void | ||
| 86 | unregister_memory(struct memory_block *memory, struct mem_section *section, | ||
| 87 | struct node *root) | ||
| 88 | { | ||
| 89 | BUG_ON(memory->sysdev.cls != &memory_sysdev_class); | ||
| 90 | BUG_ON(memory->sysdev.id != __section_nr(section)); | ||
| 91 | |||
| 92 | sysdev_unregister(&memory->sysdev); | ||
| 93 | if (root) | ||
| 94 | sysfs_remove_link(&root->sysdev.kobj, | ||
| 95 | kobject_name(&memory->sysdev.kobj)); | ||
| 96 | } | ||
| 97 | |||
| 98 | /* | ||
| 99 | * use this as the physical section index that this memsection | ||
| 100 | * uses. | ||
| 101 | */ | ||
| 102 | |||
| 103 | static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf) | ||
| 104 | { | ||
| 105 | struct memory_block *mem = | ||
| 106 | container_of(dev, struct memory_block, sysdev); | ||
| 107 | return sprintf(buf, "%08lx\n", mem->phys_index); | ||
| 108 | } | ||
| 109 | |||
| 110 | /* | ||
| 111 | * online, offline, going offline, etc. | ||
| 112 | */ | ||
| 113 | static ssize_t show_mem_state(struct sys_device *dev, char *buf) | ||
| 114 | { | ||
| 115 | struct memory_block *mem = | ||
| 116 | container_of(dev, struct memory_block, sysdev); | ||
| 117 | ssize_t len = 0; | ||
| 118 | |||
| 119 | /* | ||
| 120 | * We can probably put these states in a nice little array | ||
| 121 | * so that they're not open-coded | ||
| 122 | */ | ||
| 123 | switch (mem->state) { | ||
| 124 | case MEM_ONLINE: | ||
| 125 | len = sprintf(buf, "online\n"); | ||
| 126 | break; | ||
| 127 | case MEM_OFFLINE: | ||
| 128 | len = sprintf(buf, "offline\n"); | ||
| 129 | break; | ||
| 130 | case MEM_GOING_OFFLINE: | ||
| 131 | len = sprintf(buf, "going-offline\n"); | ||
| 132 | break; | ||
| 133 | default: | ||
| 134 | len = sprintf(buf, "ERROR-UNKNOWN-%ld\n", | ||
| 135 | mem->state); | ||
| 136 | WARN_ON(1); | ||
| 137 | break; | ||
| 138 | } | ||
| 139 | |||
| 140 | return len; | ||
| 141 | } | ||
| 142 | |||
| 143 | static inline int memory_notify(unsigned long val, void *v) | ||
| 144 | { | ||
| 145 | return notifier_call_chain(&memory_chain, val, v); | ||
| 146 | } | ||
| 147 | |||
| 148 | /* | ||
| 149 | * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is | ||
| 150 | * OK to have direct references to sparsemem variables in here. | ||
| 151 | */ | ||
| 152 | static int | ||
| 153 | memory_block_action(struct memory_block *mem, unsigned long action) | ||
| 154 | { | ||
| 155 | int i; | ||
| 156 | unsigned long psection; | ||
| 157 | unsigned long start_pfn, start_paddr; | ||
| 158 | struct page *first_page; | ||
| 159 | int ret; | ||
| 160 | int old_state = mem->state; | ||
| 161 | |||
| 162 | psection = mem->phys_index; | ||
| 163 | first_page = pfn_to_page(psection << PFN_SECTION_SHIFT); | ||
| 164 | |||
| 165 | /* | ||
| 166 | * The probe routines leave the pages reserved, just | ||
| 167 | * as the bootmem code does. Make sure they're still | ||
| 168 | * that way. | ||
| 169 | */ | ||
| 170 | if (action == MEM_ONLINE) { | ||
| 171 | for (i = 0; i < PAGES_PER_SECTION; i++) { | ||
| 172 | if (PageReserved(first_page+i)) | ||
| 173 | continue; | ||
| 174 | |||
| 175 | printk(KERN_WARNING "section number %ld page number %d " | ||
| 176 | "not reserved, was it already online? \n", | ||
| 177 | psection, i); | ||
| 178 | return -EBUSY; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | switch (action) { | ||
| 183 | case MEM_ONLINE: | ||
| 184 | start_pfn = page_to_pfn(first_page); | ||
| 185 | ret = online_pages(start_pfn, PAGES_PER_SECTION); | ||
| 186 | break; | ||
| 187 | case MEM_OFFLINE: | ||
| 188 | mem->state = MEM_GOING_OFFLINE; | ||
| 189 | memory_notify(MEM_GOING_OFFLINE, NULL); | ||
| 190 | start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; | ||
| 191 | ret = remove_memory(start_paddr, | ||
| 192 | PAGES_PER_SECTION << PAGE_SHIFT); | ||
| 193 | if (ret) { | ||
| 194 | mem->state = old_state; | ||
| 195 | break; | ||
| 196 | } | ||
| 197 | memory_notify(MEM_MAPPING_INVALID, NULL); | ||
| 198 | break; | ||
| 199 | default: | ||
| 200 | printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", | ||
| 201 | __FUNCTION__, mem, action, action); | ||
| 202 | WARN_ON(1); | ||
| 203 | ret = -EINVAL; | ||
| 204 | } | ||
| 205 | /* | ||
| 206 | * For now, only notify on successful memory operations | ||
| 207 | */ | ||
| 208 | if (!ret) | ||
| 209 | memory_notify(action, NULL); | ||
| 210 | |||
| 211 | return ret; | ||
| 212 | } | ||
| 213 | |||
| 214 | static int memory_block_change_state(struct memory_block *mem, | ||
| 215 | unsigned long to_state, unsigned long from_state_req) | ||
| 216 | { | ||
| 217 | int ret = 0; | ||
| 218 | down(&mem->state_sem); | ||
| 219 | |||
| 220 | if (mem->state != from_state_req) { | ||
| 221 | ret = -EINVAL; | ||
| 222 | goto out; | ||
| 223 | } | ||
| 224 | |||
| 225 | ret = memory_block_action(mem, to_state); | ||
| 226 | if (!ret) | ||
| 227 | mem->state = to_state; | ||
| 228 | |||
| 229 | out: | ||
| 230 | up(&mem->state_sem); | ||
| 231 | return ret; | ||
| 232 | } | ||
| 233 | |||
| 234 | static ssize_t | ||
| 235 | store_mem_state(struct sys_device *dev, const char *buf, size_t count) | ||
| 236 | { | ||
| 237 | struct memory_block *mem; | ||
| 238 | unsigned int phys_section_nr; | ||
| 239 | int ret = -EINVAL; | ||
| 240 | |||
| 241 | mem = container_of(dev, struct memory_block, sysdev); | ||
| 242 | phys_section_nr = mem->phys_index; | ||
| 243 | |||
| 244 | if (!valid_section_nr(phys_section_nr)) | ||
| 245 | goto out; | ||
| 246 | |||
| 247 | if (!strncmp(buf, "online", min((int)count, 6))) | ||
| 248 | ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); | ||
| 249 | else if(!strncmp(buf, "offline", min((int)count, 7))) | ||
| 250 | ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); | ||
| 251 | out: | ||
| 252 | if (ret) | ||
| 253 | return ret; | ||
| 254 | return count; | ||
| 255 | } | ||
| 256 | |||
| 257 | /* | ||
| 258 | * phys_device is a bad name for this. What I really want | ||
| 259 | * is a way to differentiate between memory ranges that | ||
| 260 | * are part of physical devices that constitute | ||
| 261 | * a complete removable unit or fru. | ||
| 262 | * i.e. do these ranges belong to the same physical device, | ||
| 263 | * s.t. if I offline all of these sections I can then | ||
| 264 | * remove the physical device? | ||
| 265 | */ | ||
| 266 | static ssize_t show_phys_device(struct sys_device *dev, char *buf) | ||
| 267 | { | ||
| 268 | struct memory_block *mem = | ||
| 269 | container_of(dev, struct memory_block, sysdev); | ||
| 270 | return sprintf(buf, "%d\n", mem->phys_device); | ||
| 271 | } | ||
| 272 | |||
| 273 | static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); | ||
| 274 | static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); | ||
| 275 | static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); | ||
| 276 | |||
| 277 | #define mem_create_simple_file(mem, attr_name) \ | ||
| 278 | sysdev_create_file(&mem->sysdev, &attr_##attr_name) | ||
| 279 | #define mem_remove_simple_file(mem, attr_name) \ | ||
| 280 | sysdev_remove_file(&mem->sysdev, &attr_##attr_name) | ||
| 281 | |||
| 282 | /* | ||
| 283 | * Block size attribute stuff | ||
| 284 | */ | ||
| 285 | static ssize_t | ||
| 286 | print_block_size(struct class *class, char *buf) | ||
| 287 | { | ||
| 288 | return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); | ||
| 289 | } | ||
| 290 | |||
| 291 | static CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); | ||
| 292 | |||
| 293 | static int block_size_init(void) | ||
| 294 | { | ||
| 295 | sysfs_create_file(&memory_sysdev_class.kset.kobj, | ||
| 296 | &class_attr_block_size_bytes.attr); | ||
| 297 | return 0; | ||
| 298 | } | ||
| 299 | |||
| 300 | /* | ||
| 301 | * Some architectures will have custom drivers to do this, and | ||
| 302 | * will not need to do it from userspace. The fake hot-add code | ||
| 303 | * as well as ppc64 will do all of their discovery in userspace | ||
| 304 | * and will require this interface. | ||
| 305 | */ | ||
| 306 | #ifdef CONFIG_ARCH_MEMORY_PROBE | ||
| 307 | static ssize_t | ||
| 308 | memory_probe_store(struct class *class, const char __user *buf, size_t count) | ||
| 309 | { | ||
| 310 | u64 phys_addr; | ||
| 311 | int ret; | ||
| 312 | |||
| 313 | phys_addr = simple_strtoull(buf, NULL, 0); | ||
| 314 | |||
| 315 | ret = add_memory(phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); | ||
| 316 | |||
| 317 | if (ret) | ||
| 318 | count = ret; | ||
| 319 | |||
| 320 | return count; | ||
| 321 | } | ||
| 322 | static CLASS_ATTR(probe, 0700, NULL, memory_probe_store); | ||
| 323 | |||
| 324 | static int memory_probe_init(void) | ||
| 325 | { | ||
| 326 | sysfs_create_file(&memory_sysdev_class.kset.kobj, | ||
| 327 | &class_attr_probe.attr); | ||
| 328 | return 0; | ||
| 329 | } | ||
| 330 | #else | ||
| 331 | #define memory_probe_init(...) do {} while (0) | ||
| 332 | #endif | ||
| 333 | |||
| 334 | /* | ||
| 335 | * Note that phys_device is optional. It is here to allow for | ||
| 336 | * differentiation between which *physical* devices each | ||
| 337 | * section belongs to... | ||
| 338 | */ | ||
| 339 | |||
| 340 | static int add_memory_block(unsigned long node_id, struct mem_section *section, | ||
| 341 | unsigned long state, int phys_device) | ||
| 342 | { | ||
| 343 | struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); | ||
| 344 | int ret = 0; | ||
| 345 | |||
| 346 | if (!mem) | ||
| 347 | return -ENOMEM; | ||
| 348 | |||
| 349 | mem->phys_index = __section_nr(section); | ||
| 350 | mem->state = state; | ||
| 351 | init_MUTEX(&mem->state_sem); | ||
| 352 | mem->phys_device = phys_device; | ||
| 353 | |||
| 354 | ret = register_memory(mem, section, NULL); | ||
| 355 | if (!ret) | ||
| 356 | ret = mem_create_simple_file(mem, phys_index); | ||
| 357 | if (!ret) | ||
| 358 | ret = mem_create_simple_file(mem, state); | ||
| 359 | if (!ret) | ||
| 360 | ret = mem_create_simple_file(mem, phys_device); | ||
| 361 | |||
| 362 | return ret; | ||
| 363 | } | ||
| 364 | |||
| 365 | /* | ||
| 366 | * For now, we have a linear search to go find the appropriate | ||
| 367 | * memory_block corresponding to a particular phys_index. If | ||
| 368 | * this gets to be a real problem, we can always use a radix | ||
| 369 | * tree or something here. | ||
| 370 | * | ||
| 371 | * This could be made generic for all sysdev classes. | ||
| 372 | */ | ||
| 373 | static struct memory_block *find_memory_block(struct mem_section *section) | ||
| 374 | { | ||
| 375 | struct kobject *kobj; | ||
| 376 | struct sys_device *sysdev; | ||
| 377 | struct memory_block *mem; | ||
| 378 | char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; | ||
| 379 | |||
| 380 | /* | ||
| 381 | * This only works because we know that section == sysdev->id | ||
| 382 | * slightly redundant with sysdev_register() | ||
| 383 | */ | ||
| 384 | sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section)); | ||
| 385 | |||
| 386 | kobj = kset_find_obj(&memory_sysdev_class.kset, name); | ||
| 387 | if (!kobj) | ||
| 388 | return NULL; | ||
| 389 | |||
| 390 | sysdev = container_of(kobj, struct sys_device, kobj); | ||
| 391 | mem = container_of(sysdev, struct memory_block, sysdev); | ||
| 392 | |||
| 393 | return mem; | ||
| 394 | } | ||
| 395 | |||
| 396 | int remove_memory_block(unsigned long node_id, struct mem_section *section, | ||
| 397 | int phys_device) | ||
| 398 | { | ||
| 399 | struct memory_block *mem; | ||
| 400 | |||
| 401 | mem = find_memory_block(section); | ||
| 402 | mem_remove_simple_file(mem, phys_index); | ||
| 403 | mem_remove_simple_file(mem, state); | ||
| 404 | mem_remove_simple_file(mem, phys_device); | ||
| 405 | unregister_memory(mem, section, NULL); | ||
| 406 | |||
| 407 | return 0; | ||
| 408 | } | ||
| 409 | |||
| 410 | /* | ||
| 411 | * need an interface for the VM to add new memory regions, | ||
| 412 | * but without onlining it. | ||
| 413 | */ | ||
| 414 | int register_new_memory(struct mem_section *section) | ||
| 415 | { | ||
| 416 | return add_memory_block(0, section, MEM_OFFLINE, 0); | ||
| 417 | } | ||
| 418 | |||
| 419 | int unregister_memory_section(struct mem_section *section) | ||
| 420 | { | ||
| 421 | if (!valid_section(section)) | ||
| 422 | return -EINVAL; | ||
| 423 | |||
| 424 | return remove_memory_block(0, section, 0); | ||
| 425 | } | ||
| 426 | |||
| 427 | /* | ||
| 428 | * Initialize the sysfs support for memory devices... | ||
| 429 | */ | ||
| 430 | int __init memory_dev_init(void) | ||
| 431 | { | ||
| 432 | unsigned int i; | ||
| 433 | int ret; | ||
| 434 | |||
| 435 | memory_sysdev_class.kset.hotplug_ops = &memory_hotplug_ops; | ||
| 436 | ret = sysdev_class_register(&memory_sysdev_class); | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Create entries for memory sections that were found | ||
| 440 | * during boot and have been initialized | ||
| 441 | */ | ||
| 442 | for (i = 0; i < NR_MEM_SECTIONS; i++) { | ||
| 443 | if (!valid_section_nr(i)) | ||
| 444 | continue; | ||
| 445 | add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 0); | ||
| 446 | } | ||
| 447 | |||
| 448 | memory_probe_init(); | ||
| 449 | block_size_init(); | ||
| 450 | |||
| 451 | return ret; | ||
| 452 | } | ||
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 361e204209eb..75ce8711bca5 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | #include <linux/bootmem.h> | 17 | #include <linux/bootmem.h> |
| 18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
| 19 | 19 | ||
| 20 | #include "base.h" | ||
| 21 | |||
| 20 | struct device platform_bus = { | 22 | struct device platform_bus = { |
| 21 | .bus_id = "platform", | 23 | .bus_id = "platform", |
| 22 | }; | 24 | }; |
| @@ -279,13 +281,9 @@ static int platform_suspend(struct device * dev, pm_message_t state) | |||
| 279 | { | 281 | { |
| 280 | int ret = 0; | 282 | int ret = 0; |
| 281 | 283 | ||
| 282 | if (dev->driver && dev->driver->suspend) { | 284 | if (dev->driver && dev->driver->suspend) |
| 283 | ret = dev->driver->suspend(dev, state, SUSPEND_DISABLE); | 285 | ret = dev->driver->suspend(dev, state); |
| 284 | if (ret == 0) | 286 | |
| 285 | ret = dev->driver->suspend(dev, state, SUSPEND_SAVE_STATE); | ||
| 286 | if (ret == 0) | ||
| 287 | ret = dev->driver->suspend(dev, state, SUSPEND_POWER_DOWN); | ||
| 288 | } | ||
| 289 | return ret; | 287 | return ret; |
| 290 | } | 288 | } |
| 291 | 289 | ||
| @@ -293,13 +291,9 @@ static int platform_resume(struct device * dev) | |||
| 293 | { | 291 | { |
| 294 | int ret = 0; | 292 | int ret = 0; |
| 295 | 293 | ||
| 296 | if (dev->driver && dev->driver->resume) { | 294 | if (dev->driver && dev->driver->resume) |
| 297 | ret = dev->driver->resume(dev, RESUME_POWER_ON); | 295 | ret = dev->driver->resume(dev); |
| 298 | if (ret == 0) | 296 | |
| 299 | ret = dev->driver->resume(dev, RESUME_RESTORE_STATE); | ||
| 300 | if (ret == 0) | ||
| 301 | ret = dev->driver->resume(dev, RESUME_ENABLE); | ||
| 302 | } | ||
| 303 | return ret; | 297 | return ret; |
| 304 | } | 298 | } |
| 305 | 299 | ||
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 15e6a8f951f1..0d2e101e4f15 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
| @@ -30,23 +30,6 @@ LIST_HEAD(dpm_off_irq); | |||
| 30 | DECLARE_MUTEX(dpm_sem); | 30 | DECLARE_MUTEX(dpm_sem); |
| 31 | DECLARE_MUTEX(dpm_list_sem); | 31 | DECLARE_MUTEX(dpm_list_sem); |
| 32 | 32 | ||
| 33 | /* | ||
| 34 | * PM Reference Counting. | ||
| 35 | */ | ||
| 36 | |||
| 37 | static inline void device_pm_hold(struct device * dev) | ||
| 38 | { | ||
| 39 | if (dev) | ||
| 40 | atomic_inc(&dev->power.pm_users); | ||
| 41 | } | ||
| 42 | |||
| 43 | static inline void device_pm_release(struct device * dev) | ||
| 44 | { | ||
| 45 | if (dev) | ||
| 46 | atomic_dec(&dev->power.pm_users); | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | /** | 33 | /** |
| 51 | * device_pm_set_parent - Specify power dependency. | 34 | * device_pm_set_parent - Specify power dependency. |
| 52 | * @dev: Device who needs power. | 35 | * @dev: Device who needs power. |
| @@ -62,10 +45,8 @@ static inline void device_pm_release(struct device * dev) | |||
| 62 | 45 | ||
| 63 | void device_pm_set_parent(struct device * dev, struct device * parent) | 46 | void device_pm_set_parent(struct device * dev, struct device * parent) |
| 64 | { | 47 | { |
| 65 | struct device * old_parent = dev->power.pm_parent; | 48 | put_device(dev->power.pm_parent); |
| 66 | device_pm_release(old_parent); | 49 | dev->power.pm_parent = get_device(parent); |
| 67 | dev->power.pm_parent = parent; | ||
| 68 | device_pm_hold(parent); | ||
| 69 | } | 50 | } |
| 70 | EXPORT_SYMBOL_GPL(device_pm_set_parent); | 51 | EXPORT_SYMBOL_GPL(device_pm_set_parent); |
| 71 | 52 | ||
| @@ -75,7 +56,6 @@ int device_pm_add(struct device * dev) | |||
| 75 | 56 | ||
| 76 | pr_debug("PM: Adding info for %s:%s\n", | 57 | pr_debug("PM: Adding info for %s:%s\n", |
| 77 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); | 58 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); |
| 78 | atomic_set(&dev->power.pm_users, 0); | ||
| 79 | down(&dpm_list_sem); | 59 | down(&dpm_list_sem); |
| 80 | list_add_tail(&dev->power.entry, &dpm_active); | 60 | list_add_tail(&dev->power.entry, &dpm_active); |
| 81 | device_pm_set_parent(dev, dev->parent); | 61 | device_pm_set_parent(dev, dev->parent); |
| @@ -91,7 +71,7 @@ void device_pm_remove(struct device * dev) | |||
| 91 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); | 71 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); |
| 92 | down(&dpm_list_sem); | 72 | down(&dpm_list_sem); |
| 93 | dpm_sysfs_remove(dev); | 73 | dpm_sysfs_remove(dev); |
| 94 | device_pm_release(dev->power.pm_parent); | 74 | put_device(dev->power.pm_parent); |
| 95 | list_del_init(&dev->power.entry); | 75 | list_del_init(&dev->power.entry); |
| 96 | up(&dpm_list_sem); | 76 | up(&dpm_list_sem); |
| 97 | } | 77 | } |
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index 2e700d795cf1..fb3d35a9e101 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h | |||
| @@ -67,9 +67,6 @@ extern int suspend_device(struct device *, pm_message_t); | |||
| 67 | * runtime.c | 67 | * runtime.c |
| 68 | */ | 68 | */ |
| 69 | 69 | ||
| 70 | extern int dpm_runtime_suspend(struct device *, pm_message_t); | ||
| 71 | extern void dpm_runtime_resume(struct device *); | ||
| 72 | |||
| 73 | #else /* CONFIG_PM */ | 70 | #else /* CONFIG_PM */ |
| 74 | 71 | ||
| 75 | 72 | ||
| @@ -82,14 +79,4 @@ static inline void device_pm_remove(struct device * dev) | |||
| 82 | 79 | ||
| 83 | } | 80 | } |
| 84 | 81 | ||
| 85 | static inline int dpm_runtime_suspend(struct device * dev, pm_message_t state) | ||
| 86 | { | ||
| 87 | return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | static inline void dpm_runtime_resume(struct device * dev) | ||
| 91 | { | ||
| 92 | |||
| 93 | } | ||
| 94 | |||
| 95 | #endif | 82 | #endif |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index e8f0519f5dfa..adbc3148c039 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
| @@ -36,6 +36,7 @@ void dpm_runtime_resume(struct device * dev) | |||
| 36 | runtime_resume(dev); | 36 | runtime_resume(dev); |
| 37 | up(&dpm_sem); | 37 | up(&dpm_sem); |
| 38 | } | 38 | } |
| 39 | EXPORT_SYMBOL(dpm_runtime_resume); | ||
| 39 | 40 | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index 8d04fb435c17..89c57875f3e5 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
| @@ -48,8 +48,81 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
| 48 | static DEVICE_ATTR(state, 0644, state_show, state_store); | 48 | static DEVICE_ATTR(state, 0644, state_show, state_store); |
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | /* | ||
| 52 | * wakeup - Report/change current wakeup option for device | ||
| 53 | * | ||
| 54 | * Some devices support "wakeup" events, which are hardware signals | ||
| 55 | * used to activate devices from suspended or low power states. Such | ||
| 56 | * devices have one of three values for the sysfs power/wakeup file: | ||
| 57 | * | ||
| 58 | * + "enabled\n" to issue the events; | ||
| 59 | * + "disabled\n" not to do so; or | ||
| 60 | * + "\n" for temporary or permanent inability to issue wakeup. | ||
| 61 | * | ||
| 62 | * (For example, unconfigured USB devices can't issue wakeups.) | ||
| 63 | * | ||
| 64 | * Familiar examples of devices that can issue wakeup events include | ||
| 65 | * keyboards and mice (both PS2 and USB styles), power buttons, modems, | ||
| 66 | * "Wake-On-LAN" Ethernet links, GPIO lines, and more. Some events | ||
| 67 | * will wake the entire system from a suspend state; others may just | ||
| 68 | * wake up the device (if the system as a whole is already active). | ||
| 69 | * Some wakeup events use normal IRQ lines; other use special out | ||
| 70 | * of band signaling. | ||
| 71 | * | ||
| 72 | * It is the responsibility of device drivers to enable (or disable) | ||
| 73 | * wakeup signaling as part of changing device power states, respecting | ||
| 74 | * the policy choices provided through the driver model. | ||
| 75 | * | ||
| 76 | * Devices may not be able to generate wakeup events from all power | ||
| 77 | * states. Also, the events may be ignored in some configurations; | ||
| 78 | * for example, they might need help from other devices that aren't | ||
| 79 | * active, or which may have wakeup disabled. Some drivers rely on | ||
| 80 | * wakeup events internally (unless they are disabled), keeping | ||
| 81 | * their hardware in low power modes whenever they're unused. This | ||
| 82 | * saves runtime power, without requiring system-wide sleep states. | ||
| 83 | */ | ||
| 84 | |||
| 85 | static const char enabled[] = "enabled"; | ||
| 86 | static const char disabled[] = "disabled"; | ||
| 87 | |||
| 88 | static ssize_t | ||
| 89 | wake_show(struct device * dev, struct device_attribute *attr, char * buf) | ||
| 90 | { | ||
| 91 | return sprintf(buf, "%s\n", device_can_wakeup(dev) | ||
| 92 | ? (device_may_wakeup(dev) ? enabled : disabled) | ||
| 93 | : ""); | ||
| 94 | } | ||
| 95 | |||
| 96 | static ssize_t | ||
| 97 | wake_store(struct device * dev, struct device_attribute *attr, | ||
| 98 | const char * buf, size_t n) | ||
| 99 | { | ||
| 100 | char *cp; | ||
| 101 | int len = n; | ||
| 102 | |||
| 103 | if (!device_can_wakeup(dev)) | ||
| 104 | return -EINVAL; | ||
| 105 | |||
| 106 | cp = memchr(buf, '\n', n); | ||
| 107 | if (cp) | ||
| 108 | len = cp - buf; | ||
| 109 | if (len == sizeof enabled - 1 | ||
| 110 | && strncmp(buf, enabled, sizeof enabled - 1) == 0) | ||
| 111 | device_set_wakeup_enable(dev, 1); | ||
| 112 | else if (len == sizeof disabled - 1 | ||
| 113 | && strncmp(buf, disabled, sizeof disabled - 1) == 0) | ||
| 114 | device_set_wakeup_enable(dev, 0); | ||
| 115 | else | ||
| 116 | return -EINVAL; | ||
| 117 | return n; | ||
| 118 | } | ||
| 119 | |||
| 120 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | ||
| 121 | |||
| 122 | |||
| 51 | static struct attribute * power_attrs[] = { | 123 | static struct attribute * power_attrs[] = { |
| 52 | &dev_attr_state.attr, | 124 | &dev_attr_state.attr, |
| 125 | &dev_attr_wakeup.attr, | ||
| 53 | NULL, | 126 | NULL, |
| 54 | }; | 127 | }; |
| 55 | static struct attribute_group pm_attr_group = { | 128 | static struct attribute_group pm_attr_group = { |
