arm-gic-v3.h 25.2 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-only */
2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2013, 2014 ARM Limited, All Rights Reserved.
 * Author: Marc Zyngier <marc.zyngier@arm.com>
 */
#ifndef __LINUX_IRQCHIP_ARM_GIC_V3_H
#define __LINUX_IRQCHIP_ARM_GIC_V3_H

/*
 * Distributor registers. We assume we're running non-secure, with ARE
 * being set. Secure-only and non-ARE registers are not described.
 */
#define GICD_CTLR			0x0000
#define GICD_TYPER			0x0004
#define GICD_IIDR			0x0008
16
#define GICD_TYPER2			0x000C
17 18 19 20 21 22
#define GICD_STATUSR			0x0010
#define GICD_SETSPI_NSR			0x0040
#define GICD_CLRSPI_NSR			0x0048
#define GICD_SETSPI_SR			0x0050
#define GICD_CLRSPI_SR			0x0058
#define GICD_SEIR			0x0068
23
#define GICD_IGROUPR			0x0080
24 25 26 27 28 29 30 31
#define GICD_ISENABLER			0x0100
#define GICD_ICENABLER			0x0180
#define GICD_ISPENDR			0x0200
#define GICD_ICPENDR			0x0280
#define GICD_ISACTIVER			0x0300
#define GICD_ICACTIVER			0x0380
#define GICD_IPRIORITYR			0x0400
#define GICD_ICFGR			0x0C00
32 33
#define GICD_IGRPMODR			0x0D00
#define GICD_NSACR			0x0E00
34 35 36 37 38 39 40 41 42
#define GICD_IGROUPRnE			0x1000
#define GICD_ISENABLERnE		0x1200
#define GICD_ICENABLERnE		0x1400
#define GICD_ISPENDRnE			0x1600
#define GICD_ICPENDRnE			0x1800
#define GICD_ISACTIVERnE		0x1A00
#define GICD_ICACTIVERnE		0x1C00
#define GICD_IPRIORITYRnE		0x2000
#define GICD_ICFGRnE			0x3000
43
#define GICD_IROUTER			0x6000
44
#define GICD_IROUTERnE			0x8000
45
#define GICD_IDREGS			0xFFD0
46 47
#define GICD_PIDR2			0xFFE8

48 49
#define ESPI_BASE_INTID			4096

50 51 52 53 54 55 56 57 58
/*
 * Those registers are actually from GICv2, but the spec demands that they
 * are implemented as RES0 if ARE is 1 (which we do in KVM's emulated GICv3).
 */
#define GICD_ITARGETSR			0x0800
#define GICD_SGIR			0x0F00
#define GICD_CPENDSGIR			0x0F10
#define GICD_SPENDSGIR			0x0F20

59
#define GICD_CTLR_RWP			(1U << 31)
60
#define GICD_CTLR_DS			(1U << 6)
61 62 63 64
#define GICD_CTLR_ARE_NS		(1U << 4)
#define GICD_CTLR_ENABLE_G1A		(1U << 1)
#define GICD_CTLR_ENABLE_G1		(1U << 0)

65 66 67 68 69 70 71 72 73 74
#define GICD_IIDR_IMPLEMENTER_SHIFT	0
#define GICD_IIDR_IMPLEMENTER_MASK	(0xfff << GICD_IIDR_IMPLEMENTER_SHIFT)
#define GICD_IIDR_REVISION_SHIFT	12
#define GICD_IIDR_REVISION_MASK		(0xf << GICD_IIDR_REVISION_SHIFT)
#define GICD_IIDR_VARIANT_SHIFT		16
#define GICD_IIDR_VARIANT_MASK		(0xf << GICD_IIDR_VARIANT_SHIFT)
#define GICD_IIDR_PRODUCT_ID_SHIFT	24
#define GICD_IIDR_PRODUCT_ID_MASK	(0xff << GICD_IIDR_PRODUCT_ID_SHIFT)


75 76 77 78 79 80 81
/*
 * In systems with a single security state (what we emulate in KVM)
 * the meaning of the interrupt group enable bits is slightly different
 */
#define GICD_CTLR_ENABLE_SS_G1		(1U << 1)
#define GICD_CTLR_ENABLE_SS_G0		(1U << 0)

82
#define GICD_TYPER_RSS			(1U << 26)
83 84
#define GICD_TYPER_LPIS			(1U << 17)
#define GICD_TYPER_MBIS			(1U << 16)
85
#define GICD_TYPER_ESPI			(1U << 8)
86

87
#define GICD_TYPER_ID_BITS(typer)	((((typer) >> 19) & 0x1f) + 1)
88
#define GICD_TYPER_NUM_LPIS(typer)	((((typer) >> 11) & 0x1f) + 1)
89 90 91
#define GICD_TYPER_SPIS(typer)		((((typer) & 0x1f) + 1) * 32)
#define GICD_TYPER_ESPIS(typer)						\
	(((typer) & GICD_TYPER_ESPI) ? GICD_TYPER_SPIS((typer) >> 27) : 0)
92

93 94 95
#define GICD_TYPER2_VIL			(1U << 7)
#define GICD_TYPER2_VID			GENMASK(4, 0)

