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