blob: a4cc4a5e2afb616184ca7ae19b39d28820eeb1eb [file] [log] [blame]
Yann Gautier9d135e42018-07-16 19:36:06 +02001/*
Nicolas Le Bayon50054e92023-05-16 17:23:02 +02002 * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
Yann Gautier9d135e42018-07-16 19:36:06 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <common/bl_common.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +01008#include <common/debug.h>
Nicolas Le Bayon50054e92023-05-16 17:23:02 +02009#include <common/fdt_wrappers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <drivers/arm/gicv2.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +010011#include <dt-bindings/interrupt-controller/arm-gic.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <lib/utils.h>
Yann Gautier2bbf1712019-08-06 17:28:23 +020013#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020015
Yann Gautier2bbf1712019-08-06 17:28:23 +020016#include <platform_def.h>
17
18struct stm32mp_gic_instance {
Yann Gautierf9d40d52019-01-17 14:41:46 +010019 uint32_t cells;
20 uint32_t phandle_node;
21};
22
Yann Gautier9d135e42018-07-16 19:36:06 +020023/******************************************************************************
24 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
25 * interrupts.
26 *****************************************************************************/
Yann Gautier2bbf1712019-08-06 17:28:23 +020027static const interrupt_prop_t stm32mp_interrupt_props[] = {
Yann Gautier9d135e42018-07-16 19:36:06 +020028 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
29 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
30};
31
Yann Gautierf9d40d52019-01-17 14:41:46 +010032/* Fix target_mask_array as secondary core is not able to initialize it */
33static unsigned int target_mask_array[PLATFORM_CORE_COUNT] = {1, 2};
Yann Gautier9d135e42018-07-16 19:36:06 +020034
Yann Gautierf9d40d52019-01-17 14:41:46 +010035static gicv2_driver_data_t platform_gic_data = {
Yann Gautier2bbf1712019-08-06 17:28:23 +020036 .interrupt_props = stm32mp_interrupt_props,
37 .interrupt_props_num = ARRAY_SIZE(stm32mp_interrupt_props),
Yann Gautier9d135e42018-07-16 19:36:06 +020038 .target_masks = target_mask_array,
39 .target_masks_num = ARRAY_SIZE(target_mask_array),
40};
41
Yann Gautier2bbf1712019-08-06 17:28:23 +020042static struct stm32mp_gic_instance stm32mp_gic;
Yann Gautierf9d40d52019-01-17 14:41:46 +010043
Yann Gautier2bbf1712019-08-06 17:28:23 +020044void stm32mp_gic_init(void)
Yann Gautier9d135e42018-07-16 19:36:06 +020045{
Yann Gautierf9d40d52019-01-17 14:41:46 +010046 int node;
47 void *fdt;
48 const fdt32_t *cuint;
Nicolas Le Bayon50054e92023-05-16 17:23:02 +020049 uintptr_t addr;
50 int err;
Yann Gautierf9d40d52019-01-17 14:41:46 +010051
52 if (fdt_get_address(&fdt) == 0) {
53 panic();
54 }
55
Nicolas Le Bayon50054e92023-05-16 17:23:02 +020056 node = fdt_node_offset_by_compatible(fdt, -1, "arm,cortex-a7-gic");
Yann Gautierf9d40d52019-01-17 14:41:46 +010057 if (node < 0) {
58 panic();
59 }
60
Nicolas Le Bayon50054e92023-05-16 17:23:02 +020061 err = fdt_get_reg_props_by_index(fdt, node, 0, &addr, NULL);
62 if (err < 0) {
Yann Gautierf9d40d52019-01-17 14:41:46 +010063 panic();
64 }
Nicolas Le Bayon50054e92023-05-16 17:23:02 +020065 platform_gic_data.gicd_base = addr;
Yann Gautierf9d40d52019-01-17 14:41:46 +010066
Nicolas Le Bayon50054e92023-05-16 17:23:02 +020067 err = fdt_get_reg_props_by_index(fdt, node, 1, &addr, NULL);
68 if (err < 0) {
69 panic();
70 }
71 platform_gic_data.gicc_base = addr;
Yann Gautierf9d40d52019-01-17 14:41:46 +010072
73 cuint = fdt_getprop(fdt, node, "#interrupt-cells", NULL);
74 if (cuint == NULL) {
75 panic();
76 }
77
Yann Gautier2bbf1712019-08-06 17:28:23 +020078 stm32mp_gic.cells = fdt32_to_cpu(*cuint);
Yann Gautierf9d40d52019-01-17 14:41:46 +010079
Yann Gautier2bbf1712019-08-06 17:28:23 +020080 stm32mp_gic.phandle_node = fdt_get_phandle(fdt, node);
81 if (stm32mp_gic.phandle_node == 0U) {
Yann Gautierf9d40d52019-01-17 14:41:46 +010082 panic();
83 }
84
Yann Gautier9d135e42018-07-16 19:36:06 +020085 gicv2_driver_init(&platform_gic_data);
86 gicv2_distif_init();
87
Yann Gautier2bbf1712019-08-06 17:28:23 +020088 stm32mp_gic_pcpu_init();
Yann Gautier9d135e42018-07-16 19:36:06 +020089}
90
Yann Gautier2bbf1712019-08-06 17:28:23 +020091void stm32mp_gic_pcpu_init(void)
Yann Gautier9d135e42018-07-16 19:36:06 +020092{
93 gicv2_pcpu_distif_init();
94 gicv2_set_pe_target_mask(plat_my_core_pos());
95 gicv2_cpuif_enable();
96}