96 97 98 99 100 101 102
#define GICD_IROUTER_SPI_MODE_ONE	(0U << 31)
#define GICD_IROUTER_SPI_MODE_ANY	(1U << 31)

#define GIC_PIDR2_ARCH_MASK		0xf0
#define GIC_PIDR2_ARCH_GICv3		0x30
#define GIC_PIDR2_ARCH_GICv4		0x40

103 104
#define GIC_V3_DIST_SIZE		0x10000

105 106 107 108 109
#define GIC_PAGE_SIZE_4K		0ULL
#define GIC_PAGE_SIZE_16K		1ULL
#define GIC_PAGE_SIZE_64K		2ULL
#define GIC_PAGE_SIZE_MASK		3ULL

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
/*
 * Re-Distributor registers, offsets from RD_base
 */
#define GICR_CTLR			GICD_CTLR
#define GICR_IIDR			0x0004
#define GICR_TYPER			0x0008
#define GICR_STATUSR			GICD_STATUSR
#define GICR_WAKER			0x0014
#define GICR_SETLPIR			0x0040
#define GICR_CLRLPIR			0x0048
#define GICR_SEIR			GICD_SEIR
#define GICR_PROPBASER			0x0070
#define GICR_PENDBASER			0x0078
#define GICR_INVLPIR			0x00A0
#define GICR_INVALLR			0x00B0
#define GICR_SYNCR			0x00C0
#define GICR_MOVLPIR			0x0100
#define GICR_MOVALLR			0x0110
128
#define GICR_IDREGS			GICD_IDREGS
129 130
#define GICR_PIDR2			GICD_PIDR2

M
Marc Zyngier 已提交
131
#define GICR_CTLR_ENABLE_LPIS		(1UL << 0)
132
#define GICR_CTLR_RWP			(1UL << 3)
M
Marc Zyngier 已提交
133 134 135

#define GICR_TYPER_CPU_NUMBER(r)	(((r) >> 8) & 0xffff)

136 137 138 139 140 141 142 143 144 145 146 147
#define EPPI_BASE_INTID			1056

#define GICR_TYPER_NR_PPIS(r)						\
	({								\
		unsigned int __ppinum = ((r) >> 27) & 0x1f;		\
		unsigned int __nr_ppis = 16;				\
		if (__ppinum == 1 || __ppinum == 2)			\
			__nr_ppis +=  __ppinum * 32;			\
									\
		__nr_ppis;						\
	 })

148 149 150
#define GICR_WAKER_ProcessorSleep	(1U << 1)
#define GICR_WAKER_ChildrenAsleep	(1U << 2)

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
#define GIC_BASER_CACHE_nCnB		0ULL
#define GIC_BASER_CACHE_SameAsInner	0ULL
#define GIC_BASER_CACHE_nC		1ULL
#define GIC_BASER_CACHE_RaWt		2ULL
#define GIC_BASER_CACHE_RaWb		3ULL
#define GIC_BASER_CACHE_WaWt		4ULL
#define GIC_BASER_CACHE_WaWb		5ULL
#define GIC_BASER_CACHE_RaWaWt		6ULL
#define GIC_BASER_CACHE_RaWaWb		7ULL
#define GIC_BASER_CACHE_MASK		7ULL
#define GIC_BASER_NonShareable		0ULL
#define GIC_BASER_InnerShareable	1ULL
#define GIC_BASER_OuterShareable	2ULL
#define GIC_BASER_SHAREABILITY_MASK	3ULL

