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