Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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> |
| 19 | #include <drivers/arm/gicv3.h> |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 20 | |
| 21 | #include "gicv3_private.h" |
| 22 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 23 | /* GIC-600 specific register offsets */ |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame^] | 24 | #define GICR_PWRR 0x24 |
| 25 | #define IIDR_MODEL_ARM_GIC_600 (0x0200043b) |
| 26 | #define IIDR_MODEL_ARM_GIC_600AE (0x0300043b) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 27 | |
| 28 | /* GICR_PWRR fields */ |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame^] | 29 | #define PWRR_RDPD_SHIFT 0 |
| 30 | #define PWRR_RDAG_SHIFT 1 |
| 31 | #define PWRR_RDGPD_SHIFT 2 |
| 32 | #define PWRR_RDGPO_SHIFT 3 |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 33 | |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame^] | 34 | #define PWRR_RDPD (1 << PWRR_RDPD_SHIFT) |
| 35 | #define PWRR_RDAG (1 << PWRR_RDAG_SHIFT) |
| 36 | #define PWRR_RDGPD (1 << PWRR_RDGPD_SHIFT) |
| 37 | #define PWRR_RDGPO (1 << PWRR_RDGPO_SHIFT) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 38 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 39 | /* |
| 40 | * Values to write to GICR_PWRR register to power redistributor |
| 41 | * for operating through the core (GICR_PWRR.RDAG = 0) |
| 42 | */ |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame^] | 43 | #define PWRR_ON (0 << PWRR_RDPD_SHIFT) |
| 44 | #define PWRR_OFF (1 << PWRR_RDPD_SHIFT) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 45 | |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 46 | #if GICV3_SUPPORT_GIC600 |
| 47 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 48 | /* GIC-600 specific accessor functions */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 49 | static void gicr_write_pwrr(uintptr_t base, unsigned int val) |
| 50 | { |
Douglas Raillard | 1bd2d74 | 2017-08-03 15:59:49 +0100 | [diff] [blame] | 51 | mmio_write_32(base + GICR_PWRR, val); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static uint32_t gicr_read_pwrr(uintptr_t base) |
| 55 | { |
Douglas Raillard | 1bd2d74 | 2017-08-03 15:59:49 +0100 | [diff] [blame] | 56 | return mmio_read_32(base + GICR_PWRR); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 59 | static void gicr_wait_group_not_in_transit(uintptr_t base) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 60 | { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 61 | /* Check group not transitioning: RDGPD == RDGPO */ |
| 62 | while (((gicr_read_pwrr(base) & PWRR_RDGPD) >> PWRR_RDGPD_SHIFT) != |
| 63 | ((gicr_read_pwrr(base) & PWRR_RDGPO) >> PWRR_RDGPO_SHIFT)) |
| 64 | ; |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void gic600_pwr_on(uintptr_t base) |
| 68 | { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 69 | do { /* Wait until group not transitioning */ |
| 70 | gicr_wait_group_not_in_transit(base); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 71 | |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 72 | /* Power on redistributor */ |
| 73 | gicr_write_pwrr(base, PWRR_ON); |
| 74 | |
| 75 | /* |
| 76 | * Wait until the power on state is reflected. |
| 77 | * If RDPD == 0 then powered on. |
| 78 | */ |
| 79 | } while ((gicr_read_pwrr(base) & PWRR_RDPD) != PWRR_ON); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void gic600_pwr_off(uintptr_t base) |
| 83 | { |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 84 | /* Wait until group not transitioning */ |
| 85 | gicr_wait_group_not_in_transit(base); |
| 86 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 87 | /* Power off redistributor */ |
| 88 | gicr_write_pwrr(base, PWRR_OFF); |
| 89 | |
| 90 | /* |
| 91 | * If this is the last man, turning this redistributor frame off will |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 92 | * result in the group itself being powered off and RDGPD = 1. |
| 93 | * In that case, wait as long as it's in transition, or has aborted |
| 94 | * the transition altogether for any reason. |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 95 | */ |
Alexei Fedorov | 88fba67 | 2019-07-31 13:24:22 +0100 | [diff] [blame] | 96 | if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) { |
| 97 | /* Wait until group not transitioning */ |
| 98 | gicr_wait_group_not_in_transit(base); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 102 | static uintptr_t get_gicr_base(unsigned int proc_num) |
| 103 | { |
| 104 | uintptr_t gicr_base; |
| 105 | |
| 106 | assert(gicv3_driver_data); |
| 107 | assert(proc_num < gicv3_driver_data->rdistif_num); |
| 108 | assert(gicv3_driver_data->rdistif_base_addrs); |
| 109 | |
| 110 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
| 111 | assert(gicr_base); |
| 112 | |
| 113 | return gicr_base; |
| 114 | } |
| 115 | |
| 116 | static bool gicv3_is_gic600(uintptr_t gicr_base) |
| 117 | { |
| 118 | uint32_t reg = mmio_read_32(gicr_base + GICR_IIDR); |
| 119 | |
Varun Wadekar | 7559406 | 2020-07-05 13:12:28 -0700 | [diff] [blame^] | 120 | return (((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) || |
| 121 | ((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600AE)); |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | #endif |
| 125 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 126 | void gicv3_distif_pre_save(unsigned int proc_num) |
| 127 | { |
| 128 | arm_gicv3_distif_pre_save(proc_num); |
| 129 | } |
| 130 | |
| 131 | void gicv3_distif_post_restore(unsigned int proc_num) |
| 132 | { |
| 133 | arm_gicv3_distif_post_restore(proc_num); |
| 134 | } |
| 135 | |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 136 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 137 | /* |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 138 | * Power off GIC-600 redistributor (if configured and detected) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 139 | */ |
| 140 | void gicv3_rdistif_off(unsigned int proc_num) |
| 141 | { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 142 | #if GICV3_SUPPORT_GIC600 |
| 143 | uintptr_t gicr_base = get_gicr_base(proc_num); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 144 | |
| 145 | /* Attempt to power redistributor off */ |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 146 | if (gicv3_is_gic600(gicr_base)) { |
| 147 | gic600_pwr_off(gicr_base); |
| 148 | } |
| 149 | #endif |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 153 | * Power on GIC-600 redistributor (if configured and detected) |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 154 | */ |
| 155 | void gicv3_rdistif_on(unsigned int proc_num) |
| 156 | { |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 157 | #if GICV3_SUPPORT_GIC600 |
| 158 | uintptr_t gicr_base = get_gicr_base(proc_num); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 159 | |
| 160 | /* Power redistributor on */ |
Andre Przywara | e1cc130 | 2020-03-25 15:50:38 +0000 | [diff] [blame] | 161 | if (gicv3_is_gic600(gicr_base)) { |
| 162 | gic600_pwr_on(gicr_base); |
| 163 | } |
| 164 | #endif |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 165 | } |