fdt_support.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * (C) Copyright 2007
  3. * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <linux/ctype.h>
  25. #include <linux/types.h>
  26. #include <asm/global_data.h>
  27. #include <fdt.h>
  28. #include <libfdt.h>
  29. #include <fdt_support.h>
  30. #include <exports.h>
  31. #ifdef CONFIG_QE
  32. #include "../drivers/qe/qe.h"
  33. #endif
  34. /*
  35. * Global data (for the gd->bd)
  36. */
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /*
  39. * fdt points to our working device tree.
  40. */
  41. struct fdt_header *fdt;
  42. /********************************************************************/
  43. /**
  44. * fdt_find_and_setprop: Find a node and set it's property
  45. *
  46. * @fdt: ptr to device tree
  47. * @node: path of node
  48. * @prop: property name
  49. * @val: ptr to new value
  50. * @len: length of new property value
  51. * @create: flag to create the property if it doesn't exist
  52. *
  53. * Convenience function to directly set a property given the path to the node.
  54. */
  55. int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
  56. const void *val, int len, int create)
  57. {
  58. int nodeoff = fdt_path_offset(fdt, node);
  59. if (nodeoff < 0)
  60. return nodeoff;
  61. if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL))
  62. return 0; /* create flag not set; so exit quietly */
  63. return fdt_setprop(fdt, nodeoff, prop, val, len);
  64. }
  65. #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
  66. static int fdt_fixup_stdout(void *fdt, int choosenoff)
  67. {
  68. int err = 0;
  69. #ifdef CONFIG_CONS_INDEX
  70. int node;
  71. char sername[9] = { 0 };
  72. const char *path;
  73. sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
  74. err = node = fdt_path_offset(fdt, "/aliases");
  75. if (node >= 0) {
  76. int len;
  77. path = fdt_getprop(fdt, node, sername, &len);
  78. if (path) {
  79. char *p = malloc(len);
  80. err = -FDT_ERR_NOSPACE;
  81. if (p) {
  82. memcpy(p, path, len);
  83. err = fdt_setprop(fdt, choosenoff,
  84. "linux,stdout-path", p, len);
  85. free(p);
  86. }
  87. } else {
  88. err = len;
  89. }
  90. }
  91. #endif
  92. if (err < 0)
  93. printf("WARNING: could not set linux,stdout-path %s.\n",
  94. fdt_strerror(err));
  95. return err;
  96. }
  97. #endif
  98. int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
  99. {
  100. int nodeoffset;
  101. int err;
  102. u32 tmp; /* used to set 32 bit integer properties */
  103. char *str; /* used to set string properties */
  104. const char *path;
  105. err = fdt_check_header(fdt);
  106. if (err < 0) {
  107. printf("fdt_chosen: %s\n", fdt_strerror(err));
  108. return err;
  109. }
  110. if (initrd_start && initrd_end) {
  111. uint64_t addr, size;
  112. int total = fdt_num_mem_rsv(fdt);
  113. int j;
  114. /*
  115. * Look for an existing entry and update it. If we don't find
  116. * the entry, we will j be the next available slot.
  117. */
  118. for (j = 0; j < total; j++) {
  119. err = fdt_get_mem_rsv(fdt, j, &addr, &size);
  120. if (addr == initrd_start) {
  121. fdt_del_mem_rsv(fdt, j);
  122. break;
  123. }
  124. }
  125. err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
  126. if (err < 0) {
  127. printf("fdt_chosen: %s\n", fdt_strerror(err));
  128. return err;
  129. }
  130. }
  131. /*
  132. * Find the "chosen" node.
  133. */
  134. nodeoffset = fdt_path_offset (fdt, "/chosen");
  135. /*
  136. * If there is no "chosen" node in the blob, create it.
  137. */
  138. if (nodeoffset < 0) {
  139. /*
  140. * Create a new node "/chosen" (offset 0 is root level)
  141. */
  142. nodeoffset = fdt_add_subnode(fdt, 0, "chosen");
  143. if (nodeoffset < 0) {
  144. printf("WARNING: could not create /chosen %s.\n",
  145. fdt_strerror(nodeoffset));
  146. return nodeoffset;
  147. }
  148. }
  149. /*
  150. * Create /chosen properites that don't exist in the fdt.
  151. * If the property exists, update it only if the "force" parameter
  152. * is true.
  153. */
  154. str = getenv("bootargs");
  155. if (str != NULL) {
  156. path = fdt_getprop(fdt, nodeoffset, "bootargs", NULL);
  157. if ((path == NULL) || force) {
  158. err = fdt_setprop(fdt, nodeoffset,
  159. "bootargs", str, strlen(str)+1);
  160. if (err < 0)
  161. printf("WARNING: could not set bootargs %s.\n",
  162. fdt_strerror(err));
  163. }
  164. }
  165. if (initrd_start && initrd_end) {
  166. path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
  167. if ((path == NULL) || force) {
  168. tmp = __cpu_to_be32(initrd_start);
  169. err = fdt_setprop(fdt, nodeoffset,
  170. "linux,initrd-start", &tmp, sizeof(tmp));
  171. if (err < 0)
  172. printf("WARNING: "
  173. "could not set linux,initrd-start %s.\n",
  174. fdt_strerror(err));
  175. tmp = __cpu_to_be32(initrd_end);
  176. err = fdt_setprop(fdt, nodeoffset,
  177. "linux,initrd-end", &tmp, sizeof(tmp));
  178. if (err < 0)
  179. printf("WARNING: could not set linux,initrd-end %s.\n",
  180. fdt_strerror(err));
  181. }
  182. }
  183. #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
  184. path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL);
  185. if ((path == NULL) || force)
  186. err = fdt_fixup_stdout(fdt, nodeoffset);
  187. #endif
  188. #ifdef OF_STDOUT_PATH
  189. path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL);
  190. if ((path == NULL) || force) {
  191. err = fdt_setprop(fdt, nodeoffset,
  192. "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1);
  193. if (err < 0)
  194. printf("WARNING: could not set linux,stdout-path %s.\n",
  195. fdt_strerror(err));
  196. }
  197. #endif
  198. return err;
  199. }
  200. /********************************************************************/
  201. #ifdef CONFIG_OF_HAS_UBOOT_ENV
  202. /* Function that returns a character from the environment */
  203. extern uchar(*env_get_char) (int);
  204. int fdt_env(void *fdt)
  205. {
  206. int nodeoffset;
  207. int err;
  208. int k, nxt;
  209. int i;
  210. static char tmpenv[256];
  211. err = fdt_check_header(fdt);
  212. if (err < 0) {
  213. printf("fdt_env: %s\n", fdt_strerror(err));
  214. return err;
  215. }
  216. /*
  217. * See if we already have a "u-boot-env" node, delete it if so.
  218. * Then create a new empty node.
  219. */
  220. nodeoffset = fdt_path_offset (fdt, "/u-boot-env");
  221. if (nodeoffset >= 0) {
  222. err = fdt_del_node(fdt, nodeoffset);
  223. if (err < 0) {
  224. printf("fdt_env: %s\n", fdt_strerror(err));
  225. return err;
  226. }
  227. }
  228. /*
  229. * Create a new node "/u-boot-env" (offset 0 is root level)
  230. */
  231. nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env");
  232. if (nodeoffset < 0) {
  233. printf("WARNING: could not create /u-boot-env %s.\n",
  234. fdt_strerror(nodeoffset));
  235. return nodeoffset;
  236. }
  237. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  238. char *s, *lval, *rval;
  239. /*
  240. * Find the end of the name=definition
  241. */
  242. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  243. ;
  244. s = tmpenv;
  245. for (k = i; k < nxt && s < &tmpenv[sizeof(tmpenv) - 1]; ++k)
  246. *s++ = env_get_char(k);
  247. *s++ = '\0';
  248. lval = tmpenv;
  249. /*
  250. * Find the first '=': it separates the name from the value
  251. */
  252. s = strchr(tmpenv, '=');
  253. if (s != NULL) {
  254. *s++ = '\0';
  255. rval = s;
  256. } else
  257. continue;
  258. err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1);
  259. if (err < 0) {
  260. printf("WARNING: could not set %s %s.\n",
  261. lval, fdt_strerror(err));
  262. return err;
  263. }
  264. }
  265. return 0;
  266. }
  267. #endif /* ifdef CONFIG_OF_HAS_UBOOT_ENV */
  268. /********************************************************************/
  269. #ifdef CONFIG_OF_HAS_BD_T
  270. #define BDM(x) { .name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
  271. static const struct {
  272. const char *name;
  273. int offset;
  274. } bd_map[] = {
  275. BDM(memstart),
  276. BDM(memsize),
  277. BDM(flashstart),
  278. BDM(flashsize),
  279. BDM(flashoffset),
  280. BDM(sramstart),
  281. BDM(sramsize),
  282. #if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) \
  283. || defined(CONFIG_E500)
  284. BDM(immr_base),
  285. #endif
  286. #if defined(CONFIG_MPC5xxx)
  287. BDM(mbar_base),
  288. #endif
  289. #if defined(CONFIG_MPC83XX)
  290. BDM(immrbar),
  291. #endif
  292. #if defined(CONFIG_MPC8220)
  293. BDM(mbar_base),
  294. BDM(inpfreq),
  295. BDM(pcifreq),
  296. BDM(pevfreq),
  297. BDM(flbfreq),
  298. BDM(vcofreq),
  299. #endif
  300. BDM(bootflags),
  301. BDM(ip_addr),
  302. BDM(intfreq),
  303. BDM(busfreq),
  304. #ifdef CONFIG_CPM2
  305. BDM(cpmfreq),
  306. BDM(brgfreq),
  307. BDM(sccfreq),
  308. BDM(vco),
  309. #endif
  310. #if defined(CONFIG_MPC5xxx)
  311. BDM(ipbfreq),
  312. BDM(pcifreq),
  313. #endif
  314. BDM(baudrate),
  315. };
  316. int fdt_bd_t(void *fdt)
  317. {
  318. bd_t *bd = gd->bd;
  319. int nodeoffset;
  320. int err;
  321. u32 tmp; /* used to set 32 bit integer properties */
  322. int i;
  323. err = fdt_check_header(fdt);
  324. if (err < 0) {
  325. printf("fdt_bd_t: %s\n", fdt_strerror(err));
  326. return err;
  327. }
  328. /*
  329. * See if we already have a "bd_t" node, delete it if so.
  330. * Then create a new empty node.
  331. */
  332. nodeoffset = fdt_path_offset (fdt, "/bd_t");
  333. if (nodeoffset >= 0) {
  334. err = fdt_del_node(fdt, nodeoffset);
  335. if (err < 0) {
  336. printf("fdt_bd_t: %s\n", fdt_strerror(err));
  337. return err;
  338. }
  339. }
  340. /*
  341. * Create a new node "/bd_t" (offset 0 is root level)
  342. */
  343. nodeoffset = fdt_add_subnode(fdt, 0, "bd_t");
  344. if (nodeoffset < 0) {
  345. printf("WARNING: could not create /bd_t %s.\n",
  346. fdt_strerror(nodeoffset));
  347. printf("fdt_bd_t: %s\n", fdt_strerror(nodeoffset));
  348. return nodeoffset;
  349. }
  350. /*
  351. * Use the string/pointer structure to create the entries...
  352. */
  353. for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) {
  354. tmp = cpu_to_be32(getenv("bootargs"));
  355. err = fdt_setprop(fdt, nodeoffset,
  356. bd_map[i].name, &tmp, sizeof(tmp));
  357. if (err < 0)
  358. printf("WARNING: could not set %s %s.\n",
  359. bd_map[i].name, fdt_strerror(err));
  360. }
  361. /*
  362. * Add a couple of oddball entries...
  363. */
  364. err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6);
  365. if (err < 0)
  366. printf("WARNING: could not set enetaddr %s.\n",
  367. fdt_strerror(err));
  368. err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4);
  369. if (err < 0)
  370. printf("WARNING: could not set ethspeed %s.\n",
  371. fdt_strerror(err));
  372. return 0;
  373. }
  374. #endif /* ifdef CONFIG_OF_HAS_BD_T */
  375. void do_fixup_by_path(void *fdt, const char *path, const char *prop,
  376. const void *val, int len, int create)
  377. {
  378. #if defined(DEBUG)
  379. int i;
  380. debug("Updating property '%s/%s' = ", node, prop);
  381. for (i = 0; i < len; i++)
  382. debug(" %.2x", *(u8*)(val+i));
  383. debug("\n");
  384. #endif
  385. int rc = fdt_find_and_setprop(fdt, path, prop, val, len, create);
  386. if (rc)
  387. printf("Unable to update property %s:%s, err=%s\n",
  388. path, prop, fdt_strerror(rc));
  389. }
  390. void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
  391. u32 val, int create)
  392. {
  393. val = cpu_to_fdt32(val);
  394. do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create);
  395. }
  396. void do_fixup_by_prop(void *fdt,
  397. const char *pname, const void *pval, int plen,
  398. const char *prop, const void *val, int len,
  399. int create)
  400. {
  401. int off;
  402. #if defined(DEBUG)
  403. int i;
  404. debug("Updating property '%s/%s' = ", node, prop);
  405. for (i = 0; i < len; i++)
  406. debug(" %.2x", *(u8*)(val+i));
  407. debug("\n");
  408. #endif
  409. off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen);
  410. while (off != -FDT_ERR_NOTFOUND) {
  411. if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
  412. fdt_setprop(fdt, off, prop, val, len);
  413. off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen);
  414. }
  415. }
  416. void do_fixup_by_prop_u32(void *fdt,
  417. const char *pname, const void *pval, int plen,
  418. const char *prop, u32 val, int create)
  419. {
  420. val = cpu_to_fdt32(val);
  421. do_fixup_by_prop(fdt, pname, pval, plen, prop, &val, 4, create);
  422. }
  423. void do_fixup_by_compat(void *fdt, const char *compat,
  424. const char *prop, const void *val, int len, int create)
  425. {
  426. int off = -1;
  427. #if defined(DEBUG)
  428. int i;
  429. debug("Updating property '%s/%s' = ", node, prop);
  430. for (i = 0; i < len; i++)
  431. debug(" %.2x", *(u8*)(val+i));
  432. debug("\n");
  433. #endif
  434. off = fdt_node_offset_by_compatible(fdt, -1, compat);
  435. while (off != -FDT_ERR_NOTFOUND) {
  436. if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
  437. fdt_setprop(fdt, off, prop, val, len);
  438. off = fdt_node_offset_by_compatible(fdt, off, compat);
  439. }
  440. }
  441. void do_fixup_by_compat_u32(void *fdt, const char *compat,
  442. const char *prop, u32 val, int create)
  443. {
  444. val = cpu_to_fdt32(val);
  445. do_fixup_by_compat(fdt, compat, prop, &val, 4, create);
  446. }
  447. int fdt_fixup_memory(void *blob, u64 start, u64 size)
  448. {
  449. int err, nodeoffset, len = 0;
  450. u8 tmp[16];
  451. const u32 *addrcell, *sizecell;
  452. err = fdt_check_header(blob);
  453. if (err < 0) {
  454. printf("%s: %s\n", __FUNCTION__, fdt_strerror(err));
  455. return err;
  456. }
  457. /* update, or add and update /memory node */
  458. nodeoffset = fdt_path_offset(blob, "/memory");
  459. if (nodeoffset < 0) {
  460. nodeoffset = fdt_add_subnode(blob, 0, "memory");
  461. if (nodeoffset < 0)
  462. printf("WARNING: could not create /memory: %s.\n",
  463. fdt_strerror(nodeoffset));
  464. return nodeoffset;
  465. }
  466. err = fdt_setprop(blob, nodeoffset, "device_type", "memory",
  467. sizeof("memory"));
  468. if (err < 0) {
  469. printf("WARNING: could not set %s %s.\n", "device_type",
  470. fdt_strerror(err));
  471. return err;
  472. }
  473. addrcell = fdt_getprop(blob, 0, "#address-cells", NULL);
  474. /* use shifts and mask to ensure endianness */
  475. if ((addrcell) && (*addrcell == 2)) {
  476. tmp[0] = (start >> 56) & 0xff;
  477. tmp[1] = (start >> 48) & 0xff;
  478. tmp[2] = (start >> 40) & 0xff;
  479. tmp[3] = (start >> 32) & 0xff;
  480. tmp[4] = (start >> 24) & 0xff;
  481. tmp[5] = (start >> 16) & 0xff;
  482. tmp[6] = (start >> 8) & 0xff;
  483. tmp[7] = (start ) & 0xff;
  484. len = 8;
  485. } else {
  486. tmp[0] = (start >> 24) & 0xff;
  487. tmp[1] = (start >> 16) & 0xff;
  488. tmp[2] = (start >> 8) & 0xff;
  489. tmp[3] = (start ) & 0xff;
  490. len = 4;
  491. }
  492. sizecell = fdt_getprop(blob, 0, "#size-cells", NULL);
  493. /* use shifts and mask to ensure endianness */
  494. if ((sizecell) && (*sizecell == 2)) {
  495. tmp[0+len] = (size >> 56) & 0xff;
  496. tmp[1+len] = (size >> 48) & 0xff;
  497. tmp[2+len] = (size >> 40) & 0xff;
  498. tmp[3+len] = (size >> 32) & 0xff;
  499. tmp[4+len] = (size >> 24) & 0xff;
  500. tmp[5+len] = (size >> 16) & 0xff;
  501. tmp[6+len] = (size >> 8) & 0xff;
  502. tmp[7+len] = (size ) & 0xff;
  503. len += 8;
  504. } else {
  505. tmp[0+len] = (size >> 24) & 0xff;
  506. tmp[1+len] = (size >> 16) & 0xff;
  507. tmp[2+len] = (size >> 8) & 0xff;
  508. tmp[3+len] = (size ) & 0xff;
  509. len += 4;
  510. }
  511. err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);
  512. if (err < 0) {
  513. printf("WARNING: could not set %s %s.\n",
  514. "reg", fdt_strerror(err));
  515. return err;
  516. }
  517. return 0;
  518. }
  519. #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
  520. defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
  521. void fdt_fixup_ethernet(void *fdt, bd_t *bd)
  522. {
  523. int node;
  524. const char *path;
  525. node = fdt_path_offset(fdt, "/aliases");
  526. if (node >= 0) {
  527. #if defined(CONFIG_HAS_ETH0)
  528. path = fdt_getprop(fdt, node, "ethernet0", NULL);
  529. if (path) {
  530. do_fixup_by_path(fdt, path, "mac-address",
  531. bd->bi_enetaddr, 6, 0);
  532. do_fixup_by_path(fdt, path, "local-mac-address",
  533. bd->bi_enetaddr, 6, 1);
  534. }
  535. #endif
  536. #if defined(CONFIG_HAS_ETH1)
  537. path = fdt_getprop(fdt, node, "ethernet1", NULL);
  538. if (path) {
  539. do_fixup_by_path(fdt, path, "mac-address",
  540. bd->bi_enet1addr, 6, 0);
  541. do_fixup_by_path(fdt, path, "local-mac-address",
  542. bd->bi_enet1addr, 6, 1);
  543. }
  544. #endif
  545. #if defined(CONFIG_HAS_ETH2)
  546. path = fdt_getprop(fdt, node, "ethernet2", NULL);
  547. if (path) {
  548. do_fixup_by_path(fdt, path, "mac-address",
  549. bd->bi_enet2addr, 6, 0);
  550. do_fixup_by_path(fdt, path, "local-mac-address",
  551. bd->bi_enet2addr, 6, 1);
  552. }
  553. #endif
  554. #if defined(CONFIG_HAS_ETH3)
  555. path = fdt_getprop(fdt, node, "ethernet3", NULL);
  556. if (path) {
  557. do_fixup_by_path(fdt, path, "mac-address",
  558. bd->bi_enet3addr, 6, 0);
  559. do_fixup_by_path(fdt, path, "local-mac-address",
  560. bd->bi_enet3addr, 6, 1);
  561. }
  562. #endif
  563. }
  564. }
  565. #ifdef CONFIG_QE
  566. /*
  567. * If a QE firmware has been uploaded, then add the 'firmware' node under
  568. * the 'qe' node.
  569. */
  570. void fdt_fixup_qe_firmware(void *fdt)
  571. {
  572. struct qe_firmware_info *qe_fw_info;
  573. int node, ret;
  574. qe_fw_info = qe_get_firmware_info();
  575. if (!qe_fw_info)
  576. return;
  577. node = fdt_path_offset(fdt, "/qe");
  578. if (node < 0)
  579. return;
  580. /* We assume the node doesn't exist yet */
  581. node = fdt_add_subnode(fdt, node, "firmware");
  582. if (node < 0)
  583. return;
  584. ret = fdt_setprop(fdt, node, "extended-modes",
  585. &qe_fw_info->extended_modes, sizeof(u64));
  586. if (ret < 0)
  587. goto error;
  588. ret = fdt_setprop_string(fdt, node, "id", qe_fw_info->id);
  589. if (ret < 0)
  590. goto error;
  591. ret = fdt_setprop(fdt, node, "virtual-traps", qe_fw_info->vtraps,
  592. sizeof(qe_fw_info->vtraps));
  593. if (ret < 0)
  594. goto error;
  595. return;
  596. error:
  597. fdt_del_node(fdt, node);
  598. }
  599. #endif
  600. #endif