#define GIC_BASER_CACHEABILITY(reg, inner_outer, type)			\
	(GIC_BASER_CACHE_##type << reg##_##inner_outer##_CACHEABILITY_SHIFT)

#define GIC_BASER_SHAREABILITY(reg, type)				\
	(GIC_BASER_##type << reg##_SHAREABILITY_SHIFT)

172 173 174
/* encode a size field of width @w containing @n - 1 units */
#define GIC_ENCODE_SZ(n, w) (((unsigned long)(n) - 1) & GENMASK_ULL(((w) - 1), 0))

175 176 177 178 179 180 181 182 183 184 185 186 187
#define GICR_PROPBASER_SHAREABILITY_SHIFT		(10)
#define GICR_PROPBASER_INNER_CACHEABILITY_SHIFT		(7)
#define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT		(56)
#define GICR_PROPBASER_SHAREABILITY_MASK				\
	GIC_BASER_SHAREABILITY(GICR_PROPBASER, SHAREABILITY_MASK)
#define GICR_PROPBASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, MASK)
#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_PROPBASER, OUTER, MASK)
#define GICR_PROPBASER_CACHEABILITY_MASK GICR_PROPBASER_INNER_CACHEABILITY_MASK

#define GICR_PROPBASER_InnerShareable					\
	GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable)
188 189 190 191

#define GICR_PROPBASER_nCnB	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, nCnB)
#define GICR_PROPBASER_nC 	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, nC)
#define GICR_PROPBASER_RaWt	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, RaWt)
192
#define GICR_PROPBASER_RaWb	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, RaWb)
193 194 195 196 197
#define GICR_PROPBASER_WaWt	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, WaWt)
#define GICR_PROPBASER_WaWb	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, WaWb)
#define GICR_PROPBASER_RaWaWt	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, RaWaWt)
#define GICR_PROPBASER_RaWaWb	GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, RaWaWb)

198
#define GICR_PROPBASER_IDBITS_MASK			(0x1f)
199 200
#define GICR_PROPBASER_ADDRESS(x)	((x) & GENMASK_ULL(51, 12))
#define GICR_PENDBASER_ADDRESS(x)	((x) & GENMASK_ULL(51, 16))
201 202 203 204 205 206 207 208 209 210 211 212 213 214

#define GICR_PENDBASER_SHAREABILITY_SHIFT		(10)
#define GICR_PENDBASER_INNER_CACHEABILITY_SHIFT		(7)
#define GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT		(56)
#define GICR_PENDBASER_SHAREABILITY_MASK				\
	GIC_BASER_SHAREABILITY(GICR_PENDBASER, SHAREABILITY_MASK)
#define GICR_PENDBASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, MASK)
#define GICR_PENDBASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_PENDBASER, OUTER, MASK)
#define GICR_PENDBASER_CACHEABILITY_MASK GICR_PENDBASER_INNER_CACHEABILITY_MASK

#define GICR_PENDBASER_InnerShareable					\
	GIC_BASER_SHAREABILITY(GICR_PENDBASER, InnerShareable)
215 216 217 218

#define GICR_PENDBASER_nCnB	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, nCnB)
#define GICR_PENDBASER_nC 	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, nC)
#define GICR_PENDBASER_RaWt	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, RaWt)
219
#define GICR_PENDBASER_RaWb	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, RaWb)
220 221 222 223 224
#define GICR_PENDBASER_WaWt	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, WaWt)
#define GICR_PENDBASER_WaWb	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, WaWb)
#define GICR_PENDBASER_RaWaWt	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, RaWaWt)
#define GICR_PENDBASER_RaWaWb	GIC_BASER_CACHEABILITY(GICR_PENDBASER, INNER, RaWaWb)

225
#define GICR_PENDBASER_PTZ				BIT_ULL(62)
226

227 228 229
/*
 * Re-Distributor registers, offsets from SGI_base
 */
230
#define GICR_IGROUPR0			GICD_IGROUPR
231 232 233 234 235 236 237 238
#define GICR_ISENABLER0			GICD_ISENABLER
#define GICR_ICENABLER0			GICD_ICENABLER
#define GICR_ISPENDR0			GICD_ISPENDR
#define GICR_ICPENDR0			GICD_ICPENDR
#define GICR_ISACTIVER0			GICD_ISACTIVER
#define GICR_ICACTIVER0			GICD_ICACTIVER
#define GICR_IPRIORITYR0		GICD_IPRIORITYR
#define GICR_ICFGR0			GICD_ICFGR
239 240
#define GICR_IGRPMODR0			GICD_IGRPMODR
#define GICR_NSACR			GICD_NSACR
241

M
Marc Zyngier 已提交
242
#define GICR_TYPER_PLPIS		(1U << 0)
243
#define GICR_TYPER_VLPIS		(1U << 1)
244
#define GICR_TYPER_DirectLPIS		(1U << 3)
245
#define GICR_TYPER_LAST			(1U << 4)
246
#define GICR_TYPER_RVPEID		(1U << 7)
247 248
#define GICR_TYPER_COMMON_LPI_AFF	GENMASK_ULL(25, 24)
#define GICR_TYPER_AFFINITY		GENMASK_ULL(63, 32)
249

250
#define GICR_INVLPIR_INTID		GENMASK_ULL(31, 0)
251 252 253 254 255 256
#define GICR_INVLPIR_VPEID		GENMASK_ULL(47, 32)
#define GICR_INVLPIR_V			GENMASK_ULL(63, 63)

#define GICR_INVALLR_VPEID		GICR_INVLPIR_VPEID
#define GICR_INVALLR_V			GICR_INVLPIR_V

257 258
#define GIC_V3_REDIST_SIZE		0x20000

M
Marc Zyngier 已提交
259 260 261
#define LPI_PROP_GROUP1			(1 << 1)
#define LPI_PROP_ENABLED		(1 << 0)

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
/*
 * Re-Distributor registers, offsets from VLPI_base
 */
#define GICR_VPROPBASER			0x0070

#define GICR_VPROPBASER_IDBITS_MASK	0x1f

#define GICR_VPROPBASER_SHAREABILITY_SHIFT		(10)
#define GICR_VPROPBASER_INNER_CACHEABILITY_SHIFT	(7)
#define GICR_VPROPBASER_OUTER_CACHEABILITY_SHIFT	(56)

#define GICR_VPROPBASER_SHAREABILITY_MASK				\
	GIC_BASER_SHAREABILITY(GICR_VPROPBASER, SHAREABILITY_MASK)
#define GICR_VPROPBASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, MASK)
#define GICR_VPROPBASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, OUTER, MASK)
#define GICR_VPROPBASER_CACHEABILITY_MASK				\
	GICR_VPROPBASER_INNER_CACHEABILITY_MASK

#define GICR_VPROPBASER_InnerShareable					\
	GIC_BASER_SHAREABILITY(GICR_VPROPBASER, InnerShareable)

#define GICR_VPROPBASER_nCnB	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, nCnB)
#define GICR_VPROPBASER_nC 	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, nC)
#define GICR_VPROPBASER_RaWt	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWt)
288
#define GICR_VPROPBASER_RaWb	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWb)
289 290 291 292 293
#define GICR_VPROPBASER_WaWt	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, WaWt)
#define GICR_VPROPBASER_WaWb	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, WaWb)
#define GICR_VPROPBASER_RaWaWt	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWaWt)
#define GICR_VPROPBASER_RaWaWb	GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWaWb)

294 295 296 297 298 299 300 301 302 303 304 305
/*
 * GICv4.1 VPROPBASER reinvention. A subtle mix between the old
 * VPROPBASER and ITS_BASER. Just not quite any of the two.
 */
#define GICR_VPROPBASER_4_1_VALID	(1ULL << 63)
#define GICR_VPROPBASER_4_1_ENTRY_SIZE	GENMASK_ULL(61, 59)
#define GICR_VPROPBASER_4_1_INDIRECT	(1ULL << 55)
#define GICR_VPROPBASER_4_1_PAGE_SIZE	GENMASK_ULL(54, 53)
#define GICR_VPROPBASER_4_1_Z		(1ULL << 52)
#define GICR_VPROPBASER_4_1_ADDR	GENMASK_ULL(51, 12)
#define GICR_VPROPBASER_4_1_SIZE	GENMASK_ULL(6, 0)

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
#define GICR_VPENDBASER			0x0078

#define GICR_VPENDBASER_SHAREABILITY_SHIFT		(10)
#define GICR_VPENDBASER_INNER_CACHEABILITY_SHIFT	(7)
#define GICR_VPENDBASER_OUTER_CACHEABILITY_SHIFT	(56)
#define GICR_VPENDBASER_SHAREABILITY_MASK				\
	GIC_BASER_SHAREABILITY(GICR_VPENDBASER, SHAREABILITY_MASK)
#define GICR_VPENDBASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, MASK)
#define GICR_VPENDBASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, OUTER, MASK)
#define GICR_VPENDBASER_CACHEABILITY_MASK				\
	GICR_VPENDBASER_INNER_CACHEABILITY_MASK

#define GICR_VPENDBASER_NonShareable					\
	GIC_BASER_SHAREABILITY(GICR_VPENDBASER, NonShareable)

#define GICR_VPENDBASER_nCnB	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, nCnB)
#define GICR_VPENDBASER_nC 	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, nC)
#define GICR_VPENDBASER_RaWt	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWt)
326
#define GICR_VPENDBASER_RaWb	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWb)
327 328 329 330 331
#define GICR_VPENDBASER_WaWt	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, WaWt)
#define GICR_VPENDBASER_WaWb	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, WaWb)
#define GICR_VPENDBASER_RaWaWt	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWaWt)
#define GICR_VPENDBASER_RaWaWb	GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWaWb)

332 333 334 335 336
#define GICR_VPENDBASER_Dirty		(1ULL << 60)
#define GICR_VPENDBASER_PendingLast	(1ULL << 61)
#define GICR_VPENDBASER_IDAI		(1ULL << 62)
#define GICR_VPENDBASER_Valid		(1ULL << 63)

337 338 339 340 341 342 343 344 345
/*
 * GICv4.1 VPENDBASER, used for VPE residency. On top of these fields,
 * also use the above Valid, PendingLast and Dirty.
 */
#define GICR_VPENDBASER_4_1_DB		(1ULL << 62)
#define GICR_VPENDBASER_4_1_VGRP0EN	(1ULL << 59)
#define GICR_VPENDBASER_4_1_VGRP1EN	(1ULL << 58)
#define GICR_VPENDBASER_4_1_VPEID	GENMASK_ULL(15, 0)

M
Marc Zyngier 已提交
346 347 348 349 350 351
/*
 * ITS registers, offsets from ITS_base
 */
#define GITS_CTLR			0x0000
#define GITS_IIDR			0x0004
#define GITS_TYPER			0x0008
352
#define GITS_MPIDR			0x0018
M
Marc Zyngier 已提交
353 354 355 356
#define GITS_CBASER			0x0080
#define GITS_CWRITER			0x0088
#define GITS_CREADR			0x0090
#define GITS_BASER			0x0100
357 358 359
#define GITS_IDREGS_BASE		0xffd0
#define GITS_PIDR0			0xffe0
#define GITS_PIDR1			0xffe4
M
Marc Zyngier 已提交
360
#define GITS_PIDR2			GICR_PIDR2
361 362 363 364 365
#define GITS_PIDR4			0xffd0
#define GITS_CIDR0			0xfff0
#define GITS_CIDR1			0xfff4
#define GITS_CIDR2			0xfff8
#define GITS_CIDR3			0xfffc
M
Marc Zyngier 已提交
366 367 368

#define GITS_TRANSLATER			0x10040

369
#define GITS_CTLR_ENABLE		(1U << 0)
370
#define GITS_CTLR_ImDe			(1U << 1)
371 372
#define	GITS_CTLR_ITS_NUMBER_SHIFT	4
#define	GITS_CTLR_ITS_NUMBER		(0xFU << GITS_CTLR_ITS_NUMBER_SHIFT)
373 374
#define GITS_CTLR_QUIESCENT		(1U << 31)

375
#define GITS_TYPER_PLPIS		(1UL << 0)
376
#define GITS_TYPER_VLPIS		(1UL << 1)
377
#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT	4
378
#define GITS_TYPER_ITT_ENTRY_SIZE	GENMASK_ULL(7, 4)
379
#define GITS_TYPER_IDBITS_SHIFT		8
380
#define GITS_TYPER_DEVBITS_SHIFT	13
381
#define GITS_TYPER_DEVBITS		GENMASK_ULL(17, 13)
M
Marc Zyngier 已提交
382
#define GITS_TYPER_PTA			(1UL << 19)
383 384
#define GITS_TYPER_HCC_SHIFT		24
#define GITS_TYPER_HCC(r)		(((r) >> GITS_TYPER_HCC_SHIFT) & 0xff)
385
#define GITS_TYPER_VMOVP		(1ULL << 37)
386 387
#define GITS_TYPER_VMAPP		(1ULL << 40)
#define GITS_TYPER_SVPET		GENMASK_ULL(42, 41)
388

389 390 391 392 393
#define GITS_IIDR_REV_SHIFT		12
#define GITS_IIDR_REV_MASK		(0xf << GITS_IIDR_REV_SHIFT)
#define GITS_IIDR_REV(r)		(((r) >> GITS_IIDR_REV_SHIFT) & 0xf)
#define GITS_IIDR_PRODUCTID_SHIFT	24

394
#define GITS_CBASER_VALID			(1ULL << 63)
395 396 397 398 399 400 401 402 403 404 405 406 407
#define GITS_CBASER_SHAREABILITY_SHIFT		(10)
#define GITS_CBASER_INNER_CACHEABILITY_SHIFT	(59)
#define GITS_CBASER_OUTER_CACHEABILITY_SHIFT	(53)
#define GITS_CBASER_SHAREABILITY_MASK					\
	GIC_BASER_SHAREABILITY(GITS_CBASER, SHAREABILITY_MASK)
#define GITS_CBASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, MASK)
#define GITS_CBASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GITS_CBASER, OUTER, MASK)
#define GITS_CBASER_CACHEABILITY_MASK GITS_CBASER_INNER_CACHEABILITY_MASK

#define GITS_CBASER_InnerShareable					\
	GIC_BASER_SHAREABILITY(GITS_CBASER, InnerShareable)
408 409 410 411

#define GITS_CBASER_nCnB	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, nCnB)
#define GITS_CBASER_nC		GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, nC)
#define GITS_CBASER_RaWt	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWt)
412
#define GITS_CBASER_RaWb	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWb)
413 414 415 416
#define GITS_CBASER_WaWt	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, WaWt)
#define GITS_CBASER_WaWb	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, WaWb)
#define GITS_CBASER_RaWaWt	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWt)
#define GITS_CBASER_RaWaWb	GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWb)
M
Marc Zyngier 已提交
417

418 419
#define GITS_CBASER_ADDRESS(cbaser)	((cbaser) & GENMASK_ULL(51, 12))

M
Marc Zyngier 已提交
420 421
#define GITS_BASER_NR_REGS		8

422
#define GITS_BASER_VALID			(1ULL << 63)
423
#define GITS_BASER_INDIRECT			(1ULL << 62)
424

425 426 427 428
#define GITS_BASER_INNER_CACHEABILITY_SHIFT	(59)
#define GITS_BASER_OUTER_CACHEABILITY_SHIFT	(53)
#define GITS_BASER_INNER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GITS_BASER, INNER, MASK)
429
#define GITS_BASER_CACHEABILITY_MASK		GITS_BASER_INNER_CACHEABILITY_MASK
430 431 432 433 434
#define GITS_BASER_OUTER_CACHEABILITY_MASK				\
	GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, MASK)
