gicv3_private.h 12.1 KB
Newer Older
1
/*
Roberto Vargas's avatar
Roberto Vargas committed
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
8
9
 */

#ifndef __GICV3_PRIVATE_H__
#define __GICV3_PRIVATE_H__

10
#include <assert.h>
11
#include <gic_common.h>
12
13
14
#include <gicv3.h>
#include <mmio.h>
#include <stdint.h>
15
#include "../common/gic_common_private.h"
16
17
18
19
20
21

/*******************************************************************************
 * GICv3 private macro definitions
 ******************************************************************************/

/* Constants to indicate the status of the RWP bit */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
22
23
#define RWP_TRUE		U(1)
#define RWP_FALSE		U(0)
24
25
26
27
28
29

/*
 * Macro to convert an mpidr to a value suitable for programming into a
 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
 * to GICv3.
 */
30
31
32
33
34
35
static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
						       unsigned int irm)
{
	return (mpidr & ~(U(0xff) << 24)) |
		((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
}
36
37
38
39
40

/*
 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
 * are zeroes.
 */
41
#ifdef AARCH32
42
43
44
45
static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
{
	return (((typer_val) >> 32) & U(0xffffff));
}
46
#else
47
48
49
50
51
static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
{
	return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
		((typer_val >> 32) & U(0xffffff));
}
52
#endif
53

54
55
56
57
58
/*******************************************************************************
 * GICv3 private global variables declarations
 ******************************************************************************/
extern const gicv3_driver_data_t *gicv3_driver_data;

59
/*******************************************************************************
60
61
62
 * Private GICv3 function prototypes for accessing entire registers.
 * Note: The raw register values correspond to multiple interrupt IDs and
 * the number of interrupt IDs involved depends on the register accessed.
63
64
65
 ******************************************************************************/
unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
66
67
68
69
70
71
72
73
74
void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);

/*******************************************************************************
 * Private GICv3 function prototypes for accessing the GIC registers
 * corresponding to a single interrupt ID. These functions use bitwise
 * operations or appropriate register accesses to modify or return
 * the bit-field corresponding the single interrupt ID.
 ******************************************************************************/
75
76
77
unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id);
unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id);
78
unsigned int gicr_get_isactiver0(uintptr_t base, unsigned int id);
79
80
81
void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
void gicr_set_igrpmodr0(uintptr_t base, unsigned int id);
void gicr_set_isenabler0(uintptr_t base, unsigned int id);
82
void gicr_set_icenabler0(uintptr_t base, unsigned int id);
83
84
void gicr_set_ispendr0(uintptr_t base, unsigned int id);
void gicr_set_icpendr0(uintptr_t base, unsigned int id);
85
86
87
88
void gicr_set_igroupr0(uintptr_t base, unsigned int id);
void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id);
void gicr_clr_igroupr0(uintptr_t base, unsigned int id);
89
void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
Roberto Vargas's avatar
Roberto Vargas committed
90
91
void gicr_set_icfgr0(uintptr_t base, unsigned int id, unsigned int cfg);
void gicr_set_icfgr1(uintptr_t base, unsigned int id, unsigned int cfg);
92
93
94
95

/*******************************************************************************
 * Private GICv3 helper function prototypes
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
96
97
void gicv3_spis_config_defaults(uintptr_t gicd_base);
void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
98
#if !ERROR_DEPRECATED
Daniel Boulby's avatar
Daniel Boulby committed
99
void gicv3_secure_spis_config(uintptr_t gicd_base,
100
101
102
				     unsigned int num_ints,
				     const unsigned int *sec_intr_list,
				     unsigned int int_grp);
Daniel Boulby's avatar
Daniel Boulby committed
103
void gicv3_secure_ppi_sgi_config(uintptr_t gicr_base,
104
105
106
					unsigned int num_ints,
					const unsigned int *sec_intr_list,
					unsigned int int_grp);
107
#endif
Daniel Boulby's avatar
Daniel Boulby committed
108
unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
109
110
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num);
Daniel Boulby's avatar
Daniel Boulby committed
111
unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
112
113
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num);
114
115
116
117
118
119
120
121
122
123
void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
					unsigned int rdistif_num,
					uintptr_t gicr_base,
					mpidr_hash_fn mpidr_to_core_pos);
void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);

/*******************************************************************************
 * GIC Distributor interface accessors
 ******************************************************************************/
124
125
126
127
128
129
130
131
/*
 * Wait for updates to :
 * GICD_CTLR[2:0] - the Group Enables
 * GICD_CTLR[5:4] - the ARE bits
 * GICD_ICENABLERn - the clearing of enable state for SPIs
 */
static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
132
	while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U)
133
134
135
		;
}

136
137
138
139
140
141
142
static inline unsigned int gicd_read_pidr2(uintptr_t base)
{
	return mmio_read_32(base + GICD_PIDR2_GICV3);
}

static inline unsigned long long gicd_read_irouter(uintptr_t base, unsigned int id)
{
143
	assert(id >= MIN_SPI_ID);
144
145
146
147
148
149
150
	return mmio_read_64(base + GICD_IROUTER + (id << 3));
}

