Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2025, 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 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 7 | #ifndef AMU_H |
| 8 | #define AMU_H |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | |
Arunachalam Ganapathy | cac7d16 | 2021-07-08 09:35:57 +0100 | [diff] [blame] | 13 | #include <context.h> |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 14 | |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 15 | #include <platform_def.h> |
| 16 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 17 | #if ENABLE_FEAT_AMU |
Arunachalam Ganapathy | cac7d16 | 2021-07-08 09:35:57 +0100 | [diff] [blame] | 18 | #if __aarch64__ |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 19 | void amu_enable(cpu_context_t *ctx); |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 20 | void amu_init_el3(unsigned int core_pos); |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 21 | void amu_init_el2_unused(void); |
Elizabeth Ho | 4fc00d2 | 2023-07-18 14:10:25 +0100 | [diff] [blame] | 22 | void amu_enable_per_world(per_world_context_t *per_world_ctx); |
Arunachalam Ganapathy | cac7d16 | 2021-07-08 09:35:57 +0100 | [diff] [blame] | 23 | #else |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 24 | void amu_enable(bool el2_unused); |
Elizabeth Ho | 4fc00d2 | 2023-07-18 14:10:25 +0100 | [diff] [blame] | 25 | #endif /* __aarch64__ */ |
| 26 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 27 | #else |
| 28 | #if __aarch64__ |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 29 | void amu_enable(cpu_context_t *ctx) |
| 30 | { |
| 31 | } |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 32 | void amu_init_el3(unsigned int core_pos) |
Boyan Karatotev | 1e966f3 | 2023-03-27 17:02:43 +0100 | [diff] [blame] | 33 | { |
| 34 | } |
| 35 | void amu_init_el2_unused(void) |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 36 | { |
| 37 | } |
Elizabeth Ho | 4fc00d2 | 2023-07-18 14:10:25 +0100 | [diff] [blame] | 38 | void amu_enable_per_world(per_world_context_t *per_world_ctx) |
| 39 | { |
| 40 | } |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 41 | #else |
| 42 | static inline void amu_enable(bool el2_unused) |
| 43 | { |
| 44 | } |
Elizabeth Ho | 4fc00d2 | 2023-07-18 14:10:25 +0100 | [diff] [blame] | 45 | #endif /*__aarch64__ */ |
| 46 | #endif /* ENABLE_FEAT_AMU */ |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 47 | |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 48 | /* |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 49 | * Per-core list of the counters to be enabled. Value will be written into |
| 50 | * AMCNTENSET1_EL0 verbatim. |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 51 | */ |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 52 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 53 | extern uint16_t plat_amu_aux_enables[PLATFORM_CORE_COUNT]; |
| 54 | #endif |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 55 | |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 56 | #define CTX_AMU_GRP0_ALL U(4) |
| 57 | #define CTX_AMU_GRP1_ALL U(16) |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 58 | |
Boyan Karatotev | b295347 | 2024-11-06 14:55:35 +0000 | [diff] [blame^] | 59 | typedef struct amu_regs { |
| 60 | u_register_t grp0[CTX_AMU_GRP0_ALL]; |
| 61 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 62 | u_register_t grp1[CTX_AMU_GRP1_ALL]; |
| 63 | #endif |
| 64 | } amu_regs_t; |
| 65 | |
| 66 | static inline u_register_t read_amu_grp0_ctx_reg(amu_regs_t *ctx, size_t index) |
| 67 | { |
| 68 | return ctx->grp0[index]; |
| 69 | } |
| 70 | |
| 71 | static inline void write_amu_grp0_ctx_reg(amu_regs_t *ctx, size_t index, u_register_t val) |
| 72 | { |
| 73 | ctx->grp0[index] = val; |
| 74 | } |
| 75 | |
| 76 | static inline uint16_t get_amu_aux_enables(size_t index) |
| 77 | { |
| 78 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 79 | return plat_amu_aux_enables[index]; |
| 80 | #else |
| 81 | return 0; |
| 82 | #endif |
| 83 | } |
| 84 | |
| 85 | static inline u_register_t read_amu_grp1_ctx_reg(amu_regs_t *ctx, size_t index) |
| 86 | { |
| 87 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 88 | return ctx->grp1[index]; |
| 89 | #else |
| 90 | return 0; |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | static inline void write_amu_grp1_ctx_reg(amu_regs_t *ctx, size_t index, u_register_t val) |
| 95 | { |
| 96 | #if ENABLE_AMU_AUXILIARY_COUNTERS |
| 97 | ctx->grp1[index] = val; |
| 98 | #endif |
| 99 | } |
Chris Kay | f11909f | 2021-08-19 11:21:52 +0100 | [diff] [blame] | 100 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 101 | #endif /* AMU_H */ |