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