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