blob: eda9430333426e3815a9119ed0d214e0adc15650 [file] [log] [blame]
Nishanth Menonf97ad372016-10-14 01:13:49 +00001/*
2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Nishanth Menonf97ad372016-10-14 01:13:49 +00007#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Andrew F. Davis75ad53f2019-01-22 12:39:31 -06009#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/bl_common.h>
11#include <common/interrupt_props.h>
12#include <drivers/arm/gicv3.h>
13#include <lib/utils.h>
Andrew F. Davis75ad53f2019-01-22 12:39:31 -060014#include <lib/mmio.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <plat/common/platform.h>
16
17#include <k3_gicv3.h>
Nishanth Menonf97ad372016-10-14 01:13:49 +000018
19/* The GICv3 driver only needs to be initialized in EL3 */
20uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
21
Dave Gerlachc1b0f672022-01-07 08:12:39 -060022static gicv3_redist_ctx_t rdist_ctx[PLATFORM_CORE_COUNT];
23static gicv3_dist_ctx_t dist_ctx;
Dave Gerlachc1b0f672022-01-07 08:12:39 -060024
Nishanth Menonf97ad372016-10-14 01:13:49 +000025static const interrupt_prop_t k3_interrupt_props[] = {
26 PLAT_ARM_G1S_IRQ_PROPS(INTR_GROUP1S),
27 PLAT_ARM_G0_IRQ_PROPS(INTR_GROUP0)
28};
29
30static unsigned int k3_mpidr_to_core_pos(unsigned long mpidr)
31{
32 return (unsigned int)plat_core_pos_by_mpidr(mpidr);
33}
34
35gicv3_driver_data_t k3_gic_data = {
36 .rdistif_num = PLATFORM_CORE_COUNT,
37 .rdistif_base_addrs = rdistif_base_addrs,
38 .interrupt_props = k3_interrupt_props,
39 .interrupt_props_num = ARRAY_SIZE(k3_interrupt_props),
40 .mpidr_to_core_pos = k3_mpidr_to_core_pos,
41};
42
Andrew F. Davis75ad53f2019-01-22 12:39:31 -060043void k3_gic_driver_init(uintptr_t gic_base)
Nishanth Menonf97ad372016-10-14 01:13:49 +000044{
Andrew F. Davis75ad53f2019-01-22 12:39:31 -060045 /* GIC Distributor is always at the base of the IP */
46 uintptr_t gicd_base = gic_base;
47 /* GIC Redistributor base is run-time detected */
48 uintptr_t gicr_base = 0;
49
50 for (unsigned int gicr_shift = 18; gicr_shift < 21; gicr_shift++) {
51 uintptr_t gicr_check = gic_base + BIT(gicr_shift);
52 uint32_t iidr = mmio_read_32(gicr_check + GICR_IIDR);
53 if (iidr != 0) {
54 /* Found the GICR base */
55 gicr_base = gicr_check;
56 break;
57 }
58 }
59 /* Assert if we have not found the GICR base */
60 assert(gicr_base != 0);
61
Nishanth Menonf97ad372016-10-14 01:13:49 +000062 /*
63 * The GICv3 driver is initialized in EL3 and does not need
64 * to be initialized again in SEL1. This is because the S-EL1
65 * can use GIC system registers to manage interrupts and does
66 * not need GIC interface base addresses to be configured.
67 */
68 k3_gic_data.gicd_base = gicd_base;
69 k3_gic_data.gicr_base = gicr_base;
70 gicv3_driver_init(&k3_gic_data);
71}
72
73void k3_gic_init(void)
74{
75 gicv3_distif_init();
76 gicv3_rdistif_init(plat_my_core_pos());
77 gicv3_cpuif_enable(plat_my_core_pos());
78}
79
80void k3_gic_cpuif_enable(void)
81{
82 gicv3_cpuif_enable(plat_my_core_pos());
83}
84
85void k3_gic_cpuif_disable(void)
86{
87 gicv3_cpuif_disable(plat_my_core_pos());
88}
89
90void k3_gic_pcpu_init(void)
91{
92 gicv3_rdistif_init(plat_my_core_pos());
93}
Dave Gerlachc1b0f672022-01-07 08:12:39 -060094
Dave Gerlachc1b0f672022-01-07 08:12:39 -060095void k3_gic_save_context(void)
96{
97 for (unsigned int i = 0U; i < PLATFORM_CORE_COUNT; i++) {
98 gicv3_rdistif_save(i, &rdist_ctx[i]);
99 }
100 gicv3_distif_save(&dist_ctx);
101}
102
103void k3_gic_restore_context(void)
104{
105 gicv3_distif_init_restore(&dist_ctx);
106 for (unsigned int i = 0U; i < PLATFORM_CORE_COUNT; i++) {
107 gicv3_rdistif_init_restore(i, &rdist_ctx[i]);
108 }
109}