2 * Header with function prototypes to help device tree manipulation using
3 * libfdt. It also provides functions to read entries from device tree proc
6 * Copyright 2008 IBM Corporation.
7 * Authors: Jerone Young <jyoung5@us.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
10 * This work is licensed under the GNU GPL license version 2 or later.
17 void *create_device_tree(int *sizep
);
18 void *load_device_tree(const char *filename_path
, int *sizep
);
21 * load_device_tree_from_sysfs: reads the device tree information in the
22 * /proc/device-tree directory and return the corresponding binary blob
23 * buffer pointer. Asserts in case of error.
25 void *load_device_tree_from_sysfs(void);
29 * qemu_fdt_node_path: return the paths of nodes matching a given
30 * name and compat string
31 * @fdt: pointer to the dt blob
33 * @compat: compatibility string
34 * @errp: handle to an error object
36 * returns a newly allocated NULL-terminated array of node paths.
37 * Use g_strfreev() to free it. If one or more nodes were found, the
38 * array contains the path of each node and the last element equals to
39 * NULL. If there is no error but no matching node was found, the
40 * returned array contains a single element equal to NULL. If an error
41 * was encountered when parsing the blob, the function returns NULL
43 char **qemu_fdt_node_path(void *fdt
, const char *name
, char *compat
,
47 * qemu_fdt_node_unit_path: return the paths of nodes matching a given
48 * node-name, ie. node-name and node-name@unit-address
49 * @fdt: pointer to the dt blob
51 * @errp: handle to an error object
53 * returns a newly allocated NULL-terminated array of node paths.
54 * Use g_strfreev() to free it. If one or more nodes were found, the
55 * array contains the path of each node and the last element equals to
56 * NULL. If there is no error but no matching node was found, the
57 * returned array contains a single element equal to NULL. If an error
58 * was encountered when parsing the blob, the function returns NULL
60 char **qemu_fdt_node_unit_path(void *fdt
, const char *name
, Error
**errp
);
62 int qemu_fdt_setprop(void *fdt
, const char *node_path
,
63 const char *property
, const void *val
, int size
);
64 int qemu_fdt_setprop_cell(void *fdt
, const char *node_path
,
65 const char *property
, uint32_t val
);
66 int qemu_fdt_setprop_u64(void *fdt
, const char *node_path
,
67 const char *property
, uint64_t val
);
68 int qemu_fdt_setprop_string(void *fdt
, const char *node_path
,
69 const char *property
, const char *string
);
70 int qemu_fdt_setprop_phandle(void *fdt
, const char *node_path
,
72 const char *target_node_path
);
74 * qemu_fdt_getprop: retrieve the value of a given property
75 * @fdt: pointer to the device tree blob
76 * @node_path: node path
77 * @property: name of the property to find
78 * @lenp: fdt error if any or length of the property on success
79 * @errp: handle to an error object
81 * returns a pointer to the property on success and NULL on failure
83 const void *qemu_fdt_getprop(void *fdt
, const char *node_path
,
84 const char *property
, int *lenp
,
87 * qemu_fdt_getprop_cell: retrieve the value of a given 4 byte property
88 * @fdt: pointer to the device tree blob
89 * @node_path: node path
90 * @property: name of the property to find
91 * @lenp: fdt error if any or -EINVAL if the property size is different from
92 * 4 bytes, or 4 (expected length of the property) upon success.
93 * @errp: handle to an error object
95 * returns the property value on success
97 uint32_t qemu_fdt_getprop_cell(void *fdt
, const char *node_path
,
98 const char *property
, int *lenp
,
100 uint32_t qemu_fdt_get_phandle(void *fdt
, const char *path
);
101 uint32_t qemu_fdt_alloc_phandle(void *fdt
);
102 int qemu_fdt_nop_node(void *fdt
, const char *node_path
);
103 int qemu_fdt_add_subnode(void *fdt
, const char *name
);
105 #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \
107 uint32_t qdt_tmp[] = { __VA_ARGS__ }; \
110 for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \
111 qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \
113 qemu_fdt_setprop(fdt, node_path, property, qdt_tmp, \
117 void qemu_fdt_dumpdtb(void *fdt
, int size
);
120 * qemu_fdt_setprop_sized_cells_from_array:
121 * @fdt: device tree blob
122 * @node_path: node to set property on
123 * @property: property to set
124 * @numvalues: number of values
125 * @values: array of number-of-cells, value pairs
127 * Set the specified property on the specified node in the device tree
128 * to be an array of cells. The values of the cells are specified via
129 * the values list, which alternates between "number of cells used by
130 * this value" and "value".
131 * number-of-cells must be either 1 or 2 (other values will result in
132 * an error being returned). If a value is too large to fit in the
133 * number of cells specified for it, an error is returned.
135 * This function is useful because device tree nodes often have cell arrays
136 * which are either lists of addresses or lists of address,size tuples, but
137 * the number of cells used for each element vary depending on the
138 * #address-cells and #size-cells properties of their parent node.
139 * If you know all your cell elements are one cell wide you can use the
140 * simpler qemu_fdt_setprop_cells(). If you're not setting up the
141 * array programmatically, qemu_fdt_setprop_sized_cells may be more
144 * Return value: 0 on success, <0 on error.
146 int qemu_fdt_setprop_sized_cells_from_array(void *fdt
,
147 const char *node_path
,
148 const char *property
,
153 * qemu_fdt_setprop_sized_cells:
154 * @fdt: device tree blob
155 * @node_path: node to set property on
156 * @property: property to set
157 * @...: list of number-of-cells, value pairs
159 * Set the specified property on the specified node in the device tree
160 * to be an array of cells. The values of the cells are specified via
161 * the variable arguments, which alternates between "number of cells
162 * used by this value" and "value".
164 * This is a convenience wrapper for the function
165 * qemu_fdt_setprop_sized_cells_from_array().
167 * Return value: 0 on success, <0 on error.
169 #define qemu_fdt_setprop_sized_cells(fdt, node_path, property, ...) \
171 uint64_t qdt_tmp[] = { __VA_ARGS__ }; \
172 qemu_fdt_setprop_sized_cells_from_array(fdt, node_path, \
174 ARRAY_SIZE(qdt_tmp) / 2, \
178 #define FDT_PCI_RANGE_RELOCATABLE 0x80000000
179 #define FDT_PCI_RANGE_PREFETCHABLE 0x40000000
180 #define FDT_PCI_RANGE_ALIASED 0x20000000
181 #define FDT_PCI_RANGE_TYPE_MASK 0x03000000
182 #define FDT_PCI_RANGE_MMIO_64BIT 0x03000000
183 #define FDT_PCI_RANGE_MMIO 0x02000000
184 #define FDT_PCI_RANGE_IOPORT 0x01000000
185 #define FDT_PCI_RANGE_CONFIG 0x00000000
187 #endif /* DEVICE_TREE_H */