fdtdec.h 44 KB

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