Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 1 | /* |
Govindraj Raja | eee28e7 | 2023-08-01 15:52:40 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved. |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 8 | #include <cdefs.h> |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 9 | #include <inttypes.h> |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 11 | #include <stdint.h> |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 12 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 13 | #include "../amu_private.h" |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <arch.h> |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 15 | #include <arch_features.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <arch_helpers.h> |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 17 | #include <common/debug.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 18 | #include <lib/el3_runtime/pubsub_events.h> |
| 19 | #include <lib/extensions/amu.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 21 | #include <plat/common/platform.h> |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 22 | |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 23 | #if ENABLE_AMU_FCONF |
| 24 | # include <lib/fconf/fconf.h> |
| 25 | # include <lib/fconf/fconf_amu_getter.h> |
| 26 | #endif |
| 27 | |
Chris Kay | 03be39d | 2021-05-05 13:38:30 +0100 | [diff] [blame] | 28 | #if ENABLE_MPMM |
| 29 | # include <lib/mpmm/mpmm.h> |
| 30 | #endif |
| 31 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 32 | struct amu_ctx { |
| 33 | uint64_t group0_cnts[AMU_GROUP0_MAX_COUNTERS]; |
| 34 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 35 | uint64_t group1_cnts[AMU_GROUP1_MAX_COUNTERS]; |
| 36 | #endif |
| 37 | |
| 38 | /* Architected event counter 1 does not have an offset register */ |
| 39 | uint64_t group0_voffsets[AMU_GROUP0_MAX_COUNTERS - 1U]; |
| 40 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 41 | uint64_t group1_voffsets[AMU_GROUP1_MAX_COUNTERS]; |
| 42 | #endif |
| 43 | |
| 44 | uint16_t group0_enable; |
| 45 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 46 | uint16_t group1_enable; |
| 47 | #endif |
| 48 | }; |
| 49 | |
| 50 | static struct amu_ctx amu_ctxs_[PLATFORM_CORE_COUNT]; |
| 51 | |
| 52 | CASSERT((sizeof(amu_ctxs_[0].group0_enable) * CHAR_BIT) <= AMU_GROUP0_MAX_COUNTERS, |
| 53 | amu_ctx_group0_enable_cannot_represent_all_group0_counters); |
| 54 | |
| 55 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 56 | CASSERT((sizeof(amu_ctxs_[0].group1_enable) * CHAR_BIT) <= AMU_GROUP1_MAX_COUNTERS, |
| 57 | amu_ctx_group1_enable_cannot_represent_all_group1_counters); |
| 58 | #endif |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 59 | |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 60 | static inline __unused uint64_t read_hcr_el2_amvoffen(void) |
| 61 | { |
| 62 | return (read_hcr_el2() & HCR_AMVOFFEN_BIT) >> |
| 63 | HCR_AMVOFFEN_SHIFT; |
| 64 | } |
| 65 | |
| 66 | static inline __unused void write_cptr_el2_tam(uint64_t value) |
| 67 | { |
| 68 | write_cptr_el2((read_cptr_el2() & ~CPTR_EL2_TAM_BIT) | |
| 69 | ((value << CPTR_EL2_TAM_SHIFT) & CPTR_EL2_TAM_BIT)); |
| 70 | } |
| 71 | |
John Powell | cc79927 | 2022-03-29 00:25:59 -0500 | [diff] [blame] | 72 | static inline __unused void ctx_write_scr_el3_amvoffen(cpu_context_t *ctx, uint64_t amvoffen) |
| 73 | { |
| 74 | uint64_t value = read_ctx_reg(get_el3state_ctx(ctx), CTX_SCR_EL3); |
| 75 | |
| 76 | value &= ~SCR_AMVOFFEN_BIT; |
| 77 | value |= (amvoffen << SCR_AMVOFFEN_SHIFT) & SCR_AMVOFFEN_BIT; |
| 78 | |
| 79 | write_ctx_reg(get_el3state_ctx(ctx), CTX_SCR_EL3, value); |
| 80 | } |
| 81 | |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 82 | static inline __unused void write_hcr_el2_amvoffen(uint64_t value) |
| 83 | { |
| 84 | write_hcr_el2((read_hcr_el2() & ~HCR_AMVOFFEN_BIT) | |
| 85 | ((value << HCR_AMVOFFEN_SHIFT) & HCR_AMVOFFEN_BIT)); |
| 86 | } |
| 87 | |
| 88 | static inline __unused void write_amcr_el0_cg1rz(uint64_t value) |
| 89 | { |
| 90 | write_amcr_el0((read_amcr_el0() & ~AMCR_CG1RZ_BIT) | |
| 91 | ((value << AMCR_CG1RZ_SHIFT) & AMCR_CG1RZ_BIT)); |
| 92 | } |
| 93 | |
| 94 | static inline __unused uint64_t read_amcfgr_el0_ncg(void) |
| 95 | { |
| 96 | return (read_amcfgr_el0() >> AMCFGR_EL0_NCG_SHIFT) & |
| 97 | AMCFGR_EL0_NCG_MASK; |
| 98 | } |
| 99 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 100 | static inline __unused uint64_t read_amcgcr_el0_cg0nc(void) |
Chris Kay | a40141d | 2021-05-25 12:33:18 +0100 | [diff] [blame] | 101 | { |
| 102 | return (read_amcgcr_el0() >> AMCGCR_EL0_CG0NC_SHIFT) & |
| 103 | AMCGCR_EL0_CG0NC_MASK; |
| 104 | } |
| 105 | |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 106 | static inline __unused uint64_t read_amcg1idr_el0_voff(void) |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 107 | { |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 108 | return (read_amcg1idr_el0() >> AMCG1IDR_VOFF_SHIFT) & |
| 109 | AMCG1IDR_VOFF_MASK; |
| 110 | } |
| 111 | |
| 112 | static inline __unused uint64_t read_amcgcr_el0_cg1nc(void) |
| 113 | { |
| 114 | return (read_amcgcr_el0() >> AMCGCR_EL0_CG1NC_SHIFT) & |
| 115 | AMCGCR_EL0_CG1NC_MASK; |
| 116 | } |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 117 | |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 118 | static inline __unused uint64_t read_amcntenset0_el0_px(void) |
| 119 | { |
| 120 | return (read_amcntenset0_el0() >> AMCNTENSET0_EL0_Pn_SHIFT) & |
| 121 | AMCNTENSET0_EL0_Pn_MASK; |
| 122 | } |
| 123 | |
| 124 | static inline __unused uint64_t read_amcntenset1_el0_px(void) |
| 125 | { |
| 126 | return (read_amcntenset1_el0() >> AMCNTENSET1_EL0_Pn_SHIFT) & |
| 127 | AMCNTENSET1_EL0_Pn_MASK; |
| 128 | } |
| 129 | |
| 130 | static inline __unused void write_amcntenset0_el0_px(uint64_t px) |
| 131 | { |
| 132 | uint64_t value = read_amcntenset0_el0(); |
| 133 | |
| 134 | value &= ~AMCNTENSET0_EL0_Pn_MASK; |
| 135 | value |= (px << AMCNTENSET0_EL0_Pn_SHIFT) & AMCNTENSET0_EL0_Pn_MASK; |
| 136 | |
| 137 | write_amcntenset0_el0(value); |
| 138 | } |
| 139 | |
| 140 | static inline __unused void write_amcntenset1_el0_px(uint64_t px) |
| 141 | { |
| 142 | uint64_t value = read_amcntenset1_el0(); |
| 143 | |
| 144 | value &= ~AMCNTENSET1_EL0_Pn_MASK; |
| 145 | value |= (px << AMCNTENSET1_EL0_Pn_SHIFT) & AMCNTENSET1_EL0_Pn_MASK; |
| 146 | |
| 147 | write_amcntenset1_el0(value); |
| 148 | } |
| 149 | |
| 150 | static inline __unused void write_amcntenclr0_el0_px(uint64_t px) |
| 151 | { |
| 152 | uint64_t value = read_amcntenclr0_el0(); |
| 153 | |
| 154 | value &= ~AMCNTENCLR0_EL0_Pn_MASK; |
| 155 | value |= (px << AMCNTENCLR0_EL0_Pn_SHIFT) & AMCNTENCLR0_EL0_Pn_MASK; |
| 156 | |
| 157 | write_amcntenclr0_el0(value); |
| 158 | } |
| 159 | |
| 160 | static inline __unused void write_amcntenclr1_el0_px(uint64_t px) |
| 161 | { |
| 162 | uint64_t value = read_amcntenclr1_el0(); |
| 163 | |
| 164 | value &= ~AMCNTENCLR1_EL0_Pn_MASK; |
| 165 | value |= (px << AMCNTENCLR1_EL0_Pn_SHIFT) & AMCNTENCLR1_EL0_Pn_MASK; |
| 166 | |
| 167 | write_amcntenclr1_el0(value); |
| 168 | } |
| 169 | |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 170 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 171 | static __unused bool amu_group1_supported(void) |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 172 | { |
| 173 | return read_amcfgr_el0_ncg() > 0U; |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 174 | } |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 175 | #endif |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 176 | |
| 177 | /* |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 178 | * Enable counters. This function is meant to be invoked by the context |
| 179 | * management library before exiting from EL3. |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 180 | */ |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 181 | void amu_enable(cpu_context_t *ctx) |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 182 | { |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 183 | /* |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 184 | * Set CPTR_EL3.TAM to zero so that any accesses to the Activity Monitor |
| 185 | * registers do not trap to EL3. |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 186 | */ |
Boyan Karatotev | 8ae58f0 | 2023-04-20 11:00:50 +0100 | [diff] [blame] | 187 | u_register_t cptr_el3 = read_ctx_reg(get_el3state_ctx(ctx), CTX_CPTR_EL3); |
| 188 | |
| 189 | cptr_el3 &= ~TAM_BIT; |
| 190 | write_ctx_reg(get_el3state_ctx(ctx), CTX_CPTR_EL3, cptr_el3); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 191 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 192 | /* Initialize FEAT_AMUv1p1 features if present. */ |
| 193 | if (is_feat_amuv1p1_supported()) { |
| 194 | /* |
| 195 | * Set SCR_EL3.AMVOFFEN to one so that accesses to virtual |
| 196 | * offset registers at EL2 do not trap to EL3 |
| 197 | */ |
| 198 | ctx_write_scr_el3_amvoffen(ctx, 1U); |
| 199 | } |
| 200 | } |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 201 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 202 | void amu_init_el3(void) |
| 203 | { |
| 204 | uint64_t group0_impl_ctr = read_amcgcr_el0_cg0nc(); |
| 205 | uint64_t group0_en_mask = (1 << (group0_impl_ctr)) - 1U; |
| 206 | uint64_t num_ctr_groups = read_amcfgr_el0_ncg(); |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 207 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 208 | /* Enable all architected counters by default */ |
| 209 | write_amcntenset0_el0_px(group0_en_mask); |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 210 | |
| 211 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 212 | if (num_ctr_groups > 0U) { |
| 213 | uint64_t amcntenset1_el0_px = 0x0; /* Group 1 enable mask */ |
| 214 | const struct amu_topology *topology; |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 215 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 216 | /* |
| 217 | * The platform may opt to enable specific auxiliary counters. |
| 218 | * This can be done via the common FCONF getter, or via the |
| 219 | * platform-implemented function. |
| 220 | */ |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 221 | #if ENABLE_AMU_FCONF |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 222 | topology = FCONF_GET_PROPERTY(amu, config, topology); |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 223 | #else |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 224 | topology = plat_amu_topology(); |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 225 | #endif /* ENABLE_AMU_FCONF */ |
| 226 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 227 | if (topology != NULL) { |
| 228 | unsigned int core_pos = plat_my_core_pos(); |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 229 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 230 | amcntenset1_el0_px = topology->cores[core_pos].enable; |
| 231 | } else { |
| 232 | ERROR("AMU: failed to generate AMU topology\n"); |
| 233 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 234 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 235 | write_amcntenset1_el0_px(amcntenset1_el0_px); |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 236 | } |
| 237 | #else /* ENABLE_AMU_AUXILIARY_COUNTERS */ |
| 238 | if (num_ctr_groups > 0U) { |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 239 | VERBOSE("AMU: auxiliary counters detected but support is disabled\n"); |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 240 | } |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 241 | #endif /* ENABLE_AMU_AUXILIARY_COUNTERS */ |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 242 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 243 | if (is_feat_amuv1p1_supported()) { |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 244 | #if AMU_RESTRICT_COUNTERS |
Chris Kay | 03be39d | 2021-05-05 13:38:30 +0100 | [diff] [blame] | 245 | /* |
| 246 | * FEAT_AMUv1p1 adds a register field to restrict access to |
| 247 | * group 1 counters at all but the highest implemented EL. This |
| 248 | * is controlled with the `AMU_RESTRICT_COUNTERS` compile time |
| 249 | * flag, when set, system register reads at lower ELs return |
| 250 | * zero. Reads from the memory mapped view are unaffected. |
| 251 | */ |
| 252 | VERBOSE("AMU group 1 counter access restricted.\n"); |
| 253 | write_amcr_el0_cg1rz(1U); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 254 | #else |
Chris Kay | 03be39d | 2021-05-05 13:38:30 +0100 | [diff] [blame] | 255 | write_amcr_el0_cg1rz(0U); |
| 256 | #endif |
| 257 | } |
| 258 | |
| 259 | #if ENABLE_MPMM |
| 260 | mpmm_enable(); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 261 | #endif |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 264 | void amu_init_el2_unused(void) |
| 265 | { |
| 266 | /* |
| 267 | * CPTR_EL2.TAM: Set to zero so any accesses to the Activity Monitor |
| 268 | * registers do not trap to EL2. |
| 269 | */ |
| 270 | write_cptr_el2_tam(0U); |
| 271 | |
| 272 | /* Initialize FEAT_AMUv1p1 features if present. */ |
| 273 | if (is_feat_amuv1p1_supported()) { |
| 274 | /* Make sure virtual offsets are disabled if EL2 not used. */ |
| 275 | write_hcr_el2_amvoffen(0U); |
| 276 | } |
| 277 | } |
| 278 | |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 279 | /* Read the group 0 counter identified by the given `idx`. */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 280 | static uint64_t amu_group0_cnt_read(unsigned int idx) |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 281 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 282 | assert(is_feat_amu_supported()); |
Chris Kay | a40141d | 2021-05-25 12:33:18 +0100 | [diff] [blame] | 283 | assert(idx < read_amcgcr_el0_cg0nc()); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 284 | |
| 285 | return amu_group0_cnt_read_internal(idx); |
| 286 | } |
| 287 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 288 | /* Write the group 0 counter identified by the given `idx` with `val` */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 289 | static void amu_group0_cnt_write(unsigned int idx, uint64_t val) |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 290 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 291 | assert(is_feat_amu_supported()); |
Chris Kay | a40141d | 2021-05-25 12:33:18 +0100 | [diff] [blame] | 292 | assert(idx < read_amcgcr_el0_cg0nc()); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 293 | |
| 294 | amu_group0_cnt_write_internal(idx, val); |
| 295 | isb(); |
| 296 | } |
| 297 | |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 298 | /* |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 299 | * Unlike with auxiliary counters, we cannot detect at runtime whether an |
| 300 | * architected counter supports a virtual offset. These are instead fixed |
| 301 | * according to FEAT_AMUv1p1, but this switch will need to be updated if later |
| 302 | * revisions of FEAT_AMU add additional architected counters. |
| 303 | */ |
| 304 | static bool amu_group0_voffset_supported(uint64_t idx) |
| 305 | { |
| 306 | switch (idx) { |
| 307 | case 0U: |
| 308 | case 2U: |
| 309 | case 3U: |
| 310 | return true; |
| 311 | |
| 312 | case 1U: |
| 313 | return false; |
| 314 | |
| 315 | default: |
| 316 | ERROR("AMU: can't set up virtual offset for unknown " |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 317 | "architected counter %" PRIu64 "!\n", idx); |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 318 | |
| 319 | panic(); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /* |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 324 | * Read the group 0 offset register for a given index. Index must be 0, 2, |
| 325 | * or 3, the register for 1 does not exist. |
| 326 | * |
| 327 | * Using this function requires FEAT_AMUv1p1 support. |
| 328 | */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 329 | static uint64_t amu_group0_voffset_read(unsigned int idx) |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 330 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 331 | assert(is_feat_amuv1p1_supported()); |
Chris Kay | a40141d | 2021-05-25 12:33:18 +0100 | [diff] [blame] | 332 | assert(idx < read_amcgcr_el0_cg0nc()); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 333 | assert(idx != 1U); |
| 334 | |
| 335 | return amu_group0_voffset_read_internal(idx); |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Write the group 0 offset register for a given index. Index must be 0, 2, or |
| 340 | * 3, the register for 1 does not exist. |
| 341 | * |
| 342 | * Using this function requires FEAT_AMUv1p1 support. |
| 343 | */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 344 | static void amu_group0_voffset_write(unsigned int idx, uint64_t val) |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 345 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 346 | assert(is_feat_amuv1p1_supported()); |
Chris Kay | a40141d | 2021-05-25 12:33:18 +0100 | [diff] [blame] | 347 | assert(idx < read_amcgcr_el0_cg0nc()); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 348 | assert(idx != 1U); |
| 349 | |
| 350 | amu_group0_voffset_write_internal(idx, val); |
| 351 | isb(); |
| 352 | } |
| 353 | |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 354 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 355 | /* Read the group 1 counter identified by the given `idx` */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 356 | static uint64_t amu_group1_cnt_read(unsigned int idx) |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 357 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 358 | assert(is_feat_amu_supported()); |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 359 | assert(amu_group1_supported()); |
Chris Kay | da81914 | 2021-05-25 15:24:18 +0100 | [diff] [blame] | 360 | assert(idx < read_amcgcr_el0_cg1nc()); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 361 | |
| 362 | return amu_group1_cnt_read_internal(idx); |
| 363 | } |
| 364 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 365 | /* Write the group 1 counter identified by the given `idx` with `val` */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 366 | static void amu_group1_cnt_write(unsigned int idx, uint64_t val) |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 367 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 368 | assert(is_feat_amu_supported()); |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 369 | assert(amu_group1_supported()); |
Chris Kay | da81914 | 2021-05-25 15:24:18 +0100 | [diff] [blame] | 370 | assert(idx < read_amcgcr_el0_cg1nc()); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 371 | |
| 372 | amu_group1_cnt_write_internal(idx, val); |
| 373 | isb(); |
| 374 | } |
| 375 | |
| 376 | /* |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 377 | * Read the group 1 offset register for a given index. |
| 378 | * |
| 379 | * Using this function requires FEAT_AMUv1p1 support. |
| 380 | */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 381 | static uint64_t amu_group1_voffset_read(unsigned int idx) |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 382 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 383 | assert(is_feat_amuv1p1_supported()); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 384 | assert(amu_group1_supported()); |
Chris Kay | da81914 | 2021-05-25 15:24:18 +0100 | [diff] [blame] | 385 | assert(idx < read_amcgcr_el0_cg1nc()); |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 386 | assert((read_amcg1idr_el0_voff() & (UINT64_C(1) << idx)) != 0U); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 387 | |
| 388 | return amu_group1_voffset_read_internal(idx); |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Write the group 1 offset register for a given index. |
| 393 | * |
| 394 | * Using this function requires FEAT_AMUv1p1 support. |
| 395 | */ |
Chris Kay | f13c6b5 | 2021-05-24 21:00:07 +0100 | [diff] [blame] | 396 | static void amu_group1_voffset_write(unsigned int idx, uint64_t val) |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 397 | { |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 398 | assert(is_feat_amuv1p1_supported()); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 399 | assert(amu_group1_supported()); |
Chris Kay | da81914 | 2021-05-25 15:24:18 +0100 | [diff] [blame] | 400 | assert(idx < read_amcgcr_el0_cg1nc()); |
Chris Kay | a5fde28 | 2021-05-26 11:58:23 +0100 | [diff] [blame] | 401 | assert((read_amcg1idr_el0_voff() & (UINT64_C(1) << idx)) != 0U); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 402 | |
| 403 | amu_group1_voffset_write_internal(idx, val); |
| 404 | isb(); |
| 405 | } |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 406 | #endif |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 407 | |
| 408 | static void *amu_context_save(const void *arg) |
| 409 | { |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 410 | uint64_t i, j; |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 411 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 412 | unsigned int core_pos; |
| 413 | struct amu_ctx *ctx; |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 414 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 415 | uint64_t hcr_el2_amvoffen = 0; /* AMU virtual offsets enabled */ |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 416 | uint64_t amcgcr_el0_cg0nc; /* Number of group 0 counters */ |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 417 | |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 418 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 419 | uint64_t amcg1idr_el0_voff; /* Auxiliary counters with virtual offsets */ |
| 420 | uint64_t amcfgr_el0_ncg; /* Number of counter groups */ |
| 421 | uint64_t amcgcr_el0_cg1nc; /* Number of group 1 counters */ |
| 422 | #endif |
| 423 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 424 | if (!is_feat_amu_supported()) { |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 425 | return (void *)0; |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 426 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 427 | |
| 428 | core_pos = plat_my_core_pos(); |
| 429 | ctx = &amu_ctxs_[core_pos]; |
| 430 | |
| 431 | amcgcr_el0_cg0nc = read_amcgcr_el0_cg0nc(); |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 432 | if (is_feat_amuv1p1_supported()) { |
| 433 | hcr_el2_amvoffen = read_hcr_el2_amvoffen(); |
| 434 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 435 | |
| 436 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 437 | amcfgr_el0_ncg = read_amcfgr_el0_ncg(); |
| 438 | amcgcr_el0_cg1nc = (amcfgr_el0_ncg > 0U) ? read_amcgcr_el0_cg1nc() : 0U; |
| 439 | amcg1idr_el0_voff = (hcr_el2_amvoffen != 0U) ? read_amcg1idr_el0_voff() : 0U; |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 440 | #endif |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 441 | |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 442 | /* |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 443 | * Disable all AMU counters. |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 444 | */ |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 445 | |
| 446 | ctx->group0_enable = read_amcntenset0_el0_px(); |
| 447 | write_amcntenclr0_el0_px(ctx->group0_enable); |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 448 | |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 449 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 450 | if (amcfgr_el0_ncg > 0U) { |
| 451 | ctx->group1_enable = read_amcntenset1_el0_px(); |
| 452 | write_amcntenclr1_el0_px(ctx->group1_enable); |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 453 | } |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 454 | #endif |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 455 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 456 | /* |
| 457 | * Save the counters to the local context. |
| 458 | */ |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 459 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 460 | isb(); /* Ensure counters have been stopped */ |
| 461 | |
| 462 | for (i = 0U; i < amcgcr_el0_cg0nc; i++) { |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 463 | ctx->group0_cnts[i] = amu_group0_cnt_read(i); |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 464 | } |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 465 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 466 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 467 | for (i = 0U; i < amcgcr_el0_cg1nc; i++) { |
| 468 | ctx->group1_cnts[i] = amu_group1_cnt_read(i); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 469 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 470 | #endif |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 471 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 472 | /* |
| 473 | * Save virtual offsets for counters that offer them. |
| 474 | */ |
| 475 | |
| 476 | if (hcr_el2_amvoffen != 0U) { |
| 477 | for (i = 0U, j = 0U; i < amcgcr_el0_cg0nc; i++) { |
| 478 | if (!amu_group0_voffset_supported(i)) { |
| 479 | continue; /* No virtual offset */ |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 480 | } |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 481 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 482 | ctx->group0_voffsets[j++] = amu_group0_voffset_read(i); |
| 483 | } |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 484 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 485 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 486 | for (i = 0U, j = 0U; i < amcgcr_el0_cg1nc; i++) { |
| 487 | if ((amcg1idr_el0_voff >> i) & 1U) { |
| 488 | continue; /* No virtual offset */ |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 489 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 490 | |
| 491 | ctx->group1_voffsets[j++] = amu_group1_voffset_read(i); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 492 | } |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 493 | #endif |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 494 | } |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 495 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 496 | return (void *)0; |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void *amu_context_restore(const void *arg) |
| 500 | { |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 501 | uint64_t i, j; |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 502 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 503 | unsigned int core_pos; |
| 504 | struct amu_ctx *ctx; |
| 505 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 506 | uint64_t hcr_el2_amvoffen = 0; /* AMU virtual offsets enabled */ |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 507 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 508 | uint64_t amcgcr_el0_cg0nc; /* Number of group 0 counters */ |
| 509 | |
| 510 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 511 | uint64_t amcfgr_el0_ncg; /* Number of counter groups */ |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 512 | uint64_t amcgcr_el0_cg1nc; /* Number of group 1 counters */ |
| 513 | uint64_t amcg1idr_el0_voff; /* Auxiliary counters with virtual offsets */ |
| 514 | #endif |
| 515 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 516 | if (!is_feat_amu_supported()) { |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 517 | return (void *)0; |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 518 | } |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 519 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 520 | core_pos = plat_my_core_pos(); |
| 521 | ctx = &amu_ctxs_[core_pos]; |
| 522 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 523 | amcgcr_el0_cg0nc = read_amcgcr_el0_cg0nc(); |
| 524 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 525 | if (is_feat_amuv1p1_supported()) { |
| 526 | hcr_el2_amvoffen = read_hcr_el2_amvoffen(); |
| 527 | } |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 528 | |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 529 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 530 | amcfgr_el0_ncg = read_amcfgr_el0_ncg(); |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 531 | amcgcr_el0_cg1nc = (amcfgr_el0_ncg > 0U) ? read_amcgcr_el0_cg1nc() : 0U; |
| 532 | amcg1idr_el0_voff = (hcr_el2_amvoffen != 0U) ? read_amcg1idr_el0_voff() : 0U; |
| 533 | #endif |
| 534 | |
| 535 | /* |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 536 | * Restore the counter values from the local context. |
| 537 | */ |
| 538 | |
| 539 | for (i = 0U; i < amcgcr_el0_cg0nc; i++) { |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 540 | amu_group0_cnt_write(i, ctx->group0_cnts[i]); |
| 541 | } |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 542 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 543 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 544 | for (i = 0U; i < amcgcr_el0_cg1nc; i++) { |
| 545 | amu_group1_cnt_write(i, ctx->group1_cnts[i]); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 546 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 547 | #endif |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 548 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 549 | /* |
| 550 | * Restore virtual offsets for counters that offer them. |
| 551 | */ |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 552 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 553 | if (hcr_el2_amvoffen != 0U) { |
| 554 | for (i = 0U, j = 0U; i < amcgcr_el0_cg0nc; i++) { |
| 555 | if (!amu_group0_voffset_supported(i)) { |
| 556 | continue; /* No virtual offset */ |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 557 | } |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 558 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 559 | amu_group0_voffset_write(i, ctx->group0_voffsets[j++]); |
| 560 | } |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 561 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 562 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 563 | for (i = 0U, j = 0U; i < amcgcr_el0_cg1nc; i++) { |
| 564 | if ((amcg1idr_el0_voff >> i) & 1U) { |
| 565 | continue; /* No virtual offset */ |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 566 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 567 | |
| 568 | amu_group1_voffset_write(i, ctx->group1_voffsets[j++]); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 569 | } |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 570 | #endif |
| 571 | } |
| 572 | |
| 573 | /* |
| 574 | * Re-enable counters that were disabled during context save. |
| 575 | */ |
| 576 | |
| 577 | write_amcntenset0_el0_px(ctx->group0_enable); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 578 | |
Chris Kay | 26a7961 | 2021-05-24 20:35:26 +0100 | [diff] [blame] | 579 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 580 | if (amcfgr_el0_ncg > 0) { |
| 581 | write_amcntenset1_el0_px(ctx->group1_enable); |
Chris Kay | 925fda4 | 2021-05-25 10:42:56 +0100 | [diff] [blame] | 582 | } |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 583 | #endif |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 584 | |
Chris Kay | 03be39d | 2021-05-05 13:38:30 +0100 | [diff] [blame] | 585 | #if ENABLE_MPMM |
| 586 | mpmm_enable(); |
| 587 | #endif |
| 588 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 589 | return (void *)0; |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | SUBSCRIBE_TO_EVENT(psci_suspend_pwrdown_start, amu_context_save); |
| 593 | SUBSCRIBE_TO_EVENT(psci_suspend_pwrdown_finish, amu_context_restore); |