Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 1 | /* |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -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 | |
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> |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 11 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <lib/cassert.h> |
| 14 | #include <lib/utils_def.h> |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 15 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 16 | #include <platform_def.h> |
| 17 | |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 18 | /* All group 0 counters */ |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 19 | #define AMU_GROUP0_COUNTERS_MASK U(0xf) |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 20 | #define AMU_GROUP0_NR_COUNTERS U(4) |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 21 | |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 22 | #ifdef PLAT_AMU_GROUP1_COUNTERS_MASK |
| 23 | #define AMU_GROUP1_COUNTERS_MASK PLAT_AMU_GROUP1_COUNTERS_MASK |
| 24 | #else |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 25 | #define AMU_GROUP1_COUNTERS_MASK U(0) |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 26 | #endif |
| 27 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 28 | /* Calculate number of group 1 counters */ |
| 29 | #if (AMU_GROUP1_COUNTERS_MASK & (1 << 15)) |
| 30 | #define AMU_GROUP1_NR_COUNTERS 16U |
| 31 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 14)) |
| 32 | #define AMU_GROUP1_NR_COUNTERS 15U |
| 33 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 13)) |
| 34 | #define AMU_GROUP1_NR_COUNTERS 14U |
| 35 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 12)) |
| 36 | #define AMU_GROUP1_NR_COUNTERS 13U |
| 37 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 11)) |
| 38 | #define AMU_GROUP1_NR_COUNTERS 12U |
| 39 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 10)) |
| 40 | #define AMU_GROUP1_NR_COUNTERS 11U |
| 41 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 9)) |
| 42 | #define AMU_GROUP1_NR_COUNTERS 10U |
| 43 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 8)) |
| 44 | #define AMU_GROUP1_NR_COUNTERS 9U |
| 45 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 7)) |
| 46 | #define AMU_GROUP1_NR_COUNTERS 8U |
| 47 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 6)) |
| 48 | #define AMU_GROUP1_NR_COUNTERS 7U |
| 49 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 5)) |
| 50 | #define AMU_GROUP1_NR_COUNTERS 6U |
| 51 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 4)) |
| 52 | #define AMU_GROUP1_NR_COUNTERS 5U |
| 53 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 3)) |
| 54 | #define AMU_GROUP1_NR_COUNTERS 4U |
| 55 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 2)) |
| 56 | #define AMU_GROUP1_NR_COUNTERS 3U |
| 57 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 1)) |
| 58 | #define AMU_GROUP1_NR_COUNTERS 2U |
| 59 | #elif (AMU_GROUP1_COUNTERS_MASK & (1 << 0)) |
| 60 | #define AMU_GROUP1_NR_COUNTERS 1U |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 61 | #else |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 62 | #define AMU_GROUP1_NR_COUNTERS 0U |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
| 65 | CASSERT(AMU_GROUP1_COUNTERS_MASK <= 0xffff, invalid_amu_group1_counters_mask); |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 66 | |
| 67 | struct amu_ctx { |
| 68 | uint64_t group0_cnts[AMU_GROUP0_NR_COUNTERS]; |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 69 | #if __aarch64__ |
| 70 | /* Architected event counter 1 does not have an offset register. */ |
| 71 | uint64_t group0_voffsets[AMU_GROUP0_NR_COUNTERS-1]; |
| 72 | #endif |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 73 | |
| 74 | #if AMU_GROUP1_NR_COUNTERS |
| 75 | uint64_t group1_cnts[AMU_GROUP1_NR_COUNTERS]; |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 76 | #if __aarch64__ |
| 77 | uint64_t group1_voffsets[AMU_GROUP1_NR_COUNTERS]; |
| 78 | #endif |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 79 | #endif |
| 80 | }; |
Dimitris Papastamos | 60346db | 2017-12-13 10:54:37 +0000 | [diff] [blame] | 81 | |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 82 | unsigned int amu_get_version(void); |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 83 | void amu_enable(bool el2_unused); |
Dimitris Papastamos | e08005a | 2017-10-12 13:02:29 +0100 | [diff] [blame] | 84 | |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 85 | /* Group 0 configuration helpers */ |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 86 | uint64_t amu_group0_cnt_read(unsigned int idx); |
| 87 | void amu_group0_cnt_write(unsigned int idx, uint64_t val); |
| 88 | |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 89 | #if __aarch64__ |
| 90 | uint64_t amu_group0_voffset_read(unsigned int idx); |
| 91 | void amu_group0_voffset_write(unsigned int idx, uint64_t val); |
| 92 | #endif |
| 93 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 94 | #if AMU_GROUP1_NR_COUNTERS |
| 95 | bool amu_group1_supported(void); |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 96 | |
| 97 | /* Group 1 configuration helpers */ |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 98 | uint64_t amu_group1_cnt_read(unsigned int idx); |
| 99 | void amu_group1_cnt_write(unsigned int idx, uint64_t val); |
| 100 | void amu_group1_set_evtype(unsigned int idx, unsigned int val); |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 101 | |
| 102 | #if __aarch64__ |
| 103 | uint64_t amu_group1_voffset_read(unsigned int idx); |
| 104 | void amu_group1_voffset_write(unsigned int idx, uint64_t val); |
| 105 | #endif |
| 106 | |
Alexei Fedorov | 7e6306b | 2020-07-14 08:17:56 +0100 | [diff] [blame] | 107 | #endif |
Dimitris Papastamos | 525c37a | 2017-11-13 09:49:45 +0000 | [diff] [blame] | 108 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 109 | #endif /* AMU_H */ |