stm32mp1_gic.c 2.14 KB
Newer Older
1
/*
Yann Gautier's avatar
Yann Gautier committed
2
 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

Yann Gautier's avatar
Yann Gautier committed
7
8
#include <libfdt.h>

9
#include <platform_def.h>
10
11

#include <common/bl_common.h>
Yann Gautier's avatar
Yann Gautier committed
12
#include <common/debug.h>
13
#include <drivers/arm/gicv2.h>
Yann Gautier's avatar
Yann Gautier committed
14
#include <dt-bindings/interrupt-controller/arm-gic.h>
15
16
#include <lib/utils.h>
#include <plat/common/platform.h>
17

Yann Gautier's avatar
Yann Gautier committed
18
19
20
21
22
struct stm32_gic_instance {
	uint32_t cells;
	uint32_t phandle_node;
};

23
24
25
26
27
28
29
30
31
/******************************************************************************
 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
 * interrupts.
 *****************************************************************************/
static const interrupt_prop_t stm32mp1_interrupt_props[] = {
	PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
	PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
};

Yann Gautier's avatar
Yann Gautier committed
32
33
/* Fix target_mask_array as secondary core is not able to initialize it */
static unsigned int target_mask_array[PLATFORM_CORE_COUNT] = {1, 2};
34

Yann Gautier's avatar
Yann Gautier committed
35
static gicv2_driver_data_t platform_gic_data = {
36
37
38
39
40
41
	.interrupt_props = stm32mp1_interrupt_props,
	.interrupt_props_num = ARRAY_SIZE(stm32mp1_interrupt_props),
	.target_masks = target_mask_array,
	.target_masks_num = ARRAY_SIZE(target_mask_array),
};

Yann Gautier's avatar
Yann Gautier committed
42
43
static struct stm32_gic_instance stm32_gic;

44
45
void stm32mp1_gic_init(void)
{
Yann Gautier's avatar
Yann Gautier committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	int node;
	void *fdt;
	const fdt32_t *cuint;
	struct dt_node_info dt_gic;

	if (fdt_get_address(&fdt) == 0) {
		panic();
	}

	node = dt_get_node(&dt_gic, -1, "arm,cortex-a7-gic");
	if (node < 0) {
		panic();
	}

	platform_gic_data.gicd_base = dt_gic.base;

	cuint = fdt_getprop(fdt, node, "reg", NULL);
	if (cuint == NULL) {
		panic();
	}

	platform_gic_data.gicc_base = fdt32_to_cpu(*(cuint + 2));

	cuint = fdt_getprop(fdt, node, "#interrupt-cells", NULL);
	if (cuint == NULL) {
		panic();
	}

	stm32_gic.cells = fdt32_to_cpu(*cuint);

	stm32_gic.phandle_node = fdt_get_phandle(fdt, node);
	if (stm32_gic.phandle_node == 0U) {
		panic();
	}

81
82
83
84
85
86
87
88
89
90
91
92
	gicv2_driver_init(&platform_gic_data);
	gicv2_distif_init();

	stm32mp1_gic_pcpu_init();
}

void stm32mp1_gic_pcpu_init(void)
{
	gicv2_pcpu_distif_init();
	gicv2_set_pe_target_mask(plat_my_core_pos());
	gicv2_cpuif_enable();
}