Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux

Pull device tree updates from Grant Likely:
"The branch contains the following device tree changes the v3.17 merge
window:

Group changes to the device tree. In preparation for adding device
tree overlay support, OF_DYNAMIC is reworked so that a set of device
tree changes can be prepared and applied to the tree all at once.
OF_RECONFIG notifiers see the most significant change here so that
users always get a consistent view of the tree. Notifiers generation
is moved from before a change to after it, and notifiers for a group
of changes are emitted after the entire block of changes have been
applied

Automatic console selection from DT. Console drivers can now use
of_console_check() to see if the device node is specified as a console
device. If so then it gets added as a preferred console. UART
devices get this support automatically when uart_add_one_port() is
called.

DT unit tests no longer depend on pre-loaded data in the device tree.
Data is loaded dynamically at the start of unit tests, and then
unloaded again when the tests have completed.

Also contains a few bugfixes for reserved regions and early memory
setup"

* tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux: (21 commits)
of: Fixing OF Selftest build error
drivers: of: add automated assignment of reserved regions to client devices
of: Use proper types for checking memory overflow
of: typo fix in __of_prop_dup()
Adding selftest testdata dynamically into live tree
of: Add todo tasklist for Devicetree
of: Transactional DT support.
of: Reorder device tree changes and notifiers
of: Move dynamic node fixups out of powerpc and into common code
of: Make sure attached nodes don't carry along extra children
of: Make devicetree sysfs update functions consistent.
of: Create unlocked versions of node and property add/remove functions
OF: Utility helper functions for dynamic nodes
of: Move CONFIG_OF_DYNAMIC code into a separate file
of: rename of_aliases_mutex to just of_mutex
of/platform: Fix of_platform_device_destroy iteration of devices
of: Migrate of_find_node_by_name() users to for_each_node_by_name()
tty: Update hypervisor tty drivers to use core stdout parsing code.
arm/versatile: Add the uart as the stdout device.
of: Enable console on serial ports specified by /chosen/stdout-path
...

