Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame] | 3 | * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | /* |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 9 | * Driver for GIC-500 and GIC-600 specific features. This driver only |
| 10 | * overrides APIs that are different to those generic ones in GICv3 |
| 11 | * driver. |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 12 | * |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 13 | * GIC-600 supports independently power-gating redistributor interface. |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 16 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | |
| 18 | #include <arch_helpers.h> |
Andre Przywara | daf89a7 | 2021-08-24 10:02:52 +0100 | [diff] [blame] | 19 | #include <drivers/arm/arm_gicv3_common.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | #include <drivers/arm/gicv3.h> |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 21 | |
| 22 | #include "gicv3_private.h" |
| 23 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 24 | /* GIC-600 specific register offsets */ |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 25 | #define GICR_PWRR 0x24U |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 26 | |
| 27 | /* GICR_PWRR fields */ |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame] | 28 | #define PWRR_RDPD_SHIFT 0 |
| 29 | #define PWRR_RDAG_SHIFT 1 |
| 30 | #define PWRR_RDGPD_SHIFT 2 |
| 31 | #define PWRR_RDGPO_SHIFT 3 |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 32 | |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 33 | #define PWRR_RDPD (1U << PWRR_RDPD_SHIFT) |
| 34 | #define PWRR_RDAG (1U << PWRR_RDAG_SHIFT) |
| 35 | #define PWRR_RDGPD (1U << PWRR_RDGPD_SHIFT) |
| 36 | #define PWRR_RDGPO (1U << PWRR_RDGPO_SHIFT) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 37 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 38 | /* |
| 39 | * Values to write to GICR_PWRR register to power redistributor |
| 40 | * for operating through the core (GICR_PWRR.RDAG = 0) |
| 41 | */ |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 42 | #define PWRR_ON (0U << PWRR_RDPD_SHIFT) |
| 43 | #define PWRR_OFF (1U << PWRR_RDPD_SHIFT) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 44 | |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 45 | #if GICV3_SUPPORT_GIC600 |
| 46 | |
Andre Przywara | b6c24ce | 2021-07-20 19:20:07 +0100 | [diff] [blame] | 47 | /* GIC-600/700 specific accessor functions */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 48 | static void gicr_write_pwrr(uintptr_t base, unsigned int val) |
| 49 | { |
Douglas Raillard | 1bd2d74 | 2017-08-03 15:59:49 +0100 | [diff] [blame] | 50 | mmio_write_32(base + GICR_PWRR, val); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static uint32_t gicr_read_pwrr(uintptr_t base) |
| 54 | { |
Douglas Raillard | 1bd2d74 | 2017-08-03 15:59:49 +0100 | [diff] [blame] | 55 | return mmio_read_32(base + GICR_PWRR); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 58 | static void gicr_wait_group_not_in_transit(uintptr_t base) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 59 | { |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 60 | uint32_t pwrr; |
| 61 | |
| 62 | do { |
| 63 | pwrr = gicr_read_pwrr(base); |
| 64 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 65 | /* Check group not transitioning: RDGPD == RDGPO */ |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 66 | } while (((pwrr & PWRR_RDGPD) >> PWRR_RDGPD_SHIFT) != |
| 67 | ((pwrr & PWRR_RDGPO) >> PWRR_RDGPO_SHIFT)); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static void gic600_pwr_on(uintptr_t base) |
| 71 | { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 72 | do { /* Wait until group not transitioning */ |
| 73 | gicr_wait_group_not_in_transit(base); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 74 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 75 | /* Power on redistributor */ |
| 76 | gicr_write_pwrr(base, PWRR_ON); |
| 77 | |
| 78 | /* |
| 79 | * Wait until the power on state is reflected. |
| 80 | * If RDPD == 0 then powered on. |
| 81 | */ |
| 82 | } while ((gicr_read_pwrr(base) & PWRR_RDPD) != PWRR_ON); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static void gic600_pwr_off(uintptr_t base) |
| 86 | { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 87 | /* Wait until group not transitioning */ |
| 88 | gicr_wait_group_not_in_transit(base); |
| 89 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 90 | /* Power off redistributor */ |
| 91 | gicr_write_pwrr(base, PWRR_OFF); |
| 92 | |
| 93 | /* |
| 94 | * If this is the last man, turning this redistributor frame off will |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 95 | * result in the group itself being powered off and RDGPD = 1. |
| 96 | * In that case, wait as long as it's in transition, or has aborted |
| 97 | * the transition altogether for any reason. |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 98 | */ |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 99 | if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0U) { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 100 | /* Wait until group not transitioning */ |
| 101 | gicr_wait_group_not_in_transit(base); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 105 | static uintptr_t get_gicr_base(unsigned int proc_num) |
| 106 | { |
| 107 | uintptr_t gicr_base; |
| 108 | |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 109 | assert(gicv3_driver_data != NULL); |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 110 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 111 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 112 | |
| 113 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 114 | assert(gicr_base != 0UL); |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 115 | |
| 116 | return gicr_base; |
| 117 | } |
| 118 | |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 119 | static bool gicv3_redists_need_power_mgmt(uintptr_t gicr_base) |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 120 | { |
| 121 | uint32_t reg = mmio_read_32(gicr_base + GICR_IIDR); |
| 122 | |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 123 | /* |
Andre Przywara | b6c24ce | 2021-07-20 19:20:07 +0100 | [diff] [blame] | 124 | * The Arm GIC-600 and GIC-700 models have their redistributors |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 125 | * powered down at reset. |
| 126 | */ |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame] | 127 | return (((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) || |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 128 | ((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600AE) || |
Andre Przywara | b6c24ce | 2021-07-20 19:20:07 +0100 | [diff] [blame] | 129 | ((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_700)); |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Alexei Fedorov | 06d29cf | 2020-07-29 15:16:36 +0100 | [diff] [blame] | 132 | #endif /* GICV3_SUPPORT_GIC600 */ |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 133 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 134 | void gicv3_distif_pre_save(unsigned int proc_num) |
| 135 | { |
| 136 | arm_gicv3_distif_pre_save(proc_num); |
| 137 | } |
| 138 | |
| 139 | void gicv3_distif_post_restore(unsigned int proc_num) |
| 140 | { |
| 141 | arm_gicv3_distif_post_restore(proc_num); |
| 142 | } |
| 143 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 144 | /* |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 145 | * Power off GIC-600 redistributor (if configured and detected) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 146 | */ |
| 147 | void gicv3_rdistif_off(unsigned int proc_num) |
| 148 | { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 149 | #if GICV3_SUPPORT_GIC600 |
| 150 | uintptr_t gicr_base = get_gicr_base(proc_num); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 151 | |
| 152 | /* Attempt to power redistributor off */ |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 153 | if (gicv3_redists_need_power_mgmt(gicr_base)) { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 154 | gic600_pwr_off(gicr_base); |
| 155 | } |
| 156 | #endif |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 160 | * Power on GIC-600 redistributor (if configured and detected) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 161 | */ |
| 162 | void gicv3_rdistif_on(unsigned int proc_num) |
| 163 | { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 164 | #if GICV3_SUPPORT_GIC600 |
| 165 | uintptr_t gicr_base = get_gicr_base(proc_num); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 166 | |
| 167 | /* Power redistributor on */ |
Andre Przywara | 19b2d4e | 2020-06-26 10:30:33 +0100 | [diff] [blame] | 168 | if (gicv3_redists_need_power_mgmt(gicr_base)) { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 169 | gic600_pwr_on(gicr_base); |
| 170 | } |
| 171 | #endif |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 172 | } |