1 /* 2 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /* 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. 11 * 12 * GIC-600 supports independently power-gating redistributor interface. 13 */ 14 15 #include <assert.h> 16 17 #include <arch_helpers.h> 18 #include <drivers/arm/gicv3.h> 19 20 #include "gicv3_private.h" 21 22 /* GIC-600 specific register offsets */ 23 #define GICR_PWRR 0x24 24 #define IIDR_MODEL_ARM_GIC_600 0x0200043b 25 26 /* GICR_PWRR fields */ 27 #define PWRR_RDPD_SHIFT 0 28 #define PWRR_RDAG_SHIFT 1 29 #define PWRR_RDGPD_SHIFT 2 30 #define PWRR_RDGPO_SHIFT 3 31 32 #define PWRR_RDPD (1 << PWRR_RDPD_SHIFT) 33 #define PWRR_RDAG (1 << PWRR_RDAG_SHIFT) 34 #define PWRR_RDGPD (1 << PWRR_RDGPD_SHIFT) 35 #define PWRR_RDGPO (1 << PWRR_RDGPO_SHIFT) 36 37 /* 38 * Values to write to GICR_PWRR register to power redistributor 39 * for operating through the core (GICR_PWRR.RDAG = 0) 40 */ 41 #define PWRR_ON (0 << PWRR_RDPD_SHIFT) 42 #define PWRR_OFF (1 << PWRR_RDPD_SHIFT) 43 44 #if GICV3_SUPPORT_GIC600 45 46 /* GIC-600 specific accessor functions */ 47 static void gicr_write_pwrr(uintptr_t base, unsigned int val) 48 { 49 mmio_write_32(base + GICR_PWRR, val); 50 } 51 52 static uint32_t gicr_read_pwrr(uintptr_t base) 53 { 54 return mmio_read_32(base + GICR_PWRR); 55 } 56 57 static void gicr_wait_group_not_in_transit(uintptr_t base) 58 { 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 ; 63 } 64 65 static void gic600_pwr_on(uintptr_t base) 66 { 67 do { /* Wait until group not transitioning */ 68 gicr_wait_group_not_in_transit(base); 69 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); 78 } 79 80 static void gic600_pwr_off(uintptr_t base) 81 { 82 /* Wait until group not transitioning */ 83 gicr_wait_group_not_in_transit(base); 84 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 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. 93 */ 94 if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) { 95 /* Wait until group not transitioning */ 96 gicr_wait_group_not_in_transit(base); 97 } 98 } 99 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 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 133 134 /* 135 * Power off GIC-600 redistributor (if configured and detected) 136 */ 137 void gicv3_rdistif_off(unsigned int proc_num) 138 { 139 #if GICV3_SUPPORT_GIC600 140 uintptr_t gicr_base = get_gicr_base(proc_num); 141 142 /* Attempt to power redistributor off */ 143 if (gicv3_is_gic600(gicr_base)) { 144 gic600_pwr_off(gicr_base); 145 } 146 #endif 147 } 148 149 /* 150 * Power on GIC-600 redistributor (if configured and detected) 151 */ 152 void gicv3_rdistif_on(unsigned int proc_num) 153 { 154 #if GICV3_SUPPORT_GIC600 155 uintptr_t gicr_base = get_gicr_base(proc_num); 156 157 /* Power redistributor on */ 158 if (gicv3_is_gic600(gicr_base)) { 159 gic600_pwr_on(gicr_base); 160 } 161 #endif 162 } 163