root / include / sysemu / device_tree.h @ be5907f2
History | View | Annotate | Download (5.1 kB)
1 | f652e6af | aurel32 | /*
|
---|---|---|---|
2 | f652e6af | aurel32 | * Header with function prototypes to help device tree manipulation using
|
3 | f652e6af | aurel32 | * libfdt. It also provides functions to read entries from device tree proc
|
4 | f652e6af | aurel32 | * interface.
|
5 | f652e6af | aurel32 | *
|
6 | f652e6af | aurel32 | * Copyright 2008 IBM Corporation.
|
7 | f652e6af | aurel32 | * Authors: Jerone Young <jyoung5@us.ibm.com>
|
8 | f652e6af | aurel32 | * Hollis Blanchard <hollisb@us.ibm.com>
|
9 | f652e6af | aurel32 | *
|
10 | f652e6af | aurel32 | * This work is licensed under the GNU GPL license version 2 or later.
|
11 | f652e6af | aurel32 | *
|
12 | f652e6af | aurel32 | */
|
13 | f652e6af | aurel32 | |
14 | f652e6af | aurel32 | #ifndef __DEVICE_TREE_H__
|
15 | f652e6af | aurel32 | #define __DEVICE_TREE_H__
|
16 | f652e6af | aurel32 | |
17 | ce36252c | Alexander Graf | void *create_device_tree(int *sizep); |
18 | 7ec632b4 | pbrook | void *load_device_tree(const char *filename_path, int *sizep); |
19 | f652e6af | aurel32 | |
20 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop(void *fdt, const char *node_path, |
21 | be5907f2 | Peter Crosthwaite | const char *property, const void *val, int size); |
22 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop_cell(void *fdt, const char *node_path, |
23 | 5a4348d1 | Peter Crosthwaite | const char *property, uint32_t val); |
24 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop_u64(void *fdt, const char *node_path, |
25 | 5a4348d1 | Peter Crosthwaite | const char *property, uint64_t val); |
26 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop_string(void *fdt, const char *node_path, |
27 | 5a4348d1 | Peter Crosthwaite | const char *property, const char *string); |
28 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, |
29 | 5a4348d1 | Peter Crosthwaite | const char *property, |
30 | 5a4348d1 | Peter Crosthwaite | const char *target_node_path); |
31 | 5a4348d1 | Peter Crosthwaite | const void *qemu_fdt_getprop(void *fdt, const char *node_path, |
32 | 5a4348d1 | Peter Crosthwaite | const char *property, int *lenp); |
33 | 5a4348d1 | Peter Crosthwaite | uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path, |
34 | 5a4348d1 | Peter Crosthwaite | const char *property); |
35 | 5a4348d1 | Peter Crosthwaite | uint32_t qemu_fdt_get_phandle(void *fdt, const char *path); |
36 | 5a4348d1 | Peter Crosthwaite | uint32_t qemu_fdt_alloc_phandle(void *fdt);
|
37 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_nop_node(void *fdt, const char *node_path); |
38 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_add_subnode(void *fdt, const char *name); |
39 | f652e6af | aurel32 | |
40 | 5a4348d1 | Peter Crosthwaite | #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \
|
41 | 7ae2291e | Alexander Graf | do { \
|
42 | 7ae2291e | Alexander Graf | uint32_t qdt_tmp[] = { __VA_ARGS__ }; \ |
43 | 7ae2291e | Alexander Graf | int i; \
|
44 | 7ae2291e | Alexander Graf | \ |
45 | 7ae2291e | Alexander Graf | for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \ |
46 | 7ae2291e | Alexander Graf | qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \ |
47 | 7ae2291e | Alexander Graf | } \ |
48 | 5a4348d1 | Peter Crosthwaite | qemu_fdt_setprop(fdt, node_path, property, qdt_tmp, \ |
49 | 5a4348d1 | Peter Crosthwaite | sizeof(qdt_tmp)); \
|
50 | 7ae2291e | Alexander Graf | } while (0) |
51 | 7ae2291e | Alexander Graf | |
52 | 5a4348d1 | Peter Crosthwaite | void qemu_fdt_dumpdtb(void *fdt, int size); |
53 | 71193433 | Alexander Graf | |
54 | 97c38f8c | Peter Maydell | /**
|
55 | 5a4348d1 | Peter Crosthwaite | * qemu_fdt_setprop_sized_cells_from_array:
|
56 | 97c38f8c | Peter Maydell | * @fdt: device tree blob
|
57 | 97c38f8c | Peter Maydell | * @node_path: node to set property on
|
58 | 97c38f8c | Peter Maydell | * @property: property to set
|
59 | 97c38f8c | Peter Maydell | * @numvalues: number of values
|
60 | 97c38f8c | Peter Maydell | * @values: array of number-of-cells, value pairs
|
61 | 97c38f8c | Peter Maydell | *
|
62 | 97c38f8c | Peter Maydell | * Set the specified property on the specified node in the device tree
|
63 | 97c38f8c | Peter Maydell | * to be an array of cells. The values of the cells are specified via
|
64 | 97c38f8c | Peter Maydell | * the values list, which alternates between "number of cells used by
|
65 | 97c38f8c | Peter Maydell | * this value" and "value".
|
66 | 97c38f8c | Peter Maydell | * number-of-cells must be either 1 or 2 (other values will result in
|
67 | 97c38f8c | Peter Maydell | * an error being returned). If a value is too large to fit in the
|
68 | 97c38f8c | Peter Maydell | * number of cells specified for it, an error is returned.
|
69 | 97c38f8c | Peter Maydell | *
|
70 | 97c38f8c | Peter Maydell | * This function is useful because device tree nodes often have cell arrays
|
71 | 97c38f8c | Peter Maydell | * which are either lists of addresses or lists of address,size tuples, but
|
72 | 97c38f8c | Peter Maydell | * the number of cells used for each element vary depending on the
|
73 | 97c38f8c | Peter Maydell | * #address-cells and #size-cells properties of their parent node.
|
74 | 97c38f8c | Peter Maydell | * If you know all your cell elements are one cell wide you can use the
|
75 | 5a4348d1 | Peter Crosthwaite | * simpler qemu_fdt_setprop_cells(). If you're not setting up the
|
76 | 5a4348d1 | Peter Crosthwaite | * array programmatically, qemu_fdt_setprop_sized_cells may be more
|
77 | 97c38f8c | Peter Maydell | * convenient.
|
78 | 97c38f8c | Peter Maydell | *
|
79 | 97c38f8c | Peter Maydell | * Return value: 0 on success, <0 on error.
|
80 | 97c38f8c | Peter Maydell | */
|
81 | 5a4348d1 | Peter Crosthwaite | int qemu_fdt_setprop_sized_cells_from_array(void *fdt, |
82 | 5a4348d1 | Peter Crosthwaite | const char *node_path, |
83 | 5a4348d1 | Peter Crosthwaite | const char *property, |
84 | 5a4348d1 | Peter Crosthwaite | int numvalues,
|
85 | 5a4348d1 | Peter Crosthwaite | uint64_t *values); |
86 | 97c38f8c | Peter Maydell | |
87 | 97c38f8c | Peter Maydell | /**
|
88 | 5a4348d1 | Peter Crosthwaite | * qemu_fdt_setprop_sized_cells:
|
89 | 97c38f8c | Peter Maydell | * @fdt: device tree blob
|
90 | 97c38f8c | Peter Maydell | * @node_path: node to set property on
|
91 | 97c38f8c | Peter Maydell | * @property: property to set
|
92 | 97c38f8c | Peter Maydell | * @...: list of number-of-cells, value pairs
|
93 | 97c38f8c | Peter Maydell | *
|
94 | 97c38f8c | Peter Maydell | * Set the specified property on the specified node in the device tree
|
95 | 97c38f8c | Peter Maydell | * to be an array of cells. The values of the cells are specified via
|
96 | 97c38f8c | Peter Maydell | * the variable arguments, which alternates between "number of cells
|
97 | 97c38f8c | Peter Maydell | * used by this value" and "value".
|
98 | 97c38f8c | Peter Maydell | *
|
99 | 97c38f8c | Peter Maydell | * This is a convenience wrapper for the function
|
100 | 5a4348d1 | Peter Crosthwaite | * qemu_fdt_setprop_sized_cells_from_array().
|
101 | 97c38f8c | Peter Maydell | *
|
102 | 97c38f8c | Peter Maydell | * Return value: 0 on success, <0 on error.
|
103 | 97c38f8c | Peter Maydell | */
|
104 | 5a4348d1 | Peter Crosthwaite | #define qemu_fdt_setprop_sized_cells(fdt, node_path, property, ...) \
|
105 | 5a4348d1 | Peter Crosthwaite | ({ \ |
106 | 5a4348d1 | Peter Crosthwaite | uint64_t qdt_tmp[] = { __VA_ARGS__ }; \ |
107 | 5a4348d1 | Peter Crosthwaite | qemu_fdt_setprop_sized_cells_from_array(fdt, node_path, \ |
108 | 5a4348d1 | Peter Crosthwaite | property, \ |
109 | 5a4348d1 | Peter Crosthwaite | ARRAY_SIZE(qdt_tmp) / 2, \
|
110 | 5a4348d1 | Peter Crosthwaite | qdt_tmp); \ |
111 | 97c38f8c | Peter Maydell | }) |
112 | 97c38f8c | Peter Maydell | |
113 | f652e6af | aurel32 | #endif /* __DEVICE_TREE_H__ */ |