static inline void gicd_write_irouter(uintptr_t base,
				      unsigned int id,
				      unsigned long long affinity)
{
151
	assert(id >= MIN_SPI_ID);
152
153
154
155
156
157
158
159
	mmio_write_64(base + GICD_IROUTER + (id << 3), affinity);
}

static inline void gicd_clr_ctlr(uintptr_t base,
				 unsigned int bitmap,
				 unsigned int rwp)
{
	gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
160
	if (rwp != 0U)
161
162
163
164
165
166
167
168
		gicd_wait_for_pending_write(base);
}

static inline void gicd_set_ctlr(uintptr_t base,
				 unsigned int bitmap,
				 unsigned int rwp)
{
	gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
169
	if (rwp != 0U)
170
171
172
173
174
175
		gicd_wait_for_pending_write(base);
}

/*******************************************************************************
 * GIC Redistributor interface accessors
 ******************************************************************************/
176
static inline uint32_t gicr_read_ctlr(uintptr_t base)
177
{
178
	return mmio_read_32(base + GICR_CTLR);
179
180
}

181
static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
182
{
183
	mmio_write_32(base + GICR_CTLR, val);
184
185
}

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
static inline unsigned long long gicr_read_typer(uintptr_t base)
{
	return mmio_read_64(base + GICR_TYPER);
}

static inline unsigned int gicr_read_waker(uintptr_t base)
{
	return mmio_read_32(base + GICR_WAKER);
}

static inline void gicr_write_waker(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_WAKER, val);
}

201
202
203
204
205
206
207
208
209
/*
 * Wait for updates to :
 * GICR_ICENABLER0
 * GICR_CTLR.DPG1S
 * GICR_CTLR.DPG1NS
 * GICR_CTLR.DPG0
 */
static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
210
	while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U)
211
212
213
		;
}

214
215
static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
216
	while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U)
217
218
219
220
221
222
223
		;
}

/* Private implementation of Distributor power control hooks */
void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);

224
225
226
227
228
/*******************************************************************************
 * GIC Re-distributor functions for accessing entire registers.
 * Note: The raw register values correspond to multiple interrupt IDs and
 * the number of interrupt IDs involved depends on the register accessed.
 ******************************************************************************/
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
static inline unsigned int gicr_read_icenabler0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICENABLER0);
}

static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICENABLER0, val);
}

static inline unsigned int gicr_read_isenabler0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISENABLER0);
}

244
245
246
247
248
static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICPENDR0, val);
}

249
250
251
252
253
254
255
256
257
258
static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISENABLER0, val);
}

static inline unsigned int gicr_read_igroupr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_IGROUPR0);
}

259
260
261
262
263
264
265
266
267
268
static inline unsigned int gicr_read_ispendr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISPENDR0);
}

static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISPENDR0, val);
}

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_IGROUPR0, val);
}

static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_IGRPMODR0);
}

static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_IGRPMODR0, val);
}

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
static inline unsigned int gicr_read_nsacr(uintptr_t base)
{
	return mmio_read_32(base + GICR_NSACR);
}

static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_NSACR, val);
}

static inline unsigned int gicr_read_isactiver0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISACTIVER0);
}

static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISACTIVER0, val);
}

static inline unsigned int gicr_read_icfgr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICFGR0);
}

309
310
311
312
313
static inline unsigned int gicr_read_icfgr1(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICFGR1);
}

314
315
316
317
318
static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICFGR0, val);
}

319
320
321
322
323
static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICFGR1, val);
}

324
static inline uint64_t gicr_read_propbaser(uintptr_t base)
325
{
326
	return mmio_read_64(base + GICR_PROPBASER);
327
328
}

329
static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
330
{
331
	mmio_write_64(base + GICR_PROPBASER, val);
332
333
}

334
static inline uint64_t gicr_read_pendbaser(uintptr_t base)
335
{
336
	return mmio_read_64(base + GICR_PENDBASER);
337
338
}

339
static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
340
{
341
	mmio_write_64(base + GICR_PENDBASER, val);
342
343
}

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*******************************************************************************
 * GIC ITS functions to read and write entire ITS registers.
 ******************************************************************************/
static inline uint32_t gits_read_ctlr(uintptr_t base)
{
	return mmio_read_32(base + GITS_CTLR);
}

static inline void gits_write_ctlr(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GITS_CTLR, val);
}

static inline uint64_t gits_read_cbaser(uintptr_t base)
{
	return mmio_read_64(base + GITS_CBASER);
}

static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
{
364
	mmio_write_64(base + GITS_CBASER, val);
365
366
367
368
369
370
371
372
373
}

static inline uint64_t gits_read_cwriter(uintptr_t base)
{
	return mmio_read_64(base + GITS_CWRITER);
}

static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
{
374
	mmio_write_64(base + GITS_CWRITER, val);
375
376
377
378
}

static inline uint64_t gits_read_baser(uintptr_t base, unsigned int its_table_id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
379
380
	assert(its_table_id < 8U);
	return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
381
382
383
384
}

static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id, uint64_t val)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
385
386
	assert(its_table_id < 8U);
	mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
387
388
389
390
391
392
393
}

/*
 * Wait for Quiescent bit when GIC ITS is disabled
 */
static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
394
395
	assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
	while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U)
396
397
398
399
		;
}


400
#endif /* __GICV3_PRIVATE_H__ */