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