diff options
author | Gavin Shan <gwshan@linux.vnet.ibm.com> | 2015-11-04 08:12:49 -0500 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2016-01-13 17:10:37 -0500 |
commit | 183223770ae8625df8966ed15811d1b3ee8720aa (patch) | |
tree | a7f994ffd55b80d765ac01283d7f5412fdd5d383 | |
parent | dc17340e3041511850ff6ec7299551284d6c0eb1 (diff) |
drivers/of: Export OF changeset functions
The PowerNV PCI hotplug driver is going to use the OF changeset
to manage the changed device sub-tree. This exports those OF
changeset functions for that.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/dynamic.c | 65 | ||||
-rw-r--r-- | drivers/of/of_private.h | 2 | ||||
-rw-r--r-- | drivers/of/overlay.c | 8 | ||||
-rw-r--r-- | drivers/of/unittest.c | 4 |
4 files changed, 52 insertions, 27 deletions
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 53826b84e0ec..c647bd1b6903 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c | |||
@@ -646,6 +646,7 @@ void of_changeset_init(struct of_changeset *ocs) | |||
646 | memset(ocs, 0, sizeof(*ocs)); | 646 | memset(ocs, 0, sizeof(*ocs)); |
647 | INIT_LIST_HEAD(&ocs->entries); | 647 | INIT_LIST_HEAD(&ocs->entries); |
648 | } | 648 | } |
649 | EXPORT_SYMBOL_GPL(of_changeset_init); | ||
649 | 650 | ||
650 | /** | 651 | /** |
651 | * of_changeset_destroy - Destroy a changeset | 652 | * of_changeset_destroy - Destroy a changeset |
@@ -662,20 +663,9 @@ void of_changeset_destroy(struct of_changeset *ocs) | |||
662 | list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) | 663 | list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) |
663 | __of_changeset_entry_destroy(ce); | 664 | __of_changeset_entry_destroy(ce); |
664 | } | 665 | } |
666 | EXPORT_SYMBOL_GPL(of_changeset_destroy); | ||
665 | 667 | ||
666 | /** | 668 | int __of_changeset_apply(struct of_changeset *ocs) |
667 | * of_changeset_apply - Applies a changeset | ||
668 | * | ||
669 | * @ocs: changeset pointer | ||
670 | * | ||
671 | * Applies a changeset to the live tree. | ||
672 | * Any side-effects of live tree state changes are applied here on | ||
673 | * sucess, like creation/destruction of devices and side-effects | ||
674 | * like creation of sysfs properties and directories. | ||
675 | * Returns 0 on success, a negative error value in case of an error. | ||
676 | * On error the partially applied effects are reverted. | ||
677 | */ | ||
678 | int of_changeset_apply(struct of_changeset *ocs) | ||
679 | { | 669 | { |
680 | struct of_changeset_entry *ce; | 670 | struct of_changeset_entry *ce; |
681 | int ret; | 671 | int ret; |
@@ -704,17 +694,30 @@ int of_changeset_apply(struct of_changeset *ocs) | |||
704 | } | 694 | } |
705 | 695 | ||
706 | /** | 696 | /** |
707 | * of_changeset_revert - Reverts an applied changeset | 697 | * of_changeset_apply - Applies a changeset |
708 | * | 698 | * |
709 | * @ocs: changeset pointer | 699 | * @ocs: changeset pointer |
710 | * | 700 | * |
711 | * Reverts a changeset returning the state of the tree to what it | 701 | * Applies a changeset to the live tree. |
712 | * was before the application. | 702 | * Any side-effects of live tree state changes are applied here on |
713 | * Any side-effects like creation/destruction of devices and | 703 | * success, like creation/destruction of devices and side-effects |
714 | * removal of sysfs properties and directories are applied. | 704 | * like creation of sysfs properties and directories. |
715 | * Returns 0 on success, a negative error value in case of an error. | 705 | * Returns 0 on success, a negative error value in case of an error. |
706 | * On error the partially applied effects are reverted. | ||
716 | */ | 707 | */ |
717 | int of_changeset_revert(struct of_changeset *ocs) | 708 | int of_changeset_apply(struct of_changeset *ocs) |
709 | { | ||
710 | int ret; | ||
711 | |||
712 | mutex_lock(&of_mutex); | ||
713 | ret = __of_changeset_apply(ocs); | ||
714 | mutex_unlock(&of_mutex); | ||
715 | |||
716 | return ret; | ||
717 | } | ||
718 | EXPORT_SYMBOL_GPL(of_changeset_apply); | ||
719 | |||
720 | int __of_changeset_revert(struct of_changeset *ocs) | ||
718 | { | 721 | { |
719 | struct of_changeset_entry *ce; | 722 | struct of_changeset_entry *ce; |
720 | int ret; | 723 | int ret; |
@@ -742,6 +745,29 @@ int of_changeset_revert(struct of_changeset *ocs) | |||
742 | } | 745 | } |
743 | 746 | ||
744 | /** | 747 | /** |
748 | * of_changeset_revert - Reverts an applied changeset | ||
749 | * | ||
750 | * @ocs: changeset pointer | ||
751 | * | ||
752 | * Reverts a changeset returning the state of the tree to what it | ||
753 | * was before the application. | ||
754 | * Any side-effects like creation/destruction of devices and | ||
755 | * removal of sysfs properties and directories are applied. | ||
756 | * Returns 0 on success, a negative error value in case of an error. | ||
757 | */ | ||
758 | int of_changeset_revert(struct of_changeset *ocs) | ||
759 | { | ||
760 | int ret; | ||
761 | |||
762 | mutex_lock(&of_mutex); | ||
763 | ret = __of_changeset_revert(ocs); | ||
764 | mutex_unlock(&of_mutex); | ||
765 | |||
766 | return ret; | ||
767 | } | ||
768 | EXPORT_SYMBOL_GPL(of_changeset_revert); | ||
769 | |||
770 | /** | ||
745 | * of_changeset_action - Perform a changeset action | 771 | * of_changeset_action - Perform a changeset action |
746 | * | 772 | * |
747 | * @ocs: changeset pointer | 773 | * @ocs: changeset pointer |
@@ -779,3 +805,4 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action, | |||
779 | list_add_tail(&ce->node, &ocs->entries); | 805 | list_add_tail(&ce->node, &ocs->entries); |
780 | return 0; | 806 | return 0; |
781 | } | 807 | } |
808 | EXPORT_SYMBOL_GPL(of_changeset_action); | ||
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 8e882e706cd8..829469faeb23 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h | |||
@@ -45,6 +45,8 @@ static inline struct device_node *kobj_to_device_node(struct kobject *kobj) | |||
45 | extern int of_property_notify(int action, struct device_node *np, | 45 | extern int of_property_notify(int action, struct device_node *np, |
46 | struct property *prop, struct property *old_prop); | 46 | struct property *prop, struct property *old_prop); |
47 | extern void of_node_release(struct kobject *kobj); | 47 | extern void of_node_release(struct kobject *kobj); |
48 | extern int __of_changeset_apply(struct of_changeset *ocs); | ||
49 | extern int __of_changeset_revert(struct of_changeset *ocs); | ||
48 | #else /* CONFIG_OF_DYNAMIC */ | 50 | #else /* CONFIG_OF_DYNAMIC */ |
49 | static inline int of_property_notify(int action, struct device_node *np, | 51 | static inline int of_property_notify(int action, struct device_node *np, |
50 | struct property *prop, struct property *old_prop) | 52 | struct property *prop, struct property *old_prop) |
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 54e5af9d7377..82250815e9a5 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c | |||
@@ -379,9 +379,9 @@ int of_overlay_create(struct device_node *tree) | |||
379 | } | 379 | } |
380 | 380 | ||
381 | /* apply the changeset */ | 381 | /* apply the changeset */ |
382 | err = of_changeset_apply(&ov->cset); | 382 | err = __of_changeset_apply(&ov->cset); |
383 | if (err) { | 383 | if (err) { |
384 | pr_err("%s: of_changeset_apply() failed for tree@%s\n", | 384 | pr_err("%s: __of_changeset_apply() failed for tree@%s\n", |
385 | __func__, tree->full_name); | 385 | __func__, tree->full_name); |
386 | goto err_revert_overlay; | 386 | goto err_revert_overlay; |
387 | } | 387 | } |
@@ -511,7 +511,7 @@ int of_overlay_destroy(int id) | |||
511 | 511 | ||
512 | 512 | ||
513 | list_del(&ov->node); | 513 | list_del(&ov->node); |
514 | of_changeset_revert(&ov->cset); | 514 | __of_changeset_revert(&ov->cset); |
515 | of_free_overlay_info(ov); | 515 | of_free_overlay_info(ov); |
516 | idr_remove(&ov_idr, id); | 516 | idr_remove(&ov_idr, id); |
517 | of_changeset_destroy(&ov->cset); | 517 | of_changeset_destroy(&ov->cset); |
@@ -542,7 +542,7 @@ int of_overlay_destroy_all(void) | |||
542 | /* the tail of list is guaranteed to be safe to remove */ | 542 | /* the tail of list is guaranteed to be safe to remove */ |
543 | list_for_each_entry_safe_reverse(ov, ovn, &ov_list, node) { | 543 | list_for_each_entry_safe_reverse(ov, ovn, &ov_list, node) { |
544 | list_del(&ov->node); | 544 | list_del(&ov->node); |
545 | of_changeset_revert(&ov->cset); | 545 | __of_changeset_revert(&ov->cset); |
546 | of_free_overlay_info(ov); | 546 | of_free_overlay_info(ov); |
547 | idr_remove(&ov_idr, ov->id); | 547 | idr_remove(&ov_idr, ov->id); |
548 | kfree(ov); | 548 | kfree(ov); |
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index bbff09dee1cf..979b6e415cea 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c | |||
@@ -530,18 +530,14 @@ static void __init of_unittest_changeset(void) | |||
530 | unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); | 530 | unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); |
531 | unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); | 531 | unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); |
532 | unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); | 532 | unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); |
533 | mutex_lock(&of_mutex); | ||
534 | unittest(!of_changeset_apply(&chgset), "apply failed\n"); | 533 | unittest(!of_changeset_apply(&chgset), "apply failed\n"); |
535 | mutex_unlock(&of_mutex); | ||
536 | 534 | ||
537 | /* Make sure node names are constructed correctly */ | 535 | /* Make sure node names are constructed correctly */ |
538 | unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), | 536 | unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), |
539 | "'%s' not added\n", n21->full_name); | 537 | "'%s' not added\n", n21->full_name); |
540 | of_node_put(np); | 538 | of_node_put(np); |
541 | 539 | ||
542 | mutex_lock(&of_mutex); | ||
543 | unittest(!of_changeset_revert(&chgset), "revert failed\n"); | 540 | unittest(!of_changeset_revert(&chgset), "revert failed\n"); |
544 | mutex_unlock(&of_mutex); | ||
545 | 541 | ||
546 | of_changeset_destroy(&chgset); | 542 | of_changeset_destroy(&chgset); |
547 | #endif | 543 | #endif |