1#ifndef FDT_GENERIC_UTIL_H
2#define FDT_GENERIC_UTIL_H
3
4#include "qemu-common.h"
5#include "fdt_generic.h"
6#include "exec/memory.h"
7#include "qom/object.h"
8
9
10
11
12
13
14FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq);
15
16
17
18
19
20qemu_irq *fdt_get_irq(FDTMachineInfo *fdti, char *node_path, int irq_idx,
21 bool *map_mode);
22
23
24
25
26
27
28
29qemu_irq *fdt_get_irq_info(FDTMachineInfo *fdti, char *node_path, int irq_idx,
30 char * info, bool *map_mode);
31
32#define TYPE_FDT_GENERIC_INTC "fdt-generic-intc"
33
34#define FDT_GENERIC_INTC_CLASS(klass) \
35 OBJECT_CLASS_CHECK(FDTGenericIntcClass, (klass), TYPE_FDT_GENERIC_INTC)
36#define FDT_GENERIC_INTC_GET_CLASS(obj) \
37 OBJECT_GET_CLASS(FDTGenericIntcClass, (obj), TYPE_FDT_GENERIC_INTC)
38#define FDT_GENERIC_INTC(obj) \
39 INTERFACE_CHECK(FDTGenericIntc, (obj), TYPE_FDT_GENERIC_INTC)
40
41typedef struct FDTGenericIntc {
42
43 Object parent_obj;
44} FDTGenericIntc;
45
46typedef struct FDTGenericIntcClass {
47
48 InterfaceClass parent_class;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 int (*get_irq)(FDTGenericIntc *obj, qemu_irq *irqs, uint32_t *cells,
72 int ncells, int max, Error **errp);
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 void (*auto_parent)(FDTGenericIntc *obj, Error **errp);
88
89} FDTGenericIntcClass;
90
91#define TYPE_FDT_GENERIC_MMAP "fdt-generic-mmap"
92
93#define FDT_GENERIC_MMAP_CLASS(klass) \
94 OBJECT_CLASS_CHECK(FDTGenericMMapClass, (klass), TYPE_FDT_GENERIC_MMAP)
95#define FDT_GENERIC_MMAP_GET_CLASS(obj) \
96 OBJECT_GET_CLASS(FDTGenericMMapClass, (obj), TYPE_FDT_GENERIC_MMAP)
97#define FDT_GENERIC_MMAP(obj) \
98 INTERFACE_CHECK(FDTGenericMMap, (obj), TYPE_FDT_GENERIC_MMAP)
99
100typedef struct FDTGenericMMap {
101
102 Object parent_obj;
103} FDTGenericMMap;
104
105
106
107
108
109#define FDT_GENERIC_REG_TUPLE_LENGTH 4
110
111typedef struct FDTGenericRegPropInfo {
112 int n;
113 union {
114 struct {
115 uint64_t *a;
116 uint64_t *s;
117 uint64_t *b;
118 uint64_t *p;
119 };
120 uint64_t *x[FDT_GENERIC_REG_TUPLE_LENGTH];
121 };
122 Object **parents;
123} FDTGenericRegPropInfo;
124
125typedef struct FDTGenericMMapClass {
126
127 InterfaceClass parent_class;
128
129
130 bool (*parse_reg)(FDTGenericMMap *obj, FDTGenericRegPropInfo info,
131 Error **errp);
132} FDTGenericMMapClass;
133
134#define TYPE_FDT_GENERIC_GPIO "fdt-generic-gpio"
135
136#define FDT_GENERIC_GPIO_CLASS(klass) \
137 OBJECT_CLASS_CHECK(FDTGenericGPIOClass, (klass), TYPE_FDT_GENERIC_GPIO)
138#define FDT_GENERIC_GPIO_GET_CLASS(obj) \
139 OBJECT_GET_CLASS(FDTGenericGPIOClass, (obj), TYPE_FDT_GENERIC_GPIO)
140#define FDT_GENERIC_GPIO(obj) \
141 INTERFACE_CHECK(FDTGenericGPIO, (obj), TYPE_FDT_GENERIC_GPIO)
142
143typedef struct FDTGenericGPIO {
144
145 Object parent_obj;
146} FDTGenericGPIO;
147
148typedef struct FDTGenericGPIOConnection {
149 const char *name;
150 uint16_t fdt_index;
151 uint16_t range;
152} FDTGenericGPIOConnection;
153
154typedef struct FDTGenericGPIONameSet {
155 const char *propname;
156 const char *cells_propname;
157 const char *names_propname;
158} FDTGenericGPIONameSet;
159
160typedef struct FDTGenericGPIOSet {
161 const FDTGenericGPIONameSet *names;
162 const FDTGenericGPIOConnection *gpios;
163} FDTGenericGPIOSet;
164
165static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_power_gpio = {
166 .propname = "power-gpios",
167 .cells_propname = "#gpio-cells",
168 .names_propname = "power-gpio-names",
169};
170
171static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_reset_gpio = {
172 .propname = "reset-gpios",
173 .cells_propname = "#gpio-cells",
174 .names_propname = "reset-gpio-names",
175};
176
177static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_resets = {
178 .propname = "resets",
179 .cells_propname = "#reset-cells",
180 .names_propname = "reset-names",
181};
182
183static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_gpio = {
184 .propname = "gpios",
185 .cells_propname = "#gpio-cells",
186 .names_propname = "gpio-names",
187};
188
189static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_clock = {
190 .propname = "clocks",
191 .cells_propname = "#clock-cells",
192 .names_propname = "clock-names",
193};
194
195static const FDTGenericGPIONameSet fdt_generic_gpio_name_set_interrupts = {
196 .propname = "interrupts-extended",
197 .cells_propname = "#interrupt-cells",
198 .names_propname = "interrupt-names",
199};
200
201static const FDTGenericGPIOSet default_gpio_sets [] = {
202 { .names = &fdt_generic_gpio_name_set_gpio },
203 {
204 .names = &fdt_generic_gpio_name_set_reset_gpio,
205 .gpios = (FDTGenericGPIOConnection[]) {
206 { .name = "rst_cntrl", .fdt_index = 0, .range = 6 },
207 },
208 },
209 {
210 .names = &fdt_generic_gpio_name_set_resets,
211 .gpios = (FDTGenericGPIOConnection[]) {
212 { .name = "rst_cntrl", .fdt_index = 0, .range = 6 },
213 },
214 },
215 {
216 .names = &fdt_generic_gpio_name_set_power_gpio,
217 .gpios = (FDTGenericGPIOConnection[]) {
218 { .name = "pwr_cntrl", .fdt_index = 0, .range = 1 },
219 },
220 },
221 { .names = &fdt_generic_gpio_name_set_clock },
222 { .names = &fdt_generic_gpio_name_set_interrupts },
223 { },
224};
225
226typedef struct FDTGenericGPIOClass {
227
228 InterfaceClass parent_class;
229
230
231
232
233
234
235
236
237
238
239
240
241
242 const FDTGenericGPIOSet *controller_gpios;
243 const FDTGenericGPIOSet *client_gpios;
244} FDTGenericGPIOClass;
245
246#define TYPE_FDT_GENERIC_PROPS "fdt-generic-props"
247
248#define FDT_GENERIC_PROPS_CLASS(klass) \
249 OBJECT_CLASS_CHECK(FDTGenericPropsClass, (klass), \
250 TYPE_FDT_GENERIC_PROPS)
251#define FDT_GENERIC_PROPS_GET_CLASS(obj) \
252 OBJECT_GET_CLASS(FDTGenericPropsClass, (obj), \
253 TYPE_FDT_GENERIC_PROPS)
254
255typedef struct FDTGenericPropsClass {
256
257 InterfaceClass parent_class;
258
259
260 void (*set_props)(Object *obj, Error **errp);
261} FDTGenericPropsClass;
262
263#endif
264