#define GITS_BASER_SHAREABILITY_MASK					\
	GIC_BASER_SHAREABILITY(GITS_BASER, SHAREABILITY_MASK)

435 436 437
#define GITS_BASER_nCnB		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, nCnB)
#define GITS_BASER_nC		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, nC)
#define GITS_BASER_RaWt		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWt)
438
#define GITS_BASER_RaWb		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb)
439 440 441 442 443
#define GITS_BASER_WaWt		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, WaWt)
#define GITS_BASER_WaWb		GIC_BASER_CACHEABILITY(GITS_BASER, INNER, WaWb)
#define GITS_BASER_RaWaWt	GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWaWt)
#define GITS_BASER_RaWaWb	GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWaWb)

444
#define GITS_BASER_TYPE_SHIFT			(56)
M
Marc Zyngier 已提交
445
#define GITS_BASER_TYPE(r)		(((r) >> GITS_BASER_TYPE_SHIFT) & 7)
446
#define GITS_BASER_ENTRY_SIZE_SHIFT		(48)
447
#define GITS_BASER_ENTRY_SIZE(r)	((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1)
448
#define GITS_BASER_ENTRY_SIZE_MASK	GENMASK_ULL(52, 48)
449 450
#define GITS_BASER_PHYS_52_to_48(phys)					\
	(((phys) & GENMASK_ULL(47, 16)) | (((phys) >> 48) & 0xf) << 12)
