1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2010-2016 Freescale Semiconductor, Inc.
13 #ifndef OF_INIT_DEFAULT_PATH
14 #define OF_INIT_DEFAULT_PATH "/proc/device-tree"
17 #define OF_DEFAULT_NA 1
18 #define OF_DEFAULT_NS 1
20 #define OF_FILE_BUF_MAX 256
23 * Layout of Device Tree:
34 * +------------------+
36 * |+----------------+|
38 * ||+--------------+||
40 * ||+--------------+||
42 * |+----------------+|
45 * +------------------+
49 * Device description on of a device node in device tree.
53 char full_name[PATH_MAX];
57 * List of device nodes available in a device tree layout
60 struct device_node node; /**< Property of node */
61 int is_file; /**< FALSE==dir, TRUE==file */
62 struct list_head list; /**< Nodes within a parent subdir */
66 * Types we use to represent directories and files
71 struct list_head subdirs;
72 struct list_head files;
73 struct list_head linear;
74 struct dt_dir *parent;
75 struct dt_file *compatible;
76 struct dt_file *status;
77 struct dt_file *lphandle;
78 struct dt_file *a_cells;
79 struct dt_file *s_cells;
85 struct dt_dir *parent;
87 uint64_t buf[OF_FILE_BUF_MAX >> 3];
90 const struct device_node *of_find_compatible_node(
91 const struct device_node *from,
92 const char *type __always_unused,
93 const char *compatible)
94 __attribute__((nonnull(3)));
96 #define for_each_compatible_node(dev_node, type, compatible) \
97 for (dev_node = of_find_compatible_node(NULL, type, compatible); \
99 dev_node = of_find_compatible_node(dev_node, type, compatible))
101 const void *of_get_property(const struct device_node *from, const char *name,
102 size_t *lenp) __attribute__((nonnull(2)));
103 bool of_device_is_available(const struct device_node *dev_node);
105 const struct device_node *of_find_node_by_phandle(phandle ph);
107 const struct device_node *of_get_parent(const struct device_node *dev_node);
109 const struct device_node *of_get_next_child(const struct device_node *dev_node,
110 const struct device_node *prev);
112 #define for_each_child_node(parent, child) \
113 for (child = of_get_next_child(parent, NULL); child != NULL; \
114 child = of_get_next_child(parent, child))
116 uint32_t of_n_addr_cells(const struct device_node *dev_node);
117 uint32_t of_n_size_cells(const struct device_node *dev_node);
119 const uint32_t *of_get_address(const struct device_node *dev_node, size_t idx,
120 uint64_t *size, uint32_t *flags);
122 uint64_t of_translate_address(const struct device_node *dev_node,
123 const u32 *addr) __attribute__((nonnull));
125 bool of_device_is_compatible(const struct device_node *dev_node,
126 const char *compatible);
128 /* of_init() must be called prior to initialisation or use of any driver
129 * subsystem that is device-tree-dependent. Eg. Qman/Bman, config layers, etc.
130 * The path should usually be "/proc/device-tree".
132 int of_init_path(const char *dt_path);
134 /* of_finish() allows a controlled tear-down of the device-tree layer, eg. if a
135 * full reload is desired without a process exit.
137 void of_finish(void);
139 /* Use of this wrapper is recommended. */
140 static inline int of_init(void)
142 return of_init_path(OF_INIT_DEFAULT_PATH);
145 /* Read a numeric property according to its size and return it as a 64-bit
148 static inline uint64_t of_read_number(const __be32 *cell, int size)
153 r = (r << 32) | be32toh(*(cell++));