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>
28 #ifndef OF_INIT_DEFAULT_PATH
29 #define OF_INIT_DEFAULT_PATH "/proc/device-tree"
32 #define OF_DEFAULT_NA 1
33 #define OF_DEFAULT_NS 1
35 #define OF_FILE_BUF_MAX 256
38 * Layout of Device Tree:
49 * +------------------+
51 * |+----------------+|
53 * ||+--------------+||
55 * ||+--------------+||
57 * |+----------------+|
60 * +------------------+
64 * Device description on of a device node in device tree.
68 char full_name[PATH_MAX];
72 * List of device nodes available in a device tree layout
75 struct device_node node; /**< Property of node */
76 int is_file; /**< FALSE==dir, TRUE==file */
77 struct list_head list; /**< Nodes within a parent subdir */
81 * Types we use to represent directories and files
86 struct list_head subdirs;
87 struct list_head files;
88 struct list_head linear;
89 struct dt_dir *parent;
90 struct dt_file *compatible;
91 struct dt_file *status;
92 struct dt_file *lphandle;
93 struct dt_file *a_cells;
94 struct dt_file *s_cells;
100 struct dt_dir *parent;
102 uint64_t buf[OF_FILE_BUF_MAX >> 3];
105 const struct device_node *of_find_compatible_node(
106 const struct device_node *from,
107 const char *type __rte_unused,
108 const char *compatible)
109 __attribute__((nonnull(3)));
111 #define for_each_compatible_node(dev_node, type, compatible) \
112 for (dev_node = of_find_compatible_node(NULL, type, compatible); \
114 dev_node = of_find_compatible_node(dev_node, type, compatible))
116 const void *of_get_property(const struct device_node *from, const char *name,
117 size_t *lenp) __attribute__((nonnull(2)));
118 bool of_device_is_available(const struct device_node *dev_node);
120 const struct device_node *of_find_node_by_phandle(uint64_t ph);
122 const struct device_node *of_get_parent(const struct device_node *dev_node);
124 const struct device_node *of_get_next_child(const struct device_node *dev_node,
125 const struct device_node *prev);
127 const void *of_get_mac_address(const struct device_node *np);
129 #define for_each_child_node(parent, child) \
130 for (child = of_get_next_child(parent, NULL); child != NULL; \
131 child = of_get_next_child(parent, child))
133 uint32_t of_n_addr_cells(const struct device_node *dev_node);
134 uint32_t of_n_size_cells(const struct device_node *dev_node);
136 const uint32_t *of_get_address(const struct device_node *dev_node, size_t idx,
137 uint64_t *size, uint32_t *flags);
139 uint64_t of_translate_address(const struct device_node *dev_node,
140 const uint32_t *addr) __attribute__((nonnull));
142 bool of_device_is_compatible(const struct device_node *dev_node,
143 const char *compatible);
145 /* of_init() must be called prior to initialisation or use of any driver
146 * subsystem that is device-tree-dependent. Eg. Qman/Bman, config layers, etc.
147 * The path should usually be "/proc/device-tree".
149 int of_init_path(const char *dt_path);
151 /* of_finish() allows a controlled tear-down of the device-tree layer, eg. if a
152 * full reload is desired without a process exit.
154 void of_finish(void);
156 /* Use of this wrapper is recommended. */
157 static inline int of_init(void)
159 return of_init_path(OF_INIT_DEFAULT_PATH);
162 /* Read a numeric property according to its size and return it as a 64-bit
165 static inline uint64_t of_read_number(const uint32_t *cell, int size)
170 r = (r << 32) | be32toh(*(cell++));