451 452 453
#define GITS_BASER_ADDR_48_to_52(baser)					\
	(((baser) & GENMASK_ULL(47, 16)) | (((baser) >> 12) & 0xf) << 48)

M
Marc Zyngier 已提交
454
#define GITS_BASER_SHAREABILITY_SHIFT	(10)
455 456
#define GITS_BASER_InnerShareable					\
	GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable)
M
Marc Zyngier 已提交
457
#define GITS_BASER_PAGE_SIZE_SHIFT	(8)
458 459 460 461 462
#define __GITS_BASER_PSZ(sz)		(GIC_PAGE_SIZE_ ## sz << GITS_BASER_PAGE_SIZE_SHIFT)
#define GITS_BASER_PAGE_SIZE_4K		__GITS_BASER_PSZ(4K)
#define GITS_BASER_PAGE_SIZE_16K	__GITS_BASER_PSZ(16K)
#define GITS_BASER_PAGE_SIZE_64K	__GITS_BASER_PSZ(64K)
#define GITS_BASER_PAGE_SIZE_MASK	__GITS_BASER_PSZ(MASK)
463
#define GITS_BASER_PAGES_MAX		256
464
#define GITS_BASER_PAGES_SHIFT		(0)
465
#define GITS_BASER_NR_PAGES(r)		(((r) & 0xff) + 1)
M
Marc Zyngier 已提交
466 467 468 469

