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