1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2010-2016 Freescale Semiconductor, Inc.
18 #include <sys/types.h>
25 #include <rte_common.h>
26 #include <dpaa_list.h>
27 #include <rte_compat.h>
29 #ifndef OF_INIT_DEFAULT_PATH
30 #define OF_INIT_DEFAULT_PATH "/proc/device-tree"
33 #define OF_DEFAULT_NA 1
34 #define OF_DEFAULT_NS 1
36 #define OF_FILE_BUF_MAX 256
39 * Layout of Device Tree:
50 * +------------------+
52 * |+----------------+|
54 * ||+--------------+||
56 * ||+--------------+||
58 * |+----------------+|
61 * +------------------+
65 * Device description on of a device node in device tree.
69 char full_name[PATH_MAX];
73 * List of device nodes available in a device tree layout
76 struct device_node node; /**< Property of node */
77 int is_file; /**< FALSE==dir, TRUE==file */
78 struct list_head list; /**< Nodes within a parent subdir */
82 * Types we use to represent directories and files
87 struct list_head subdirs;
88 struct list_head files;
89 struct list_head linear;
90 struct dt_dir *parent;
91 struct dt_file *compatible;
92 struct dt_file *status;
93 struct dt_file *lphandle;
94 struct dt_file *a_cells;
95 struct dt_file *s_cells;
101 struct dt_dir *parent;
103 uint64_t buf[OF_FILE_BUF_MAX >> 3];
107 const struct device_node *of_find_compatible_node(
108 const struct device_node *from,
109 const char *type __rte_unused,
110 const char *compatible)
111 __attribute__((nonnull(3)));
113 #define for_each_compatible_node(dev_node, type, compatible) \
114 for (dev_node = of_find_compatible_node(NULL, type, compatible); \
116 dev_node = of_find_compatible_node(dev_node, type, compatible))
119 const void *of_get_property(const struct device_node *from, const char *name,
120 size_t *lenp) __attribute__((nonnull(2)));
122 bool of_device_is_available(const struct device_node *dev_node);
125 const struct device_node *of_find_node_by_phandle(uint64_t ph);
128 const struct device_node *of_get_parent(const struct device_node *dev_node);
131 const struct device_node *of_get_next_child(const struct device_node *dev_node,
132 const struct device_node *prev);
135 const void *of_get_mac_address(const struct device_node *np);
137 #define for_each_child_node(parent, child) \
138 for (child = of_get_next_child(parent, NULL); child != NULL; \
139 child = of_get_next_child(parent, child))
142 uint32_t of_n_addr_cells(const struct device_node *dev_node);
143 uint32_t of_n_size_cells(const struct device_node *dev_node);
146 const uint32_t *of_get_address(const struct device_node *dev_node, size_t idx,
147 uint64_t *size, uint32_t *flags);
150 uint64_t of_translate_address(const struct device_node *dev_node,
151 const uint32_t *addr) __attribute__((nonnull));
154 bool of_device_is_compatible(const struct device_node *dev_node,
155 const char *compatible);
157 /* of_init() must be called prior to initialisation or use of any driver
158 * subsystem that is device-tree-dependent. Eg. Qman/Bman, config layers, etc.
159 * The path should usually be "/proc/device-tree".
162 int of_init_path(const char *dt_path);
164 /* of_finish() allows a controlled tear-down of the device-tree layer, eg. if a
165 * full reload is desired without a process exit.
167 void of_finish(void);
169 /* Use of this wrapper is recommended. */
170 static inline int of_init(void)
172 return of_init_path(OF_INIT_DEFAULT_PATH);
175 /* Read a numeric property according to its size and return it as a 64-bit
178 static inline uint64_t of_read_number(const uint32_t *cell, int size)
183 r = (r << 32) | be32toh(*(cell++));