fdtdec.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. */
  5. #ifndef __fdtdec_h
  6. #define __fdtdec_h
  7. /*
  8. * This file contains convenience functions for decoding useful and
  9. * enlightening information from FDTs. It is intended to be used by device
  10. * drivers and board-specific code within U-Boot. It aims to reduce the
  11. * amount of FDT munging required within U-Boot itself, so that driver code
  12. * changes to support FDT are minimized.
  13. */
  14. #include <linux/libfdt.h>
  15. #include <pci.h>
  16. /*
  17. * A typedef for a physical address. Note that fdt data is always big
  18. * endian even on a litle endian machine.
  19. */
  20. typedef phys_addr_t fdt_addr_t;
  21. typedef phys_size_t fdt_size_t;
  22. #ifdef CONFIG_PHYS_64BIT
  23. #define FDT_ADDR_T_NONE (-1U)
  24. #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
  25. #define fdt_size_to_cpu(reg) be64_to_cpu(reg)
  26. #define cpu_to_fdt_addr(reg) cpu_to_be64(reg)
  27. #define cpu_to_fdt_size(reg) cpu_to_be64(reg)
  28. typedef fdt64_t fdt_val_t;
  29. #else
  30. #define FDT_ADDR_T_NONE (-1U)
  31. #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
  32. #define fdt_size_to_cpu(reg) be32_to_cpu(reg)
  33. #define cpu_to_fdt_addr(reg) cpu_to_be32(reg)
  34. #define cpu_to_fdt_size(reg) cpu_to_be32(reg)
  35. typedef fdt32_t fdt_val_t;
  36. #endif
  37. /* Information obtained about memory from the FDT */
  38. struct fdt_memory {
  39. fdt_addr_t start;
  40. fdt_addr_t end;
  41. };
  42. struct bd_info;
  43. #ifdef CONFIG_SPL_BUILD
  44. #define SPL_BUILD 1
  45. #else
  46. #define SPL_BUILD 0
  47. #endif
  48. #ifdef CONFIG_OF_PRIOR_STAGE
  49. extern phys_addr_t prior_stage_fdt_address;
  50. #endif
  51. /*
  52. * Information about a resource. start is the first address of the resource
  53. * and end is the last address (inclusive). The length of the resource will
  54. * be equal to: end - start + 1.
  55. */
  56. struct fdt_resource {
  57. fdt_addr_t start;
  58. fdt_addr_t end;
  59. };
  60. enum fdt_pci_space {
  61. FDT_PCI_SPACE_CONFIG = 0,
  62. FDT_PCI_SPACE_IO = 0x01000000,
  63. FDT_PCI_SPACE_MEM32 = 0x02000000,
  64. FDT_PCI_SPACE_MEM64 = 0x03000000,
  65. FDT_PCI_SPACE_MEM32_PREF = 0x42000000,
  66. FDT_PCI_SPACE_MEM64_PREF = 0x43000000,
  67. };
  68. #define FDT_PCI_ADDR_CELLS 3
  69. #define FDT_PCI_SIZE_CELLS 2
  70. #define FDT_PCI_REG_SIZE \
  71. ((FDT_PCI_ADDR_CELLS + FDT_PCI_SIZE_CELLS) * sizeof(u32))
  72. /*
  73. * The Open Firmware spec defines PCI physical address as follows:
  74. *
  75. * bits# 31 .... 24 23 .... 16 15 .... 08 07 .... 00
  76. *
  77. * phys.hi cell: npt000ss bbbbbbbb dddddfff rrrrrrrr
  78. * phys.mid cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh
  79. * phys.lo cell: llllllll llllllll llllllll llllllll
  80. *
  81. * where:
  82. *
  83. * n: is 0 if the address is relocatable, 1 otherwise
  84. * p: is 1 if addressable region is prefetchable, 0 otherwise
  85. * t: is 1 if the address is aliased (for non-relocatable I/O) below 1MB
  86. * (for Memory), or below 64KB (for relocatable I/O)
  87. * ss: is the space code, denoting the address space
  88. * bbbbbbbb: is the 8-bit Bus Number
  89. * ddddd: is the 5-bit Device Number
  90. * fff: is the 3-bit Function Number
  91. * rrrrrrrr: is the 8-bit Register Number
  92. * hhhhhhhh: is a 32-bit unsigned number
  93. * llllllll: is a 32-bit unsigned number
  94. */
  95. struct fdt_pci_addr {
  96. u32 phys_hi;
  97. u32 phys_mid;
  98. u32 phys_lo;
  99. };
  100. /**
  101. * Compute the size of a resource.
  102. *
  103. * @param res the resource to operate on
  104. * @return the size of the resource
  105. */
  106. static inline fdt_size_t fdt_resource_size(const struct fdt_resource *res)
  107. {
  108. return res->end - res->start + 1;
  109. }
  110. /**
  111. * Compat types that we know about and for which we might have drivers.
  112. * Each is named COMPAT_<dir>_<filename> where <dir> is the directory
  113. * within drivers.
  114. */
  115. enum fdt_compat_id {
  116. COMPAT_UNKNOWN,
  117. COMPAT_NVIDIA_TEGRA20_EMC, /* Tegra20 memory controller */
  118. COMPAT_NVIDIA_TEGRA20_EMC_TABLE, /* Tegra20 memory timing table */
  119. COMPAT_NVIDIA_TEGRA20_NAND, /* Tegra2 NAND controller */
  120. COMPAT_NVIDIA_TEGRA124_XUSB_PADCTL,
  121. /* Tegra124 XUSB pad controller */
  122. COMPAT_NVIDIA_TEGRA210_XUSB_PADCTL,
  123. /* Tegra210 XUSB pad controller */
  124. COMPAT_SMSC_LAN9215, /* SMSC 10/100 Ethernet LAN9215 */
  125. COMPAT_SAMSUNG_EXYNOS5_SROMC, /* Exynos5 SROMC */
  126. COMPAT_SAMSUNG_EXYNOS_USB_PHY, /* Exynos phy controller for usb2.0 */
  127. COMPAT_SAMSUNG_EXYNOS5_USB3_PHY,/* Exynos phy controller for usb3.0 */
  128. COMPAT_SAMSUNG_EXYNOS_TMU, /* Exynos TMU */
  129. COMPAT_SAMSUNG_EXYNOS_MIPI_DSI, /* Exynos mipi dsi */
  130. COMPAT_SAMSUNG_EXYNOS_DWMMC, /* Exynos DWMMC controller */
  131. COMPAT_GENERIC_SPI_FLASH, /* Generic SPI Flash chip */
  132. COMPAT_SAMSUNG_EXYNOS_SYSMMU, /* Exynos sysmmu */
  133. COMPAT_INTEL_MICROCODE, /* Intel microcode update */
  134. COMPAT_INTEL_QRK_MRC, /* Intel Quark MRC */
  135. COMPAT_ALTERA_SOCFPGA_DWMAC, /* SoCFPGA Ethernet controller */
  136. COMPAT_ALTERA_SOCFPGA_DWMMC, /* SoCFPGA DWMMC controller */
  137. COMPAT_ALTERA_SOCFPGA_DWC2USB, /* SoCFPGA DWC2 USB controller */
  138. COMPAT_INTEL_BAYTRAIL_FSP, /* Intel Bay Trail FSP */
  139. COMPAT_INTEL_BAYTRAIL_FSP_MDP, /* Intel FSP memory-down params */
  140. COMPAT_INTEL_IVYBRIDGE_FSP, /* Intel Ivy Bridge FSP */
  141. COMPAT_SUNXI_NAND, /* SUNXI NAND controller */
  142. COMPAT_ALTERA_SOCFPGA_CLK, /* SoCFPGA Clock initialization */
  143. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE, /* SoCFPGA pinctrl-single */
  144. COMPAT_ALTERA_SOCFPGA_H2F_BRG, /* SoCFPGA hps2fpga bridge */
  145. COMPAT_ALTERA_SOCFPGA_LWH2F_BRG, /* SoCFPGA lwhps2fpga bridge */
  146. COMPAT_ALTERA_SOCFPGA_F2H_BRG, /* SoCFPGA fpga2hps bridge */
  147. COMPAT_ALTERA_SOCFPGA_F2SDR0, /* SoCFPGA fpga2SDRAM0 bridge */
  148. COMPAT_ALTERA_SOCFPGA_F2SDR1, /* SoCFPGA fpga2SDRAM1 bridge */
  149. COMPAT_ALTERA_SOCFPGA_F2SDR2, /* SoCFPGA fpga2SDRAM2 bridge */
  150. COMPAT_ALTERA_SOCFPGA_FPGA0, /* SOCFPGA FPGA manager */
  151. COMPAT_ALTERA_SOCFPGA_NOC, /* SOCFPGA Arria 10 NOC */
  152. COMPAT_ALTERA_SOCFPGA_CLK_INIT, /* SOCFPGA Arria 10 clk init */
  153. COMPAT_COUNT,
  154. };
  155. #define MAX_PHANDLE_ARGS 16
  156. struct fdtdec_phandle_args {
  157. int node;
  158. int args_count;
  159. uint32_t args[MAX_PHANDLE_ARGS];
  160. };
  161. /**
  162. * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list
  163. *
  164. * This function is useful to parse lists of phandles and their arguments.
  165. *
  166. * Example:
  167. *
  168. * phandle1: node1 {
  169. * #list-cells = <2>;
  170. * }
  171. *
  172. * phandle2: node2 {
  173. * #list-cells = <1>;
  174. * }
  175. *
  176. * node3 {
  177. * list = <&phandle1 1 2 &phandle2 3>;
  178. * }
  179. *
  180. * To get a device_node of the `node2' node you may call this:
  181. * fdtdec_parse_phandle_with_args(blob, node3, "list", "#list-cells", 0, 1,
  182. * &args);
  183. *
  184. * (This function is a modified version of __of_parse_phandle_with_args() from
  185. * Linux 3.18)
  186. *
  187. * @blob: Pointer to device tree
  188. * @src_node: Offset of device tree node containing a list
  189. * @list_name: property name that contains a list
  190. * @cells_name: property name that specifies the phandles' arguments count,
  191. * or NULL to use @cells_count
  192. * @cells_count: Cell count to use if @cells_name is NULL
  193. * @index: index of a phandle to parse out
  194. * @out_args: optional pointer to output arguments structure (will be filled)
  195. * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
  196. * @list_name does not exist, a phandle was not found, @cells_name
  197. * could not be found, the arguments were truncated or there were too
  198. * many arguments.
  199. *
  200. */
  201. int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
  202. const char *list_name,
  203. const char *cells_name,
  204. int cell_count, int index,
  205. struct fdtdec_phandle_args *out_args);
  206. /**
  207. * Find the next numbered alias for a peripheral. This is used to enumerate
  208. * all the peripherals of a certain type.
  209. *
  210. * Do the first call with *upto = 0. Assuming /aliases/<name>0 exists then
  211. * this function will return a pointer to the node the alias points to, and
  212. * then update *upto to 1. Next time you call this function, the next node
  213. * will be returned.
  214. *
  215. * All nodes returned will match the compatible ID, as it is assumed that
  216. * all peripherals use the same driver.
  217. *
  218. * @param blob FDT blob to use
  219. * @param name Root name of alias to search for
  220. * @param id Compatible ID to look for
  221. * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
  222. */
  223. int fdtdec_next_alias(const void *blob, const char *name,
  224. enum fdt_compat_id id, int *upto);
  225. /**
  226. * Find the compatible ID for a given node.
  227. *
  228. * Generally each node has at least one compatible string attached to it.
  229. * This function looks through our list of known compatible strings and
  230. * returns the corresponding ID which matches the compatible string.
  231. *
  232. * @param blob FDT blob to use
  233. * @param node Node containing compatible string to find
  234. * @return compatible ID, or COMPAT_UNKNOWN if we cannot find a match
  235. */
  236. enum fdt_compat_id fdtdec_lookup(const void *blob, int node);
  237. /**
  238. * Find the next compatible node for a peripheral.
  239. *
  240. * Do the first call with node = 0. This function will return a pointer to
  241. * the next compatible node. Next time you call this function, pass the
  242. * value returned, and the next node will be provided.
  243. *
  244. * @param blob FDT blob to use
  245. * @param node Start node for search
  246. * @param id Compatible ID to look for (enum fdt_compat_id)
  247. * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
  248. */
  249. int fdtdec_next_compatible(const void *blob, int node,
  250. enum fdt_compat_id id);
  251. /**
  252. * Find the next compatible subnode for a peripheral.
  253. *
  254. * Do the first call with node set to the parent and depth = 0. This
  255. * function will return the offset of the next compatible node. Next time
  256. * you call this function, pass the node value returned last time, with
  257. * depth unchanged, and the next node will be provided.
  258. *
  259. * @param blob FDT blob to use
  260. * @param node Start node for search
  261. * @param id Compatible ID to look for (enum fdt_compat_id)
  262. * @param depthp Current depth (set to 0 before first call)
  263. * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
  264. */
  265. int fdtdec_next_compatible_subnode(const void *blob, int node,
  266. enum fdt_compat_id id, int *depthp);
  267. /*
  268. * Look up an address property in a node and return the parsed address, and
  269. * optionally the parsed size.
  270. *
  271. * This variant assumes a known and fixed number of cells are used to
  272. * represent the address and size.
  273. *
  274. * You probably don't want to use this function directly except to parse
  275. * non-standard properties, and never to parse the "reg" property. Instead,
  276. * use one of the "auto" variants below, which automatically honor the
  277. * #address-cells and #size-cells properties in the parent node.
  278. *
  279. * @param blob FDT blob
  280. * @param node node to examine
  281. * @param prop_name name of property to find
  282. * @param index which address to retrieve from a list of addresses. Often 0.
  283. * @param na the number of cells used to represent an address
  284. * @param ns the number of cells used to represent a size
  285. * @param sizep a pointer to store the size into. Use NULL if not required
  286. * @param translate Indicates whether to translate the returned value
  287. * using the parent node's ranges property.
  288. * @return address, if found, or FDT_ADDR_T_NONE if not
  289. */
  290. fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
  291. const char *prop_name, int index, int na, int ns,
  292. fdt_size_t *sizep, bool translate);
  293. /*
  294. * Look up an address property in a node and return the parsed address, and
  295. * optionally the parsed size.
  296. *
  297. * This variant automatically determines the number of cells used to represent
  298. * the address and size by parsing the provided parent node's #address-cells
  299. * and #size-cells properties.
  300. *
  301. * @param blob FDT blob
  302. * @param parent parent node of @node
  303. * @param node node to examine
  304. * @param prop_name name of property to find
  305. * @param index which address to retrieve from a list of addresses. Often 0.
  306. * @param sizep a pointer to store the size into. Use NULL if not required
  307. * @param translate Indicates whether to translate the returned value
  308. * using the parent node's ranges property.
  309. * @return address, if found, or FDT_ADDR_T_NONE if not
  310. */
  311. fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
  312. int node, const char *prop_name, int index, fdt_size_t *sizep,
  313. bool translate);
  314. /*
  315. * Look up an address property in a node and return the parsed address, and
  316. * optionally the parsed size.
  317. *
  318. * This variant automatically determines the number of cells used to represent
  319. * the address and size by parsing the parent node's #address-cells
  320. * and #size-cells properties. The parent node is automatically found.
  321. *
  322. * The automatic parent lookup implemented by this function is slow.
  323. * Consequently, fdtdec_get_addr_size_auto_parent() should be used where
  324. * possible.
  325. *
  326. * @param blob FDT blob
  327. * @param parent parent node of @node
  328. * @param node node to examine
  329. * @param prop_name name of property to find
  330. * @param index which address to retrieve from a list of addresses. Often 0.
  331. * @param sizep a pointer to store the size into. Use NULL if not required
  332. * @param translate Indicates whether to translate the returned value
  333. * using the parent node's ranges property.
  334. * @return address, if found, or FDT_ADDR_T_NONE if not
  335. */
  336. fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
  337. const char *prop_name, int index, fdt_size_t *sizep,
  338. bool translate);
  339. /*
  340. * Look up an address property in a node and return the parsed address.
  341. *
  342. * This variant hard-codes the number of cells used to represent the address
  343. * and size based on sizeof(fdt_addr_t) and sizeof(fdt_size_t). It also
  344. * always returns the first address value in the property (index 0).
  345. *
  346. * Use of this function is not recommended due to the hard-coding of cell
  347. * counts. There is no programmatic validation that these hard-coded values
  348. * actually match the device tree content in any way at all. This assumption
  349. * can be satisfied by manually ensuring CONFIG_PHYS_64BIT is appropriately
  350. * set in the U-Boot build and exercising strict control over DT content to
  351. * ensure use of matching #address-cells/#size-cells properties. However, this
  352. * approach is error-prone; those familiar with DT will not expect the
  353. * assumption to exist, and could easily invalidate it. If the assumption is
  354. * invalidated, this function will not report the issue, and debugging will
  355. * be required. Instead, use fdtdec_get_addr_size_auto_parent().
  356. *
  357. * @param blob FDT blob
  358. * @param node node to examine
  359. * @param prop_name name of property to find
  360. * @return address, if found, or FDT_ADDR_T_NONE if not
  361. */
  362. fdt_addr_t fdtdec_get_addr(const void *blob, int node,
  363. const char *prop_name);
  364. /*
  365. * Look up an address property in a node and return the parsed address, and
  366. * optionally the parsed size.
  367. *
  368. * This variant hard-codes the number of cells used to represent the address
  369. * and size based on sizeof(fdt_addr_t) and sizeof(fdt_size_t). It also
  370. * always returns the first address value in the property (index 0).
  371. *
  372. * Use of this function is not recommended due to the hard-coding of cell
  373. * counts. There is no programmatic validation that these hard-coded values
  374. * actually match the device tree content in any way at all. This assumption
  375. * can be satisfied by manually ensuring CONFIG_PHYS_64BIT is appropriately
  376. * set in the U-Boot build and exercising strict control over DT content to
  377. * ensure use of matching #address-cells/#size-cells properties. However, this
  378. * approach is error-prone; those familiar with DT will not expect the
  379. * assumption to exist, and could easily invalidate it. If the assumption is
  380. * invalidated, this function will not report the issue, and debugging will
  381. * be required. Instead, use fdtdec_get_addr_size_auto_parent().
  382. *
  383. * @param blob FDT blob
  384. * @param node node to examine
  385. * @param prop_name name of property to find
  386. * @param sizep a pointer to store the size into. Use NULL if not required
  387. * @return address, if found, or FDT_ADDR_T_NONE if not
  388. */
  389. fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
  390. const char *prop_name, fdt_size_t *sizep);
  391. /**
  392. * Look at the compatible property of a device node that represents a PCI
  393. * device and extract pci vendor id and device id from it.
  394. *
  395. * @param blob FDT blob
  396. * @param node node to examine
  397. * @param vendor vendor id of the pci device
  398. * @param device device id of the pci device
  399. * @return 0 if ok, negative on error
  400. */
  401. int fdtdec_get_pci_vendev(const void *blob, int node,
  402. u16 *vendor, u16 *device);
  403. /**
  404. * Look at the pci address of a device node that represents a PCI device
  405. * and return base address of the pci device's registers.
  406. *
  407. * @param dev device to examine
  408. * @param addr pci address in the form of fdt_pci_addr
  409. * @param bar returns base address of the pci device's registers
  410. * @return 0 if ok, negative on error
  411. */
  412. int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
  413. u32 *bar);
  414. /**
  415. * Look up a 32-bit integer property in a node and return it. The property
  416. * must have at least 4 bytes of data. The value of the first cell is
  417. * returned.
  418. *
  419. * @param blob FDT blob
  420. * @param node node to examine
  421. * @param prop_name name of property to find
  422. * @param default_val default value to return if the property is not found
  423. * @return integer value, if found, or default_val if not
  424. */
  425. s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
  426. s32 default_val);
  427. /**
  428. * Unsigned version of fdtdec_get_int. The property must have at least
  429. * 4 bytes of data. The value of the first cell is returned.
  430. *
  431. * @param blob FDT blob
  432. * @param node node to examine
  433. * @param prop_name name of property to find
  434. * @param default_val default value to return if the property is not found
  435. * @return unsigned integer value, if found, or default_val if not
  436. */
  437. unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
  438. unsigned int default_val);
  439. /**
  440. * Get a variable-sized number from a property
  441. *
  442. * This reads a number from one or more cells.
  443. *
  444. * @param ptr Pointer to property
  445. * @param cells Number of cells containing the number
  446. * @return the value in the cells
  447. */
  448. u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells);
  449. /**
  450. * Look up a 64-bit integer property in a node and return it. The property
  451. * must have at least 8 bytes of data (2 cells). The first two cells are
  452. * concatenated to form a 8 bytes value, where the first cell is top half and
  453. * the second cell is bottom half.
  454. *
  455. * @param blob FDT blob
  456. * @param node node to examine
  457. * @param prop_name name of property to find
  458. * @param default_val default value to return if the property is not found
  459. * @return integer value, if found, or default_val if not
  460. */
  461. uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
  462. uint64_t default_val);
  463. /**
  464. * Checks whether a node is enabled.
  465. * This looks for a 'status' property. If this exists, then returns 1 if
  466. * the status is 'ok' and 0 otherwise. If there is no status property,
  467. * it returns 1 on the assumption that anything mentioned should be enabled
  468. * by default.
  469. *
  470. * @param blob FDT blob
  471. * @param node node to examine
  472. * @return integer value 0 (not enabled) or 1 (enabled)
  473. */
  474. int fdtdec_get_is_enabled(const void *blob, int node);
  475. /**
  476. * Make sure we have a valid fdt available to control U-Boot.
  477. *
  478. * If not, a message is printed to the console if the console is ready.
  479. *
  480. * @return 0 if all ok, -1 if not
  481. */
  482. int fdtdec_prepare_fdt(void);
  483. /**
  484. * Checks that we have a valid fdt available to control U-Boot.
  485. * However, if not then for the moment nothing is done, since this function
  486. * is called too early to panic().
  487. *
  488. * @returns 0
  489. */
  490. int fdtdec_check_fdt(void);
  491. /**
  492. * Find the nodes for a peripheral and return a list of them in the correct
  493. * order. This is used to enumerate all the peripherals of a certain type.
  494. *
  495. * To use this, optionally set up a /aliases node with alias properties for
  496. * a peripheral. For example, for usb you could have:
  497. *
  498. * aliases {
  499. * usb0 = "/ehci@c5008000";
  500. * usb1 = "/ehci@c5000000";
  501. * };
  502. *
  503. * Pass "usb" as the name to this function and will return a list of two
  504. * nodes offsets: /ehci@c5008000 and ehci@c5000000.
  505. *
  506. * All nodes returned will match the compatible ID, as it is assumed that
  507. * all peripherals use the same driver.
  508. *
  509. * If no alias node is found, then the node list will be returned in the
  510. * order found in the fdt. If the aliases mention a node which doesn't
  511. * exist, then this will be ignored. If nodes are found with no aliases,
  512. * they will be added in any order.
  513. *
  514. * If there is a gap in the aliases, then this function return a 0 node at
  515. * that position. The return value will also count these gaps.
  516. *
  517. * This function checks node properties and will not return nodes which are
  518. * marked disabled (status = "disabled").
  519. *
  520. * @param blob FDT blob to use
  521. * @param name Root name of alias to search for
  522. * @param id Compatible ID to look for
  523. * @param node_list Place to put list of found nodes
  524. * @param maxcount Maximum number of nodes to find
  525. * @return number of nodes found on success, FDT_ERR_... on error
  526. */
  527. int fdtdec_find_aliases_for_id(const void *blob, const char *name,
  528. enum fdt_compat_id id, int *node_list, int maxcount);
  529. /*
  530. * This function is similar to fdtdec_find_aliases_for_id() except that it
  531. * adds to the node_list that is passed in. Any 0 elements are considered
  532. * available for allocation - others are considered already used and are
  533. * skipped.
  534. *
  535. * You can use this by calling fdtdec_find_aliases_for_id() with an
  536. * uninitialised array, then setting the elements that are returned to -1,
  537. * say, then calling this function, perhaps with a different compat id.
  538. * Any elements you get back that are >0 are new nodes added by the call
  539. * to this function.
  540. *
  541. * Note that if you have some nodes with aliases and some without, you are
  542. * sailing close to the wind. The call to fdtdec_find_aliases_for_id() with
  543. * one compat_id may fill in positions for which you have aliases defined
  544. * for another compat_id. When you later call *this* function with the second
  545. * compat_id, the alias positions may already be used. A debug warning may
  546. * be generated in this case, but it is safest to define aliases for all
  547. * nodes when you care about the ordering.
  548. */
  549. int fdtdec_add_aliases_for_id(const void *blob, const char *name,
  550. enum fdt_compat_id id, int *node_list, int maxcount);
  551. /**
  552. * Get the alias sequence number of a node
  553. *
  554. * This works out whether a node is pointed to by an alias, and if so, the
  555. * sequence number of that alias. Aliases are of the form <base><num> where
  556. * <num> is the sequence number. For example spi2 would be sequence number
  557. * 2.
  558. *
  559. * @param blob Device tree blob (if NULL, then error is returned)
  560. * @param base Base name for alias (before the underscore)
  561. * @param node Node to look up
  562. * @param seqp This is set to the sequence number if one is found,
  563. * but otherwise the value is left alone
  564. * @return 0 if a sequence was found, -ve if not
  565. */
  566. int fdtdec_get_alias_seq(const void *blob, const char *base, int node,
  567. int *seqp);
  568. /**
  569. * Get the highest alias number for susbystem.
  570. *
  571. * It parses all aliases and find out highest recorded alias for subsystem.
  572. * Aliases are of the form <base><num> where <num> is the sequence number.
  573. *
  574. * @param blob Device tree blob (if NULL, then error is returned)
  575. * @param base Base name for alias susbystem (before the number)
  576. *
  577. * @return 0 highest alias ID, -1 if not found
  578. */
  579. int fdtdec_get_alias_highest_id(const void *blob, const char *base);
  580. /**
  581. * Get a property from the /chosen node
  582. *
  583. * @param blob Device tree blob (if NULL, then NULL is returned)
  584. * @param name Property name to look up
  585. * @return Value of property, or NULL if it does not exist
  586. */
  587. const char *fdtdec_get_chosen_prop(const void *blob, const char *name);
  588. /**
  589. * Get the offset of the given /chosen node
  590. *
  591. * This looks up a property in /chosen containing the path to another node,
  592. * then finds the offset of that node.
  593. *
  594. * @param blob Device tree blob (if NULL, then error is returned)
  595. * @param name Property name, e.g. "stdout-path"
  596. * @return Node offset referred to by that chosen node, or -ve FDT_ERR_...
  597. */
  598. int fdtdec_get_chosen_node(const void *blob, const char *name);
  599. /*
  600. * Get the name for a compatible ID
  601. *
  602. * @param id Compatible ID to look for
  603. * @return compatible string for that id
  604. */
  605. const char *fdtdec_get_compatible(enum fdt_compat_id id);
  606. /* Look up a phandle and follow it to its node. Then return the offset
  607. * of that node.
  608. *
  609. * @param blob FDT blob
  610. * @param node node to examine
  611. * @param prop_name name of property to find
  612. * @return node offset if found, -ve error code on error
  613. */
  614. int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name);
  615. /**
  616. * Look up a property in a node and return its contents in an integer
  617. * array of given length. The property must have at least enough data for
  618. * the array (4*count bytes). It may have more, but this will be ignored.
  619. *
  620. * @param blob FDT blob
  621. * @param node node to examine
  622. * @param prop_name name of property to find
  623. * @param array array to fill with data
  624. * @param count number of array elements
  625. * @return 0 if ok, or -FDT_ERR_NOTFOUND if the property is not found,
  626. * or -FDT_ERR_BADLAYOUT if not enough data
  627. */
  628. int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
  629. u32 *array, int count);
  630. /**
  631. * Look up a property in a node and return its contents in an integer
  632. * array of given length. The property must exist but may have less data that
  633. * expected (4*count bytes). It may have more, but this will be ignored.
  634. *
  635. * @param blob FDT blob
  636. * @param node node to examine
  637. * @param prop_name name of property to find
  638. * @param array array to fill with data
  639. * @param count number of array elements
  640. * @return number of array elements if ok, or -FDT_ERR_NOTFOUND if the
  641. * property is not found
  642. */
  643. int fdtdec_get_int_array_count(const void *blob, int node,
  644. const char *prop_name, u32 *array, int count);
  645. /**
  646. * Look up a property in a node and return a pointer to its contents as a
  647. * unsigned int array of given length. The property must have at least enough
  648. * data for the array ('count' cells). It may have more, but this will be
  649. * ignored. The data is not copied.
  650. *
  651. * Note that you must access elements of the array with fdt32_to_cpu(),
  652. * since the elements will be big endian even on a little endian machine.
  653. *
  654. * @param blob FDT blob
  655. * @param node node to examine
  656. * @param prop_name name of property to find
  657. * @param count number of array elements
  658. * @return pointer to array if found, or NULL if the property is not
  659. * found or there is not enough data
  660. */
  661. const u32 *fdtdec_locate_array(const void *blob, int node,
  662. const char *prop_name, int count);
  663. /**
  664. * Look up a boolean property in a node and return it.
  665. *
  666. * A boolean properly is true if present in the device tree and false if not
  667. * present, regardless of its value.
  668. *
  669. * @param blob FDT blob
  670. * @param node node to examine
  671. * @param prop_name name of property to find
  672. * @return 1 if the properly is present; 0 if it isn't present
  673. */
  674. int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
  675. /*
  676. * Count child nodes of one parent node.
  677. *
  678. * @param blob FDT blob
  679. * @param node parent node
  680. * @return number of child node; 0 if there is not child node
  681. */
  682. int fdtdec_get_child_count(const void *blob, int node);
  683. /**
  684. * Look in the FDT for a config item with the given name and return its value
  685. * as a 32-bit integer. The property must have at least 4 bytes of data. The
  686. * value of the first cell is returned.
  687. *
  688. * @param blob FDT blob to use
  689. * @param prop_name Node property name
  690. * @param default_val default value to return if the property is not found
  691. * @return integer value, if found, or default_val if not
  692. */
  693. int fdtdec_get_config_int(const void *blob, const char *prop_name,
  694. int default_val);
  695. /**
  696. * Look in the FDT for a config item with the given name
  697. * and return whether it exists.
  698. *
  699. * @param blob FDT blob
  700. * @param prop_name property name to look up
  701. * @return 1, if it exists, or 0 if not
  702. */
  703. int fdtdec_get_config_bool(const void *blob, const char *prop_name);
  704. /**
  705. * Look in the FDT for a config item with the given name and return its value
  706. * as a string.
  707. *
  708. * @param blob FDT blob
  709. * @param prop_name property name to look up
  710. * @returns property string, NULL on error.
  711. */
  712. char *fdtdec_get_config_string(const void *blob, const char *prop_name);
  713. /*
  714. * Look up a property in a node and return its contents in a byte
  715. * array of given length. The property must have at least enough data for
  716. * the array (count bytes). It may have more, but this will be ignored.
  717. *
  718. * @param blob FDT blob
  719. * @param node node to examine
  720. * @param prop_name name of property to find
  721. * @param array array to fill with data
  722. * @param count number of array elements
  723. * @return 0 if ok, or -FDT_ERR_MISSING if the property is not found,
  724. * or -FDT_ERR_BADLAYOUT if not enough data
  725. */
  726. int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
  727. u8 *array, int count);
  728. /**
  729. * Look up a property in a node and return a pointer to its contents as a
  730. * byte array of given length. The property must have at least enough data
  731. * for the array (count bytes). It may have more, but this will be ignored.
  732. * The data is not copied.
  733. *
  734. * @param blob FDT blob
  735. * @param node node to examine
  736. * @param prop_name name of property to find
  737. * @param count number of array elements
  738. * @return pointer to byte array if found, or NULL if the property is not
  739. * found or there is not enough data
  740. */
  741. const u8 *fdtdec_locate_byte_array(const void *blob, int node,
  742. const char *prop_name, int count);
  743. /**
  744. * Obtain an indexed resource from a device property.
  745. *
  746. * @param fdt FDT blob
  747. * @param node node to examine
  748. * @param property name of the property to parse
  749. * @param index index of the resource to retrieve
  750. * @param res returns the resource
  751. * @return 0 if ok, negative on error
  752. */
  753. int fdt_get_resource(const void *fdt, int node, const char *property,
  754. unsigned int index, struct fdt_resource *res);
  755. /**
  756. * Obtain a named resource from a device property.
  757. *
  758. * Look up the index of the name in a list of strings and return the resource
  759. * at that index.
  760. *
  761. * @param fdt FDT blob
  762. * @param node node to examine
  763. * @param property name of the property to parse
  764. * @param prop_names name of the property containing the list of names
  765. * @param name the name of the entry to look up
  766. * @param res returns the resource
  767. */
  768. int fdt_get_named_resource(const void *fdt, int node, const char *property,
  769. const char *prop_names, const char *name,
  770. struct fdt_resource *res);
  771. /* Display timings from linux include/video/display_timing.h */
  772. enum display_flags {
  773. DISPLAY_FLAGS_HSYNC_LOW = 1 << 0,
  774. DISPLAY_FLAGS_HSYNC_HIGH = 1 << 1,
  775. DISPLAY_FLAGS_VSYNC_LOW = 1 << 2,
  776. DISPLAY_FLAGS_VSYNC_HIGH = 1 << 3,
  777. /* data enable flag */
  778. DISPLAY_FLAGS_DE_LOW = 1 << 4,
  779. DISPLAY_FLAGS_DE_HIGH = 1 << 5,
  780. /* drive data on pos. edge */
  781. DISPLAY_FLAGS_PIXDATA_POSEDGE = 1 << 6,
  782. /* drive data on neg. edge */
  783. DISPLAY_FLAGS_PIXDATA_NEGEDGE = 1 << 7,
  784. DISPLAY_FLAGS_INTERLACED = 1 << 8,
  785. DISPLAY_FLAGS_DOUBLESCAN = 1 << 9,
  786. DISPLAY_FLAGS_DOUBLECLK = 1 << 10,
  787. };
  788. /*
  789. * A single signal can be specified via a range of minimal and maximal values
  790. * with a typical value, that lies somewhere inbetween.
  791. */
  792. struct timing_entry {
  793. u32 min;
  794. u32 typ;
  795. u32 max;
  796. };
  797. /*
  798. * Single "mode" entry. This describes one set of signal timings a display can
  799. * have in one setting. This struct can later be converted to struct videomode
  800. * (see include/video/videomode.h). As each timing_entry can be defined as a
  801. * range, one struct display_timing may become multiple struct videomodes.
  802. *
  803. * Example: hsync active high, vsync active low
  804. *
  805. * Active Video
  806. * Video ______________________XXXXXXXXXXXXXXXXXXXXXX_____________________
  807. * |<- sync ->|<- back ->|<----- active ----->|<- front ->|<- sync..
  808. * | | porch | | porch |
  809. *
  810. * HSync _|¯¯¯¯¯¯¯¯¯¯|___________________________________________|¯¯¯¯¯¯¯¯¯
  811. *
  812. * VSync ¯|__________|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|_________
  813. */
  814. struct display_timing {
  815. struct timing_entry pixelclock;
  816. struct timing_entry hactive; /* hor. active video */
  817. struct timing_entry hfront_porch; /* hor. front porch */
  818. struct timing_entry hback_porch; /* hor. back porch */
  819. struct timing_entry hsync_len; /* hor. sync len */
  820. struct timing_entry vactive; /* ver. active video */
  821. struct timing_entry vfront_porch; /* ver. front porch */
  822. struct timing_entry vback_porch; /* ver. back porch */
  823. struct timing_entry vsync_len; /* ver. sync len */
  824. enum display_flags flags; /* display flags */
  825. bool hdmi_monitor; /* is hdmi monitor? */
  826. };
  827. /**
  828. * fdtdec_decode_display_timing() - decode display timings
  829. *
  830. * Decode display timings from the supplied 'display-timings' node.
  831. * See doc/device-tree-bindings/video/display-timing.txt for binding
  832. * information.
  833. *
  834. * @param blob FDT blob
  835. * @param node 'display-timing' node containing the timing subnodes
  836. * @param index Index number to read (0=first timing subnode)
  837. * @param config Place to put timings
  838. * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
  839. */
  840. int fdtdec_decode_display_timing(const void *blob, int node, int index,
  841. struct display_timing *config);
  842. /**
  843. * fdtdec_setup_mem_size_base_fdt() - decode and setup gd->ram_size and
  844. * gd->ram_start
  845. *
  846. * Decode the /memory 'reg' property to determine the size and start of the
  847. * first memory bank, populate the global data with the size and start of the
  848. * first bank of memory.
  849. *
  850. * This function should be called from a boards dram_init(). This helper
  851. * function allows for boards to query the device tree for DRAM size and start
  852. * address instead of hard coding the value in the case where the memory size
  853. * and start address cannot be detected automatically.
  854. *
  855. * @param blob FDT blob
  856. *
  857. * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or
  858. * invalid
  859. */
  860. int fdtdec_setup_mem_size_base_fdt(const void *blob);
  861. /**
  862. * fdtdec_setup_mem_size_base() - decode and setup gd->ram_size and
  863. * gd->ram_start
  864. *
  865. * Decode the /memory 'reg' property to determine the size and start of the
  866. * first memory bank, populate the global data with the size and start of the
  867. * first bank of memory.
  868. *
  869. * This function should be called from a boards dram_init(). This helper
  870. * function allows for boards to query the device tree for DRAM size and start
  871. * address instead of hard coding the value in the case where the memory size
  872. * and start address cannot be detected automatically.
  873. *
  874. * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or
  875. * invalid
  876. */
  877. int fdtdec_setup_mem_size_base(void);
  878. /**
  879. * fdtdec_setup_memory_banksize_fdt() - decode and populate gd->bd->bi_dram
  880. *
  881. * Decode the /memory 'reg' property to determine the address and size of the
  882. * memory banks. Use this data to populate the global data board info with the
  883. * phys address and size of memory banks.
  884. *
  885. * This function should be called from a boards dram_init_banksize(). This
  886. * helper function allows for boards to query the device tree for memory bank
  887. * information instead of hard coding the information in cases where it cannot
  888. * be detected automatically.
  889. *
  890. * @param blob FDT blob
  891. *
  892. * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or
  893. * invalid
  894. */
  895. int fdtdec_setup_memory_banksize_fdt(const void *blob);
  896. /**
  897. * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram
  898. *
  899. * Decode the /memory 'reg' property to determine the address and size of the
  900. * memory banks. Use this data to populate the global data board info with the
  901. * phys address and size of memory banks.
  902. *
  903. * This function should be called from a boards dram_init_banksize(). This
  904. * helper function allows for boards to query the device tree for memory bank
  905. * information instead of hard coding the information in cases where it cannot
  906. * be detected automatically.
  907. *
  908. * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or
  909. * invalid
  910. */
  911. int fdtdec_setup_memory_banksize(void);
  912. /**
  913. * fdtdec_set_ethernet_mac_address() - set MAC address for default interface
  914. *
  915. * Looks up the default interface via the "ethernet" alias (in the /aliases
  916. * node) and stores the given MAC in its "local-mac-address" property. This
  917. * is useful on platforms that store the MAC address in a custom location.
  918. * Board code can call this in the late init stage to make sure that the
  919. * interface device tree node has the right MAC address configured for the
  920. * Ethernet uclass to pick it up.
  921. *
  922. * Typically the FDT passed into this function will be U-Boot's control DTB.
  923. * Given that a lot of code may be holding offsets to various nodes in that
  924. * tree, this code will only set the "local-mac-address" property in-place,
  925. * which means that it needs to exist and have space for the 6-byte address.
  926. * This ensures that the operation is non-destructive and does not invalidate
  927. * offsets that other drivers may be using.
  928. *
  929. * @param fdt FDT blob
  930. * @param mac buffer containing the MAC address to set
  931. * @param size size of MAC address
  932. * @return 0 on success or a negative error code on failure
  933. */
  934. int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size);
  935. /**
  936. * fdtdec_set_phandle() - sets the phandle of a given node
  937. *
  938. * @param blob FDT blob
  939. * @param node offset in the FDT blob of the node whose phandle is to
  940. * be set
  941. * @param phandle phandle to set for the given node
  942. * @return 0 on success or a negative error code on failure
  943. */
  944. static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle)
  945. {
  946. return fdt_setprop_u32(blob, node, "phandle", phandle);
  947. }
  948. /**
  949. * fdtdec_add_reserved_memory() - add or find a reserved-memory node
  950. *
  951. * If a reserved-memory node already exists for the given carveout, a phandle
  952. * for that node will be returned. Otherwise a new node will be created and a
  953. * phandle corresponding to it will be returned.
  954. *
  955. * See Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
  956. * for details on how to use reserved memory regions.
  957. *
  958. * As an example, consider the following code snippet:
  959. *
  960. * struct fdt_memory fb = {
  961. * .start = 0x92cb3000,
  962. * .end = 0x934b2fff,
  963. * };
  964. * uint32_t phandle;
  965. *
  966. * fdtdec_add_reserved_memory(fdt, "framebuffer", &fb, &phandle);
  967. *
  968. * This results in the following subnode being added to the top-level
  969. * /reserved-memory node:
  970. *
  971. * reserved-memory {
  972. * #address-cells = <0x00000002>;
  973. * #size-cells = <0x00000002>;
  974. * ranges;
  975. *
  976. * framebuffer@92cb3000 {
  977. * reg = <0x00000000 0x92cb3000 0x00000000 0x00800000>;
  978. * phandle = <0x0000004d>;
  979. * };
  980. * };
  981. *
  982. * If the top-level /reserved-memory node does not exist, it will be created.
  983. * The phandle returned from the function call can be used to reference this
  984. * reserved memory region from other nodes.
  985. *
  986. * See fdtdec_set_carveout() for a more elaborate example.
  987. *
  988. * @param blob FDT blob
  989. * @param basename base name of the node to create
  990. * @param carveout information about the carveout region
  991. * @param phandlep return location for the phandle of the carveout region
  992. * can be NULL if no phandle should be added
  993. * @return 0 on success or a negative error code on failure
  994. */
  995. int fdtdec_add_reserved_memory(void *blob, const char *basename,
  996. const struct fdt_memory *carveout,
  997. uint32_t *phandlep);
  998. /**
  999. * fdtdec_get_carveout() - reads a carveout from an FDT
  1000. *
  1001. * Reads information about a carveout region from an FDT. The carveout is a
  1002. * referenced by its phandle that is read from a given property in a given
  1003. * node.
  1004. *
  1005. * @param blob FDT blob
  1006. * @param node name of a node
  1007. * @param name name of the property in the given node that contains
  1008. * the phandle for the carveout
  1009. * @param index index of the phandle for which to read the carveout
  1010. * @param carveout return location for the carveout information
  1011. * @return 0 on success or a negative error code on failure
  1012. */
  1013. int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
  1014. unsigned int index, struct fdt_memory *carveout);
  1015. /**
  1016. * fdtdec_set_carveout() - sets a carveout region for a given node
  1017. *
  1018. * Sets a carveout region for a given node. If a reserved-memory node already
  1019. * exists for the carveout, the phandle for that node will be reused. If no
  1020. * such node exists, a new one will be created and a phandle to it stored in
  1021. * a specified property of the given node.
  1022. *
  1023. * As an example, consider the following code snippet:
  1024. *
  1025. * const char *node = "/host1x@50000000/dc@54240000";
  1026. * struct fdt_memory fb = {
  1027. * .start = 0x92cb3000,
  1028. * .end = 0x934b2fff,
  1029. * };
  1030. *
  1031. * fdtdec_set_carveout(fdt, node, "memory-region", 0, "framebuffer", &fb);
  1032. *
  1033. * dc@54200000 is a display controller and was set up by the bootloader to
  1034. * scan out the framebuffer specified by "fb". This would cause the following
  1035. * reserved memory region to be added:
  1036. *
  1037. * reserved-memory {
  1038. * #address-cells = <0x00000002>;
  1039. * #size-cells = <0x00000002>;
  1040. * ranges;
  1041. *
  1042. * framebuffer@92cb3000 {
  1043. * reg = <0x00000000 0x92cb3000 0x00000000 0x00800000>;
  1044. * phandle = <0x0000004d>;
  1045. * };
  1046. * };
  1047. *
  1048. * A "memory-region" property will also be added to the node referenced by the
  1049. * offset parameter.
  1050. *
  1051. * host1x@50000000 {
  1052. * ...
  1053. *
  1054. * dc@54240000 {
  1055. * ...
  1056. * memory-region = <0x0000004d>;
  1057. * ...
  1058. * };
  1059. *
  1060. * ...
  1061. * };
  1062. *
  1063. * @param blob FDT blob
  1064. * @param node name of the node to add the carveout to
  1065. * @param prop_name name of the property in which to store the phandle of
  1066. * the carveout
  1067. * @param index index of the phandle to store
  1068. * @param name base name of the reserved-memory node to create
  1069. * @param carveout information about the carveout to add
  1070. * @return 0 on success or a negative error code on failure
  1071. */
  1072. int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
  1073. unsigned int index, const char *name,
  1074. const struct fdt_memory *carveout);
  1075. /**
  1076. * Set up the device tree ready for use
  1077. */
  1078. int fdtdec_setup(void);
  1079. #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  1080. /**
  1081. * fdtdec_resetup() - Set up the device tree again
  1082. *
  1083. * The main difference with fdtdec_setup() is that it returns if the fdt has
  1084. * changed because a better match has been found.
  1085. * This is typically used for boards that rely on a DM driver to detect the
  1086. * board type. This function sould be called by the board code after the stuff
  1087. * needed by board_fit_config_name_match() to operate porperly is available.
  1088. * If this functions signals that a rescan is necessary, the board code must
  1089. * unbind all the drivers using dm_uninit() and then rescan the DT with
  1090. * dm_init_and_scan().
  1091. *
  1092. * @param rescan Returns a flag indicating that fdt has changed and rescanning
  1093. * the fdt is required
  1094. *
  1095. * @return 0 if OK, -ve on error
  1096. */
  1097. int fdtdec_resetup(int *rescan);
  1098. #endif
  1099. /**
  1100. * Board-specific FDT initialization. Returns the address to a device tree blob.
  1101. * Called when CONFIG_OF_BOARD is defined, or if CONFIG_OF_SEPARATE is defined
  1102. * and the board implements it.
  1103. */
  1104. void *board_fdt_blob_setup(void);
  1105. /*
  1106. * Decode the size of memory
  1107. *
  1108. * RAM size is normally set in a /memory node and consists of a list of
  1109. * (base, size) cells in the 'reg' property. This information is used to
  1110. * determine the total available memory as well as the address and size
  1111. * of each bank.
  1112. *
  1113. * Optionally the memory configuration can vary depending on a board id,
  1114. * typically read from strapping resistors or an EEPROM on the board.
  1115. *
  1116. * Finally, memory size can be detected (within certain limits) by probing
  1117. * the available memory. It is safe to do so within the limits provides by
  1118. * the board's device tree information. This makes it possible to produce
  1119. * boards with different memory sizes, where the device tree specifies the
  1120. * maximum memory configuration, and the smaller memory configuration is
  1121. * probed.
  1122. *
  1123. * This function decodes that information, returning the memory base address,
  1124. * size and bank information. See the memory.txt binding for full
  1125. * documentation.
  1126. *
  1127. * @param blob Device tree blob
  1128. * @param area Name of node to check (NULL means "/memory")
  1129. * @param board_id Board ID to look up
  1130. * @param basep Returns base address of first memory bank (NULL to
  1131. * ignore)
  1132. * @param sizep Returns total memory size (NULL to ignore)
  1133. * @param bd Updated with the memory bank information (NULL to skip)
  1134. * @return 0 if OK, -ve on error
  1135. */
  1136. int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
  1137. phys_addr_t *basep, phys_size_t *sizep,
  1138. struct bd_info *bd);
  1139. #endif