blob: d02b635a8995f7ec0681e2f0a232deba60777e14 [file] [log] [blame]
Yann Gautier9d135e42018-07-16 19:36:06 +02001/*
Yann Gautier2bbf1712019-08-06 17:28:23 +02002 * Copyright (c) 2016-2023, 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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <drivers/arm/gicv2.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +010010#include <dt-bindings/interrupt-controller/arm-gic.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <lib/utils.h>
Yann Gautier2bbf1712019-08-06 17:28:23 +020012#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <plat/common/platform.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020014
Yann Gautier2bbf1712019-08-06 17:28:23 +020015#include <platform_def.h>
16
17struct stm32mp_gic_instance {
Yann Gautierf9d40d52019-01-17 14:41:46 +010018 uint32_t cells;
19 uint32_t phandle_node;
20};
21
Yann Gautier9d135e42018-07-16 19:36:06 +020022/******************************************************************************
23 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
24 * interrupts.
25 *****************************************************************************/
Yann Gautier2bbf1712019-08-06 17:28:23 +020026static const interrupt_prop_t stm32mp_interrupt_props[] = {
Yann Gautier9d135e42018-07-16 19:36:06 +020027 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
28 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
29};
30
Yann Gautierf9d40d52019-01-17 14:41:46 +010031/* Fix target_mask_array as secondary core is not able to initialize it */
32static unsigned int target_mask_array[PLATFORM_CORE_COUNT] = {1, 2};
Yann Gautier9d135e42018-07-16 19:36:06 +020033
Yann Gautierf9d40d52019-01-17 14:41:46 +010034static gicv2_driver_data_t platform_gic_data = {
Yann Gautier2bbf1712019-08-06 17:28:23 +020035 .interrupt_props = stm32mp_interrupt_props,
36 .interrupt_props_num = ARRAY_SIZE(stm32mp_interrupt_props),
Yann Gautier9d135e42018-07-16 19:36:06 +020037 .target_masks = target_mask_array,
38 .target_masks_num = ARRAY_SIZE(target_mask_array),
39};
40
Yann Gautier2bbf1712019-08-06 17:28:23 +020041static struct stm32mp_gic_instance stm32mp_gic;
Yann Gautierf9d40d52019-01-17 14:41:46 +010042
Yann Gautier2bbf1712019-08-06 17:28:23 +020043void stm32mp_gic_init(void)
Yann Gautier9d135e42018-07-16 19:36:06 +020044{
Yann Gautierf9d40d52019-01-17 14:41:46 +010045 int node;
46 void *fdt;
47 const fdt32_t *cuint;
48 struct dt_node_info dt_gic;
49
50 if (fdt_get_address(&fdt) == 0) {
51 panic();
52 }
53
54 node = dt_get_node(&dt_gic, -1, "arm,cortex-a7-gic");
55 if (node < 0) {
56 panic();
57 }
58
59 platform_gic_data.gicd_base = dt_gic.base;
60
61 cuint = fdt_getprop(fdt, node, "reg", NULL);
62 if (cuint == NULL) {
63 panic();
64 }
65
66 platform_gic_data.gicc_base = fdt32_to_cpu(*(cuint + 2));
67
68 cuint = fdt_getprop(fdt, node, "#interrupt-cells", NULL);
69 if (cuint == NULL) {
70 panic();
71 }
72
Yann Gautier2bbf1712019-08-06 17:28:23 +020073 stm32mp_gic.cells = fdt32_to_cpu(*cuint);
Yann Gautierf9d40d52019-01-17 14:41:46 +010074
Yann Gautier2bbf1712019-08-06 17:28:23 +020075 stm32mp_gic.phandle_node = fdt_get_phandle(fdt, node);
76 if (stm32mp_gic.phandle_node == 0U) {
Yann Gautierf9d40d52019-01-17 14:41:46 +010077 panic();
78 }
79
Yann Gautier9d135e42018-07-16 19:36:06 +020080 gicv2_driver_init(&platform_gic_data);
81 gicv2_distif_init();
82
Yann Gautier2bbf1712019-08-06 17:28:23 +020083 stm32mp_gic_pcpu_init();
Yann Gautier9d135e42018-07-16 19:36:06 +020084}
85
Yann Gautier2bbf1712019-08-06 17:28:23 +020086void stm32mp_gic_pcpu_init(void)
Yann Gautier9d135e42018-07-16 19:36:06 +020087{
88 gicv2_pcpu_distif_init();
89 gicv2_set_pe_target_mask(plat_my_core_pos());
90 gicv2_cpuif_enable();
91}