#define GITS_BASER_TYPE_NONE		0
#define GITS_BASER_TYPE_DEVICE		1
#define GITS_BASER_TYPE_VCPU		2
470
#define GITS_BASER_TYPE_RESERVED3	3
M
Marc Zyngier 已提交
471 472 473 474 475
#define GITS_BASER_TYPE_COLLECTION	4
#define GITS_BASER_TYPE_RESERVED5	5
#define GITS_BASER_TYPE_RESERVED6	6
#define GITS_BASER_TYPE_RESERVED7	7

476 477
#define GITS_LVL1_ENTRY_SIZE           (8UL)

M
Marc Zyngier 已提交
478 479 480 481 482
/*
 * ITS commands
 */
#define GITS_CMD_MAPD			0x08
#define GITS_CMD_MAPC			0x09
483 484
#define GITS_CMD_MAPTI			0x0a
#define GITS_CMD_MAPI			0x0b
M
Marc Zyngier 已提交
485 486 487 488 489 490 491 492 493
#define GITS_CMD_MOVI			0x01
#define GITS_CMD_DISCARD		0x0f
#define GITS_CMD_INV			0x0c
#define GITS_CMD_MOVALL			0x0e
#define GITS_CMD_INVALL			0x0d
#define GITS_CMD_INT			0x03
#define GITS_CMD_CLEAR			0x04
#define GITS_CMD_SYNC			0x05

494 495 496 497 498 499 500 501 502
/*
 * GICv4 ITS specific commands
 */
#define GITS_CMD_GICv4(x)		((x) | 0x20)
#define GITS_CMD_VINVALL		GITS_CMD_GICv4(GITS_CMD_INVALL)
#define GITS_CMD_VMAPP			GITS_CMD_GICv4(GITS_CMD_MAPC)
#define GITS_CMD_VMAPTI			GITS_CMD_GICv4(GITS_CMD_MAPTI)
#define GITS_CMD_VMOVI			GITS_CMD_GICv4(GITS_CMD_MOVI)
#define GITS_CMD_VSYNC			GITS_CMD_GICv4(GITS_CMD_SYNC)
503
/* VMOVP and INVDB are the odd ones, as they dont have a physical counterpart */
504
#define GITS_CMD_VMOVP			GITS_CMD_GICv4(2)
505
#define GITS_CMD_INVDB			GITS_CMD_GICv4(0xe)
506

507 508 509 510 511
/*
 * ITS error numbers
 */
#define E_ITS_MOVI_UNMAPPED_INTERRUPT		0x010107
#define E_ITS_MOVI_UNMAPPED_COLLECTION		0x010109
512
#define E_ITS_INT_UNMAPPED_INTERRUPT		0x010307
513 514
#define E_ITS_CLEAR_UNMAPPED_INTERRUPT		0x010507
#define E_ITS_MAPD_DEVICE_OOR			0x010801
515
#define E_ITS_MAPD_ITTSIZE_OOR			0x010802
516 517 518
#define E_ITS_MAPC_PROCNUM_OOR			0x010902
#define E_ITS_MAPC_COLLECTION_OOR		0x010903
#define E_ITS_MAPTI_UNMAPPED_DEVICE		0x010a04
519
#define E_ITS_MAPTI_ID_OOR			0x010a05
520 521 522 523 524 525
#define E_ITS_MAPTI_PHYSICALID_OOR		0x010a06
#define E_ITS_INV_UNMAPPED_INTERRUPT		0x010c07
#define E_ITS_INVALL_UNMAPPED_COLLECTION	0x010d09
#define E_ITS_MOVALL_PROCNUM_OOR		0x010e01
#define E_ITS_DISCARD_UNMAPPED_INTERRUPT	0x010f07

526 527 528
/*
 * CPU interface registers
 */