+1385 -584
+40
Documentation/devicetree/changesets.txt
··· 1 + A DT changeset is a method which allows one to apply changes 2 + in the live tree in such a way that either the full set of changes 3 + will be applied, or none of them will be. If an error occurs partway 4 + through applying the changeset, then the tree will be rolled back to the 5 + previous state. A changeset can also be removed after it has been 6 + applied. 7 + 8 + When a changeset is applied, all of the changes get applied to the tree 9 + at once before emitting OF_RECONFIG notifiers. This is so that the 10 + receiver sees a complete and consistent state of the tree when it 11 + receives the notifier. 12 + 13 + The sequence of a changeset is as follows. 14 + 15 + 1. of_changeset_init() - initializes a changeset 16 + 17 + 2. A number of DT tree change calls, of_changeset_attach_node(), 18 + of_changeset_detach_node(), of_changeset_add_property(), 19 + of_changeset_remove_property, of_changeset_update_property() to prepare 20 + a set of changes. No changes to the active tree are made at this point. 21 + All the change operations are recorded in the of_changeset 'entries' 22 + list. 23 + 24 + 3. mutex_lock(of_mutex) - starts a changeset; The global of_mutex 25 + ensures there can only be one editor at a time. 26 + 27 + 4. of_changeset_apply() - Apply the changes to the tree. Either the 28 + entire changeset will get applied, or if there is an error the tree will 29 + be restored to the previous state 30 + 31 + 5. mutex_unlock(of_mutex) - All operations complete, release the mutex 32 + 33 + If a successfully applied changeset needs to be removed, it can be done 34 + with the following sequence. 35 + 36 + 1. mutex_lock(of_mutex) 37 + 38 + 2. of_changeset_revert() 39 + 40 + 3. mutex_unlock(of_mutex)
+11
Documentation/devicetree/todo.txt
··· 1 + Todo list for devicetree: 2 + 3 + === General structure === 4 + - Switch from custom lists to (h)list_head for nodes and properties structure 5 + - Remove of_allnodes list and iterate using list of child nodes alone 6 + 7 + === CONFIG_OF_DYNAMIC === 8 + - Switch to RCU for tree updates and get rid of global spinlock 9 + - Document node lifecycle for CONFIG_OF_DYNAMIC 10 + - Always set ->full_name at of_attach_node() time 11 + - pseries: Get rid of open-coded tree modification from arch/powerpc/platforms/pseries/dlpar.c
+4
arch/arm/boot/dts/versatile-ab.dts
··· 15 15 i2c0 = &i2c0; 16 16 }; 17 17 18 + chosen { 19 + stdout-path = &uart0; 20 + }; 21 + 18 22 memory { 19 23 reg = <0x0 0x08000000>; 20 24 };
-2
arch/arm/boot/dts/versatile-pb.dts
··· 56 56 }; 57 57 }; 58 58 }; 59 - 60 - #include <testcases.dtsi>
-70
arch/powerpc/kernel/prom.c
··· 818 818 } 819 819 EXPORT_SYMBOL(cpu_to_chip_id); 820 820 821 - #ifdef CONFIG_PPC_PSERIES 822 - /* 823 - * Fix up the uninitialized fields in a new device node: 824 - * name, type and pci-specific fields 825 - */ 826 - 827 - static int of_finish_dynamic_node(struct device_node *node) 828 - { 829 - struct device_node *parent = of_get_parent(node); 830 - int err = 0; 831 - const phandle *ibm_phandle; 832 - 833 - node->name = of_get_property(node, "name", NULL); 834 - node->type = of_get_property(node, "device_type", NULL); 835 - 836 - if (!node->name) 837 - node->name = "<NULL>"; 838 - if (!node->type) 839 - node->type = "<NULL>"; 840 - 841 - if (!parent) { 842 - err = -ENODEV; 843 - goto out; 844 - } 845 - 846 - /* We don't support that function on PowerMac, at least 847 - * not yet 848 - */ 849 - if (machine_is(powermac)) 850 - return -ENODEV; 851 - 852 - /* fix up new node's phandle field */ 853 - if ((ibm_phandle = of_get_property(node, "ibm,phandle", NULL))) 854 - node->phandle = *ibm_phandle; 855 - 856 - out: 857 - of_node_put(parent); 858 - return err; 859 - } 860 - 861 - static int prom_reconfig_notifier(struct notifier_block *nb, 862 - unsigned long action, void *node) 863 - { 864 - int err; 865 - 866 - switch (action) { 867 - case OF_RECONFIG_ATTACH_NODE: 868 - err = of_finish_dynamic_node(node); 869 - if (err < 0) 870 - printk(KERN_ERR "finish_node returned %d\n", err); 871 - break; 872 - default: 873 - err = 0; 874 - break; 875 - } 876 - return notifier_from_errno(err); 877 - } 878 - 879 - static struct notifier_block prom_reconfig_nb = { 880 - .notifier_call = prom_reconfig_notifier, 881 - .priority = 10, /* This one needs to run first */ 882 - }; 883 - 884 - static int __init prom_reconfig_setup(void) 885 - { 886 - return of_reconfig_notifier_register(&prom_reconfig_nb); 887 - } 888 - __initcall(prom_reconfig_setup); 889 - #endif 890 - 891 821 bool arch_match_cpu_phys_id(int cpu, u64 phys_id) 892 822 { 893 823 return (int)phys_id == get_hard_smp_processor_id(cpu);
+5 -15
arch/powerpc/platforms/powermac/feature.c
··· 2805 2805 /* Enable GMAC for now for PCI probing. It will be disabled 2806 2806 * later on after PCI probe 2807 2807 */ 2808 - np = of_find_node_by_name(NULL, "ethernet"); 2809 - while(np) { 2808 + for_each_node_by_name(np, "ethernet") 2810 2809 if (of_device_is_compatible(np, "K2-GMAC")) 2811 2810 g5_gmac_enable(np, 0, 1); 2812 - np = of_find_node_by_name(np, "ethernet"); 2813 - } 2814 2811 2815 2812 /* Enable FW before PCI probe. Will be disabled later on 2816 2813 * Note: We should have a batter way to check that we are 2817 2814 * dealing with uninorth internal cell and not a PCI cell 2818 2815 * on the external PCI. The code below works though. 2819 2816 */ 2820 - np = of_find_node_by_name(NULL, "firewire"); 2821 - while(np) { 2817 + for_each_node_by_name(np, "firewire") { 2822 2818 if (of_device_is_compatible(np, "pci106b,5811")) { 2823 2819 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; 2824 2820 g5_fw_enable(np, 0, 1); 2825 2821 } 2826 - np = of_find_node_by_name(np, "firewire"); 2827 2822 } 2828 2823 } 2829 2824 #else /* CONFIG_PPC64 */ ··· 2829 2834 /* Enable GMAC for now for PCI probing. It will be disabled 2830 2835 * later on after PCI probe 2831 2836 */ 2832 - np = of_find_node_by_name(NULL, "ethernet"); 2833 - while(np) { 2837 + for_each_node_by_name(np, "ethernet") { 2834 2838 if (np->parent 2835 2839 && of_device_is_compatible(np->parent, "uni-north") 2836 2840 && of_device_is_compatible(np, "gmac")) 2837 2841 core99_gmac_enable(np, 0, 1); 2838 - np = of_find_node_by_name(np, "ethernet"); 2839 2842 } 2840 2843 2841 2844 /* Enable FW before PCI probe. Will be disabled later on ··· 2841 2848 * dealing with uninorth internal cell and not a PCI cell 2842 2849 * on the external PCI. The code below works though. 2843 2850 */ 2844 - np = of_find_node_by_name(NULL, "firewire"); 2845 - while(np) { 2851 + for_each_node_by_name(np, "firewire") { 2846 2852 if (np->parent 2847 2853 && of_device_is_compatible(np->parent, "uni-north") 2848 2854 && (of_device_is_compatible(np, "pci106b,18") || ··· 2850 2858 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; 2851 2859 core99_firewire_enable(np, 0, 1); 2852 2860 } 2853 - np = of_find_node_by_name(np, "firewire"); 2854 2861 } 2855 2862 2856 2863 /* Enable ATA-100 before PCI probe. */ 2857 2864 np = of_find_node_by_name(NULL, "ata-6"); 2858 - while(np) { 2865 + for_each_node_by_name(np, "ata-6") { 2859 2866 if (np->parent 2860 2867 && of_device_is_compatible(np->parent, "uni-north") 2861 2868 && of_device_is_compatible(np, "kauai-ata")) { 2862 2869 core99_ata100_enable(np, 1); 2863 2870 } 2864 - np = of_find_node_by_name(np, "ata-6"); 2865 2871 } 2866 2872 2867 2873 /* Switch airport off */
+1 -1
arch/powerpc/platforms/powermac/pci.c
··· 698 698 { 699 699 struct device_node *nec; 700 700 701 - for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) { 701 + for_each_node_by_name(nec, "usb") { 702 702 struct pci_controller *hose; 703 703 u32 data; 704 704 const u32 *prop;
+1 -1
arch/powerpc/platforms/powermac/smp.c
··· 577 577 int ok; 578 578 579 579 /* Look for the clock chip */ 580 - while ((cc = of_find_node_by_name(cc, "i2c-hwclock")) != NULL) { 580 + for_each_node_by_name(cc, "i2c-hwclock") { 581 581 p = of_get_parent(cc); 582 582 ok = p && of_device_is_compatible(p, "uni-n-i2c"); 583 583 of_node_put(p);
+1 -1
arch/powerpc/platforms/powermac/udbg_adb.c
··· 191 191 * of type "adb". If not, we return a failure, but we keep the 192 192 * bext output set for now 193 193 */ 194 - for (np = NULL; (np = of_find_node_by_name(np, "keyboard")) != NULL;) { 194 + for_each_node_by_name(np, "keyboard") { 195 195 struct device_node *parent = of_get_parent(np); 196 196 int found = (parent && strcmp(parent->type, "adb") == 0); 197 197 of_node_put(parent);
+1 -1
arch/powerpc/platforms/pseries/hotplug-memory.c
··· 194 194 if (!memblock_size) 195 195 return -EINVAL; 196 196 197 - p = (u32 *)of_get_property(pr->dn, "ibm,dynamic-memory", NULL); 197 + p = (u32 *) pr->old_prop->value; 198 198 if (!p) 199 199 return -EINVAL; 200 200
+1 -2
arch/powerpc/platforms/pseries/setup.c
··· 232 232 struct device_node *np; 233 233 const char *typep; 234 234 235 - for (np = NULL; (np = of_find_node_by_name(np, 236 - "interrupt-controller"));) { 235 + for_each_node_by_name(np, "interrupt-controller") { 237 236 typep = of_get_property(np, "compatible", NULL); 238 237 if (strstr(typep, "open-pic")) { 239 238 pSeries_mpic_node = of_node_get(np);
+1 -2
drivers/cpufreq/pmac64-cpufreq.c
··· 499 499 } 500 500 501 501 /* Lookup the i2c hwclock */ 502 - for (hwclock = NULL; 503 - (hwclock = of_find_node_by_name(hwclock, "i2c-hwclock")) != NULL;){ 502 + for_each_node_by_name(hwclock, "i2c-hwclock") { 504 503 const char *loc = of_get_property(hwclock, 505 504 "hwctrl-location", NULL); 506 505 if (loc == NULL)
+8 -22
drivers/crypto/nx/nx-842.c
··· 936 936 goto error_out; 937 937 } 938 938 939 - /* Set ptr to new property if provided */ 940 - if (new_prop) { 941 - /* Single property */ 942 - if (!strncmp(new_prop->name, "status", new_prop->length)) { 943 - status = new_prop; 944 - 945 - } else if (!strncmp(new_prop->name, "ibm,max-sg-len", 946 - new_prop->length)) { 947 - maxsglen = new_prop; 948 - 949 - } else if (!strncmp(new_prop->name, "ibm,max-sync-cop", 950 - new_prop->length)) { 951 - maxsyncop = new_prop; 952 - 953 - } else { 954 - /* 955 - * Skip the update, the property being updated 956 - * has no impact. 957 - */ 958 - goto out; 959 - } 960 - } 939 + /* 940 + * If this is a property update, there are only certain properties that 941 + * we care about. Bail if it isn't in the below list 942 + */ 943 + if (new_prop && (strncmp(new_prop->name, "status", new_prop->length) || 944 + strncmp(new_prop->name, "ibm,max-sg-len", new_prop->length) || 945 + strncmp(new_prop->name, "ibm,max-sync-cop", new_prop->length))) 946 + goto out; 961 947 962 948 /* Perform property updates */ 963 949 ret = nx842_OF_upd_status(new_devdata, status);
+1 -2
drivers/edac/cell_edac.c
··· 134 134 int j; 135 135 u32 nr_pages; 136 136 137 - for (np = NULL; 138 - (np = of_find_node_by_name(np, "memory")) != NULL;) { 137 + for_each_node_by_name(np, "memory") { 139 138 struct resource r; 140 139 141 140 /* We "know" that the Cell firmware only creates one entry
+2 -1
drivers/of/Kconfig
··· 9 9 10 10 config OF_SELFTEST 11 11 bool "Device Tree Runtime self tests" 12 - depends on OF_IRQ 12 + depends on OF_IRQ && OF_EARLY_FLATTREE 13 + select OF_DYNAMIC 13 14 help 14 15 This option builds in test cases for the device tree infrastructure 15 16 that are executed once at boot time, and the results dumped to the
+3 -1
drivers/of/Makefile
··· 1 1 obj-y = base.o device.o platform.o 2 + obj-$(CONFIG_OF_DYNAMIC) += dynamic.o 2 3 obj-$(CONFIG_OF_FLATTREE) += fdt.o 3 4 obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o 4 5 obj-$(CONFIG_OF_PROMTREE) += pdt.o 5 6 obj-$(CONFIG_OF_ADDRESS) += address.o 6 7 obj-$(CONFIG_OF_IRQ) += irq.o 7 8 obj-$(CONFIG_OF_NET) += of_net.o 8 - obj-$(CONFIG_OF_SELFTEST) += selftest.o 9 + obj-$(CONFIG_OF_SELFTEST) += of_selftest.o 10 + of_selftest-objs := selftest.o testcase-data/testcases.dtb.o 9 11 obj-$(CONFIG_OF_MDIO) += of_mdio.o 10 12 obj-$(CONFIG_OF_PCI) += of_pci.o 11 13 obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o
+126 -331
drivers/of/base.c
··· 17 17 * as published by the Free Software Foundation; either version 18 18 * 2 of the License, or (at your option) any later version. 19 19 */ 20 + #include <linux/console.h> 20 21 #include <linux/ctype.h> 21 22 #include <linux/cpu.h> 22 23 #include <linux/module.h> ··· 36 35 EXPORT_SYMBOL(of_allnodes); 37 36 struct device_node *of_chosen; 38 37 struct device_node *of_aliases; 39 - static struct device_node *of_stdout; 38 + struct device_node *of_stdout; 40 39 41 - static struct kset *of_kset; 40 + struct kset *of_kset; 42 41 43 42 /* 44 - * Used to protect the of_aliases; but also overloaded to hold off addition of 45 - * nodes to sysfs 43 + * Used to protect the of_aliases, to hold off addition of nodes to sysfs. 44 + * This mutex must be held whenever modifications are being made to the 45 + * device tree. The of_{attach,detach}_node() and 46 + * of_{add,remove,update}_property() helpers make sure this happens. 46 47 */ 47 - DEFINE_MUTEX(of_aliases_mutex); 48 + DEFINE_MUTEX(of_mutex); 48 49 49 50 /* use when traversing tree through the allnext, child, sibling, 50 51 * or parent members of struct device_node. ··· 92 89 } 93 90 #endif 94 91 95 - #if defined(CONFIG_OF_DYNAMIC) 96 - /** 97 - * of_node_get - Increment refcount of a node 98 - * @node: Node to inc refcount, NULL is supported to 99 - * simplify writing of callers 100 - * 101 - * Returns node. 102 - */ 103 - struct device_node *of_node_get(struct device_node *node) 104 - { 105 - if (node) 106 - kobject_get(&node->kobj); 107 - return node; 108 - } 109 - EXPORT_SYMBOL(of_node_get); 110 - 111 - static inline struct device_node *kobj_to_device_node(struct kobject *kobj) 112 - { 113 - return container_of(kobj, struct device_node, kobj); 114 - } 115 - 116 - /** 117 - * of_node_release - release a dynamically allocated node 118 - * @kref: kref element of the node to be released 119 - * 120 - * In of_node_put() this function is passed to kref_put() 121 - * as the destructor. 122 - */ 123 - static void of_node_release(struct kobject *kobj) 124 - { 125 - struct device_node *node = kobj_to_device_node(kobj); 126 - struct property *prop = node->properties; 127 - 128 - /* We should never be releasing nodes that haven't been detached. */ 129 - if (!of_node_check_flag(node, OF_DETACHED)) { 130 - pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name); 131 - dump_stack(); 132 - return; 133 - } 134 - 135 - if (!of_node_check_flag(node, OF_DYNAMIC)) 136 - return; 137 - 138 - while (prop) { 139 - struct property *next = prop->next; 140 - kfree(prop->name); 141 - kfree(prop->value); 142 - kfree(prop); 143 - prop = next; 144 - 145 - if (!prop) { 146 - prop = node->deadprops; 147 - node->deadprops = NULL; 148 - } 149 - } 150 - kfree(node->full_name); 151 - kfree(node->data); 152 - kfree(node); 153 - } 154 - 155 - /** 156 - * of_node_put - Decrement refcount of a node 157 - * @node: Node to dec refcount, NULL is supported to 158 - * simplify writing of callers 159 - * 160 - */ 161 - void of_node_put(struct device_node *node) 162 - { 163 - if (node) 164 - kobject_put(&node->kobj); 165 - } 166 - EXPORT_SYMBOL(of_node_put); 167 - #else 92 + #ifndef CONFIG_OF_DYNAMIC 168 93 static void of_node_release(struct kobject *kobj) 169 94 { 170 95 /* Without CONFIG_OF_DYNAMIC, no nodes gets freed */ ··· 131 200 return name; 132 201 } 133 202 134 - static int __of_add_property_sysfs(struct device_node *np, struct property *pp) 203 + int __of_add_property_sysfs(struct device_node *np, struct property *pp) 135 204 { 136 205 int rc; 137 206 138 207 /* Important: Don't leak passwords */ 139 208 bool secure = strncmp(pp->name, "security-", 9) == 0; 209 + 210 + if (!of_kset || !of_node_is_attached(np)) 211 + return 0; 140 212 141 213 sysfs_bin_attr_init(&pp->attr); 142 214 pp->attr.attr.name = safe_name(&np->kobj, pp->name); ··· 152 218 return rc; 153 219 } 154 220 155 - static int __of_node_add(struct device_node *np) 221 + int __of_attach_node_sysfs(struct device_node *np) 156 222 { 157 223 const char *name; 158 224 struct property *pp; 159 225 int rc; 226 + 227 + if (!of_kset) 228 + return 0; 160 229 161 230 np->kobj.kset = of_kset; 162 231 if (!np->parent) { ··· 182 245 return 0; 183 246 } 184 247 185 - int of_node_add(struct device_node *np) 186 - { 187 - int rc = 0; 188 - 189 - BUG_ON(!of_node_is_initialized(np)); 190 - 191 - /* 192 - * Grab the mutex here so that in a race condition between of_init() and 193 - * of_node_add(), node addition will still be consistent. 194 - */ 195 - mutex_lock(&of_aliases_mutex); 196 - if (of_kset) 197 - rc = __of_node_add(np); 198 - else 199 - /* This scenario may be perfectly valid, but report it anyway */ 200 - pr_info("of_node_add(%s) before of_init()\n", np->full_name); 201 - mutex_unlock(&of_aliases_mutex); 202 - return rc; 203 - } 204 - 205 - #if defined(CONFIG_OF_DYNAMIC) 206 - static void of_node_remove(struct device_node *np) 207 - { 208 - struct property *pp; 209 - 210 - BUG_ON(!of_node_is_initialized(np)); 211 - 212 - /* only remove properties if on sysfs */ 213 - if (of_node_is_attached(np)) { 214 - for_each_property_of_node(np, pp) 215 - sysfs_remove_bin_file(&np->kobj, &pp->attr); 216 - kobject_del(&np->kobj); 217 - } 218 - 219 - /* finally remove the kobj_init ref */ 220 - of_node_put(np); 221 - } 222 - #endif 223 - 224 248 static int __init of_init(void) 225 249 { 226 250 struct device_node *np; 227 251 228 252 /* Create the kset, and register existing nodes */ 229 - mutex_lock(&of_aliases_mutex); 253 + mutex_lock(&of_mutex); 230 254 of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj); 231 255 if (!of_kset) { 232 - mutex_unlock(&of_aliases_mutex); 256 + mutex_unlock(&of_mutex); 233 257 return -ENOMEM; 234 258 } 235 259 for_each_of_allnodes(np) 236 - __of_node_add(np); 237 - mutex_unlock(&of_aliases_mutex); 260 + __of_attach_node_sysfs(np); 261 + mutex_unlock(&of_mutex); 238 262 239 263 /* Symlink in /proc as required by userspace ABI */ 240 264 if (of_allnodes) ··· 267 369 * Find a property with a given name for a given node 268 370 * and return the value. 269 371 */ 270 - static const void *__of_get_property(const struct device_node *np, 271 - const char *name, int *lenp) 372 + const void *__of_get_property(const struct device_node *np, 373 + const char *name, int *lenp) 272 374 { 273 375 struct property *pp = __of_find_property(np, name, lenp); 274 376 ··· 1646 1748 } 1647 1749 EXPORT_SYMBOL(of_count_phandle_with_args); 1648 1750 1649 - #if defined(CONFIG_OF_DYNAMIC) 1650 - static int of_property_notify(int action, struct device_node *np, 1651 - struct property *prop) 1652 - { 1653 - struct of_prop_reconfig pr; 1654 - 1655 - /* only call notifiers if the node is attached */ 1656 - if (!of_node_is_attached(np)) 1657 - return 0; 1658 - 1659 - pr.dn = np; 1660 - pr.prop = prop; 1661 - return of_reconfig_notify(action, &pr); 1662 - } 1663 - #else 1664 - static int of_property_notify(int action, struct device_node *np, 1665 - struct property *prop) 1666 - { 1667 - return 0; 1668 - } 1669 - #endif 1670 - 1671 1751 /** 1672 1752 * __of_add_property - Add a property to a node without lock operations 1673 1753 */ 1674 - static int __of_add_property(struct device_node *np, struct property *prop) 1754 + int __of_add_property(struct device_node *np, struct property *prop) 1675 1755 { 1676 1756 struct property **next; 1677 1757 ··· 1675 1799 unsigned long flags; 1676 1800 int rc; 1677 1801 1678 - rc = of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop); 1679 - if (rc) 1680 - return rc; 1802 + mutex_lock(&of_mutex); 1681 1803 1682 1804 raw_spin_lock_irqsave(&devtree_lock, flags); 1683 1805 rc = __of_add_property(np, prop); 1684 1806 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1685 - if (rc) 1686 - return rc; 1687 1807 1688 - if (of_node_is_attached(np)) 1808 + if (!rc) 1689 1809 __of_add_property_sysfs(np, prop); 1690 1810 1811 + mutex_unlock(&of_mutex); 1812 + 1813 + if (!rc) 1814 + of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop, NULL); 1815 + 1691 1816 return rc; 1817 + } 1818 + 1819 + int __of_remove_property(struct device_node *np, struct property *prop) 1820 + { 1821 + struct property **next; 1822 + 1823 + for (next = &np->properties; *next; next = &(*next)->next) { 1824 + if (*next == prop) 1825 + break; 1826 + } 1827 + if (*next == NULL) 1828 + return -ENODEV; 1829 + 1830 + /* found the node */ 1831 + *next = prop->next; 1832 + prop->next = np->deadprops; 1833 + np->deadprops = prop; 1834 + 1835 + return 0; 1836 + } 1837 + 1838 + void __of_remove_property_sysfs(struct device_node *np, struct property *prop) 1839 + { 1840 + /* at early boot, bail here and defer setup to of_init() */ 1841 + if (of_kset && of_node_is_attached(np)) 1842 + sysfs_remove_bin_file(&np->kobj, &prop->attr); 1692 1843 } 1693 1844 1694 1845 /** ··· 1728 1825 */ 1729 1826 int of_remove_property(struct device_node *np, struct property *prop) 1730 1827 { 1731 - struct property **next; 1732 1828 unsigned long flags; 1733 - int found = 0; 1734 1829 int rc; 1735 1830 1736 - rc = of_property_notify(OF_RECONFIG_REMOVE_PROPERTY, np, prop); 1737 - if (rc) 1738 - return rc; 1831 + mutex_lock(&of_mutex); 1739 1832 1740 1833 raw_spin_lock_irqsave(&devtree_lock, flags); 1741 - next = &np->properties; 1742 - while (*next) { 1743 - if (*next == prop) { 1744 - /* found the node */ 1745 - *next = prop->next; 1746 - prop->next = np->deadprops; 1747 - np->deadprops = prop; 1748 - found = 1; 1749 - break; 1750 - } 1751 - next = &(*next)->next; 1752 - } 1834 + rc = __of_remove_property(np, prop); 1753 1835 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1754 1836 1755 - if (!found) 1756 - return -ENODEV; 1837 + if (!rc) 1838 + __of_remove_property_sysfs(np, prop); 1757 1839 1758 - /* at early boot, bail hear and defer setup to of_init() */ 1759 - if (!of_kset) 1760 - return 0; 1840 + mutex_unlock(&of_mutex); 1761 1841 1762 - sysfs_remove_bin_file(&np->kobj, &prop->attr); 1842 + if (!rc) 1843 + of_property_notify(OF_RECONFIG_REMOVE_PROPERTY, np, prop, NULL); 1844 + 1845 + return rc; 1846 + } 1847 + 1848 + int __of_update_property(struct device_node *np, struct property *newprop, 1849 + struct property **oldpropp) 1850 + { 1851 + struct property **next, *oldprop; 1852 + 1853 + for (next = &np->properties; *next; next = &(*next)->next) { 1854 + if (of_prop_cmp((*next)->name, newprop->name) == 0) 1855 + break; 1856 + } 1857 + *oldpropp = oldprop = *next; 1858 + 1859 + if (oldprop) { 1860 + /* replace the node */ 1861 + newprop->next = oldprop->next; 1862 + *next = newprop; 1863 + oldprop->next = np->deadprops; 1864 + np->deadprops = oldprop; 1865 + } else { 1866 + /* new node */ 1867 + newprop->next = NULL; 1868 + *next = newprop; 1869 + } 1763 1870 1764 1871 return 0; 1872 + } 1873 + 1874 + void __of_update_property_sysfs(struct device_node *np, struct property *newprop, 1875 + struct property *oldprop) 1876 + { 1877 + /* At early boot, bail out and defer setup to of_init() */ 1878 + if (!of_kset) 1879 + return; 1880 + 1881 + if (oldprop) 1882 + sysfs_remove_bin_file(&np->kobj, &oldprop->attr); 1883 + __of_add_property_sysfs(np, newprop); 1765 1884 } 1766 1885 1767 1886 /* ··· 1797 1872 */ 1798 1873 int of_update_property(struct device_node *np, struct property *newprop) 1799 1874 { 1800 - struct property **next, *oldprop; 1875 + struct property *oldprop; 1801 1876 unsigned long flags; 1802 1877 int rc; 1803 - 1804 - rc = of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop); 1805 - if (rc) 1806 - return rc; 1807 1878 1808 1879 if (!newprop->name) 1809 1880 return -EINVAL; 1810 1881 1811 - raw_spin_lock_irqsave(&devtree_lock, flags); 1812 - next = &np->properties; 1813 - oldprop = __of_find_property(np, newprop->name, NULL); 1814 - if (!oldprop) { 1815 - /* add the new node */ 1816 - rc = __of_add_property(np, newprop); 1817 - } else while (*next) { 1818 - /* replace the node */ 1819 - if (*next == oldprop) { 1820 - newprop->next = oldprop->next; 1821 - *next = newprop; 1822 - oldprop->next = np->deadprops; 1823 - np->deadprops = oldprop; 1824 - break; 1825 - } 1826 - next = &(*next)->next; 1827 - } 1828 - raw_spin_unlock_irqrestore(&devtree_lock, flags); 1829 - if (rc) 1830 - return rc; 1831 - 1832 - /* At early boot, bail out and defer setup to of_init() */ 1833 - if (!of_kset) 1834 - return 0; 1835 - 1836 - /* Update the sysfs attribute */ 1837 - if (oldprop) 1838 - sysfs_remove_bin_file(&np->kobj, &oldprop->attr); 1839 - __of_add_property_sysfs(np, newprop); 1840 - 1841 - return 0; 1842 - } 1843 - 1844 - #if defined(CONFIG_OF_DYNAMIC) 1845 - /* 1846 - * Support for dynamic device trees. 1847 - * 1848 - * On some platforms, the device tree can be manipulated at runtime. 1849 - * The routines in this section support adding, removing and changing 1850 - * device tree nodes. 1851 - */ 1852 - 1853 - static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain); 1854 - 1855 - int of_reconfig_notifier_register(struct notifier_block *nb) 1856 - { 1857 - return blocking_notifier_chain_register(&of_reconfig_chain, nb); 1858 - } 1859 - EXPORT_SYMBOL_GPL(of_reconfig_notifier_register); 1860 - 1861 - int of_reconfig_notifier_unregister(struct notifier_block *nb) 1862 - { 1863 - return blocking_notifier_chain_unregister(&of_reconfig_chain, nb); 1864 - } 1865 - EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); 1866 - 1867 - int of_reconfig_notify(unsigned long action, void *p) 1868 - { 1869 - int rc; 1870 - 1871 - rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p); 1872 - return notifier_to_errno(rc); 1873 - } 1874 - 1875 - /** 1876 - * of_attach_node - Plug a device node into the tree and global list. 1877 - */ 1878 - int of_attach_node(struct device_node *np) 1879 - { 1880 - unsigned long flags; 1881 - int rc; 1882 - 1883 - rc = of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np); 1884 - if (rc) 1885 - return rc; 1882 + mutex_lock(&of_mutex); 1886 1883 1887 1884 raw_spin_lock_irqsave(&devtree_lock, flags); 1888 - np->sibling = np->parent->child; 1889 - np->allnext = np->parent->allnext; 1890 - np->parent->allnext = np; 1891 - np->parent->child = np; 1892 - of_node_clear_flag(np, OF_DETACHED); 1885 + rc = __of_update_property(np, newprop, &oldprop); 1893 1886 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1894 1887 1895 - of_node_add(np); 1896 - return 0; 1897 - } 1888 + if (!rc) 1889 + __of_update_property_sysfs(np, newprop, oldprop); 1898 1890 1899 - /** 1900 - * of_detach_node - "Unplug" a node from the device tree. 1901 - * 1902 - * The caller must hold a reference to the node. The memory associated with 1903 - * the node is not freed until its refcount goes to zero. 1904 - */ 1905 - int of_detach_node(struct device_node *np) 1906 - { 1907 - struct device_node *parent; 1908 - unsigned long flags; 1909 - int rc = 0; 1891 + mutex_unlock(&of_mutex); 1910 1892 1911 - rc = of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np); 1912 - if (rc) 1913 - return rc; 1893 + if (!rc) 1894 + of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop, oldprop); 1914 1895 1915 - raw_spin_lock_irqsave(&devtree_lock, flags); 1916 - 1917 - if (of_node_check_flag(np, OF_DETACHED)) { 1918 - /* someone already detached it */ 1919 - raw_spin_unlock_irqrestore(&devtree_lock, flags); 1920 - return rc; 1921 - } 1922 - 1923 - parent = np->parent; 1924 - if (!parent) { 1925 - raw_spin_unlock_irqrestore(&devtree_lock, flags); 1926 - return rc; 1927 - } 1928 - 1929 - if (of_allnodes == np) 1930 - of_allnodes = np->allnext; 1931 - else { 1932 - struct device_node *prev; 1933 - for (prev = of_allnodes; 1934 - prev->allnext != np; 1935 - prev = prev->allnext) 1936 - ; 1937 - prev->allnext = np->allnext; 1938 - } 1939 - 1940 - if (parent->child == np) 1941 - parent->child = np->sibling; 1942 - else { 1943 - struct device_node *prevsib; 1944 - for (prevsib = np->parent->child; 1945 - prevsib->sibling != np; 1946 - prevsib = prevsib->sibling) 1947 - ; 1948 - prevsib->sibling = np->sibling; 1949 - } 1950 - 1951 - of_node_set_flag(np, OF_DETACHED); 1952 - raw_spin_unlock_irqrestore(&devtree_lock, flags); 1953 - 1954 - of_node_remove(np); 1955 1896 return rc; 1956 1897 } 1957 - #endif /* defined(CONFIG_OF_DYNAMIC) */ 1958 1898 1959 1899 static void of_alias_add(struct alias_prop *ap, struct device_node *np, 1960 1900 int id, const char *stem, int stem_len) ··· 1852 2062 of_chosen = of_find_node_by_path("/chosen@0"); 1853 2063 1854 2064 if (of_chosen) { 2065 + /* linux,stdout-path and /aliases/stdout are for legacy compatibility */ 1855 2066 const char *name = of_get_property(of_chosen, "stdout-path", NULL); 1856 2067 if (!name) 1857 2068 name = of_get_property(of_chosen, "linux,stdout-path", NULL); 2069 + if (IS_ENABLED(CONFIG_PPC) && !name) 2070 + name = of_get_property(of_aliases, "stdout", NULL); 1858 2071 if (name) 1859 2072 of_stdout = of_find_node_by_path(name); 1860 2073 } ··· 1915 2122 struct alias_prop *app; 1916 2123 int id = -ENODEV; 1917 2124 1918 - mutex_lock(&of_aliases_mutex); 2125 + mutex_lock(&of_mutex); 1919 2126 list_for_each_entry(app, &aliases_lookup, link) { 1920 2127 if (strcmp(app->stem, stem) != 0) 1921 2128 continue; ··· 1925 2132 break; 1926 2133 } 1927 2134 } 1928 - mutex_unlock(&of_aliases_mutex); 2135 + mutex_unlock(&of_mutex); 1929 2136 1930 2137 return id; 1931 2138 } ··· 1973 2180 EXPORT_SYMBOL_GPL(of_prop_next_string); 1974 2181 1975 2182 /** 1976 - * of_device_is_stdout_path - check if a device node matches the 1977 - * linux,stdout-path property 2183 + * of_console_check() - Test and setup console for DT setup 2184 + * @dn - Pointer to device node 2185 + * @name - Name to use for preferred console without index. ex. "ttyS" 2186 + * @index - Index to use for preferred console. 1978 2187 * 1979 - * Check if this device node matches the linux,stdout-path property 1980 - * in the chosen node. return true if yes, false otherwise. 2188 + * Check if the given device node matches the stdout-path property in the 2189 + * /chosen node. If it does then register it as the preferred console and return 2190 + * TRUE. Otherwise return FALSE. 1981 2191 */ 1982 - int of_device_is_stdout_path(struct device_node *dn) 2192 + bool of_console_check(struct device_node *dn, char *name, int index) 1983 2193 { 1984 - if (!of_stdout) 2194 + if (!dn || dn != of_stdout || console_set_on_cmdline) 1985 2195 return false; 1986 - 1987 - return of_stdout == dn; 2196 + return add_preferred_console(name, index, NULL); 1988 2197 } 1989 - EXPORT_SYMBOL_GPL(of_device_is_stdout_path); 2198 + EXPORT_SYMBOL_GPL(of_console_check); 1990 2199 1991 2200 /** 1992 2201 * of_find_next_cache_node - Find a node's subsidiary cache
+2 -2
drivers/of/device.c
··· 160 160 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen); 161 161 162 162 seen = 0; 163 - mutex_lock(&of_aliases_mutex); 163 + mutex_lock(&of_mutex); 164 164 list_for_each_entry(app, &aliases_lookup, link) { 165 165 if (dev->of_node == app->np) { 166 166 add_uevent_var(env, "OF_ALIAS_%d=%s", seen, ··· 168 168 seen++; 169 169 } 170 170 } 171 - mutex_unlock(&of_aliases_mutex); 171 + mutex_unlock(&of_mutex); 172 172 } 173 173 174 174 int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+660
drivers/of/dynamic.c
··· 1 + /* 2 + * Support for dynamic device trees. 3 + * 4 + * On some platforms, the device tree can be manipulated at runtime. 5 + * The routines in this section support adding, removing and changing 6 + * device tree nodes. 7 + */ 8 + 9 + #include <linux/of.h> 10 + #include <linux/spinlock.h> 11 + #include <linux/slab.h> 12 + #include <linux/string.h> 13 + #include <linux/proc_fs.h> 14 + 15 + #include "of_private.h" 16 + 17 + /** 18 + * of_node_get() - Increment refcount of a node 19 + * @node: Node to inc refcount, NULL is supported to simplify writing of 20 + * callers 21 + * 22 + * Returns node. 23 + */ 24 + struct device_node *of_node_get(struct device_node *node) 25 + { 26 + if (node) 27 + kobject_get(&node->kobj); 28 + return node; 29 + } 30 + EXPORT_SYMBOL(of_node_get); 31 + 32 + /** 33 + * of_node_put() - Decrement refcount of a node 34 + * @node: Node to dec refcount, NULL is supported to simplify writing of 35 + * callers 36 + */ 37 + void of_node_put(struct device_node *node) 38 + { 39 + if (node) 40 + kobject_put(&node->kobj); 41 + } 42 + EXPORT_SYMBOL(of_node_put); 43 + 44 + void __of_detach_node_sysfs(struct device_node *np) 45 + { 46 + struct property *pp; 47 + 48 + BUG_ON(!of_node_is_initialized(np)); 49 + if (!of_kset) 50 + return; 51 + 52 + /* only remove properties if on sysfs */ 53 + if (of_node_is_attached(np)) { 54 + for_each_property_of_node(np, pp) 55 + sysfs_remove_bin_file(&np->kobj, &pp->attr); 56 + kobject_del(&np->kobj); 57 + } 58 + 59 + /* finally remove the kobj_init ref */ 60 + of_node_put(np); 61 + } 62 + 63 + static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain); 64 + 65 + int of_reconfig_notifier_register(struct notifier_block *nb) 66 + { 67 + return blocking_notifier_chain_register(&of_reconfig_chain, nb); 68 + } 69 + EXPORT_SYMBOL_GPL(of_reconfig_notifier_register); 70 + 71 + int of_reconfig_notifier_unregister(struct notifier_block *nb) 72 + { 73 + return blocking_notifier_chain_unregister(&of_reconfig_chain, nb); 74 + } 75 + EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister); 76 + 77 + int of_reconfig_notify(unsigned long action, void *p) 78 + { 79 + int rc; 80 + 81 + rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p); 82 + return notifier_to_errno(rc); 83 + } 84 + 85 + int of_property_notify(int action, struct device_node *np, 86 + struct property *prop, struct property *oldprop) 87 + { 88 + struct of_prop_reconfig pr; 89 + 90 + /* only call notifiers if the node is attached */ 91 + if (!of_node_is_attached(np)) 92 + return 0; 93 + 94 + pr.dn = np; 95 + pr.prop = prop; 96 + pr.old_prop = oldprop; 97 + return of_reconfig_notify(action, &pr); 98 + } 99 + 100 + void __of_attach_node(struct device_node *np) 101 + { 102 + const __be32 *phandle; 103 + int sz; 104 + 105 + np->name = __of_get_property(np, "name", NULL) ? : "<NULL>"; 106 + np->type = __of_get_property(np, "device_type", NULL) ? : "<NULL>"; 107 + 108 + phandle = __of_get_property(np, "phandle", &sz); 109 + if (!phandle) 110 + phandle = __of_get_property(np, "linux,phandle", &sz); 111 + if (IS_ENABLED(PPC_PSERIES) && !phandle) 112 + phandle = __of_get_property(np, "ibm,phandle", &sz); 113 + np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0; 114 + 115 + np->child = NULL; 116 + np->sibling = np->parent->child; 117 + np->allnext = np->parent->allnext; 118 + np->parent->allnext = np; 119 + np->parent->child = np; 120 + of_node_clear_flag(np, OF_DETACHED); 121 + } 122 + 123 + /** 124 + * of_attach_node() - Plug a device node into the tree and global list. 125 + */ 126 + int of_attach_node(struct device_node *np) 127 + { 128 + unsigned long flags; 129 + 130 + mutex_lock(&of_mutex); 131 + raw_spin_lock_irqsave(&devtree_lock, flags); 132 + __of_attach_node(np); 133 + raw_spin_unlock_irqrestore(&devtree_lock, flags); 134 + 135 + __of_attach_node_sysfs(np); 136 + mutex_unlock(&of_mutex); 137 + 138 + of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np); 139 + 140 + return 0; 141 + } 142 + 143 + void __of_detach_node(struct device_node *np) 144 + { 145 + struct device_node *parent; 146 + 147 + if (WARN_ON(of_node_check_flag(np, OF_DETACHED))) 148 + return; 149 + 150 + parent = np->parent; 151 + if (WARN_ON(!parent)) 152 + return; 153 + 154 + if (of_allnodes == np) 155 + of_allnodes = np->allnext; 156 + else { 157 + struct device_node *prev; 158 + for (prev = of_allnodes; 159 + prev->allnext != np; 160 + prev = prev->allnext) 161 + ; 162 + prev->allnext = np->allnext; 163 + } 164 + 165 + if (parent->child == np) 166 + parent->child = np->sibling; 167 + else { 168 + struct device_node *prevsib; 169 + for (prevsib = np->parent->child; 170 + prevsib->sibling != np; 171 + prevsib = prevsib->sibling) 172 + ; 173 + prevsib->sibling = np->sibling; 174 + } 175 + 176 + of_node_set_flag(np, OF_DETACHED); 177 + } 178 + 179 + /** 180 + * of_detach_node() - "Unplug" a node from the device tree. 181 + * 182 + * The caller must hold a reference to the node. The memory associated with 183 + * the node is not freed until its refcount goes to zero. 184 + */ 185 + int of_detach_node(struct device_node *np) 186 + { 187 + unsigned long flags; 188 + int rc = 0; 189 + 190 + mutex_lock(&of_mutex); 191 + raw_spin_lock_irqsave(&devtree_lock, flags); 192 + __of_detach_node(np); 193 + raw_spin_unlock_irqrestore(&devtree_lock, flags); 194 + 195 + __of_detach_node_sysfs(np); 196 + mutex_unlock(&of_mutex); 197 + 198 + of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np); 199 + 200 + return rc; 201 + } 202 + 203 + /** 204 + * of_node_release() - release a dynamically allocated node 205 + * @kref: kref element of the node to be released 206 + * 207 + * In of_node_put() this function is passed to kref_put() as the destructor. 208 + */ 209 + void of_node_release(struct kobject *kobj) 210 + { 211 + struct device_node *node = kobj_to_device_node(kobj); 212 + struct property *prop = node->properties; 213 + 214 + /* We should never be releasing nodes that haven't been detached. */ 215 + if (!of_node_check_flag(node, OF_DETACHED)) { 216 + pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name); 217 + dump_stack(); 218 + return; 219 + } 220 + 221 + if (!of_node_check_flag(node, OF_DYNAMIC)) 222 + return; 223 + 224 + while (prop) { 225 + struct property *next = prop->next; 226 + kfree(prop->name); 227 + kfree(prop->value); 228 + kfree(prop); 229 + prop = next; 230 + 231 + if (!prop) { 232 + prop = node->deadprops; 233 + node->deadprops = NULL; 234 + } 235 + } 236 + kfree(node->full_name); 237 + kfree(node->data); 238 + kfree(node); 239 + } 240 + 241 + /** 242 + * __of_prop_dup - Copy a property dynamically. 243 + * @prop: Property to copy 244 + * @allocflags: Allocation flags (typically pass GFP_KERNEL) 245 + * 246 + * Copy a property by dynamically allocating the memory of both the 247 + * property stucture and the property name & contents. The property's 248 + * flags have the OF_DYNAMIC bit set so that we can differentiate between 249 + * dynamically allocated properties and not. 250 + * Returns the newly allocated property or NULL on out of memory error. 251 + */ 252 + struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) 253 + { 254 + struct property *new; 255 + 256 + new = kzalloc(sizeof(*new), allocflags); 257 + if (!new) 258 + return NULL; 259 + 260 + /* 261 + * NOTE: There is no check for zero length value. 262 + * In case of a boolean property, this will allocate a value 263 + * of zero bytes. We do this to work around the use 264 + * of of_get_property() calls on boolean values. 265 + */ 266 + new->name = kstrdup(prop->name, allocflags); 267 + new->value = kmemdup(prop->value, prop->length, allocflags); 268 + new->length = prop->length; 269 + if (!new->name || !new->value) 270 + goto err_free; 271 + 272 + /* mark the property as dynamic */ 273 + of_property_set_flag(new, OF_DYNAMIC); 274 + 275 + return new; 276 + 277 + err_free: 278 + kfree(new->name); 279 + kfree(new->value); 280 + kfree(new); 281 + return NULL; 282 + } 283 + 284 + /** 285 + * __of_node_alloc() - Create an empty device node dynamically. 286 + * @full_name: Full name of the new device node 287 + * @allocflags: Allocation flags (typically pass GFP_KERNEL) 288 + * 289 + * Create an empty device tree node, suitable for further modification. 290 + * The node data are dynamically allocated and all the node flags 291 + * have the OF_DYNAMIC & OF_DETACHED bits set. 292 + * Returns the newly allocated node or NULL on out of memory error. 293 + */ 294 + struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags) 295 + { 296 + struct device_node *node; 297 + 298 + node = kzalloc(sizeof(*node), allocflags); 299 + if (!node) 300 + return NULL; 301 + 302 + node->full_name = kstrdup(full_name, allocflags); 303 + of_node_set_flag(node, OF_DYNAMIC); 304 + of_node_set_flag(node, OF_DETACHED); 305 + if (!node->full_name) 306 + goto err_free; 307 + 308 + of_node_init(node); 309 + 310 + return node; 311 + 312 + err_free: 313 + kfree(node->full_name); 314 + kfree(node); 315 + return NULL; 316 + } 317 + 318 + static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) 319 + { 320 + of_node_put(ce->np); 321 + list_del(&ce->node); 322 + kfree(ce); 323 + } 324 + 325 + #ifdef DEBUG 326 + static void __of_changeset_entry_dump(struct of_changeset_entry *ce) 327 + { 328 + switch (ce->action) { 329 + case OF_RECONFIG_ADD_PROPERTY: 330 + pr_debug("%p: %s %s/%s\n", 331 + ce, "ADD_PROPERTY ", ce->np->full_name, 332 + ce->prop->name); 333 + break; 334 + case OF_RECONFIG_REMOVE_PROPERTY: 335 + pr_debug("%p: %s %s/%s\n", 336 + ce, "REMOVE_PROPERTY", ce->np->full_name, 337 + ce->prop->name); 338 + break; 339 + case OF_RECONFIG_UPDATE_PROPERTY: 340 + pr_debug("%p: %s %s/%s\n", 341 + ce, "UPDATE_PROPERTY", ce->np->full_name, 342 + ce->prop->name); 343 + break; 344 + case OF_RECONFIG_ATTACH_NODE: 345 + pr_debug("%p: %s %s\n", 346 + ce, "ATTACH_NODE ", ce->np->full_name); 347 + break; 348 + case OF_RECONFIG_DETACH_NODE: 349 + pr_debug("%p: %s %s\n", 350 + ce, "DETACH_NODE ", ce->np->full_name); 351 + break; 352 + } 353 + } 354 + #else 355 + static inline void __of_changeset_entry_dump(struct of_changeset_entry *ce) 356 + { 357 + /* empty */ 358 + } 359 + #endif 360 + 361 + static void __of_changeset_entry_invert(struct of_changeset_entry *ce, 362 + struct of_changeset_entry *rce) 363 + { 364 + memcpy(rce, ce, sizeof(*rce)); 365 + 366 + switch (ce->action) { 367 + case OF_RECONFIG_ATTACH_NODE: 368 + rce->action = OF_RECONFIG_DETACH_NODE; 369 + break; 370 + case OF_RECONFIG_DETACH_NODE: 371 + rce->action = OF_RECONFIG_ATTACH_NODE; 372 + break; 373 + case OF_RECONFIG_ADD_PROPERTY: 374 + rce->action = OF_RECONFIG_REMOVE_PROPERTY; 375 + break; 376 + case OF_RECONFIG_REMOVE_PROPERTY: 377 + rce->action = OF_RECONFIG_ADD_PROPERTY; 378 + break; 379 + case OF_RECONFIG_UPDATE_PROPERTY: 380 + rce->old_prop = ce->prop; 381 + rce->prop = ce->old_prop; 382 + break; 383 + } 384 + } 385 + 386 + static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool revert) 387 + { 388 + struct of_changeset_entry ce_inverted; 389 + int ret; 390 + 391 + if (revert) { 392 + __of_changeset_entry_invert(ce, &ce_inverted); 393 + ce = &ce_inverted; 394 + } 395 + 396 + switch (ce->action) { 397 + case OF_RECONFIG_ATTACH_NODE: 398 + case OF_RECONFIG_DETACH_NODE: 399 + ret = of_reconfig_notify(ce->action, ce->np); 400 + break; 401 + case OF_RECONFIG_ADD_PROPERTY: 402 + case OF_RECONFIG_REMOVE_PROPERTY: 403 + case OF_RECONFIG_UPDATE_PROPERTY: 404 + ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop); 405 + break; 406 + default: 407 + pr_err("%s: invalid devicetree changeset action: %i\n", __func__, 408 + (int)ce->action); 409 + return; 410 + } 411 + 412 + if (ret) 413 + pr_err("%s: notifier error @%s\n", __func__, ce->np->full_name); 414 + } 415 + 416 + static int __of_changeset_entry_apply(struct of_changeset_entry *ce) 417 + { 418 + struct property *old_prop, **propp; 419 + unsigned long flags; 420 + int ret = 0; 421 + 422 + __of_changeset_entry_dump(ce); 423 + 424 + raw_spin_lock_irqsave(&devtree_lock, flags); 425 + switch (ce->action) { 426 + case OF_RECONFIG_ATTACH_NODE: 427 + __of_attach_node(ce->np); 428 + break; 429 + case OF_RECONFIG_DETACH_NODE: 430 + __of_detach_node(ce->np); 431 + break; 432 + case OF_RECONFIG_ADD_PROPERTY: 433 + /* If the property is in deadprops then it must be removed */ 434 + for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) { 435 + if (*propp == ce->prop) { 436 + *propp = ce->prop->next; 437 + ce->prop->next = NULL; 438 + break; 439 + } 440 + } 441 + 442 + ret = __of_add_property(ce->np, ce->prop); 443 + if (ret) { 444 + pr_err("%s: add_property failed @%s/%s\n", 445 + __func__, ce->np->full_name, 446 + ce->prop->name); 447 + break; 448 + } 449 + break; 450 + case OF_RECONFIG_REMOVE_PROPERTY: 451 + ret = __of_remove_property(ce->np, ce->prop); 452 + if (ret) { 453 + pr_err("%s: remove_property failed @%s/%s\n", 454 + __func__, ce->np->full_name, 455 + ce->prop->name); 456 + break; 457 + } 458 + break; 459 + 460 + case OF_RECONFIG_UPDATE_PROPERTY: 461 + /* If the property is in deadprops then it must be removed */ 462 + for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) { 463 + if (*propp == ce->prop) { 464 + *propp = ce->prop->next; 465 + ce->prop->next = NULL; 466 + break; 467 + } 468 + } 469 + 470 + ret = __of_update_property(ce->np, ce->prop, &old_prop); 471 + if (ret) { 472 + pr_err("%s: update_property failed @%s/%s\n", 473 + __func__, ce->np->full_name, 474 + ce->prop->name); 475 + break; 476 + } 477 + break; 478 + default: 479 + ret = -EINVAL; 480 + } 481 + raw_spin_unlock_irqrestore(&devtree_lock, flags); 482 + 483 + if (ret) 484 + return ret; 485 + 486 + switch (ce->action) { 487 + case OF_RECONFIG_ATTACH_NODE: 488 + __of_attach_node_sysfs(ce->np); 489 + break; 490 + case OF_RECONFIG_DETACH_NODE: 491 + __of_detach_node_sysfs(ce->np); 492 + break; 493 + case OF_RECONFIG_ADD_PROPERTY: 494 + /* ignore duplicate names */ 495 + __of_add_property_sysfs(ce->np, ce->prop); 496 + break; 497 + case OF_RECONFIG_REMOVE_PROPERTY: 498 + __of_remove_property_sysfs(ce->np, ce->prop); 499 + break; 500 + case OF_RECONFIG_UPDATE_PROPERTY: 501 + __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop); 502 + break; 503 + } 504 + 505 + return 0; 506 + } 507 + 508 + static inline int __of_changeset_entry_revert(struct of_changeset_entry *ce) 509 + { 510 + struct of_changeset_entry ce_inverted; 511 + 512 + __of_changeset_entry_invert(ce, &ce_inverted); 513 + return __of_changeset_entry_apply(&ce_inverted); 514 + } 515 + 516 + /** 517 + * of_changeset_init - Initialize a changeset for use 518 + * 519 + * @ocs: changeset pointer 520 + * 521 + * Initialize a changeset structure 522 + */ 523 + void of_changeset_init(struct of_changeset *ocs) 524 + { 525 + memset(ocs, 0, sizeof(*ocs)); 526 + INIT_LIST_HEAD(&ocs->entries); 527 + } 528 + 529 + /** 530 + * of_changeset_destroy - Destroy a changeset 531 + * 532 + * @ocs: changeset pointer 533 + * 534 + * Destroys a changeset. Note that if a changeset is applied, 535 + * its changes to the tree cannot be reverted. 536 + */ 537 + void of_changeset_destroy(struct of_changeset *ocs) 538 + { 539 + struct of_changeset_entry *ce, *cen; 540 + 541 + list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) 542 + __of_changeset_entry_destroy(ce); 543 + } 544 + 545 + /** 546 + * of_changeset_apply - Applies a changeset 547 + * 548 + * @ocs: changeset pointer 549 + * 550 + * Applies a changeset to the live tree. 551 + * Any side-effects of live tree state changes are applied here on 552 + * sucess, like creation/destruction of devices and side-effects 553 + * like creation of sysfs properties and directories. 554 + * Returns 0 on success, a negative error value in case of an error. 555 + * On error the partially applied effects are reverted. 556 + */ 557 + int of_changeset_apply(struct of_changeset *ocs) 558 + { 559 + struct of_changeset_entry *ce; 560 + int ret; 561 + 562 + /* perform the rest of the work */ 563 + pr_debug("of_changeset: applying...\n"); 564 + list_for_each_entry(ce, &ocs->entries, node) { 565 + ret = __of_changeset_entry_apply(ce); 566 + if (ret) { 567 + pr_err("%s: Error applying changeset (%d)\n", __func__, ret); 568 + list_for_each_entry_continue_reverse(ce, &ocs->entries, node) 569 + __of_changeset_entry_revert(ce); 570 + return ret; 571 + } 572 + } 573 + pr_debug("of_changeset: applied, emitting notifiers.\n"); 574 + 575 + /* drop the global lock while emitting notifiers */ 576 + mutex_unlock(&of_mutex); 577 + list_for_each_entry(ce, &ocs->entries, node) 578 + __of_changeset_entry_notify(ce, 0); 579 + mutex_lock(&of_mutex); 580 + pr_debug("of_changeset: notifiers sent.\n"); 581 + 582 + return 0; 583 + } 584 + 585 + /** 586 + * of_changeset_revert - Reverts an applied changeset 587 + * 588 + * @ocs: changeset pointer 589 + * 590 + * Reverts a changeset returning the state of the tree to what it 591 + * was before the application. 592 + * Any side-effects like creation/destruction of devices and 593 + * removal of sysfs properties and directories are applied. 594 + * Returns 0 on success, a negative error value in case of an error. 595 + */ 596 + int of_changeset_revert(struct of_changeset *ocs) 597 + { 598 + struct of_changeset_entry *ce; 599 + int ret; 600 + 601 + pr_debug("of_changeset: reverting...\n"); 602 + list_for_each_entry_reverse(ce, &ocs->entries, node) { 603 + ret = __of_changeset_entry_revert(ce); 604 + if (ret) { 605 + pr_err("%s: Error reverting changeset (%d)\n", __func__, ret); 606 + list_for_each_entry_continue(ce, &ocs->entries, node) 607 + __of_changeset_entry_apply(ce); 608 + return ret; 609 + } 610 + } 611 + pr_debug("of_changeset: reverted, emitting notifiers.\n"); 612 + 613 + /* drop the global lock while emitting notifiers */ 614 + mutex_unlock(&of_mutex); 615 + list_for_each_entry_reverse(ce, &ocs->entries, node) 616 + __of_changeset_entry_notify(ce, 1); 617 + mutex_lock(&of_mutex); 618 + pr_debug("of_changeset: notifiers sent.\n"); 619 + 620 + return 0; 621 + } 622 + 623 + /** 624 + * of_changeset_action - Perform a changeset action 625 + * 626 + * @ocs: changeset pointer 627 + * @action: action to perform 628 + * @np: Pointer to device node 629 + * @prop: Pointer to property 630 + * 631 + * On action being one of: 632 + * + OF_RECONFIG_ATTACH_NODE 633 + * + OF_RECONFIG_DETACH_NODE, 634 + * + OF_RECONFIG_ADD_PROPERTY 635 + * + OF_RECONFIG_REMOVE_PROPERTY, 636 + * + OF_RECONFIG_UPDATE_PROPERTY 637 + * Returns 0 on success, a negative error value in case of an error. 638 + */ 639 + int of_changeset_action(struct of_changeset *ocs, unsigned long action, 640 + struct device_node *np, struct property *prop) 641 + { 642 + struct of_changeset_entry *ce; 643 + 644 + ce = kzalloc(sizeof(*ce), GFP_KERNEL); 645 + if (!ce) { 646 + pr_err("%s: Failed to allocate\n", __func__); 647 + return -ENOMEM; 648 + } 649 + /* get a reference to the node */ 650 + ce->action = action; 651 + ce->np = of_node_get(np); 652 + ce->prop = prop; 653 + 654 + if (action == OF_RECONFIG_UPDATE_PROPERTY && prop) 655 + ce->old_prop = of_find_property(np, prop->name, NULL); 656 + 657 + /* add it to the list */ 658 + list_add_tail(&ce->node, &ocs->entries); 659 + return 0; 660 + }
+11 -11
drivers/of/fdt.c
··· 923 923 } 924 924 925 925 #ifdef CONFIG_HAVE_MEMBLOCK 926 + #define MAX_PHYS_ADDR ((phys_addr_t)~0) 927 + 926 928 void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) 927 929 { 928 930 const u64 phys_offset = __pa(PAGE_OFFSET); 929 931 base &= PAGE_MASK; 930 932 size &= PAGE_MASK; 931 933 932 - if (sizeof(phys_addr_t) < sizeof(u64)) { 933 - if (base > ULONG_MAX) { 934 - pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", 935 - base, base + size); 936 - return; 937 - } 934 + if (base > MAX_PHYS_ADDR) { 935 + pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", 936 + base, base + size); 937 + return; 938 + } 938 939 939 - if (base + size > ULONG_MAX) { 940 - pr_warning("Ignoring memory range 0x%lx - 0x%llx\n", 941 - ULONG_MAX, base + size); 942 - size = ULONG_MAX - base; 943 - } 940 + if (base + size > MAX_PHYS_ADDR) { 941 + pr_warning("Ignoring memory range 0x%lx - 0x%llx\n", 942 + ULONG_MAX, base + size); 943 + size = MAX_PHYS_ADDR - base; 944 944 } 945 945 946 946 if (base + size < phys_offset) {
+58 -1
drivers/of/of_private.h
··· 31 31 char stem[0]; 32 32 }; 33 33 34 - extern struct mutex of_aliases_mutex; 34 + extern struct mutex of_mutex; 35 35 extern struct list_head aliases_lookup; 36 + extern struct kset *of_kset; 37 + 38 + 39 + static inline struct device_node *kobj_to_device_node(struct kobject *kobj) 40 + { 41 + return container_of(kobj, struct device_node, kobj); 42 + } 43 + 44 + #if defined(CONFIG_OF_DYNAMIC) 45 + extern int of_property_notify(int action, struct device_node *np, 46 + struct property *prop, struct property *old_prop); 47 + extern void of_node_release(struct kobject *kobj); 48 + #else /* CONFIG_OF_DYNAMIC */ 49 + static inline int of_property_notify(int action, struct device_node *np, 50 + struct property *prop, struct property *old_prop) 51 + { 52 + return 0; 53 + } 54 + #endif /* CONFIG_OF_DYNAMIC */ 55 + 56 + /** 57 + * General utilities for working with live trees. 58 + * 59 + * All functions with two leading underscores operate 60 + * without taking node references, so you either have to 61 + * own the devtree lock or work on detached trees only. 62 + */ 63 + struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); 64 + struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags); 65 + 66 + extern const void *__of_get_property(const struct device_node *np, 67 + const char *name, int *lenp); 68 + extern int __of_add_property(struct device_node *np, struct property *prop); 69 + extern int __of_add_property_sysfs(struct device_node *np, 70 + struct property *prop); 71 + extern int __of_remove_property(struct device_node *np, struct property *prop); 72 + extern void __of_remove_property_sysfs(struct device_node *np, 73 + struct property *prop); 74 + extern int __of_update_property(struct device_node *np, 75 + struct property *newprop, struct property **oldprop); 76 + extern void __of_update_property_sysfs(struct device_node *np, 77 + struct property *newprop, struct property *oldprop); 78 + 79 + extern void __of_attach_node(struct device_node *np); 80 + extern int __of_attach_node_sysfs(struct device_node *np); 81 + extern void __of_detach_node(struct device_node *np); 82 + extern void __of_detach_node_sysfs(struct device_node *np); 83 + 84 + /* iterators for transactions, used for overlays */ 85 + /* forward iterator */ 86 + #define for_each_transaction_entry(_oft, _te) \ 87 + list_for_each_entry(_te, &(_oft)->te_list, node) 88 + 89 + /* reverse iterator */ 90 + #define for_each_transaction_entry_reverse(_oft, _te) \ 91 + list_for_each_entry_reverse(_te, &(_oft)->te_list, node) 92 + 36 93 #endif /* _LINUX_OF_PRIVATE_H */
+70
drivers/of/of_reserved_mem.c
··· 206 206 for (i = 0; i < reserved_mem_count; i++) { 207 207 struct reserved_mem *rmem = &reserved_mem[i]; 208 208 unsigned long node = rmem->fdt_node; 209 + int len; 210 + const __be32 *prop; 209 211 int err = 0; 212 + 213 + prop = of_get_flat_dt_prop(node, "phandle", &len); 214 + if (!prop) 215 + prop = of_get_flat_dt_prop(node, "linux,phandle", &len); 216 + if (prop) 217 + rmem->phandle = of_read_number(prop, len/4); 210 218 211 219 if (rmem->size == 0) 212 220 err = __reserved_mem_alloc_size(node, rmem->name, ··· 222 214 if (err == 0) 223 215 __reserved_mem_init_node(rmem); 224 216 } 217 + } 218 + 219 + static inline struct reserved_mem *__find_rmem(struct device_node *node) 220 + { 221 + unsigned int i; 222 + 223 + if (!node->phandle) 224 + return NULL; 225 + 226 + for (i = 0; i < reserved_mem_count; i++) 227 + if (reserved_mem[i].phandle == node->phandle) 228 + return &reserved_mem[i]; 229 + return NULL; 230 + } 231 + 232 + /** 233 + * of_reserved_mem_device_init() - assign reserved memory region to given device 234 + * 235 + * This function assign memory region pointed by "memory-region" device tree 236 + * property to the given device. 237 + */ 238 + void of_reserved_mem_device_init(struct device *dev) 239 + { 240 + struct reserved_mem *rmem; 241 + struct device_node *np; 242 + 243 + np = of_parse_phandle(dev->of_node, "memory-region", 0); 244 + if (!np) 245 + return; 246 + 247 + rmem = __find_rmem(np); 248 + of_node_put(np); 249 + 250 + if (!rmem || !rmem->ops || !rmem->ops->device_init) 251 + return; 252 + 253 + rmem->ops->device_init(rmem, dev); 254 + dev_info(dev, "assigned reserved memory node %s\n", rmem->name); 255 + } 256 + 257 + /** 258 + * of_reserved_mem_device_release() - release reserved memory device structures 259 + * 260 + * This function releases structures allocated for memory region handling for 261 + * the given device. 262 + */ 263 + void of_reserved_mem_device_release(struct device *dev) 264 + { 265 + struct reserved_mem *rmem; 266 + struct device_node *np; 267 + 268 + np = of_parse_phandle(dev->of_node, "memory-region", 0); 269 + if (!np) 270 + return; 271 + 272 + rmem = __find_rmem(np); 273 + of_node_put(np); 274 + 275 + if (!rmem || !rmem->ops || !rmem->ops->device_release) 276 + return; 277 + 278 + rmem->ops->device_release(rmem, dev); 225 279 }
+9 -23
drivers/of/platform.c
··· 422 422 break; 423 423 } 424 424 } 425 + of_node_set_flag(bus, OF_POPULATED_BUS); 425 426 return rc; 426 427 } 427 428 ··· 509 508 510 509 static int of_platform_device_destroy(struct device *dev, void *data) 511 510 { 512 - bool *children_left = data; 513 - 514 511 /* Do not touch devices not populated from the device tree */ 515 - if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { 516 - *children_left = true; 512 + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) 517 513 return 0; 518 - } 519 514 520 - /* Recurse, but don't touch this device if it has any children left */ 521 - if (of_platform_depopulate(dev) != 0) { 522 - *children_left = true; 523 - return 0; 524 - } 515 + /* Recurse for any nodes that were treated as busses */ 516 + if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) 517 + device_for_each_child(dev, NULL, of_platform_device_destroy); 525 518 526 519 if (dev->bus == &platform_bus_type) 527 520 platform_device_unregister(to_platform_device(dev)); ··· 523 528 else if (dev->bus == &amba_bustype) 524 529 amba_device_unregister(to_amba_device(dev)); 525 530 #endif 526 - else { 527 - *children_left = true; 528 - return 0; 529 - } 530 531 531 532 of_node_clear_flag(dev->of_node, OF_POPULATED); 532 - 533 + of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); 533 534 return 0; 534 535 } 535 536 536 537 /** 537 538 * of_platform_depopulate() - Remove devices populated from device tree 538 - * @parent: device which childred will be removed 539 + * @parent: device which children will be removed 539 540 * 540 541 * Complementary to of_platform_populate(), this function removes children 541 542 * of the given device (and, recurrently, their children) that have been ··· 541 550 * Returns 0 when all children devices have been removed or 542 551 * -EBUSY when some children remained. 543 552 */ 544 - int of_platform_depopulate(struct device *parent) 553 + void of_platform_depopulate(struct device *parent) 545 554 { 546 - bool children_left = false; 547 - 548 - device_for_each_child(parent, &children_left, 549 - of_platform_device_destroy); 550 - 551 - return children_left ? -EBUSY : 0; 555 + device_for_each_child(parent, NULL, of_platform_device_destroy); 552 556 } 553 557 EXPORT_SYMBOL_GPL(of_platform_depopulate); 554 558
+235
drivers/of/selftest.c
··· 9 9 #include <linux/errno.h> 10 10 #include <linux/module.h> 11 11 #include <linux/of.h> 12 + #include <linux/of_fdt.h> 12 13 #include <linux/of_irq.h> 13 14 #include <linux/of_platform.h> 14 15 #include <linux/list.h> ··· 17 16 #include <linux/slab.h> 18 17 #include <linux/device.h> 19 18 19 + #include "of_private.h" 20 + 20 21 static struct selftest_results { 21 22 int passed; 22 23 int failed; 23 24 } selftest_results; 25 + 26 + #define NO_OF_NODES 2 27 + static struct device_node *nodes[NO_OF_NODES]; 28 + static int last_node_index; 24 29 25 30 #define selftest(result, fmt, ...) { \ 26 31 if (!(result)) { \ ··· 271 264 selftest(rc == -ENODATA, "empty property; rc=%i", rc); 272 265 rc = of_property_match_string(np, "unterminated-string", "blah"); 273 266 selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc); 267 + } 268 + 269 + #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ 270 + (p1)->value && (p2)->value && \ 271 + !memcmp((p1)->value, (p2)->value, (p1)->length) && \ 272 + !strcmp((p1)->name, (p2)->name)) 273 + static void __init of_selftest_property_copy(void) 274 + { 275 + #ifdef CONFIG_OF_DYNAMIC 276 + struct property p1 = { .name = "p1", .length = 0, .value = "" }; 277 + struct property p2 = { .name = "p2", .length = 5, .value = "abcd" }; 278 + struct property *new; 279 + 280 + new = __of_prop_dup(&p1, GFP_KERNEL); 281 + selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n"); 282 + kfree(new->value); 283 + kfree(new->name); 284 + kfree(new); 285 + 286 + new = __of_prop_dup(&p2, GFP_KERNEL); 287 + selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n"); 288 + kfree(new->value); 289 + kfree(new->name); 290 + kfree(new); 291 + #endif 292 + } 293 + 294 + static void __init of_selftest_changeset(void) 295 + { 296 + #ifdef CONFIG_OF_DYNAMIC 297 + struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; 298 + struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; 299 + struct property *ppremove; 300 + struct device_node *n1, *n2, *n21, *nremove, *parent; 301 + struct of_changeset chgset; 302 + 303 + of_changeset_init(&chgset); 304 + n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); 305 + selftest(n1, "testcase setup failure\n"); 306 + n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); 307 + selftest(n2, "testcase setup failure\n"); 308 + n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); 309 + selftest(n21, "testcase setup failure %p\n", n21); 310 + nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); 311 + selftest(nremove, "testcase setup failure\n"); 312 + ppadd = __of_prop_dup(&padd, GFP_KERNEL); 313 + selftest(ppadd, "testcase setup failure\n"); 314 + ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL); 315 + selftest(ppupdate, "testcase setup failure\n"); 316 + parent = nremove->parent; 317 + n1->parent = parent; 318 + n2->parent = parent; 319 + n21->parent = n2; 320 + n2->child = n21; 321 + ppremove = of_find_property(parent, "prop-remove", NULL); 322 + selftest(ppremove, "failed to find removal prop"); 323 + 324 + of_changeset_init(&chgset); 325 + selftest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n"); 326 + selftest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n"); 327 + selftest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n"); 328 + selftest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n"); 329 + selftest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); 330 + selftest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); 331 + selftest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); 332 + mutex_lock(&of_mutex); 333 + selftest(!of_changeset_apply(&chgset), "apply failed\n"); 334 + mutex_unlock(&of_mutex); 335 + 336 + mutex_lock(&of_mutex); 337 + selftest(!of_changeset_revert(&chgset), "revert failed\n"); 338 + mutex_unlock(&of_mutex); 339 + 340 + of_changeset_destroy(&chgset); 341 + #endif 274 342 } 275 343 276 344 static void __init of_selftest_parse_interrupts(void) ··· 599 517 } 600 518 } 601 519 520 + /** 521 + * update_node_properties - adds the properties 522 + * of np into dup node (present in live tree) and 523 + * updates parent of children of np to dup. 524 + * 525 + * @np: node already present in live tree 526 + * @dup: node present in live tree to be updated 527 + */ 528 + static void update_node_properties(struct device_node *np, 529 + struct device_node *dup) 530 + { 531 + struct property *prop; 532 + struct device_node *child; 533 + 534 + for_each_property_of_node(np, prop) 535 + of_add_property(dup, prop); 536 + 537 + for_each_child_of_node(np, child) 538 + child->parent = dup; 539 + } 540 + 541 + /** 542 + * attach_node_and_children - attaches nodes 543 + * and its children to live tree 544 + * 545 + * @np: Node to attach to live tree 546 + */ 547 + static int attach_node_and_children(struct device_node *np) 548 + { 549 + struct device_node *next, *root = np, *dup; 550 + 551 + if (!np) { 552 + pr_warn("%s: No tree to attach; not running tests\n", 553 + __func__); 554 + return -ENODATA; 555 + } 556 + 557 + 558 + /* skip root node */ 559 + np = np->child; 560 + /* storing a copy in temporary node */ 561 + dup = np; 562 + 563 + while (dup) { 564 + nodes[last_node_index++] = dup; 565 + dup = dup->sibling; 566 + } 567 + dup = NULL; 568 + 569 + while (np) { 570 + next = np->allnext; 571 + dup = of_find_node_by_path(np->full_name); 572 + if (dup) 573 + update_node_properties(np, dup); 574 + else { 575 + np->child = NULL; 576 + if (np->parent == root) 577 + np->parent = of_allnodes; 578 + of_attach_node(np); 579 + } 580 + np = next; 581 + } 582 + 583 + return 0; 584 + } 585 + 586 + /** 587 + * selftest_data_add - Reads, copies data from 588 + * linked tree and attaches it to the live tree 589 + */ 590 + static int __init selftest_data_add(void) 591 + { 592 + void *selftest_data; 593 + struct device_node *selftest_data_node; 594 + extern uint8_t __dtb_testcases_begin[]; 595 + extern uint8_t __dtb_testcases_end[]; 596 + const int size = __dtb_testcases_end - __dtb_testcases_begin; 597 + 598 + if (!size || !of_allnodes) { 599 + pr_warn("%s: No testcase data to attach; not running tests\n", 600 + __func__); 601 + return -ENODATA; 602 + } 603 + 604 + /* creating copy */ 605 + selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL); 606 + 607 + if (!selftest_data) { 608 + pr_warn("%s: Failed to allocate memory for selftest_data; " 609 + "not running tests\n", __func__); 610 + return -ENOMEM; 611 + } 612 + of_fdt_unflatten_tree(selftest_data, &selftest_data_node); 613 + 614 + /* attach the sub-tree to live tree */ 615 + return attach_node_and_children(selftest_data_node); 616 + } 617 + 618 + /** 619 + * detach_node_and_children - detaches node 620 + * and its children from live tree 621 + * 622 + * @np: Node to detach from live tree 623 + */ 624 + static void detach_node_and_children(struct device_node *np) 625 + { 626 + while (np->child) 627 + detach_node_and_children(np->child); 628 + 629 + while (np->sibling) 630 + detach_node_and_children(np->sibling); 631 + 632 + of_detach_node(np); 633 + } 634 + 635 + /** 636 + * selftest_data_remove - removes the selftest data 637 + * nodes from the live tree 638 + */ 639 + static void selftest_data_remove(void) 640 + { 641 + struct device_node *np; 642 + struct property *prop; 643 + 644 + while (last_node_index >= 0) { 645 + if (nodes[last_node_index]) { 646 + np = of_find_node_by_path(nodes[last_node_index]->full_name); 647 + if (strcmp(np->full_name, "/aliases") != 0) { 648 + detach_node_and_children(np->child); 649 + of_detach_node(np); 650 + } else { 651 + for_each_property_of_node(np, prop) { 652 + if (strcmp(prop->name, "testcase-alias") == 0) 653 + of_remove_property(np, prop); 654 + } 655 + } 656 + } 657 + last_node_index--; 658 + } 659 + } 660 + 602 661 static int __init of_selftest(void) 603 662 { 604 663 struct device_node *np; 664 + int res; 665 + 666 + /* adding data for selftest */ 667 + res = selftest_data_add(); 668 + if (res) 669 + return res; 605 670 606 671 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); 607 672 if (!np) { ··· 762 533 of_selftest_dynamic(); 763 534 of_selftest_parse_phandle_with_args(); 764 535 of_selftest_property_match_string(); 536 + of_selftest_property_copy(); 537 + of_selftest_changeset(); 765 538 of_selftest_parse_interrupts(); 766 539 of_selftest_parse_interrupts_extended(); 767 540 of_selftest_match_node(); 768 541 of_selftest_platform_populate(); 769 542 pr_info("end of selftest - %i passed, %i failed\n", 770 543 selftest_results.passed, selftest_results.failed); 544 + 545 + /* removing selftest data from live tree */ 546 + selftest_data_remove(); 547 + 771 548 return 0; 772 549 } 773 550 late_initcall(of_selftest);
+15
drivers/of/testcase-data/testcases.dts
··· 1 + /dts-v1/; 2 + / { 3 + testcase-data { 4 + changeset { 5 + prop-update = "hello"; 6 + prop-remove = "world"; 7 + node-remove { 8 + }; 9 + }; 10 + }; 11 + }; 12 + #include "tests-phandle.dtsi" 13 + #include "tests-interrupts.dtsi" 14 + #include "tests-match.dtsi" 15 + #include "tests-platform.dtsi"
-4
drivers/of/testcase-data/testcases.dtsi
··· 1 - #include "tests-phandle.dtsi" 2 - #include "tests-interrupts.dtsi" 3 - #include "tests-match.dtsi" 4 - #include "tests-platform.dtsi"
+2 -2
drivers/pci/hotplug/rpaphp_core.c
··· 375 375 376 376 static int __init rpaphp_init(void) 377 377 { 378 - struct device_node *dn = NULL; 378 + struct device_node *dn; 379 379 380 380 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 381 381 382 - while ((dn = of_find_node_by_name(dn, "pci"))) 382 + for_each_node_by_name(dn, "pci") 383 383 rpaphp_add_slot(dn); 384 384 385 385 return 0;
+4 -39
drivers/tty/ehv_bytechan.c
··· 108 108 * 109 109 * The byte channel to be used for the console is specified via a "stdout" 110 110 * property in the /chosen node. 111 - * 112 - * For compatible with legacy device trees, we also look for a "stdout" alias. 113 111 */ 114 112 static int find_console_handle(void) 115 113 { 116 - struct device_node *np, *np2; 114 + struct device_node *np = of_stdout; 117 115 const char *sprop = NULL; 118 116 const uint32_t *iprop; 119 117 120 - np = of_find_node_by_path("/chosen"); 121 - if (np) 122 - sprop = of_get_property(np, "stdout-path", NULL); 123 - 124 - if (!np || !sprop) { 125 - of_node_put(np); 126 - np = of_find_node_by_name(NULL, "aliases"); 127 - if (np) 128 - sprop = of_get_property(np, "stdout", NULL); 129 - } 130 - 131 - if (!sprop) { 132 - of_node_put(np); 133 - return 0; 134 - } 135 - 136 118 /* We don't care what the aliased node is actually called. We only 137 119 * care if it's compatible with "epapr,hv-byte-channel", because that 138 - * indicates that it's a byte channel node. We use a temporary 139 - * variable, 'np2', because we can't release 'np' until we're done with 140 - * 'sprop'. 120 + * indicates that it's a byte channel node. 141 121 */ 142 - np2 = of_find_node_by_path(sprop); 143 - of_node_put(np); 144 - np = np2; 145 - if (!np) { 146 - pr_warning("ehv-bc: stdout node '%s' does not exist\n", sprop); 122 + if (!np || !of_device_is_compatible(np, "epapr,hv-byte-channel")) 147 123 return 0; 148 - } 149 - 150 - /* Is it a byte channel? */ 151 - if (!of_device_is_compatible(np, "epapr,hv-byte-channel")) { 152 - of_node_put(np); 153 - return 0; 154 - } 155 124 156 125 stdout_irq = irq_of_parse_and_map(np, 0); 157 126 if (stdout_irq == NO_IRQ) { 158 - pr_err("ehv-bc: no 'interrupts' property in %s node\n", sprop); 159 - of_node_put(np); 127 + pr_err("ehv-bc: no 'interrupts' property in %s node\n", np->full_name); 160 128 return 0; 161 129 } 162 130 ··· 135 167 if (!iprop) { 136 168 pr_err("ehv-bc: no 'hv-handle' property in %s node\n", 137 169 np->name); 138 - of_node_put(np); 139 170 return 0; 140 171 } 141 172 stdout_bc = be32_to_cpu(*iprop); 142 - 143 - of_node_put(np); 144 173 return 1; 145 174 } 146 175
+3 -12
drivers/tty/hvc/hvc_opal.c
··· 342 342 343 343 void __init hvc_opal_init_early(void) 344 344 { 345 - struct device_node *stdout_node = NULL; 345 + struct device_node *stdout_node = of_node_get(of_stdout); 346 346 const __be32 *termno; 347 - const char *name = NULL; 348 347 const struct hv_ops *ops; 349 348 u32 index; 350 349 351 - /* find the boot console from /chosen/stdout */ 352 - if (of_chosen) 353 - name = of_get_property(of_chosen, "linux,stdout-path", NULL); 354 - if (name) { 355 - stdout_node = of_find_node_by_path(name); 356 - if (!stdout_node) { 357 - pr_err("hvc_opal: Failed to locate default console!\n"); 358 - return; 359 - } 360 - } else { 350 + /* If the console wasn't in /chosen, try /ibm,opal */ 351 + if (!stdout_node) { 361 352 struct device_node *opal, *np; 362 353 363 354 /* Current OPAL takeover doesn't provide the stdout
+10 -19
drivers/tty/hvc/hvc_vio.c
··· 404 404 405 405 void __init hvc_vio_init_early(void) 406 406 { 407 - struct device_node *stdout_node; 408 407 const __be32 *termno; 409 408 const char *name; 410 409 const struct hv_ops *ops; 411 410 412 411 /* find the boot console from /chosen/stdout */ 413 - if (!of_chosen) 412 + if (!of_stdout) 414 413 return; 415 - name = of_get_property(of_chosen, "linux,stdout-path", NULL); 416 - if (name == NULL) 417 - return; 418 - stdout_node = of_find_node_by_path(name); 419 - if (!stdout_node) 420 - return; 421 - name = of_get_property(stdout_node, "name", NULL); 414 + name = of_get_property(of_stdout, "name", NULL); 422 415 if (!name) { 423 416 printk(KERN_WARNING "stdout node missing 'name' property!\n"); 424 - goto out; 417 + return; 425 418 } 426 419 427 420 /* Check if it's a virtual terminal */ 428 421 if (strncmp(name, "vty", 3) != 0) 429 - goto out; 430 - termno = of_get_property(stdout_node, "reg", NULL); 422 + return; 423 + termno = of_get_property(of_stdout, "reg", NULL); 431 424 if (termno == NULL) 432 - goto out; 425 + return; 433 426 hvterm_priv0.termno = of_read_number(termno, 1); 434 427 spin_lock_init(&hvterm_priv0.buf_lock); 435 428 hvterm_privs[0] = &hvterm_priv0; 436 429 437 430 /* Check the protocol */ 438 - if (of_device_is_compatible(stdout_node, "hvterm1")) { 431 + if (of_device_is_compatible(of_stdout, "hvterm1")) { 439 432 hvterm_priv0.proto = HV_PROTOCOL_RAW; 440 433 ops = &hvterm_raw_ops; 441 434 } 442 - else if (of_device_is_compatible(stdout_node, "hvterm-protocol")) { 435 + else if (of_device_is_compatible(of_stdout, "hvterm-protocol")) { 443 436 hvterm_priv0.proto = HV_PROTOCOL_HVSI; 444 437 ops = &hvterm_hvsi_ops; 445 438 hvsilib_init(&hvterm_priv0.hvsi, hvc_get_chars, hvc_put_chars, ··· 440 447 /* HVSI, perform the handshake now */ 441 448 hvsilib_establish(&hvterm_priv0.hvsi); 442 449 } else 443 - goto out; 450 + return; 444 451 udbg_putc = udbg_hvc_putc; 445 452 udbg_getc = udbg_hvc_getc; 446 453 udbg_getc_poll = udbg_hvc_getc_poll; ··· 449 456 * backend for HVSI, only do udbg 450 457 */ 451 458 if (hvterm_priv0.proto == HV_PROTOCOL_HVSI) 452 - goto out; 459 + return; 453 460 #endif 454 461 /* Check whether the user has requested a different console. */ 455 462 if (!strstr(cmd_line, "console=")) 456 463 add_preferred_console("hvc", 0, NULL); 457 464 hvc_instantiate(0, 0, ops); 458 - out: 459 - of_node_put(stdout_node); 460 465 } 461 466 462 467 /* call this from early_init() for a working debug console on
+3 -6
drivers/tty/serial/pmac_zilog.c
··· 1653 1653 /* 1654 1654 * Find all escc chips in the system 1655 1655 */ 1656 - node_p = of_find_node_by_name(NULL, "escc"); 1657 - while (node_p) { 1656 + for_each_node_by_name(node_p, "escc") { 1658 1657 /* 1659 1658 * First get channel A/B node pointers 1660 1659 * ··· 1671 1672 of_node_put(node_b); 1672 1673 printk(KERN_ERR "pmac_zilog: missing node %c for escc %s\n", 1673 1674 (!node_a) ? 'a' : 'b', node_p->full_name); 1674 - goto next; 1675 + continue; 1675 1676 } 1676 1677 1677 1678 /* ··· 1698 1699 of_node_put(node_b); 1699 1700 memset(&pmz_ports[count], 0, sizeof(struct uart_pmac_port)); 1700 1701 memset(&pmz_ports[count+1], 0, sizeof(struct uart_pmac_port)); 1701 - goto next; 1702 + continue; 1702 1703 } 1703 1704 count += 2; 1704 - next: 1705 - node_p = of_find_node_by_name(node_p, "escc"); 1706 1705 } 1707 1706 pmz_ports_count = count; 1708 1707
+3
drivers/tty/serial/serial_core.c
··· 26 26 #include <linux/slab.h> 27 27 #include <linux/init.h> 28 28 #include <linux/console.h> 29 + #include <linux/of.h> 29 30 #include <linux/proc_fs.h> 30 31 #include <linux/seq_file.h> 31 32 #include <linux/device.h> ··· 2612 2611 spin_lock_init(&uport->lock); 2613 2612 lockdep_set_class(&uport->lock, &port_lock_key); 2614 2613 } 2614 + if (uport->cons && uport->dev) 2615 + of_console_check(uport->dev->of_node, uport->cons->name, uport->line); 2615 2616 2616 2617 uart_configure_port(drv, state, uport); 2617 2618
+82 -5
include/linux/of.h
··· 74 74 uint32_t args[MAX_PHANDLE_ARGS]; 75 75 }; 76 76 77 - extern int of_node_add(struct device_node *node); 78 - 79 77 /* initialize a node */ 80 78 extern struct kobj_type of_node_ktype; 81 79 static inline void of_node_init(struct device_node *node) ··· 111 113 extern struct device_node *of_allnodes; 112 114 extern struct device_node *of_chosen; 113 115 extern struct device_node *of_aliases; 116 + extern struct device_node *of_stdout; 114 117 extern raw_spinlock_t devtree_lock; 115 118 116 119 static inline bool of_have_populated_dt(void) ··· 203 204 #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ 204 205 #define OF_DETACHED 2 /* node has been detached from the device tree */ 205 206 #define OF_POPULATED 3 /* device already created for the node */ 207 + #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ 206 208 207 209 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 208 210 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) ··· 322 322 struct of_prop_reconfig { 323 323 struct device_node *dn; 324 324 struct property *prop; 325 + struct property *old_prop; 325 326 }; 326 327 327 328 extern int of_reconfig_notifier_register(struct notifier_block *); ··· 353 352 */ 354 353 const char *of_prop_next_string(struct property *prop, const char *cur); 355 354 356 - int of_device_is_stdout_path(struct device_node *dn); 355 + bool of_console_check(struct device_node *dn, char *name, int index); 357 356 358 357 #else /* CONFIG_OF */ 359 358 ··· 565 564 return 0; 566 565 } 567 566 568 - static inline int of_device_is_stdout_path(struct device_node *dn) 567 + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) 569 568 { 570 - return 0; 569 + return false; 571 570 } 572 571 573 572 static inline const __be32 *of_prop_next_u32(struct property *prop, ··· 786 785 _OF_DECLARE(table, name, compat, fn, of_init_fn_1) 787 786 #define OF_DECLARE_2(table, name, compat, fn) \ 788 787 _OF_DECLARE(table, name, compat, fn, of_init_fn_2) 788 + 789 + /** 790 + * struct of_changeset_entry - Holds a changeset entry 791 + * 792 + * @node: list_head for the log list 793 + * @action: notifier action 794 + * @np: pointer to the device node affected 795 + * @prop: pointer to the property affected 796 + * @old_prop: hold a pointer to the original property 797 + * 798 + * Every modification of the device tree during a changeset 799 + * is held in a list of of_changeset_entry structures. 800 + * That way we can recover from a partial application, or we can 801 + * revert the changeset 802 + */ 803 + struct of_changeset_entry { 804 + struct list_head node; 805 + unsigned long action; 806 + struct device_node *np; 807 + struct property *prop; 808 + struct property *old_prop; 809 + }; 810 + 811 + /** 812 + * struct of_changeset - changeset tracker structure 813 + * 814 + * @entries: list_head for the changeset entries 815 + * 816 + * changesets are a convenient way to apply bulk changes to the 817 + * live tree. In case of an error, changes are rolled-back. 818 + * changesets live on after initial application, and if not 819 + * destroyed after use, they can be reverted in one single call. 820 + */ 821 + struct of_changeset { 822 + struct list_head entries; 823 + }; 824 + 825 + #ifdef CONFIG_OF_DYNAMIC 826 + extern void of_changeset_init(struct of_changeset *ocs); 827 + extern void of_changeset_destroy(struct of_changeset *ocs); 828 + extern int of_changeset_apply(struct of_changeset *ocs); 829 + extern int of_changeset_revert(struct of_changeset *ocs); 830 + extern int of_changeset_action(struct of_changeset *ocs, 831 + unsigned long action, struct device_node *np, 832 + struct property *prop); 833 + 834 + static inline int of_changeset_attach_node(struct of_changeset *ocs, 835 + struct device_node *np) 836 + { 837 + return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL); 838 + } 839 + 840 + static inline int of_changeset_detach_node(struct of_changeset *ocs, 841 + struct device_node *np) 842 + { 843 + return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL); 844 + } 845 + 846 + static inline int of_changeset_add_property(struct of_changeset *ocs, 847 + struct device_node *np, struct property *prop) 848 + { 849 + return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop); 850 + } 851 + 852 + static inline int of_changeset_remove_property(struct of_changeset *ocs, 853 + struct device_node *np, struct property *prop) 854 + { 855 + return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop); 856 + } 857 + 858 + static inline int of_changeset_update_property(struct of_changeset *ocs, 859 + struct device_node *np, struct property *prop) 860 + { 861 + return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); 862 + } 863 + #endif 789 864 790 865 #endif /* _LINUX_OF_H */
+2 -5
include/linux/of_platform.h
··· 72 72 const struct of_device_id *matches, 73 73 const struct of_dev_auxdata *lookup, 74 74 struct device *parent); 75 - extern int of_platform_depopulate(struct device *parent); 75 + extern void of_platform_depopulate(struct device *parent); 76 76 #else 77 77 static inline int of_platform_populate(struct device_node *root, 78 78 const struct of_device_id *matches, ··· 81 81 { 82 82 return -ENODEV; 83 83 } 84 - static inline int of_platform_depopulate(struct device *parent) 85 - { 86 - return -ENODEV; 87 - } 84 + static inline void of_platform_depopulate(struct device *parent) { } 88 85 #endif 89 86 90 87 #endif /* _LINUX_OF_PLATFORM_H */
+7
include/linux/of_reserved_mem.h
··· 8 8 struct reserved_mem { 9 9 const char *name; 10 10 unsigned long fdt_node; 11 + unsigned long phandle; 11 12 const struct reserved_mem_ops *ops; 12 13 phys_addr_t base; 13 14 phys_addr_t size; ··· 28 27 _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) 29 28 30 29 #ifdef CONFIG_OF_RESERVED_MEM 30 + void of_reserved_mem_device_init(struct device *dev); 31 + void of_reserved_mem_device_release(struct device *dev); 32 + 31 33 void fdt_init_reserved_mem(void); 32 34 void fdt_reserved_mem_save_node(unsigned long node, const char *uname, 33 35 phys_addr_t base, phys_addr_t size); 34 36 #else 37 + static inline void of_reserved_mem_device_init(struct device *dev) { } 38 + static inline void of_reserved_mem_device_release(struct device *pdev) { } 39 + 35 40 static inline void fdt_init_reserved_mem(void) { } 36 41 static inline void fdt_reserved_mem_save_node(unsigned long node, 37 42 const char *uname, phys_addr_t base, phys_addr_t size) { }
+3 -3
sound/ppc/pmac.c
··· 992 992 return -ENODEV; 993 993 994 994 if (!sound) { 995 - sound = of_find_node_by_name(NULL, "sound"); 996 - while (sound && sound->parent != chip->node) 997 - sound = of_find_node_by_name(sound, "sound"); 995 + for_each_node_by_name(sound, "sound") 996 + if (sound->parent == chip->node) 997 + break; 998 998 } 999 999 if (! sound) { 1000 1000 of_node_put(chip->node);