diff options
| author | Grant Likely <grant.likely@secretlab.ca> | 2009-11-23 22:16:45 -0500 |
|---|---|---|
| committer | Grant Likely <grant.likely@secretlab.ca> | 2009-11-23 22:16:45 -0500 |
| commit | 02af11b03fce3ddb264d7873d7a2e295e697938c (patch) | |
| tree | 5118d53f2c28d128d23fbf1b2d79d9ec15e5b6ab | |
| parent | 41f880091c15b039ffcc8b3d831656b81517a6d3 (diff) | |
of: merge prom_{add,remove,modify}_property
Merge common code between PowerPC and MicroBlaze
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Reviewed-by: Wolfram Sang <w.sang@pengutronix.de>
Tested-by: Michal Simek <monstr@monstr.eu>
| -rw-r--r-- | arch/microblaze/kernel/prom.c | 113 | ||||
| -rw-r--r-- | arch/powerpc/kernel/prom.c | 114 | ||||
| -rw-r--r-- | drivers/of/base.c | 116 |
3 files changed, 116 insertions, 227 deletions
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c index 901d538c15ef..a38e3733a09c 100644 --- a/arch/microblaze/kernel/prom.c +++ b/arch/microblaze/kernel/prom.c | |||
| @@ -606,119 +606,6 @@ out_unlock: | |||
| 606 | write_unlock_irqrestore(&devtree_lock, flags); | 606 | write_unlock_irqrestore(&devtree_lock, flags); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | /* | ||
| 610 | * Add a property to a node | ||
| 611 | */ | ||
| 612 | int prom_add_property(struct device_node *np, struct property *prop) | ||
| 613 | { | ||
| 614 | struct property **next; | ||
| 615 | unsigned long flags; | ||
| 616 | |||
| 617 | prop->next = NULL; | ||
| 618 | write_lock_irqsave(&devtree_lock, flags); | ||
| 619 | next = &np->properties; | ||
| 620 | while (*next) { | ||
| 621 | if (strcmp(prop->name, (*next)->name) == 0) { | ||
| 622 | /* duplicate ! don't insert it */ | ||
| 623 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 624 | return -1; | ||
| 625 | } | ||
| 626 | next = &(*next)->next; | ||
| 627 | } | ||
| 628 | *next = prop; | ||
| 629 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 630 | |||
| 631 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 632 | /* try to add to proc as well if it was initialized */ | ||
| 633 | if (np->pde) | ||
| 634 | proc_device_tree_add_prop(np->pde, prop); | ||
| 635 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 636 | |||
| 637 | return 0; | ||
| 638 | } | ||
| 639 | |||
| 640 | /* | ||
| 641 | * Remove a property from a node. Note that we don't actually | ||
| 642 | * remove it, since we have given out who-knows-how-many pointers | ||
| 643 | * to the data using get-property. Instead we just move the property | ||
| 644 | * to the "dead properties" list, so it won't be found any more. | ||
| 645 | */ | ||
| 646 | int prom_remove_property(struct device_node *np, struct property *prop) | ||
| 647 | { | ||
| 648 | struct property **next; | ||
| 649 | unsigned long flags; | ||
| 650 | int found = 0; | ||
| 651 | |||
| 652 | write_lock_irqsave(&devtree_lock, flags); | ||
| 653 | next = &np->properties; | ||
| 654 | while (*next) { | ||
| 655 | if (*next == prop) { | ||
| 656 | /* found the node */ | ||
| 657 | *next = prop->next; | ||
| 658 | prop->next = np->deadprops; | ||
| 659 | np->deadprops = prop; | ||
| 660 | found = 1; | ||
| 661 | break; | ||
| 662 | } | ||
| 663 | next = &(*next)->next; | ||
| 664 | } | ||
| 665 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 666 | |||
| 667 | if (!found) | ||
| 668 | return -ENODEV; | ||
| 669 | |||
| 670 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 671 | /* try to remove the proc node as well */ | ||
| 672 | if (np->pde) | ||
| 673 | proc_device_tree_remove_prop(np->pde, prop); | ||
| 674 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 675 | |||
| 676 | return 0; | ||
| 677 | } | ||
| 678 | |||
| 679 | /* | ||
| 680 | * Update a property in a node. Note that we don't actually | ||
| 681 | * remove it, since we have given out who-knows-how-many pointers | ||
| 682 | * to the data using get-property. Instead we just move the property | ||
| 683 | * to the "dead properties" list, and add the new property to the | ||
| 684 | * property list | ||
| 685 | */ | ||
| 686 | int prom_update_property(struct device_node *np, | ||
| 687 | struct property *newprop, | ||
| 688 | struct property *oldprop) | ||
| 689 | { | ||
| 690 | struct property **next; | ||
| 691 | unsigned long flags; | ||
| 692 | int found = 0; | ||
| 693 | |||
| 694 | write_lock_irqsave(&devtree_lock, flags); | ||
| 695 | next = &np->properties; | ||
| 696 | while (*next) { | ||
| 697 | if (*next == oldprop) { | ||
| 698 | /* found the node */ | ||
| 699 | newprop->next = oldprop->next; | ||
| 700 | *next = newprop; | ||
| 701 | oldprop->next = np->deadprops; | ||
| 702 | np->deadprops = oldprop; | ||
| 703 | found = 1; | ||
| 704 | break; | ||
| 705 | } | ||
| 706 | next = &(*next)->next; | ||
| 707 | } | ||
| 708 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 709 | |||
| 710 | if (!found) | ||
| 711 | return -ENODEV; | ||
| 712 | |||
| 713 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 714 | /* try to add to proc as well if it was initialized */ | ||
| 715 | if (np->pde) | ||
| 716 | proc_device_tree_update_prop(np->pde, newprop, oldprop); | ||
| 717 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 718 | |||
| 719 | return 0; | ||
| 720 | } | ||
| 721 | |||
| 722 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) | 609 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
| 723 | static struct debugfs_blob_wrapper flat_dt_blob; | 610 | static struct debugfs_blob_wrapper flat_dt_blob; |
| 724 | 611 | ||
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 1280f3484ad3..7f8856655144 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c | |||
| @@ -1130,120 +1130,6 @@ static int __init prom_reconfig_setup(void) | |||
| 1130 | __initcall(prom_reconfig_setup); | 1130 | __initcall(prom_reconfig_setup); |
| 1131 | #endif | 1131 | #endif |
| 1132 | 1132 | ||
| 1133 | /* | ||
| 1134 | * Add a property to a node | ||
| 1135 | */ | ||
| 1136 | int prom_add_property(struct device_node* np, struct property* prop) | ||
| 1137 | { | ||
| 1138 | struct property **next; | ||
| 1139 | unsigned long flags; | ||
| 1140 | |||
| 1141 | prop->next = NULL; | ||
| 1142 | write_lock_irqsave(&devtree_lock, flags); | ||
| 1143 | next = &np->properties; | ||
| 1144 | while (*next) { | ||
| 1145 | if (strcmp(prop->name, (*next)->name) == 0) { | ||
| 1146 | /* duplicate ! don't insert it */ | ||
| 1147 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 1148 | return -1; | ||
| 1149 | } | ||
| 1150 | next = &(*next)->next; | ||
| 1151 | } | ||
| 1152 | *next = prop; | ||
| 1153 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 1154 | |||
| 1155 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 1156 | /* try to add to proc as well if it was initialized */ | ||
| 1157 | if (np->pde) | ||
| 1158 | proc_device_tree_add_prop(np->pde, prop); | ||
| 1159 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 1160 | |||
| 1161 | return 0; | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | /* | ||
| 1165 | * Remove a property from a node. Note that we don't actually | ||
| 1166 | * remove it, since we have given out who-knows-how-many pointers | ||
| 1167 | * to the data using get-property. Instead we just move the property | ||
| 1168 | * to the "dead properties" list, so it won't be found any more. | ||
| 1169 | */ | ||
| 1170 | int prom_remove_property(struct device_node *np, struct property *prop) | ||
| 1171 | { | ||
| 1172 | struct property **next; | ||
| 1173 | unsigned long flags; | ||
| 1174 | int found = 0; | ||
| 1175 | |||
| 1176 | write_lock_irqsave(&devtree_lock, flags); | ||
| 1177 | next = &np->properties; | ||
| 1178 | while (*next) { | ||
| 1179 | if (*next == prop) { | ||
| 1180 | /* found the node */ | ||
| 1181 | *next = prop->next; | ||
| 1182 | prop->next = np->deadprops; | ||
| 1183 | np->deadprops = prop; | ||
| 1184 | found = 1; | ||
| 1185 | break; | ||
| 1186 | } | ||
| 1187 | next = &(*next)->next; | ||
| 1188 | } | ||
| 1189 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 1190 | |||
| 1191 | if (!found) | ||
| 1192 | return -ENODEV; | ||
| 1193 | |||
| 1194 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 1195 | /* try to remove the proc node as well */ | ||
| 1196 | if (np->pde) | ||
| 1197 | proc_device_tree_remove_prop(np->pde, prop); | ||
| 1198 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 1199 | |||
| 1200 | return 0; | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | /* | ||
| 1204 | * Update a property in a node. Note that we don't actually | ||
| 1205 | * remove it, since we have given out who-knows-how-many pointers | ||
| 1206 | * to the data using get-property. Instead we just move the property | ||
| 1207 | * to the "dead properties" list, and add the new property to the | ||
| 1208 | * property list | ||
| 1209 | */ | ||
| 1210 | int prom_update_property(struct device_node *np, | ||
| 1211 | struct property *newprop, | ||
| 1212 | struct property *oldprop) | ||
| 1213 | { | ||
| 1214 | struct property **next; | ||
| 1215 | unsigned long flags; | ||
| 1216 | int found = 0; | ||
| 1217 | |||
| 1218 | write_lock_irqsave(&devtree_lock, flags); | ||
| 1219 | next = &np->properties; | ||
| 1220 | while (*next) { | ||
| 1221 | if (*next == oldprop) { | ||
| 1222 | /* found the node */ | ||
| 1223 | newprop->next = oldprop->next; | ||
| 1224 | *next = newprop; | ||
| 1225 | oldprop->next = np->deadprops; | ||
| 1226 | np->deadprops = oldprop; | ||
| 1227 | found = 1; | ||
| 1228 | break; | ||
| 1229 | } | ||
| 1230 | next = &(*next)->next; | ||
| 1231 | } | ||
| 1232 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 1233 | |||
| 1234 | if (!found) | ||
| 1235 | return -ENODEV; | ||
| 1236 | |||
| 1237 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 1238 | /* try to add to proc as well if it was initialized */ | ||
| 1239 | if (np->pde) | ||
| 1240 | proc_device_tree_update_prop(np->pde, newprop, oldprop); | ||
| 1241 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 1242 | |||
| 1243 | return 0; | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | |||
| 1247 | /* Find the device node for a given logical cpu number, also returns the cpu | 1133 | /* Find the device node for a given logical cpu number, also returns the cpu |
| 1248 | * local thread number (index in ibm,interrupt-server#s) if relevant and | 1134 | * local thread number (index in ibm,interrupt-server#s) if relevant and |
| 1249 | * asked for (non NULL) | 1135 | * asked for (non NULL) |
diff --git a/drivers/of/base.c b/drivers/of/base.c index e6627b2320f1..ec56739eb247 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
| @@ -658,3 +658,119 @@ err0: | |||
| 658 | return ret; | 658 | return ret; |
| 659 | } | 659 | } |
| 660 | EXPORT_SYMBOL(of_parse_phandles_with_args); | 660 | EXPORT_SYMBOL(of_parse_phandles_with_args); |
| 661 | |||
| 662 | /** | ||
| 663 | * prom_add_property - Add a property to a node | ||
| 664 | */ | ||
| 665 | int prom_add_property(struct device_node *np, struct property *prop) | ||
| 666 | { | ||
| 667 | struct property **next; | ||
| 668 | unsigned long flags; | ||
| 669 | |||
| 670 | prop->next = NULL; | ||
| 671 | write_lock_irqsave(&devtree_lock, flags); | ||
| 672 | next = &np->properties; | ||
| 673 | while (*next) { | ||
| 674 | if (strcmp(prop->name, (*next)->name) == 0) { | ||
| 675 | /* duplicate ! don't insert it */ | ||
| 676 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 677 | return -1; | ||
| 678 | } | ||
| 679 | next = &(*next)->next; | ||
| 680 | } | ||
| 681 | *next = prop; | ||
| 682 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 683 | |||
| 684 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 685 | /* try to add to proc as well if it was initialized */ | ||
| 686 | if (np->pde) | ||
| 687 | proc_device_tree_add_prop(np->pde, prop); | ||
| 688 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 689 | |||
| 690 | return 0; | ||
| 691 | } | ||
| 692 | |||
| 693 | /** | ||
| 694 | * prom_remove_property - Remove a property from a node. | ||
| 695 | * | ||
| 696 | * Note that we don't actually remove it, since we have given out | ||
| 697 | * who-knows-how-many pointers to the data using get-property. | ||
| 698 | * Instead we just move the property to the "dead properties" | ||
| 699 | * list, so it won't be found any more. | ||
| 700 | */ | ||
| 701 | int prom_remove_property(struct device_node *np, struct property *prop) | ||
| 702 | { | ||
| 703 | struct property **next; | ||
| 704 | unsigned long flags; | ||
| 705 | int found = 0; | ||
| 706 | |||
| 707 | write_lock_irqsave(&devtree_lock, flags); | ||
| 708 | next = &np->properties; | ||
| 709 | while (*next) { | ||
| 710 | if (*next == prop) { | ||
| 711 | /* found the node */ | ||
| 712 | *next = prop->next; | ||
| 713 | prop->next = np->deadprops; | ||
| 714 | np->deadprops = prop; | ||
| 715 | found = 1; | ||
| 716 | break; | ||
| 717 | } | ||
| 718 | next = &(*next)->next; | ||
| 719 | } | ||
| 720 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 721 | |||
| 722 | if (!found) | ||
| 723 | return -ENODEV; | ||
| 724 | |||
| 725 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 726 | /* try to remove the proc node as well */ | ||
| 727 | if (np->pde) | ||
| 728 | proc_device_tree_remove_prop(np->pde, prop); | ||
| 729 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 730 | |||
| 731 | return 0; | ||
| 732 | } | ||
| 733 | |||
| 734 | /* | ||
| 735 | * prom_update_property - Update a property in a node. | ||
| 736 | * | ||
| 737 | * Note that we don't actually remove it, since we have given out | ||
| 738 | * who-knows-how-many pointers to the data using get-property. | ||
| 739 | * Instead we just move the property to the "dead properties" list, | ||
| 740 | * and add the new property to the property list | ||
| 741 | */ | ||
| 742 | int prom_update_property(struct device_node *np, | ||
| 743 | struct property *newprop, | ||
| 744 | struct property *oldprop) | ||
| 745 | { | ||
| 746 | struct property **next; | ||
| 747 | unsigned long flags; | ||
| 748 | int found = 0; | ||
| 749 | |||
| 750 | write_lock_irqsave(&devtree_lock, flags); | ||
| 751 | next = &np->properties; | ||
| 752 | while (*next) { | ||
| 753 | if (*next == oldprop) { | ||
| 754 | /* found the node */ | ||
| 755 | newprop->next = oldprop->next; | ||
| 756 | *next = newprop; | ||
| 757 | oldprop->next = np->deadprops; | ||
| 758 | np->deadprops = oldprop; | ||
| 759 | found = 1; | ||
| 760 | break; | ||
| 761 | } | ||
| 762 | next = &(*next)->next; | ||
| 763 | } | ||
| 764 | write_unlock_irqrestore(&devtree_lock, flags); | ||
| 765 | |||
| 766 | if (!found) | ||
| 767 | return -ENODEV; | ||
| 768 | |||
| 769 | #ifdef CONFIG_PROC_DEVICETREE | ||
| 770 | /* try to add to proc as well if it was initialized */ | ||
| 771 | if (np->pde) | ||
| 772 | proc_device_tree_update_prop(np->pde, newprop, oldprop); | ||
| 773 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
| 774 | |||
| 775 | return 0; | ||
| 776 | } | ||