529 530 531 532 533 534
#define ICC_CTLR_EL1_EOImode_SHIFT	(1)
#define ICC_CTLR_EL1_EOImode_drop_dir	(0U << ICC_CTLR_EL1_EOImode_SHIFT)
#define ICC_CTLR_EL1_EOImode_drop	(1U << ICC_CTLR_EL1_EOImode_SHIFT)
#define ICC_CTLR_EL1_EOImode_MASK	(1 << ICC_CTLR_EL1_EOImode_SHIFT)
#define ICC_CTLR_EL1_CBPR_SHIFT		0
#define ICC_CTLR_EL1_CBPR_MASK		(1 << ICC_CTLR_EL1_CBPR_SHIFT)
535 536
#define ICC_CTLR_EL1_PMHE_SHIFT		6
#define ICC_CTLR_EL1_PMHE_MASK		(1 << ICC_CTLR_EL1_PMHE_SHIFT)
537 538 539 540 541 542 543 544
#define ICC_CTLR_EL1_PRI_BITS_SHIFT	8
#define ICC_CTLR_EL1_PRI_BITS_MASK	(0x7 << ICC_CTLR_EL1_PRI_BITS_SHIFT)
#define ICC_CTLR_EL1_ID_BITS_SHIFT	11
#define ICC_CTLR_EL1_ID_BITS_MASK	(0x7 << ICC_CTLR_EL1_ID_BITS_SHIFT)
#define ICC_CTLR_EL1_SEIS_SHIFT		14
#define ICC_CTLR_EL1_SEIS_MASK		(0x1 << ICC_CTLR_EL1_SEIS_SHIFT)
#define ICC_CTLR_EL1_A3V_SHIFT		15
#define ICC_CTLR_EL1_A3V_MASK		(0x1 << ICC_CTLR_EL1_A3V_SHIFT)
545
#define ICC_CTLR_EL1_RSS		(0x1 << 18)
546
#define ICC_CTLR_EL1_ExtRange		(0x1 << 19)
547 548 549 550 551 552 553 554 555 556
#define ICC_PMR_EL1_SHIFT		0
#define ICC_PMR_EL1_MASK		(0xff << ICC_PMR_EL1_SHIFT)
#define ICC_BPR0_EL1_SHIFT		0
#define ICC_BPR0_EL1_MASK		(0x7 << ICC_BPR0_EL1_SHIFT)
#define ICC_BPR1_EL1_SHIFT		0
#define ICC_BPR1_EL1_MASK		(0x7 << ICC_BPR1_EL1_SHIFT)
#define ICC_IGRPEN0_EL1_SHIFT		0
#define ICC_IGRPEN0_EL1_MASK		(1 << ICC_IGRPEN0_EL1_SHIFT)
#define ICC_IGRPEN1_EL1_SHIFT		0
#define ICC_IGRPEN1_EL1_MASK		(1 << ICC_IGRPEN1_EL1_SHIFT)
557 558
#define ICC_SRE_EL1_DIB			(1U << 2)
#define ICC_SRE_EL1_DFB			(1U << 1)
559 560 561 562 563
#define ICC_SRE_EL1_SRE			(1U << 0)

/*
 * Hypervisor interface registers (SRE only)
 */
564 565 566 567 568 569 570 571
#define ICH_LR_VIRTUAL_ID_MASK		((1ULL << 32) - 1)

#define ICH_LR_EOI			(1ULL << 41)
#define ICH_LR_GROUP			(1ULL << 60)
#define ICH_LR_HW			(1ULL << 61)
#define ICH_LR_STATE			(3ULL << 62)
#define ICH_LR_PENDING_BIT		(1ULL << 62)
#define ICH_LR_ACTIVE_BIT		(1ULL << 63)
572
#define ICH_LR_PHYS_ID_SHIFT		32
573
#define ICH_LR_PHYS_ID_MASK		(0x3ffULL << ICH_LR_PHYS_ID_SHIFT)
574
#define ICH_LR_PRIORITY_SHIFT		48
575
#define ICH_LR_PRIORITY_MASK		(0xffULL << ICH_LR_PRIORITY_SHIFT)
576

577 578 579 580
/* These are for GICv2 emulation only */
#define GICH_LR_VIRTUALID		(0x3ffUL << 0)
#define GICH_LR_PHYSID_CPUID_SHIFT	(10)
#define GICH_LR_PHYSID_CPUID		(7UL << GICH_LR_PHYSID_CPUID_SHIFT)
581 582 583 584 585 586

#define ICH_MISR_EOI			(1 << 0)
#define ICH_MISR_U			(1 << 1)

#define ICH_HCR_EN			(1 << 0)
#define ICH_HCR_UIE			(1 << 1)
587
#define ICH_HCR_NPIE			(1 << 3)
588
#define ICH_HCR_TC			(1 << 10)
589
#define ICH_HCR_TALL0			(1 << 11)
590
#define ICH_HCR_TALL1			(1 << 12)
591 592
#define ICH_HCR_EOIcount_SHIFT		27
#define ICH_HCR_EOIcount_MASK		(0x1f << ICH_HCR_EOIcount_SHIFT)
593

