1 #ifndef __LUNAIX_GIC_COMMON_H
2 #define __LUNAIX_GIC_COMMON_H
4 #include <lunaix/types.h>
5 #include <lunaix/status.h>
8 #define PAD(body, name, offset) \
9 struct { char _pad_##name[offset]; body; } compact
11 #define PAD_STRUCT(body, name, offset) \
12 PAD(struct body, name, offset)
14 #define FIELD_AT(type, field, offset) \
15 PAD(volatile type field, field, offset)
17 #define ARRAY_AT(type, arr, offset, end) \
18 PAD(volatile type arr[((end) - (offset)) / sizeof(type) + 1], arr, offset)
21 typedef unsigned int intid_t;
55 enum gic_intkind kind;
56 enum gic_trigger trig;
66 struct irq_object* irq;
68 #define GIC_INTR_RAW_AFF 1
70 struct gic_int_class_ops
72 int (*set_enabled)(struct gic_int_class*, intid_t, bool);
73 int (*set_prority)(struct gic_int_class*, intid_t, int);
74 int (*set_nmi)(struct gic_int_class*, intid_t, bool);
75 int (*set_route)(struct gic_int_class*,intid_t, struct gic_pe*);
76 int (*set_trigger)(struct gic_int_class*,intid_t, enum gic_trigger);
78 int (*retrieve)(struct gic_int_class*, struct gic_interrupt*, intid_t);
79 int (*install)(struct gic_int_class*, struct gic_interrupt*);
80 int (*delete)(struct gic_int_class*, intid_t);
82 int (*fire)(struct gic_int_class*, intid_t);
84 extern const struct gic_int_class_ops aa64_gic_fallback_ops;
90 enum gic_intkind kind;
97 struct gic_int_class_ops* ops;
102 bool (*ack_int)(struct gic_pe*);
103 int (*notify_eoi)(struct gic_pe*);
104 int (*set_priority_mask)(struct gic_pe*, int);
111 struct gic_int_class sgi;
112 struct gic_int_class ppi;
113 struct gic_int_class ppi_e;
114 struct gic_int_class lpi;
116 struct gic_int_class classes[4];
122 struct gic_interrupt active_int;
133 struct gic_pe_ops* ops;
139 struct gic_pe** cores;
143 struct gic_int_class spi;
144 struct gic_int_class spi_e;
146 struct gic_int_class classes[2];
151 struct irq_domain* domain;
155 gic_init_int_class(struct gic_int_class* class,
156 enum gic_intkind kind, intid_t start, intid_t end)
158 *class = (struct gic_int_class) {
159 .range.start = start,
166 gic_valid_int_class(struct gic_int_class* class) {
167 return class->ops && (class->range.start < class->range.stop);
171 gic_intr_set_raw_affval(struct gic_interrupt* intr, u32_t affval)
173 intr->affinity.raw_val = ((u64_t)affval << 1) | GIC_INTR_RAW_AFF;
177 gic_assign_intid(struct gic_int_class* class, irq_t irq)
182 if (!gic_valid_int_class(class)) {
183 // selected class not present or disabled
187 gic = gic_global_context_of(class);
188 err = irq_alloc_id(gic->domain, irq,
189 class->range.start, class->range.stop);
195 gic_create_pe_context(struct gic* gic, void* pe_impl);
198 gic_local_context_of(struct gic_int_class* int_class);
201 gic_global_context_of(struct gic_int_class* int_class);
204 gic_get_interrupt(struct gic* gic, intid_t id, struct gic_interrupt* intr_out);
207 gic_create_context(struct device* gicdev);
213 __fallback_set_enabled(struct gic_int_class* class, intid_t intid, bool en);
216 __fallback_set_prority(struct gic_int_class* class, intid_t intid, int prio);
219 __fallback_set_nmi(struct gic_int_class* class, intid_t intid, bool nmi);
222 __fallback_set_route(struct gic_int_class* class,
223 intid_t intid, struct gic_pe* target);
226 __fallback_set_trigger(struct gic_int_class* class,
227 intid_t intid, enum gic_trigger trig);
231 __fallback_retrieve(struct gic_int_class* class,
232 struct gic_interrupt*, intid_t intid);
235 __fallback_install(struct gic_int_class* class, struct gic_interrupt* gic);
238 __fallback_delete(struct gic_int_class* class, intid_t intid);
239 #endif /* __LUNAIX_GIC_COMMON_H */