fdtdec.h 44 KB

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