blob: 473fdb15bf78d276b522c767f5dde638d8cfbc6b [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Soby Mathew50f6fe42016-02-01 17:59:22 +00002 * Copyright (c) 2015-2016, 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
10#include <gicv3.h>
11#include <mmio.h>
12#include <stdint.h>
13
14/*******************************************************************************
15 * GICv3 private macro definitions
16 ******************************************************************************/
17
18/* Constants to indicate the status of the RWP bit */
19#define RWP_TRUE 1
20#define RWP_FALSE 0
21
22/*
23 * Macro to wait for updates to :
24 * GICD_CTLR[2:0] - the Group Enables
25 * GICD_CTLR[5:4] - the ARE bits
26 * GICD_ICENABLERn - the clearing of enable state for SPIs
27 */
28#define gicd_wait_for_pending_write(gicd_base) \
29 do { \
30 ; \
31 } while (gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT)
32
33/*
34 * Macro to convert an mpidr to a value suitable for programming into a
35 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
36 * to GICv3.
37 */
38#define gicd_irouter_val_from_mpidr(mpidr, irm) \
39 ((mpidr & ~(0xff << 24)) | \
40 (irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT)
41
42/*
43 * Macro to wait for updates to :
44 * GICR_ICENABLER0
45 * GICR_CTLR.DPG1S
46 * GICR_CTLR.DPG1NS
47 * GICR_CTLR.DPG0
48 */
49#define gicr_wait_for_pending_write(gicr_base) \
50 do { \
51 ; \
52 } while (gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT)
53
54/*
55 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
56 * are zeroes.
57 */
Soby Mathewd6452322016-05-05 13:59:07 +010058#ifdef AARCH32
59#define mpidr_from_gicr_typer(typer_val) (((typer_val) >> 32) & 0xffffff)
60#else
Achin Gupta92712a52015-09-03 14:18:02 +010061#define mpidr_from_gicr_typer(typer_val) \
Soby Mathewd6452322016-05-05 13:59:07 +010062 (((((typer_val) >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) | \
63 (((typer_val) >> 32) & 0xffffff))
64#endif
Achin Gupta92712a52015-09-03 14:18:02 +010065
66/*******************************************************************************
Soby Mathew50f6fe42016-02-01 17:59:22 +000067 * Private GICv3 function prototypes for accessing entire registers.
68 * Note: The raw register values correspond to multiple interrupt IDs and
69 * the number of interrupt IDs involved depends on the register accessed.
Achin Gupta92712a52015-09-03 14:18:02 +010070 ******************************************************************************/
71unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
72unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +000073void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
74void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
75
76/*******************************************************************************
77 * Private GICv3 function prototypes for accessing the GIC registers
78 * corresponding to a single interrupt ID. These functions use bitwise
79 * operations or appropriate register accesses to modify or return
80 * the bit-field corresponding the single interrupt ID.
81 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +010082unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
83unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id);
84unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +010085void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
86void gicr_set_igrpmodr0(uintptr_t base, unsigned int id);
87void gicr_set_isenabler0(uintptr_t base, unsigned int id);
88void gicr_set_igroupr0(uintptr_t base, unsigned int id);
89void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
90void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id);
91void gicr_clr_igroupr0(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +000092void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
93
94/*******************************************************************************
95 * Private GICv3 helper function prototypes
96 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +010097void gicv3_spis_configure_defaults(uintptr_t gicd_base);
98void gicv3_ppi_sgi_configure_defaults(uintptr_t gicr_base);
99void gicv3_secure_spis_configure(uintptr_t gicd_base,
100 unsigned int num_ints,
101 const unsigned int *sec_intr_list,
102 unsigned int int_grp);
103void gicv3_secure_ppi_sgi_configure(uintptr_t gicr_base,
104 unsigned int num_ints,
105 const unsigned int *sec_intr_list,
106 unsigned int int_grp);
107void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
108 unsigned int rdistif_num,
109 uintptr_t gicr_base,
110 mpidr_hash_fn mpidr_to_core_pos);
111void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
112void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
113
114/*******************************************************************************
115 * GIC Distributor interface accessors
116 ******************************************************************************/
117static inline unsigned int gicd_read_pidr2(uintptr_t base)
118{
119 return mmio_read_32(base + GICD_PIDR2_GICV3);
120}
121
122static inline unsigned long long gicd_read_irouter(uintptr_t base, unsigned int id)
123{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100124 assert(id >= MIN_SPI_ID);
Achin Gupta92712a52015-09-03 14:18:02 +0100125 return mmio_read_64(base + GICD_IROUTER + (id << 3));
126}
127
128static inline void gicd_write_irouter(uintptr_t base,
129 unsigned int id,
130 unsigned long long affinity)
131{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100132 assert(id >= MIN_SPI_ID);
Achin Gupta92712a52015-09-03 14:18:02 +0100133 mmio_write_64(base + GICD_IROUTER + (id << 3), affinity);
134}
135
136static inline void gicd_clr_ctlr(uintptr_t base,
137 unsigned int bitmap,
138 unsigned int rwp)
139{
140 gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
141 if (rwp)
142 gicd_wait_for_pending_write(base);
143}
144
145static inline void gicd_set_ctlr(uintptr_t base,
146 unsigned int bitmap,
147 unsigned int rwp)
148{
149 gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
150 if (rwp)
151 gicd_wait_for_pending_write(base);
152}
153
154/*******************************************************************************
155 * GIC Redistributor interface accessors
156 ******************************************************************************/
157static inline unsigned long long gicr_read_ctlr(uintptr_t base)
158{
159 return mmio_read_64(base + GICR_CTLR);
160}
161
162static inline unsigned long long gicr_read_typer(uintptr_t base)
163{
164 return mmio_read_64(base + GICR_TYPER);
165}
166
167static inline unsigned int gicr_read_waker(uintptr_t base)
168{
169 return mmio_read_32(base + GICR_WAKER);
170}
171
172static inline void gicr_write_waker(uintptr_t base, unsigned int val)
173{
174 mmio_write_32(base + GICR_WAKER, val);
175}
176
Soby Mathew50f6fe42016-02-01 17:59:22 +0000177/*******************************************************************************
178 * GIC Re-distributor functions for accessing entire registers.
179 * Note: The raw register values correspond to multiple interrupt IDs and
180 * the number of interrupt IDs involved depends on the register accessed.
181 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100182static inline unsigned int gicr_read_icenabler0(uintptr_t base)
183{
184 return mmio_read_32(base + GICR_ICENABLER0);
185}
186
187static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
188{
189 mmio_write_32(base + GICR_ICENABLER0, val);
190}
191
192static inline unsigned int gicr_read_isenabler0(uintptr_t base)
193{
194 return mmio_read_32(base + GICR_ISENABLER0);
195}
196
197static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
198{
199 mmio_write_32(base + GICR_ISENABLER0, val);
200}
201
202static inline unsigned int gicr_read_igroupr0(uintptr_t base)
203{
204 return mmio_read_32(base + GICR_IGROUPR0);
205}
206
207static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
208{
209 mmio_write_32(base + GICR_IGROUPR0, val);
210}
211
212static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
213{
214 return mmio_read_32(base + GICR_IGRPMODR0);
215}
216
217static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
218{
219 mmio_write_32(base + GICR_IGRPMODR0, val);
220}
221
222static inline unsigned int gicr_read_icfgr1(uintptr_t base)
223{
224 return mmio_read_32(base + GICR_ICFGR1);
225}
226
227static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
228{
229 mmio_write_32(base + GICR_ICFGR1, val);
230}
231
232#endif /* __GICV3_PRIVATE_H__ */