fdtdec.h 45 KB

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