Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Functions for dealing with DT resolution |
| 3 | * |
| 4 | * Copyright (C) 2012 Pantelis Antoniou <panto@antoniou-consulting.com> |
| 5 | * Copyright (C) 2012 Texas Instruments Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 12 | #define pr_fmt(fmt) "OF: resolver: " fmt |
| 13 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/of_device.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/ctype.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/slab.h> |
| 23 | |
| 24 | /* illegal phandle value (set when unresolved) */ |
| 25 | #define OF_PHANDLE_ILLEGAL 0xdeadbeef |
| 26 | |
| 27 | /** |
| 28 | * Find a node with the give full name by recursively following any of |
| 29 | * the child node links. |
| 30 | */ |
| 31 | static struct device_node *__of_find_node_by_full_name(struct device_node *node, |
| 32 | const char *full_name) |
| 33 | { |
| 34 | struct device_node *child, *found; |
| 35 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 36 | if (!node) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 37 | return NULL; |
| 38 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 39 | if (!of_node_cmp(node->full_name, full_name)) |
Amitoj Kaur Chawla | 82f6875 | 2016-02-03 23:39:01 +0530 | [diff] [blame] | 40 | return of_node_get(node); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 41 | |
| 42 | for_each_child_of_node(node, child) { |
| 43 | found = __of_find_node_by_full_name(child, full_name); |
Amitoj Kaur Chawla | 82f6875 | 2016-02-03 23:39:01 +0530 | [diff] [blame] | 44 | if (found != NULL) { |
| 45 | of_node_put(child); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 46 | return found; |
Amitoj Kaur Chawla | 82f6875 | 2016-02-03 23:39:01 +0530 | [diff] [blame] | 47 | } |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Find live tree's maximum phandle value. |
| 55 | */ |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 56 | static phandle live_tree_max_phandle(void) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 57 | { |
| 58 | struct device_node *node; |
| 59 | phandle phandle; |
| 60 | unsigned long flags; |
| 61 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 62 | raw_spin_lock_irqsave(&devtree_lock, flags); |
| 63 | phandle = 0; |
| 64 | for_each_of_allnodes(node) { |
| 65 | if (node->phandle != OF_PHANDLE_ILLEGAL && |
| 66 | node->phandle > phandle) |
| 67 | phandle = node->phandle; |
| 68 | } |
| 69 | raw_spin_unlock_irqrestore(&devtree_lock, flags); |
| 70 | |
| 71 | return phandle; |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Adjust a subtree's phandle values by a given delta. |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 76 | */ |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 77 | static void adjust_overlay_phandles(struct device_node *node, |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 78 | int phandle_delta) |
| 79 | { |
| 80 | struct device_node *child; |
| 81 | struct property *prop; |
| 82 | phandle phandle; |
| 83 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 84 | if (node->phandle != 0 && node->phandle != OF_PHANDLE_ILLEGAL) |
| 85 | node->phandle += phandle_delta; |
| 86 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 87 | for_each_property_of_node(node, prop) { |
| 88 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 89 | if (of_prop_cmp(prop->name, "phandle") && |
| 90 | of_prop_cmp(prop->name, "linux,phandle")) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 91 | continue; |
| 92 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 93 | if (prop->length < 4) |
| 94 | continue; |
| 95 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 96 | phandle = be32_to_cpup(prop->value); |
Frank Rowand | a67976e | 2016-10-28 23:26:21 -0700 | [diff] [blame] | 97 | if (phandle == OF_PHANDLE_ILLEGAL) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 98 | continue; |
| 99 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 100 | *(uint32_t *)prop->value = cpu_to_be32(node->phandle); |
| 101 | } |
| 102 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 103 | for_each_child_of_node(node, child) |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 104 | adjust_overlay_phandles(child, phandle_delta); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 105 | } |
| 106 | |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 107 | static int update_usages_of_a_phandle_reference(struct device_node *node, |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 108 | struct property *rprop, int value) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 109 | { |
| 110 | phandle phandle; |
| 111 | struct device_node *refnode; |
| 112 | struct property *sprop; |
| 113 | char *propval, *propcur, *propend, *nodestr, *propstr, *s; |
| 114 | int offset, propcurlen; |
| 115 | int err = 0; |
| 116 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 117 | propval = kmalloc(rprop->length, GFP_KERNEL); |
Frank Rowand | 96d1c8e | 2016-10-28 23:26:22 -0700 | [diff] [blame] | 118 | if (!propval) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 119 | return -ENOMEM; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 120 | memcpy(propval, rprop->value, rprop->length); |
| 121 | |
| 122 | propend = propval + rprop->length; |
| 123 | for (propcur = propval; propcur < propend; propcur += propcurlen + 1) { |
| 124 | propcurlen = strlen(propcur); |
| 125 | |
| 126 | nodestr = propcur; |
| 127 | s = strchr(propcur, ':'); |
| 128 | if (!s) { |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 129 | err = -EINVAL; |
| 130 | goto err_fail; |
| 131 | } |
| 132 | *s++ = '\0'; |
| 133 | |
| 134 | propstr = s; |
| 135 | s = strchr(s, ':'); |
| 136 | if (!s) { |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 137 | err = -EINVAL; |
| 138 | goto err_fail; |
| 139 | } |
| 140 | |
| 141 | *s++ = '\0'; |
| 142 | err = kstrtoint(s, 10, &offset); |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 143 | if (err) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 144 | goto err_fail; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 145 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 146 | refnode = __of_find_node_by_full_name(node, nodestr); |
Frank Rowand | 96d1c8e | 2016-10-28 23:26:22 -0700 | [diff] [blame] | 147 | if (!refnode) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 148 | continue; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 149 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 150 | for_each_property_of_node(refnode, sprop) { |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 151 | if (!of_prop_cmp(sprop->name, propstr)) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 152 | break; |
| 153 | } |
Amitoj Kaur Chawla | 82f6875 | 2016-02-03 23:39:01 +0530 | [diff] [blame] | 154 | of_node_put(refnode); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 155 | |
| 156 | if (!sprop) { |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 157 | err = -ENOENT; |
| 158 | goto err_fail; |
| 159 | } |
| 160 | |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 161 | phandle = value; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 162 | *(__be32 *)(sprop->value + offset) = cpu_to_be32(phandle); |
| 163 | } |
| 164 | |
| 165 | err_fail: |
| 166 | kfree(propval); |
| 167 | return err; |
| 168 | } |
| 169 | |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 170 | /* compare nodes taking into account that 'name' strips out the @ part */ |
| 171 | static int __of_node_name_cmp(const struct device_node *dn1, |
| 172 | const struct device_node *dn2) |
| 173 | { |
| 174 | const char *n1 = strrchr(dn1->full_name, '/') ? : "/"; |
| 175 | const char *n2 = strrchr(dn2->full_name, '/') ? : "/"; |
| 176 | |
| 177 | return of_node_cmp(n1, n2); |
| 178 | } |
| 179 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 180 | /* |
| 181 | * Adjust the local phandle references by the given phandle delta. |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 182 | * Assumes the existances of a __local_fixups__ node at the root. |
| 183 | * Assumes that __of_verify_tree_phandle_references has been called. |
| 184 | * Does not take any devtree locks so make sure you call this on a tree |
| 185 | * which is at the detached state. |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 186 | */ |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 187 | static int adjust_local_phandle_references(struct device_node *node, |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 188 | struct device_node *target, int phandle_delta) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 189 | { |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 190 | struct device_node *child, *childtarget; |
| 191 | struct property *rprop, *sprop; |
| 192 | int err, i, count; |
| 193 | unsigned int off; |
| 194 | phandle phandle; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 195 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 196 | if (!node) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 197 | return 0; |
| 198 | |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 199 | for_each_property_of_node(node, rprop) { |
| 200 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 201 | /* skip properties added automatically */ |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 202 | if (!of_prop_cmp(rprop->name, "name") || |
| 203 | !of_prop_cmp(rprop->name, "phandle") || |
| 204 | !of_prop_cmp(rprop->name, "linux,phandle")) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 205 | continue; |
| 206 | |
Frank Rowand | 96d1c8e | 2016-10-28 23:26:22 -0700 | [diff] [blame] | 207 | if ((rprop->length % 4) != 0 || rprop->length == 0) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 208 | return -EINVAL; |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 209 | count = rprop->length / sizeof(__be32); |
| 210 | |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 211 | for_each_property_of_node(target, sprop) { |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 212 | if (!of_prop_cmp(sprop->name, rprop->name)) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 216 | if (!sprop) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 217 | return -EINVAL; |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 218 | |
| 219 | for (i = 0; i < count; i++) { |
| 220 | off = be32_to_cpu(((__be32 *)rprop->value)[i]); |
Frank Rowand | 96d1c8e | 2016-10-28 23:26:22 -0700 | [diff] [blame] | 221 | if (off >= sprop->length || (off + 4) > sprop->length) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 222 | return -EINVAL; |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 223 | |
| 224 | if (phandle_delta) { |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 225 | phandle = be32_to_cpu(*(__be32 *)(sprop->value + off)); |
| 226 | phandle += phandle_delta; |
| 227 | *(__be32 *)(sprop->value + off) = cpu_to_be32(phandle); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | for_each_child_of_node(node, child) { |
| 233 | |
| 234 | for_each_child_of_node(target, childtarget) |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 235 | if (!__of_node_name_cmp(child, childtarget)) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 236 | break; |
| 237 | |
Frank Rowand | 96d1c8e | 2016-10-28 23:26:22 -0700 | [diff] [blame] | 238 | if (!childtarget) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 239 | return -EINVAL; |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 240 | |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 241 | err = adjust_local_phandle_references(child, childtarget, |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 242 | phandle_delta); |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 243 | if (err) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 244 | return err; |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * of_resolve - Resolve the given node against the live tree. |
| 252 | * |
| 253 | * @resolve: Node to resolve |
| 254 | * |
| 255 | * Perform dynamic Device Tree resolution against the live tree |
| 256 | * to the given node to resolve. This depends on the live tree |
| 257 | * having a __symbols__ node, and the resolve node the __fixups__ & |
| 258 | * __local_fixups__ nodes (if needed). |
| 259 | * The result of the operation is a resolve node that it's contents |
| 260 | * are fit to be inserted or operate upon the live tree. |
| 261 | * Returns 0 on success or a negative error value on error. |
| 262 | */ |
| 263 | int of_resolve_phandles(struct device_node *resolve) |
| 264 | { |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 265 | struct device_node *child, *childroot, *refnode; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 266 | struct device_node *root_sym, *resolve_sym, *resolve_fix; |
| 267 | struct property *rprop; |
| 268 | const char *refpath; |
| 269 | phandle phandle, phandle_delta; |
| 270 | int err; |
| 271 | |
Michal Suchanek | 5de3bbc | 2016-06-26 22:11:58 +0200 | [diff] [blame] | 272 | if (!resolve) |
| 273 | pr_err("%s: null node\n", __func__); |
| 274 | if (resolve && !of_node_check_flag(resolve, OF_DETACHED)) |
| 275 | pr_err("%s: node %s not detached\n", __func__, |
| 276 | resolve->full_name); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 277 | if (!resolve || !of_node_check_flag(resolve, OF_DETACHED)) |
| 278 | return -EINVAL; |
| 279 | |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 280 | phandle_delta = live_tree_max_phandle() + 1; |
| 281 | adjust_overlay_phandles(resolve, phandle_delta); |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 282 | |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 283 | childroot = NULL; |
| 284 | for_each_child_of_node(resolve, childroot) |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 285 | if (!of_node_cmp(childroot->name, "__local_fixups__")) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 286 | break; |
| 287 | |
| 288 | if (childroot != NULL) { |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 289 | err = adjust_local_phandle_references(childroot, |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 290 | resolve, 0); |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 291 | if (err) |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 292 | return err; |
| 293 | |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 294 | BUG_ON(adjust_local_phandle_references(childroot, |
Pantelis Antoniou | da56d04 | 2014-10-28 22:33:49 +0200 | [diff] [blame] | 295 | resolve, phandle_delta)); |
| 296 | } |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 297 | |
| 298 | root_sym = NULL; |
| 299 | resolve_sym = NULL; |
| 300 | resolve_fix = NULL; |
| 301 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 302 | root_sym = of_find_node_by_path("/__symbols__"); |
| 303 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 304 | for_each_child_of_node(resolve, child) { |
| 305 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 306 | if (!resolve_sym && !of_node_cmp(child->name, "__symbols__")) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 307 | resolve_sym = child; |
| 308 | |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 309 | if (!resolve_fix && !of_node_cmp(child->name, "__fixups__")) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 310 | resolve_fix = child; |
| 311 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 312 | if (resolve_sym && resolve_fix) |
| 313 | break; |
| 314 | } |
| 315 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 316 | if (!resolve_fix) { |
Frank Rowand | a67976e | 2016-10-28 23:26:21 -0700 | [diff] [blame] | 317 | err = 0; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 318 | goto out; |
| 319 | } |
| 320 | |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 321 | if (!root_sym) { |
Michal Suchanek | 5de3bbc | 2016-06-26 22:11:58 +0200 | [diff] [blame] | 322 | pr_err("%s: no symbols in root of device tree.\n", __func__); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 323 | err = -EINVAL; |
| 324 | goto out; |
| 325 | } |
| 326 | |
| 327 | for_each_property_of_node(resolve_fix, rprop) { |
| 328 | |
| 329 | /* skip properties added automatically */ |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 330 | if (!of_prop_cmp(rprop->name, "name")) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 331 | continue; |
| 332 | |
| 333 | err = of_property_read_string(root_sym, |
| 334 | rprop->name, &refpath); |
Frank Rowand | 9f27ede | 2016-10-28 23:26:23 -0700 | [diff] [blame] | 335 | if (err) |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 336 | goto out; |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 337 | |
| 338 | refnode = of_find_node_by_path(refpath); |
| 339 | if (!refnode) { |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 340 | err = -ENOENT; |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | phandle = refnode->phandle; |
| 345 | of_node_put(refnode); |
| 346 | |
Frank Rowand | f94823f | 2016-10-28 23:26:24 -0700 | [diff] [blame^] | 347 | err = update_usages_of_a_phandle_reference(resolve, rprop, phandle); |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 348 | if (err) |
| 349 | break; |
| 350 | } |
| 351 | |
| 352 | out: |
Pantelis Antoniou | 7941b27 | 2014-07-04 19:59:20 +0300 | [diff] [blame] | 353 | of_node_put(root_sym); |
| 354 | |
| 355 | return err; |
| 356 | } |
| 357 | EXPORT_SYMBOL_GPL(of_resolve_phandles); |