Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 7 | #include <platform_def.h> |
| 8 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 9 | #include <drivers/arm/gic.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <drivers/arm/gicv2.h> |
Antonio Nino Diaz | bd9344f | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 11 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <plat/common/platform.h> |
| 13 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 14 | #if USE_GIC_DRIVER != 2 |
Boyan Karatotev | df21ca0 | 2025-04-22 10:17:37 +0100 | [diff] [blame^] | 15 | #error "This file should only be used with USE_GIC_DRIVER=2" |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 16 | #endif |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 17 | |
| 18 | /****************************************************************************** |
| 19 | * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0 |
| 20 | * interrupts. |
| 21 | *****************************************************************************/ |
Jeenu Viswambharan | b2c363b | 2017-09-22 08:59:59 +0100 | [diff] [blame] | 22 | static const interrupt_prop_t arm_interrupt_props[] = { |
| 23 | PLAT_ARM_G1S_IRQ_PROPS(GICV2_INTR_GROUP0), |
| 24 | PLAT_ARM_G0_IRQ_PROPS(GICV2_INTR_GROUP0) |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Jeenu Viswambharan | dea417c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 27 | static unsigned int target_mask_array[PLATFORM_CORE_COUNT]; |
| 28 | |
Soby Mathew | 21a3973 | 2016-01-13 17:06:00 +0000 | [diff] [blame] | 29 | static const gicv2_driver_data_t arm_gic_data = { |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 30 | .gicd_base = PLAT_ARM_GICD_BASE, |
| 31 | .gicc_base = PLAT_ARM_GICC_BASE, |
Jeenu Viswambharan | b2c363b | 2017-09-22 08:59:59 +0100 | [diff] [blame] | 32 | .interrupt_props = arm_interrupt_props, |
| 33 | .interrupt_props_num = ARRAY_SIZE(arm_interrupt_props), |
Jeenu Viswambharan | dea417c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 34 | .target_masks = target_mask_array, |
| 35 | .target_masks_num = ARRAY_SIZE(target_mask_array), |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /****************************************************************************** |
| 39 | * ARM common helper to initialize the GICv2 only driver. |
| 40 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 41 | void __init gic_init(unsigned int cpu_idx) |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 42 | { |
| 43 | gicv2_driver_init(&arm_gic_data); |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 44 | gicv2_distif_init(); |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /****************************************************************************** |
| 48 | * ARM common helper to enable the GICv2 CPU interface |
| 49 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 50 | void gic_cpuif_enable(unsigned int cpu_idx) |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 51 | { |
| 52 | gicv2_cpuif_enable(); |
| 53 | } |
| 54 | |
| 55 | /****************************************************************************** |
| 56 | * ARM common helper to disable the GICv2 CPU interface |
| 57 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 58 | void gic_cpuif_disable(unsigned int cpu_idx) |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 59 | { |
| 60 | gicv2_cpuif_disable(); |
| 61 | } |
| 62 | |
| 63 | /****************************************************************************** |
| 64 | * ARM common helper to initialize the per cpu distributor interface in GICv2 |
| 65 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 66 | void gic_pcpu_init(unsigned int cpu_idx) |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 67 | { |
| 68 | gicv2_pcpu_distif_init(); |
Jeenu Viswambharan | dea417c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 69 | gicv2_set_pe_target_mask(plat_my_core_pos()); |
Achin Gupta | 27573c5 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 70 | } |
Jeenu Viswambharan | d17b953 | 2016-12-09 11:12:34 +0000 | [diff] [blame] | 71 | |
| 72 | /****************************************************************************** |
| 73 | * Stubs for Redistributor power management. Although GICv2 doesn't have |
| 74 | * Redistributor interface, these are provided for the sake of uniform GIC API |
| 75 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 76 | void gic_pcpu_off(unsigned int cpu_idx) |
Jeenu Viswambharan | d17b953 | 2016-12-09 11:12:34 +0000 | [diff] [blame] | 77 | { |
| 78 | return; |
| 79 | } |
| 80 | |
Soby Mathew | e35a3fb | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 81 | /****************************************************************************** |
| 82 | * ARM common helper to save & restore the GICv3 on resume from system suspend. |
| 83 | * The normal world currently takes care of saving and restoring the GICv2 |
| 84 | * registers due to legacy reasons. Hence we just initialize the Distributor |
| 85 | * on resume from system suspend. |
| 86 | *****************************************************************************/ |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 87 | void gic_save(void) |
Soby Mathew | e35a3fb | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 88 | { |
| 89 | return; |
| 90 | } |
| 91 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 92 | void gic_resume(void) |
Soby Mathew | e35a3fb | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 93 | { |
| 94 | gicv2_distif_init(); |
| 95 | gicv2_pcpu_distif_init(); |
| 96 | } |