594 595 596 597
#define ICH_VMCR_ACK_CTL_SHIFT		2
#define ICH_VMCR_ACK_CTL_MASK		(1 << ICH_VMCR_ACK_CTL_SHIFT)
#define ICH_VMCR_FIQ_EN_SHIFT		3
#define ICH_VMCR_FIQ_EN_MASK		(1 << ICH_VMCR_FIQ_EN_SHIFT)
598 599 600 601
#define ICH_VMCR_CBPR_SHIFT		4
#define ICH_VMCR_CBPR_MASK		(1 << ICH_VMCR_CBPR_SHIFT)
#define ICH_VMCR_EOIM_SHIFT		9
#define ICH_VMCR_EOIM_MASK		(1 << ICH_VMCR_EOIM_SHIFT)
602 603 604 605 606 607
#define ICH_VMCR_BPR1_SHIFT		18
#define ICH_VMCR_BPR1_MASK		(7 << ICH_VMCR_BPR1_SHIFT)
#define ICH_VMCR_BPR0_SHIFT		21
#define ICH_VMCR_BPR0_MASK		(7 << ICH_VMCR_BPR0_SHIFT)
#define ICH_VMCR_PMR_SHIFT		24
#define ICH_VMCR_PMR_MASK		(0xffUL << ICH_VMCR_PMR_SHIFT)
608 609 610 611 612 613 614 615 616 617 618 619 620
#define ICH_VMCR_ENG0_SHIFT		0
#define ICH_VMCR_ENG0_MASK		(1 << ICH_VMCR_ENG0_SHIFT)
#define ICH_VMCR_ENG1_SHIFT		1
#define ICH_VMCR_ENG1_MASK		(1 << ICH_VMCR_ENG1_SHIFT)

#define ICH_VTR_PRI_BITS_SHIFT		29
#define ICH_VTR_PRI_BITS_MASK		(7 << ICH_VTR_PRI_BITS_SHIFT)
#define ICH_VTR_ID_BITS_SHIFT		23
#define ICH_VTR_ID_BITS_MASK		(7 << ICH_VTR_ID_BITS_SHIFT)
#define ICH_VTR_SEIS_SHIFT		22
#define ICH_VTR_SEIS_MASK		(1 << ICH_VTR_SEIS_SHIFT)
#define ICH_VTR_A3V_SHIFT		21
#define ICH_VTR_A3V_MASK		(1 << ICH_VTR_A3V_SHIFT)
621 622 623 624 625 626

#define ICC_IAR1_EL1_SPURIOUS		0x3ff

#define ICC_SRE_EL2_SRE			(1 << 0)
#define ICC_SRE_EL2_ENABLE		(1 << 3)

627 628 629 630 631
#define ICC_SGI1R_TARGET_LIST_SHIFT	0
#define ICC_SGI1R_TARGET_LIST_MASK	(0xffff << ICC_SGI1R_TARGET_LIST_SHIFT)
#define ICC_SGI1R_AFFINITY_1_SHIFT	16
#define ICC_SGI1R_AFFINITY_1_MASK	(0xff << ICC_SGI1R_AFFINITY_1_SHIFT)
#define ICC_SGI1R_SGI_ID_SHIFT		24
632
#define ICC_SGI1R_SGI_ID_MASK		(0xfULL << ICC_SGI1R_SGI_ID_SHIFT)
633
#define ICC_SGI1R_AFFINITY_2_SHIFT	32
634
#define ICC_SGI1R_AFFINITY_2_MASK	(0xffULL << ICC_SGI1R_AFFINITY_2_SHIFT)
635
#define ICC_SGI1R_IRQ_ROUTING_MODE_BIT	40
636 637
#define ICC_SGI1R_RS_SHIFT		44
#define ICC_SGI1R_RS_MASK		(0xfULL << ICC_SGI1R_RS_SHIFT)
638
#define ICC_SGI1R_AFFINITY_3_SHIFT	48
639
#define ICC_SGI1R_AFFINITY_3_MASK	(0xffULL << ICC_SGI1R_AFFINITY_3_SHIFT)
640

641
#include <asm/arch_gicv3.h>
642 643 644

#ifndef __ASSEMBLY__

M
Marc Zyngier 已提交
645 646 647 648 649 650
/*
 * We need a value to serve as a irq-type for LPIs. Choose one that will
 * hopefully pique the interest of the reviewer.
 */
#define GIC_IRQ_TYPE_LPI		0xa110c8ed

651 652 653 654
struct rdists {
	struct {
		void __iomem	*rd_base;
		struct page	*pend_page;
655
		struct page	*vpe_l1_page;
656
		phys_addr_t	phys_base;
657
		bool		lpi_enabled;
658
		cpumask_t	*vpe_table_mask;
659
	} __percpu		*rdist;
660 661
	phys_addr_t		prop_table_pa;
	void			*prop_table_va;
662
	u64			flags;
663
	u32			gicd_typer;
664
	u32			gicd_typer2;
665
	bool			has_vlpis;
666
	bool			has_rvpeid;
667
	bool			has_direct_lpi;
668 669
};

670
struct irq_domain;
671
struct fwnode_handle;
672
int its_cpu_init(void);
673
int its_init(struct fwnode_handle *handle, struct rdists *rdists,
674
	     struct irq_domain *domain);
675
int mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent);
676

677 678
static inline bool gic_enable_sre(void)
{
679
	u32 val;
680

681
	val = gic_read_sre();
682 683 684 685
	if (val & ICC_SRE_EL1_SRE)
		return true;

	val |= ICC_SRE_EL1_SRE;
686 687
	gic_write_sre(val);
	val = gic_read_sre();
688 689 690 691

	return !!(val & ICC_SRE_EL1_SRE);
}

692 693 694
#endif

#endif