2 * Copyright (c) 2017 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/u-boot.h>
12 #include <asm/global_data.h>
14 /* integer value within a device tree property which references another node */
18 * struct property: Device tree property
20 * @name: Property name
21 * @length: Length of property in bytes
22 * @value: Pointer to property value
23 * @next: Pointer to next property, or NULL if none
29 struct property *next;
33 * struct device_node: Device tree node
36 * @type: Node type (value of device_type property) or "<NULL>" if none
37 * @phandle: Phandle value of this none, or 0 if none
38 * @full_name: Full path to node, e.g. "/bus@1/spi@1100"
39 * @properties: Pointer to head of list of properties, or NULL if none
40 * @parent: Pointer to parent node, or NULL if this is the root node
41 * @child: Pointer to head of child node list, or NULL if no children
42 * @sibling: Pointer to the next sibling node, or NULL if this is the last
48 const char *full_name;
50 struct property *properties;
51 struct device_node *parent;
52 struct device_node *child;
53 struct device_node *sibling;
56 #define OF_MAX_PHANDLE_ARGS 16
59 * struct of_phandle_args - structure to hold phandle and arguments
61 * This is used when decoding a phandle in a device tree property. Typically
62 * these look like this:
69 * some-prop = <&wibble 1 2 3>
71 * Here &node is the phandle of the node 'wibble', i.e. 5. There are three
74 * So when decoding the phandle in some-prop, np will point to wibble,
75 * args_count will be 3 and the three arguments will be in args.
77 * @np: Node that the phandle refers to
78 * @args_count: Number of arguments
79 * @args: Argument values
81 struct of_phandle_args {
82 struct device_node *np;
84 uint32_t args[OF_MAX_PHANDLE_ARGS];
87 DECLARE_GLOBAL_DATA_PTR;
90 * of_live_active() - check if livetree is active
92 * @returns true if livetree is active, false it not
95 static inline bool of_live_active(void)
97 return gd->of_root != NULL;
100 static inline bool of_live_active(void)
106 #define OF_BAD_ADDR ((u64)-1)
108 static inline const char *of_node_full_name(const struct device_node *np)
110 return np ? np->full_name : "<no-node>";
113 /* Default #address and #size cells */
114 #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)
115 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
116 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
119 /* Default string compare functions */
120 #if !defined(of_compat_cmp)
121 #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
122 #define of_prop_cmp(s1, s2) strcmp((s1), (s2))
123 #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
126 /* Helper to read a big number; size is in cells (not bytes) */
127 static inline u64 of_read_number(const __be32 *cell, int size)
131 r = (r << 32) | be32_to_cpu(*(cell++));
135 /* Like of_read_number, but we want an unsigned long result */
136 static inline unsigned long of_read_ulong(const __be32 *cell, int size)
138 /* toss away upper bits if unsigned long is smaller than u64 */
139 return of_read_number(cell, size);