blob: becb925c2373ec3802797e57589ced91bb15620b [file] [log] [blame]
Yann Gautier9d135e42018-07-16 19:36:06 +02001/*
Yann Gautierf9d40d52019-01-17 14:41:46 +01002 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
Yann Gautier9d135e42018-07-16 19:36:06 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautierf9d40d52019-01-17 14:41:46 +01007#include <libfdt.h>
8
Yann Gautier9d135e42018-07-16 19:36:06 +02009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <common/bl_common.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +010012#include <common/debug.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <drivers/arm/gicv2.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +010014#include <dt-bindings/interrupt-controller/arm-gic.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/utils.h>
16#include <plat/common/platform.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020017
Yann Gautierf9d40d52019-01-17 14:41:46 +010018#include <stm32mp1_dt.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020019#include <stm32mp1_private.h>
20
Yann Gautierf9d40d52019-01-17 14:41:46 +010021struct stm32_gic_instance {
22 uint32_t cells;
23 uint32_t phandle_node;
24};
25
Yann Gautier9d135e42018-07-16 19:36:06 +020026/******************************************************************************
27 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
28 * interrupts.
29 *****************************************************************************/
30static const interrupt_prop_t stm32mp1_interrupt_props[] = {
31 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
32 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
33};
34
Yann Gautierf9d40d52019-01-17 14:41:46 +010035/* Fix target_mask_array as secondary core is not able to initialize it */
36static unsigned int target_mask_array[PLATFORM_CORE_COUNT] = {1, 2};
Yann Gautier9d135e42018-07-16 19:36:06 +020037
Yann Gautierf9d40d52019-01-17 14:41:46 +010038static gicv2_driver_data_t platform_gic_data = {
Yann Gautier9d135e42018-07-16 19:36:06 +020039 .interrupt_props = stm32mp1_interrupt_props,
40 .interrupt_props_num = ARRAY_SIZE(stm32mp1_interrupt_props),
41 .target_masks = target_mask_array,
42 .target_masks_num = ARRAY_SIZE(target_mask_array),
43};
44
Yann Gautierf9d40d52019-01-17 14:41:46 +010045static struct stm32_gic_instance stm32_gic;
46
Yann Gautier9d135e42018-07-16 19:36:06 +020047void stm32mp1_gic_init(void)
48{
Yann Gautierf9d40d52019-01-17 14:41:46 +010049 int node;
50 void *fdt;
51 const fdt32_t *cuint;
52 struct dt_node_info dt_gic;
53
54 if (fdt_get_address(&fdt) == 0) {
55 panic();
56 }
57
58 node = dt_get_node(&dt_gic, -1, "arm,cortex-a7-gic");
59 if (node < 0) {
60 panic();
61 }
62
63 platform_gic_data.gicd_base = dt_gic.base;
64
65 cuint = fdt_getprop(fdt, node, "reg", NULL);
66 if (cuint == NULL) {
67 panic();
68 }
69
70 platform_gic_data.gicc_base = fdt32_to_cpu(*(cuint + 2));
71
72 cuint = fdt_getprop(fdt, node, "#interrupt-cells", NULL);
73 if (cuint == NULL) {
74 panic();
75 }
76
77 stm32_gic.cells = fdt32_to_cpu(*cuint);
78
79 stm32_gic.phandle_node = fdt_get_phandle(fdt, node);
80 if (stm32_gic.phandle_node == 0U) {
81 panic();
82 }
83
Yann Gautier9d135e42018-07-16 19:36:06 +020084 gicv2_driver_init(&platform_gic_data);
85 gicv2_distif_init();
86
87 stm32mp1_gic_pcpu_init();
88}
89
90void stm32mp1_gic_pcpu_init(void)
91{
92 gicv2_pcpu_distif_init();
93 gicv2_set_pe_target_mask(plat_my_core_pos());
94 gicv2_cpuif_enable();
95}