move syscall_nr to generic for sharing between arch impls
[lunaix-os.git] / lunaix-os / arch / aarch64 / soc / gic / v3.h
1 #ifndef __LUNAIX_V3_H
2 #define __LUNAIX_V3_H
3
4 #include <asm/aa64_gic.h>
5
6 #include "gic-common.h"
7
8 #define PAGE_64K        (1 << 16)
9 #define GIC_FRAME_SIZE  PAGE_64K
10
11 union v3_rdbase_map
12 {
13     FIELD_AT(u32_t, ctlr,           0x0000);
14     FIELD_AT(u32_t, iidr,           0x0004);
15     FIELD_AT(u64_t, typer,          0x0008);
16
17     // LPI
18     FIELD_AT(u64_t, setlpir,        0x0040);
19     FIELD_AT(u64_t, clrlpir,        0x0048);
20
21     FIELD_AT(u64_t, propbaser,      0x0070);
22     FIELD_AT(u64_t, pendbaser,      0x0078);
23     FIELD_AT(u64_t, invlpir,        0x00a0);
24     FIELD_AT(u64_t, invllr,         0x00b0);
25     FIELD_AT(u64_t, syncr,          0x00c0);
26 } compact;
27
28 union v3_sgibase_map
29 {
30     FIELD_AT(u32_t, igroupr0,       0x0080);
31     ARRAY_AT(u32_t, igroupr_e,      0x0084, 0x0088);
32
33     FIELD_AT(u32_t, isenabler0,     0x0100);
34     ARRAY_AT(u32_t, isenabler_e,    0x0104, 0x0108);
35     
36     FIELD_AT(u32_t, icenabler0,     0x0180);
37     ARRAY_AT(u32_t, icenabler_e,    0x0184, 0x0188);
38
39     FIELD_AT(u32_t, ispendr0,       0x0200);
40     ARRAY_AT(u32_t, ispendr_e,      0x0204, 0x0208);
41
42     FIELD_AT(u32_t, icpendr0,       0x280);
43     ARRAY_AT(u32_t, icpendr_e,      0x284,  0x0288);
44
45     FIELD_AT(u32_t, isactiver0,     0x300);
46     ARRAY_AT(u32_t, isactiver_e,    0x304,  0x0308);
47
48     FIELD_AT(u32_t, icactiver0,     0x380);
49     ARRAY_AT(u32_t, icactiver_e,    0x384,  0x0388);
50
51     ARRAY_AT(u32_t, ipriorityr,     0x0400, 0x041c);
52     ARRAY_AT(u32_t, ipriorityr_e,   0x0420, 0x045c);
53
54     FIELD_AT(u32_t, icfgr0,         0x0c00);
55     FIELD_AT(u32_t, icfgr1,         0x0c04);
56     ARRAY_AT(u32_t, icfgr_e,        0x0c08, 0x0c14);
57
58     FIELD_AT(u32_t, igrpmodr,       0x0d00);
59     ARRAY_AT(u32_t, igrpmodr_e,     0x0d04, 0x0d08);
60
61     FIELD_AT(u32_t, inmir,          0x0f80);
62     ARRAY_AT(u32_t, inmir_e,        0x0f84, 0x0ffc);
63 } compact;
64
65 union v3_gicd_map
66 {
67     FIELD_AT(u32_t, ctlr,         0x0000        );
68     FIELD_AT(u32_t, typer,        0x0004        );
69     FIELD_AT(u32_t, iidr,         0x0008        );
70
71     FIELD_AT(u32_t, setspi_nsr,   0x0040        );
72     FIELD_AT(u32_t, clrspi_nsr,   0x0048        );
73     FIELD_AT(u32_t, setspi_sr,    0x0050        );
74     FIELD_AT(u32_t, clrspi_sr,    0x0058        );
75
76     // SPI
77     ARRAY_AT(u32_t, igroupr,      0x0084, 0x00fc);
78     ARRAY_AT(u32_t, isenabler,    0x0100, 0x017c);
79     ARRAY_AT(u32_t, icenabler,    0x0180, 0x01fc);
80     ARRAY_AT(u32_t, ispendr,      0x0200, 0x027c);
81     ARRAY_AT(u32_t, icpendr,      0x0280, 0x02fc);
82     ARRAY_AT(u32_t, isactiver,    0x0300, 0x037c);
83     ARRAY_AT(u32_t, icactiver,    0x0380, 0x03fc);
84     ARRAY_AT(u32_t, ipriorityr,   0x0400, 0x07f8);
85     ARRAY_AT(u32_t, itargetsr,    0x0800, 0x0bf8);
86     ARRAY_AT(u32_t, icfgr,        0x0c00, 0x0cfc);
87     ARRAY_AT(u32_t, igrpmodr,     0x0d00, 0x0d7c);
88     ARRAY_AT(u32_t, inmir,        0x0f80, 0x0ffc);
89
90     // eSPI
91     ARRAY_AT(u32_t, igroupr_e,    0x1000, 0x107c);
92     ARRAY_AT(u32_t, isenabler_e,  0x1200, 0x127c);
93     ARRAY_AT(u32_t, icenabler_e,  0x1400, 0x147c);
94     ARRAY_AT(u32_t, ispendr_e,    0x1600, 0x167c);
95     ARRAY_AT(u32_t, icpendr_e,    0x1800, 0x187c);
96     ARRAY_AT(u32_t, isactiver_e,  0x1a00, 0x1a7c);
97     ARRAY_AT(u32_t, icactiver_e,  0x1c00, 0x1c7c);
98     ARRAY_AT(u32_t, ipriorityr_e, 0x2000, 0x23fc);
99     ARRAY_AT(u32_t, icfgr_e,      0x3000, 0x30fc);
100     ARRAY_AT(u32_t, igrpmodr_e,   0x3400, 0x347c);
101     ARRAY_AT(u32_t, inmir_e,      0x3b00, 0x3b7c);
102
103     ARRAY_AT(u64_t, irouter,      0x6100, 0x7fd8);
104     ARRAY_AT(u64_t, irouter_e,    0x8000, 0x9ffc);
105 } compact;
106
107 union v3_gicc_regs
108 {
109     FIELD_AT(u32_t, ctlr,         0x0000        );
110     FIELD_AT(u32_t, pmr,          0x0004        );
111     FIELD_AT(u32_t, bpr,          0x0008        );
112     FIELD_AT(u32_t, iar,          0x000c        );
113     FIELD_AT(u32_t, eoir,         0x0010        );
114     FIELD_AT(u32_t, ppr,          0x0014        );
115
116     FIELD_AT(u32_t, iidr,         0x00fc        );
117     FIELD_AT(u32_t, dir,          0x1000        );
118 } compact;
119
120 union v3_its_regs
121 {
122     FIELD_AT(u32_t, ctlr,         0x0000        );
123     FIELD_AT(u32_t, iidr,         0x0004        );
124     FIELD_AT(u32_t, typer,        0x0008        );
125     FIELD_AT(u64_t, cbaser,       0x0080        );
126     FIELD_AT(u64_t, cwriter,      0x0088        );
127     FIELD_AT(u64_t, creadr,       0x0090        );
128     ARRAY_AT(u64_t, basern,       0x0100, 0x0138);
129 } compact;
130
131 union v3_its_translation
132 {
133     FIELD_AT(u32_t, translater,   0x0040        );
134 } compact;
135
136 union v3_reg_map
137 {
138     ptr_t reg_ptrs;
139     union v3_rdbase_map*    red;
140     union v3_sgibase_map*   red_sgi;
141     union v3_gicd_map*      distr;
142     union v3_gicc_map*      icc;
143 };
144
145 struct v3_pe
146 {
147     ptr_t rd_base;
148     
149     union {
150         ptr_t red_ptr;
151         union v3_rdbase_map* gicr;
152     };
153
154     union {
155         ptr_t sgi_ptr;
156         union v3_rdbase_map* gicr_sgi;
157     };
158
159     union {
160         struct {
161             bool direct_lpi:1;
162         };
163         int flags;
164     };
165
166     union {
167         ptr_t lpi_tab_ptr;
168         u8_t* lpi_tab;
169     };
170
171     struct gic_pe* pe;
172 };
173
174 struct v3_itt_alloc
175 {
176     ptr_t page;
177     u8_t free_map[PAGE_SIZE / 256 / 8];
178 };
179
180 struct v3_its_cmd
181 {
182     union {
183         struct {
184             u64_t dw0;
185             u64_t dw1;
186             u64_t dw2;
187             u64_t dw3;
188         };
189         u64_t dws[4];
190     };
191 } compact;
192
193 struct v3_its
194 {
195     union {
196         ptr_t base_ptr;
197         union v3_its_regs* gits;
198     };
199
200     union {
201         ptr_t trns_phys_ptr;
202         union v3_its_translation* gtrn;
203     };
204
205     struct v3_itt_alloc itt_alloc;
206
207     size_t cmdq_size;
208     struct v3_its_cmd *cmdq;
209
210     struct gic* gic;
211 };
212
213
214 struct v3_distr
215 {
216     union {
217         ptr_t dist_ptr;
218         union v3_gicd_map* gicd;
219     };
220
221     struct gic* gic;
222 };
223
224 #define v3distr(gic)  ((struct v3_distr*)(gic)->impl)
225 #define v3pe(pe)  ((struct v3_pe*)(pe)->impl)
226
227 #define v3distr_class(class)  v3distr(gic_global_context_of(class))
228 #define v3pe_class(local_class)  v3distr(gic_local_context_of(local_class))
229
230 #endif /* __LUNAIX_V3_H */