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