blob: 85231ad9d727d2d643e485b6f950e7123b735955 [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Roberto Vargas2ca18d92018-02-12 12:36:17 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Achin Gupta92712a52015-09-03 14:18:02 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta92712a52015-09-03 14:18:02 +01005 */
6
7#ifndef __GICV3_PRIVATE_H__
8#define __GICV3_PRIVATE_H__
9
Soby Mathew327548c2017-07-13 15:19:51 +010010#include <assert.h>
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000011#include <gic_common.h>
Achin Gupta92712a52015-09-03 14:18:02 +010012#include <gicv3.h>
13#include <mmio.h>
14#include <stdint.h>
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000015#include "../common/gic_common_private.h"
Achin Gupta92712a52015-09-03 14:18:02 +010016
17/*******************************************************************************
18 * GICv3 private macro definitions
19 ******************************************************************************/
20
21/* Constants to indicate the status of the RWP bit */
Antonio Nino Diaz2e590712018-08-24 11:46:33 +010022#define RWP_TRUE U(1)
23#define RWP_FALSE U(0)
Achin Gupta92712a52015-09-03 14:18:02 +010024
25/*
Achin Gupta92712a52015-09-03 14:18:02 +010026 * Macro to convert an mpidr to a value suitable for programming into a
27 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
28 * to GICv3.
29 */
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +010030static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
31 unsigned int irm)
32{
33 return (mpidr & ~(U(0xff) << 24)) |
34 ((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
35}
Achin Gupta92712a52015-09-03 14:18:02 +010036
37/*
Achin Gupta92712a52015-09-03 14:18:02 +010038 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
39 * are zeroes.
40 */
Soby Mathewd6452322016-05-05 13:59:07 +010041#ifdef AARCH32
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +010042static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
43{
44 return (((typer_val) >> 32) & U(0xffffff));
45}
Soby Mathewd6452322016-05-05 13:59:07 +010046#else
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +010047static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
48{
49 return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
50 ((typer_val >> 32) & U(0xffffff));
51}
Soby Mathewd6452322016-05-05 13:59:07 +010052#endif
Achin Gupta92712a52015-09-03 14:18:02 +010053
54/*******************************************************************************
Soby Mathew327548c2017-07-13 15:19:51 +010055 * GICv3 private global variables declarations
56 ******************************************************************************/
57extern const gicv3_driver_data_t *gicv3_driver_data;
58
59/*******************************************************************************
Soby Mathew50f6fe42016-02-01 17:59:22 +000060 * Private GICv3 function prototypes for accessing entire registers.
61 * Note: The raw register values correspond to multiple interrupt IDs and
62 * the number of interrupt IDs involved depends on the register accessed.
Achin Gupta92712a52015-09-03 14:18:02 +010063 ******************************************************************************/
64unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
65unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +000066void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
67void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
68
69/*******************************************************************************
70 * Private GICv3 function prototypes for accessing the GIC registers
71 * corresponding to a single interrupt ID. These functions use bitwise
72 * operations or appropriate register accesses to modify or return
73 * the bit-field corresponding the single interrupt ID.
74 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +010075unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
76unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id);
77unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id);
Jeenu Viswambharan24e70292017-09-22 08:32:09 +010078unsigned int gicr_get_isactiver0(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +010079void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
80void gicr_set_igrpmodr0(uintptr_t base, unsigned int id);
81void gicr_set_isenabler0(uintptr_t base, unsigned int id);
Jeenu Viswambharan0fcdfff2017-09-22 08:32:09 +010082void gicr_set_icenabler0(uintptr_t base, unsigned int id);
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +010083void gicr_set_ispendr0(uintptr_t base, unsigned int id);
84void gicr_set_icpendr0(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +010085void gicr_set_igroupr0(uintptr_t base, unsigned int id);
86void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
87void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id);
88void gicr_clr_igroupr0(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +000089void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
Roberto Vargas2ca18d92018-02-12 12:36:17 +000090void gicr_set_icfgr0(uintptr_t base, unsigned int id, unsigned int cfg);
91void gicr_set_icfgr1(uintptr_t base, unsigned int id, unsigned int cfg);
Soby Mathew50f6fe42016-02-01 17:59:22 +000092
93/*******************************************************************************
94 * Private GICv3 helper function prototypes
95 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +010096void gicv3_spis_config_defaults(uintptr_t gicd_base);
97void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
Daniel Boulby4e83abb2018-05-01 15:15:34 +010098unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +010099 const interrupt_prop_t *interrupt_props,
100 unsigned int interrupt_props_num);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100101unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100102 const interrupt_prop_t *interrupt_props,
103 unsigned int interrupt_props_num);
Achin Gupta92712a52015-09-03 14:18:02 +0100104void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
105 unsigned int rdistif_num,
106 uintptr_t gicr_base,
107 mpidr_hash_fn mpidr_to_core_pos);
108void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
109void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
110
111/*******************************************************************************
112 * GIC Distributor interface accessors
113 ******************************************************************************/
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100114/*
115 * Wait for updates to :
116 * GICD_CTLR[2:0] - the Group Enables
117 * GICD_CTLR[5:4] - the ARE bits
118 * GICD_ICENABLERn - the clearing of enable state for SPIs
119 */
120static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
121{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100122 while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U)
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100123 ;
124}
125
Achin Gupta92712a52015-09-03 14:18:02 +0100126static inline unsigned int gicd_read_pidr2(uintptr_t base)
127{
128 return mmio_read_32(base + GICD_PIDR2_GICV3);
129}
130
131static inline unsigned long long gicd_read_irouter(uintptr_t base, unsigned int id)
132{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100133 assert(id >= MIN_SPI_ID);
Achin Gupta92712a52015-09-03 14:18:02 +0100134 return mmio_read_64(base + GICD_IROUTER + (id << 3));
135}
136
137static inline void gicd_write_irouter(uintptr_t base,
138 unsigned int id,
139 unsigned long long affinity)
140{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100141 assert(id >= MIN_SPI_ID);
Achin Gupta92712a52015-09-03 14:18:02 +0100142 mmio_write_64(base + GICD_IROUTER + (id << 3), affinity);
143}
144
145static inline void gicd_clr_ctlr(uintptr_t base,
146 unsigned int bitmap,
147 unsigned int rwp)
148{
149 gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100150 if (rwp != 0U)
Achin Gupta92712a52015-09-03 14:18:02 +0100151 gicd_wait_for_pending_write(base);
152}
153
154static inline void gicd_set_ctlr(uintptr_t base,
155 unsigned int bitmap,
156 unsigned int rwp)
157{
158 gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100159 if (rwp != 0U)
Achin Gupta92712a52015-09-03 14:18:02 +0100160 gicd_wait_for_pending_write(base);
161}
162
163/*******************************************************************************
164 * GIC Redistributor interface accessors
165 ******************************************************************************/
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100166static inline uint32_t gicr_read_ctlr(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100167{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100168 return mmio_read_32(base + GICR_CTLR);
Achin Gupta92712a52015-09-03 14:18:02 +0100169}
170
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100171static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100172{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100173 mmio_write_32(base + GICR_CTLR, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100174}
175
Achin Gupta92712a52015-09-03 14:18:02 +0100176static inline unsigned long long gicr_read_typer(uintptr_t base)
177{
178 return mmio_read_64(base + GICR_TYPER);
179}
180
181static inline unsigned int gicr_read_waker(uintptr_t base)
182{
183 return mmio_read_32(base + GICR_WAKER);
184}
185
186static inline void gicr_write_waker(uintptr_t base, unsigned int val)
187{
188 mmio_write_32(base + GICR_WAKER, val);
189}
190
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100191/*
192 * Wait for updates to :
193 * GICR_ICENABLER0
194 * GICR_CTLR.DPG1S
195 * GICR_CTLR.DPG1NS
196 * GICR_CTLR.DPG0
197 */
198static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
199{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100200 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U)
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100201 ;
202}
203
Soby Mathew327548c2017-07-13 15:19:51 +0100204static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
205{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100206 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U)
Soby Mathew327548c2017-07-13 15:19:51 +0100207 ;
208}
209
210/* Private implementation of Distributor power control hooks */
211void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
212void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);
213
Soby Mathew50f6fe42016-02-01 17:59:22 +0000214/*******************************************************************************
215 * GIC Re-distributor functions for accessing entire registers.
216 * Note: The raw register values correspond to multiple interrupt IDs and
217 * the number of interrupt IDs involved depends on the register accessed.
218 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100219static inline unsigned int gicr_read_icenabler0(uintptr_t base)
220{
221 return mmio_read_32(base + GICR_ICENABLER0);
222}
223
224static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
225{
226 mmio_write_32(base + GICR_ICENABLER0, val);
227}
228
229static inline unsigned int gicr_read_isenabler0(uintptr_t base)
230{
231 return mmio_read_32(base + GICR_ISENABLER0);
232}
233
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100234static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
235{
236 mmio_write_32(base + GICR_ICPENDR0, val);
237}
238
Achin Gupta92712a52015-09-03 14:18:02 +0100239static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
240{
241 mmio_write_32(base + GICR_ISENABLER0, val);
242}
243
244static inline unsigned int gicr_read_igroupr0(uintptr_t base)
245{
246 return mmio_read_32(base + GICR_IGROUPR0);
247}
248
Soby Mathew327548c2017-07-13 15:19:51 +0100249static inline unsigned int gicr_read_ispendr0(uintptr_t base)
250{
251 return mmio_read_32(base + GICR_ISPENDR0);
252}
253
254static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
255{
256 mmio_write_32(base + GICR_ISPENDR0, val);
257}
258
Achin Gupta92712a52015-09-03 14:18:02 +0100259static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
260{
261 mmio_write_32(base + GICR_IGROUPR0, val);
262}
263
264static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
265{
266 return mmio_read_32(base + GICR_IGRPMODR0);
267}
268
269static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
270{
271 mmio_write_32(base + GICR_IGRPMODR0, val);
272}
273
Soby Mathew327548c2017-07-13 15:19:51 +0100274static inline unsigned int gicr_read_nsacr(uintptr_t base)
275{
276 return mmio_read_32(base + GICR_NSACR);
277}
278
279static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
280{
281 mmio_write_32(base + GICR_NSACR, val);
282}
283
284static inline unsigned int gicr_read_isactiver0(uintptr_t base)
285{
286 return mmio_read_32(base + GICR_ISACTIVER0);
287}
288
289static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
290{
291 mmio_write_32(base + GICR_ISACTIVER0, val);
292}
293
294static inline unsigned int gicr_read_icfgr0(uintptr_t base)
295{
296 return mmio_read_32(base + GICR_ICFGR0);
297}
298
Achin Gupta92712a52015-09-03 14:18:02 +0100299static inline unsigned int gicr_read_icfgr1(uintptr_t base)
300{
301 return mmio_read_32(base + GICR_ICFGR1);
302}
303
Soby Mathew327548c2017-07-13 15:19:51 +0100304static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
305{
306 mmio_write_32(base + GICR_ICFGR0, val);
307}
308
Achin Gupta92712a52015-09-03 14:18:02 +0100309static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
310{
311 mmio_write_32(base + GICR_ICFGR1, val);
312}
313
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100314static inline uint64_t gicr_read_propbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100315{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100316 return mmio_read_64(base + GICR_PROPBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100317}
318
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100319static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100320{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100321 mmio_write_64(base + GICR_PROPBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100322}
323
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100324static inline uint64_t gicr_read_pendbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100325{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100326 return mmio_read_64(base + GICR_PENDBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100327}
328
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100329static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100330{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100331 mmio_write_64(base + GICR_PENDBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100332}
333
Soby Mathewf6f1a322017-07-18 16:12:45 +0100334/*******************************************************************************
335 * GIC ITS functions to read and write entire ITS registers.
336 ******************************************************************************/
337static inline uint32_t gits_read_ctlr(uintptr_t base)
338{
339 return mmio_read_32(base + GITS_CTLR);
340}
341
342static inline void gits_write_ctlr(uintptr_t base, unsigned int val)
343{
344 mmio_write_32(base + GITS_CTLR, val);
345}
346
347static inline uint64_t gits_read_cbaser(uintptr_t base)
348{
349 return mmio_read_64(base + GITS_CBASER);
350}
351
352static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
353{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100354 mmio_write_64(base + GITS_CBASER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100355}
356
357static inline uint64_t gits_read_cwriter(uintptr_t base)
358{
359 return mmio_read_64(base + GITS_CWRITER);
360}
361
362static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
363{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100364 mmio_write_64(base + GITS_CWRITER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100365}
366
367static inline uint64_t gits_read_baser(uintptr_t base, unsigned int its_table_id)
368{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100369 assert(its_table_id < 8U);
370 return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
Soby Mathewf6f1a322017-07-18 16:12:45 +0100371}
372
373static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id, uint64_t val)
374{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100375 assert(its_table_id < 8U);
376 mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100377}
378
379/*
380 * Wait for Quiescent bit when GIC ITS is disabled
381 */
382static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
383{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100384 assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
385 while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100386 ;
387}
388
389
Achin Gupta92712a52015-09-03 14:18:02 +0100390#endif /* __GICV3_PRIVATE_H__ */