aboutsummaryrefslogtreecommitdiffstats
path: root/gic.c
blob: a84779e603fb130a55935a1219cf921c75735848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * gic.c - Secure gic initialisation for stand-alone Linux booting
 *
 * Copyright (C) 2015 ARM Limited. All rights reserved.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE.txt file.
 */

#include <stdint.h>

#include <cpu.h>
#include <asm/gic-v3.h>
#include <asm/io.h>

#define GICD_CTLR			0x0
#define GICD_TYPER			0x4
#define GICD_IGROUPRn			0x80

#define GICD_CTLR_EnableGrp0		(1 << 0)
#define GICD_CTLR_EnableGrp1		(1 << 1)
#define GICD_TYPER_ITLineNumber		0x1f

#define GICC_CTLR			0x0
#define GICC_PMR			0x4

#define GICC_CTLR_EnableGrp0		(1 << 0)
#define GICC_CTLR_EnableGrp1		(1 << 1)

void gic_secure_init(void)
{
	unsigned int i;

	uint32_t cpu = read_mpidr();
	void *gicd_base = (void *)GIC_DIST_BASE;
	void *gicc_base = (void *)GIC_CPU_BASE;

	/* Set local interrupts to Group 1 (those fields are banked) */
	raw_writel(~0, gicd_base + GICD_IGROUPRn);

	if (cpu == 0) {
		uint32_t typer = raw_readl(gicd_base + GICD_TYPER);

		/* Set SPIs to Group 1 */
		for (i = 1; i < (typer & GICD_TYPER_ITLineNumber); i++)
			raw_writel(~0, gicd_base + GICD_IGROUPRn + i * 4);

		raw_writel(GICD_CTLR_EnableGrp0 | GICD_CTLR_EnableGrp1,
			   gicd_base + GICD_CTLR);
	}

	raw_writel(GICC_CTLR_EnableGrp0 | GICC_CTLR_EnableGrp1,
		   gicc_base + GICC_CTLR);

	/* Allow NS access to GICC_PMR */
	raw_writel(1 << 7, gicc_base + GICC_PMR);
}