of_access.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Originally from Linux v4.9
  4. * Paul Mackerras August 1996.
  5. * Copyright (C) 1996-2005 Paul Mackerras.
  6. *
  7. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  8. * {engebret|bergner}@us.ibm.com
  9. *
  10. * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
  11. *
  12. * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
  13. * Grant Likely.
  14. *
  15. * Modified for U-Boot
  16. * Copyright (c) 2017 Google, Inc
  17. *
  18. * This file follows drivers/of/base.c with functions in the same order as the
  19. * Linux version.
  20. */
  21. #include <common.h>
  22. #include <linux/libfdt.h>
  23. #include <dm/of_access.h>
  24. #include <linux/ctype.h>
  25. #include <linux/err.h>
  26. #include <linux/ioport.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* list of struct alias_prop aliases */
  29. LIST_HEAD(aliases_lookup);
  30. /* "/aliaes" node */
  31. static struct device_node *of_aliases;
  32. /* "/chosen" node */
  33. static struct device_node *of_chosen;
  34. /* node pointed to by the stdout-path alias */
  35. static struct device_node *of_stdout;
  36. /* pointer to options given after the alias (separated by :) or NULL if none */
  37. static const char *of_stdout_options;
  38. /**
  39. * struct alias_prop - Alias property in 'aliases' node
  40. *
  41. * The structure represents one alias property of 'aliases' node as
  42. * an entry in aliases_lookup list.
  43. *
  44. * @link: List node to link the structure in aliases_lookup list
  45. * @alias: Alias property name
  46. * @np: Pointer to device_node that the alias stands for
  47. * @id: Index value from end of alias name
  48. * @stem: Alias string without the index
  49. */
  50. struct alias_prop {
  51. struct list_head link;
  52. const char *alias;
  53. struct device_node *np;
  54. int id;
  55. char stem[0];
  56. };
  57. int of_n_addr_cells(const struct device_node *np)
  58. {
  59. const __be32 *ip;
  60. do {
  61. if (np->parent)
  62. np = np->parent;
  63. ip = of_get_property(np, "#address-cells", NULL);
  64. if (ip)
  65. return be32_to_cpup(ip);
  66. } while (np->parent);
  67. /* No #address-cells property for the root node */
  68. return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
  69. }
  70. int of_n_size_cells(const struct device_node *np)
  71. {
  72. const __be32 *ip;
  73. do {
  74. if (np->parent)
  75. np = np->parent;
  76. ip = of_get_property(np, "#size-cells", NULL);
  77. if (ip)
  78. return be32_to_cpup(ip);
  79. } while (np->parent);
  80. /* No #size-cells property for the root node */
  81. return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
  82. }
  83. int of_simple_addr_cells(const struct device_node *np)
  84. {
  85. const __be32 *ip;
  86. ip = of_get_property(np, "#address-cells", NULL);
  87. if (ip)
  88. return be32_to_cpup(ip);
  89. /* Return a default of 2 to match fdt_address_cells()*/
  90. return 2;
  91. }
  92. int of_simple_size_cells(const struct device_node *np)
  93. {
  94. const __be32 *ip;
  95. ip = of_get_property(np, "#size-cells", NULL);
  96. if (ip)
  97. return be32_to_cpup(ip);
  98. /* Return a default of 2 to match fdt_size_cells()*/
  99. return 2;
  100. }
  101. struct property *of_find_property(const struct device_node *np,
  102. const char *name, int *lenp)
  103. {
  104. struct property *pp;
  105. if (!np)
  106. return NULL;
  107. for (pp = np->properties; pp; pp = pp->next) {
  108. if (strcmp(pp->name, name) == 0) {
  109. if (lenp)
  110. *lenp = pp->length;
  111. break;
  112. }
  113. }
  114. if (!pp && lenp)
  115. *lenp = -FDT_ERR_NOTFOUND;
  116. return pp;
  117. }
  118. struct device_node *of_find_all_nodes(struct device_node *prev)
  119. {
  120. struct device_node *np;
  121. if (!prev) {
  122. np = gd->of_root;
  123. } else if (prev->child) {
  124. np = prev->child;
  125. } else {
  126. /*
  127. * Walk back up looking for a sibling, or the end of the
  128. * structure
  129. */
  130. np = prev;
  131. while (np->parent && !np->sibling)
  132. np = np->parent;
  133. np = np->sibling; /* Might be null at the end of the tree */
  134. }
  135. return np;
  136. }
  137. const void *of_get_property(const struct device_node *np, const char *name,
  138. int *lenp)
  139. {
  140. struct property *pp = of_find_property(np, name, lenp);
  141. return pp ? pp->value : NULL;
  142. }
  143. static const char *of_prop_next_string(struct property *prop, const char *cur)
  144. {
  145. const void *curv = cur;
  146. if (!prop)
  147. return NULL;
  148. if (!cur)
  149. return prop->value;
  150. curv += strlen(cur) + 1;
  151. if (curv >= prop->value + prop->length)
  152. return NULL;
  153. return curv;
  154. }
  155. int of_device_is_compatible(const struct device_node *device,
  156. const char *compat, const char *type,
  157. const char *name)
  158. {
  159. struct property *prop;
  160. const char *cp;
  161. int index = 0, score = 0;
  162. /* Compatible match has highest priority */
  163. if (compat && compat[0]) {
  164. prop = of_find_property(device, "compatible", NULL);
  165. for (cp = of_prop_next_string(prop, NULL); cp;
  166. cp = of_prop_next_string(prop, cp), index++) {
  167. if (of_compat_cmp(cp, compat, strlen(compat)) == 0) {
  168. score = INT_MAX/2 - (index << 2);
  169. break;
  170. }
  171. }
  172. if (!score)
  173. return 0;
  174. }
  175. /* Matching type is better than matching name */
  176. if (type && type[0]) {
  177. if (!device->type || of_node_cmp(type, device->type))
  178. return 0;
  179. score += 2;
  180. }
  181. /* Matching name is a bit better than not */
  182. if (name && name[0]) {
  183. if (!device->name || of_node_cmp(name, device->name))
  184. return 0;
  185. score++;
  186. }
  187. return score;
  188. }
  189. bool of_device_is_available(const struct device_node *device)
  190. {
  191. const char *status;
  192. int statlen;
  193. if (!device)
  194. return false;
  195. status = of_get_property(device, "status", &statlen);
  196. if (status == NULL)
  197. return true;
  198. if (statlen > 0) {
  199. if (!strcmp(status, "okay"))
  200. return true;
  201. }
  202. return false;
  203. }
  204. struct device_node *of_get_parent(const struct device_node *node)
  205. {
  206. const struct device_node *np;
  207. if (!node)
  208. return NULL;
  209. np = of_node_get(node->parent);
  210. return (struct device_node *)np;
  211. }
  212. static struct device_node *__of_get_next_child(const struct device_node *node,
  213. struct device_node *prev)
  214. {
  215. struct device_node *next;
  216. if (!node)
  217. return NULL;
  218. next = prev ? prev->sibling : node->child;
  219. /*
  220. * coverity[dead_error_line : FALSE]
  221. * Dead code here since our current implementation of of_node_get()
  222. * always returns NULL (Coverity CID 163245). But we leave it as is
  223. * since we may want to implement get/put later.
  224. */
  225. for (; next; next = next->sibling)
  226. if (of_node_get(next))
  227. break;
  228. of_node_put(prev);
  229. return next;
  230. }
  231. #define __for_each_child_of_node(parent, child) \
  232. for (child = __of_get_next_child(parent, NULL); child != NULL; \
  233. child = __of_get_next_child(parent, child))
  234. static struct device_node *__of_find_node_by_path(struct device_node *parent,
  235. const char *path)
  236. {
  237. struct device_node *child;
  238. int len;
  239. len = strcspn(path, "/:");
  240. if (!len)
  241. return NULL;
  242. __for_each_child_of_node(parent, child) {
  243. const char *name = strrchr(child->full_name, '/');
  244. name++;
  245. if (strncmp(path, name, len) == 0 && (strlen(name) == len))
  246. return child;
  247. }
  248. return NULL;
  249. }
  250. #define for_each_property_of_node(dn, pp) \
  251. for (pp = dn->properties; pp != NULL; pp = pp->next)
  252. struct device_node *of_find_node_opts_by_path(const char *path,
  253. const char **opts)
  254. {
  255. struct device_node *np = NULL;
  256. struct property *pp;
  257. const char *separator = strchr(path, ':');
  258. if (opts)
  259. *opts = separator ? separator + 1 : NULL;
  260. if (strcmp(path, "/") == 0)
  261. return of_node_get(gd->of_root);
  262. /* The path could begin with an alias */
  263. if (*path != '/') {
  264. int len;
  265. const char *p = separator;
  266. if (!p)
  267. p = strchrnul(path, '/');
  268. len = p - path;
  269. /* of_aliases must not be NULL */
  270. if (!of_aliases)
  271. return NULL;
  272. for_each_property_of_node(of_aliases, pp) {
  273. if (strlen(pp->name) == len && !strncmp(pp->name, path,
  274. len)) {
  275. np = of_find_node_by_path(pp->value);
  276. break;
  277. }
  278. }
  279. if (!np)
  280. return NULL;
  281. path = p;
  282. }
  283. /* Step down the tree matching path components */
  284. if (!np)
  285. np = of_node_get(gd->of_root);
  286. while (np && *path == '/') {
  287. struct device_node *tmp = np;
  288. path++; /* Increment past '/' delimiter */
  289. np = __of_find_node_by_path(np, path);
  290. of_node_put(tmp);
  291. path = strchrnul(path, '/');
  292. if (separator && separator < path)
  293. break;
  294. }
  295. return np;
  296. }
  297. struct device_node *of_find_compatible_node(struct device_node *from,
  298. const char *type, const char *compatible)
  299. {
  300. struct device_node *np;
  301. for_each_of_allnodes_from(from, np)
  302. if (of_device_is_compatible(np, compatible, type, NULL) &&
  303. of_node_get(np))
  304. break;
  305. of_node_put(from);
  306. return np;
  307. }
  308. static int of_device_has_prop_value(const struct device_node *device,
  309. const char *propname, const void *propval,
  310. int proplen)
  311. {
  312. struct property *prop = of_find_property(device, propname, NULL);
  313. if (!prop || !prop->value || prop->length != proplen)
  314. return 0;
  315. return !memcmp(prop->value, propval, proplen);
  316. }
  317. struct device_node *of_find_node_by_prop_value(struct device_node *from,
  318. const char *propname,
  319. const void *propval, int proplen)
  320. {
  321. struct device_node *np;
  322. for_each_of_allnodes_from(from, np) {
  323. if (of_device_has_prop_value(np, propname, propval, proplen) &&
  324. of_node_get(np))
  325. break;
  326. }
  327. of_node_put(from);
  328. return np;
  329. }
  330. struct device_node *of_find_node_by_phandle(phandle handle)
  331. {
  332. struct device_node *np;
  333. if (!handle)
  334. return NULL;
  335. for_each_of_allnodes(np)
  336. if (np->phandle == handle)
  337. break;
  338. (void)of_node_get(np);
  339. return np;
  340. }
  341. /**
  342. * of_find_property_value_of_size() - find property of given size
  343. *
  344. * Search for a property in a device node and validate the requested size.
  345. *
  346. * @np: device node from which the property value is to be read.
  347. * @propname: name of the property to be searched.
  348. * @len: requested length of property value
  349. *
  350. * @return the property value on success, -EINVAL if the property does not
  351. * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
  352. * property data isn't large enough.
  353. */
  354. static void *of_find_property_value_of_size(const struct device_node *np,
  355. const char *propname, u32 len)
  356. {
  357. struct property *prop = of_find_property(np, propname, NULL);
  358. if (!prop)
  359. return ERR_PTR(-EINVAL);
  360. if (!prop->value)
  361. return ERR_PTR(-ENODATA);
  362. if (len > prop->length)
  363. return ERR_PTR(-EOVERFLOW);
  364. return prop->value;
  365. }
  366. int of_read_u32(const struct device_node *np, const char *propname, u32 *outp)
  367. {
  368. const __be32 *val;
  369. debug("%s: %s: ", __func__, propname);
  370. if (!np)
  371. return -EINVAL;
  372. val = of_find_property_value_of_size(np, propname, sizeof(*outp));
  373. if (IS_ERR(val)) {
  374. debug("(not found)\n");
  375. return PTR_ERR(val);
  376. }
  377. *outp = be32_to_cpup(val);
  378. debug("%#x (%d)\n", *outp, *outp);
  379. return 0;
  380. }
  381. int of_read_u32_array(const struct device_node *np, const char *propname,
  382. u32 *out_values, size_t sz)
  383. {
  384. const __be32 *val;
  385. debug("%s: %s: ", __func__, propname);
  386. val = of_find_property_value_of_size(np, propname,
  387. sz * sizeof(*out_values));
  388. if (IS_ERR(val))
  389. return PTR_ERR(val);
  390. debug("size %zd\n", sz);
  391. while (sz--)
  392. *out_values++ = be32_to_cpup(val++);
  393. return 0;
  394. }
  395. int of_read_u64(const struct device_node *np, const char *propname, u64 *outp)
  396. {
  397. const __be64 *val;
  398. debug("%s: %s: ", __func__, propname);
  399. if (!np)
  400. return -EINVAL;
  401. val = of_find_property_value_of_size(np, propname, sizeof(*outp));
  402. if (IS_ERR(val)) {
  403. debug("(not found)\n");
  404. return PTR_ERR(val);
  405. }
  406. *outp = be64_to_cpup(val);
  407. debug("%#llx (%lld)\n", (unsigned long long)*outp,
  408. (unsigned long long)*outp);
  409. return 0;
  410. }
  411. int of_property_match_string(const struct device_node *np, const char *propname,
  412. const char *string)
  413. {
  414. const struct property *prop = of_find_property(np, propname, NULL);
  415. size_t l;
  416. int i;
  417. const char *p, *end;
  418. if (!prop)
  419. return -EINVAL;
  420. if (!prop->value)
  421. return -ENODATA;
  422. p = prop->value;
  423. end = p + prop->length;
  424. for (i = 0; p < end; i++, p += l) {
  425. l = strnlen(p, end - p) + 1;
  426. if (p + l > end)
  427. return -EILSEQ;
  428. debug("comparing %s with %s\n", string, p);
  429. if (strcmp(string, p) == 0)
  430. return i; /* Found it; return index */
  431. }
  432. return -ENODATA;
  433. }
  434. /**
  435. * of_property_read_string_helper() - Utility helper for parsing string properties
  436. * @np: device node from which the property value is to be read.
  437. * @propname: name of the property to be searched.
  438. * @out_strs: output array of string pointers.
  439. * @sz: number of array elements to read.
  440. * @skip: Number of strings to skip over at beginning of list.
  441. *
  442. * Don't call this function directly. It is a utility helper for the
  443. * of_property_read_string*() family of functions.
  444. */
  445. int of_property_read_string_helper(const struct device_node *np,
  446. const char *propname, const char **out_strs,
  447. size_t sz, int skip)
  448. {
  449. const struct property *prop = of_find_property(np, propname, NULL);
  450. int l = 0, i = 0;
  451. const char *p, *end;
  452. if (!prop)
  453. return -EINVAL;
  454. if (!prop->value)
  455. return -ENODATA;
  456. p = prop->value;
  457. end = p + prop->length;
  458. for (i = 0; p < end && (!out_strs || i < skip + sz); i++, p += l) {
  459. l = strnlen(p, end - p) + 1;
  460. if (p + l > end)
  461. return -EILSEQ;
  462. if (out_strs && i >= skip)
  463. *out_strs++ = p;
  464. }
  465. i -= skip;
  466. return i <= 0 ? -ENODATA : i;
  467. }
  468. static int __of_parse_phandle_with_args(const struct device_node *np,
  469. const char *list_name,
  470. const char *cells_name,
  471. int cell_count, int index,
  472. struct of_phandle_args *out_args)
  473. {
  474. const __be32 *list, *list_end;
  475. int rc = 0, cur_index = 0;
  476. uint32_t count = 0;
  477. struct device_node *node = NULL;
  478. phandle phandle;
  479. int size;
  480. /* Retrieve the phandle list property */
  481. list = of_get_property(np, list_name, &size);
  482. if (!list)
  483. return -ENOENT;
  484. list_end = list + size / sizeof(*list);
  485. /* Loop over the phandles until all the requested entry is found */
  486. while (list < list_end) {
  487. rc = -EINVAL;
  488. count = 0;
  489. /*
  490. * If phandle is 0, then it is an empty entry with no
  491. * arguments. Skip forward to the next entry.
  492. */
  493. phandle = be32_to_cpup(list++);
  494. if (phandle) {
  495. /*
  496. * Find the provider node and parse the #*-cells
  497. * property to determine the argument length.
  498. *
  499. * This is not needed if the cell count is hard-coded
  500. * (i.e. cells_name not set, but cell_count is set),
  501. * except when we're going to return the found node
  502. * below.
  503. */
  504. if (cells_name || cur_index == index) {
  505. node = of_find_node_by_phandle(phandle);
  506. if (!node) {
  507. debug("%s: could not find phandle\n",
  508. np->full_name);
  509. goto err;
  510. }
  511. }
  512. if (cells_name) {
  513. if (of_read_u32(node, cells_name, &count)) {
  514. debug("%s: could not get %s for %s\n",
  515. np->full_name, cells_name,
  516. node->full_name);
  517. goto err;
  518. }
  519. } else {
  520. count = cell_count;
  521. }
  522. /*
  523. * Make sure that the arguments actually fit in the
  524. * remaining property data length
  525. */
  526. if (list + count > list_end) {
  527. debug("%s: arguments longer than property\n",
  528. np->full_name);
  529. goto err;
  530. }
  531. }
  532. /*
  533. * All of the error cases above bail out of the loop, so at
  534. * this point, the parsing is successful. If the requested
  535. * index matches, then fill the out_args structure and return,
  536. * or return -ENOENT for an empty entry.
  537. */
  538. rc = -ENOENT;
  539. if (cur_index == index) {
  540. if (!phandle)
  541. goto err;
  542. if (out_args) {
  543. int i;
  544. if (WARN_ON(count > OF_MAX_PHANDLE_ARGS))
  545. count = OF_MAX_PHANDLE_ARGS;
  546. out_args->np = node;
  547. out_args->args_count = count;
  548. for (i = 0; i < count; i++)
  549. out_args->args[i] =
  550. be32_to_cpup(list++);
  551. } else {
  552. of_node_put(node);
  553. }
  554. /* Found it! return success */
  555. return 0;
  556. }
  557. of_node_put(node);
  558. node = NULL;
  559. list += count;
  560. cur_index++;
  561. }
  562. /*
  563. * Unlock node before returning result; will be one of:
  564. * -ENOENT : index is for empty phandle
  565. * -EINVAL : parsing error on data
  566. * [1..n] : Number of phandle (count mode; when index = -1)
  567. */
  568. rc = index < 0 ? cur_index : -ENOENT;
  569. err:
  570. if (node)
  571. of_node_put(node);
  572. return rc;
  573. }
  574. struct device_node *of_parse_phandle(const struct device_node *np,
  575. const char *phandle_name, int index)
  576. {
  577. struct of_phandle_args args;
  578. if (index < 0)
  579. return NULL;
  580. if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0, index,
  581. &args))
  582. return NULL;
  583. return args.np;
  584. }
  585. int of_parse_phandle_with_args(const struct device_node *np,
  586. const char *list_name, const char *cells_name,
  587. int index, struct of_phandle_args *out_args)
  588. {
  589. if (index < 0)
  590. return -EINVAL;
  591. return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
  592. index, out_args);
  593. }
  594. int of_count_phandle_with_args(const struct device_node *np,
  595. const char *list_name, const char *cells_name)
  596. {
  597. return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
  598. -1, NULL);
  599. }
  600. static void of_alias_add(struct alias_prop *ap, struct device_node *np,
  601. int id, const char *stem, int stem_len)
  602. {
  603. ap->np = np;
  604. ap->id = id;
  605. strncpy(ap->stem, stem, stem_len);
  606. ap->stem[stem_len] = 0;
  607. list_add_tail(&ap->link, &aliases_lookup);
  608. debug("adding DT alias:%s: stem=%s id=%i node=%s\n",
  609. ap->alias, ap->stem, ap->id, of_node_full_name(np));
  610. }
  611. int of_alias_scan(void)
  612. {
  613. struct property *pp;
  614. of_aliases = of_find_node_by_path("/aliases");
  615. of_chosen = of_find_node_by_path("/chosen");
  616. if (of_chosen == NULL)
  617. of_chosen = of_find_node_by_path("/chosen@0");
  618. if (of_chosen) {
  619. const char *name;
  620. name = of_get_property(of_chosen, "stdout-path", NULL);
  621. if (name)
  622. of_stdout = of_find_node_opts_by_path(name,
  623. &of_stdout_options);
  624. }
  625. if (!of_aliases)
  626. return 0;
  627. for_each_property_of_node(of_aliases, pp) {
  628. const char *start = pp->name;
  629. const char *end = start + strlen(start);
  630. struct device_node *np;
  631. struct alias_prop *ap;
  632. ulong id;
  633. int len;
  634. /* Skip those we do not want to proceed */
  635. if (!strcmp(pp->name, "name") ||
  636. !strcmp(pp->name, "phandle") ||
  637. !strcmp(pp->name, "linux,phandle"))
  638. continue;
  639. np = of_find_node_by_path(pp->value);
  640. if (!np)
  641. continue;
  642. /*
  643. * walk the alias backwards to extract the id and work out
  644. * the 'stem' string
  645. */
  646. while (isdigit(*(end-1)) && end > start)
  647. end--;
  648. len = end - start;
  649. if (strict_strtoul(end, 10, &id) < 0)
  650. continue;
  651. /* Allocate an alias_prop with enough space for the stem */
  652. ap = malloc(sizeof(*ap) + len + 1);
  653. if (!ap)
  654. return -ENOMEM;
  655. memset(ap, 0, sizeof(*ap) + len + 1);
  656. ap->alias = start;
  657. of_alias_add(ap, np, id, start, len);
  658. }
  659. return 0;
  660. }
  661. int of_alias_get_id(const struct device_node *np, const char *stem)
  662. {
  663. struct alias_prop *app;
  664. int id = -ENODEV;
  665. mutex_lock(&of_mutex);
  666. list_for_each_entry(app, &aliases_lookup, link) {
  667. if (strcmp(app->stem, stem) != 0)
  668. continue;
  669. if (np == app->np) {
  670. id = app->id;
  671. break;
  672. }
  673. }
  674. mutex_unlock(&of_mutex);
  675. return id;
  676. }
  677. struct device_node *of_get_stdout(void)
  678. {
  679. return of_stdout;
  680. }