fdtdec.h 44 KB

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