Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 1 | /* |
Roberto Vargas | 777dd43 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 7 | #ifndef PMF_H |
| 8 | #define PMF_H |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 9 | |
| 10 | #include <cassert.h> |
| 11 | #include <pmf_helpers.h> |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 12 | #include <utils_def.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * Constants used for/by PMF services. |
| 16 | */ |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 17 | #define PMF_ARM_TIF_IMPL_ID U(0x41) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 18 | #define PMF_TID_SHIFT 0 |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 19 | #define PMF_TID_MASK (U(0xFF) << PMF_TID_SHIFT) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 20 | #define PMF_SVC_ID_SHIFT 10 |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 21 | #define PMF_SVC_ID_MASK (U(0x3F) << PMF_SVC_ID_SHIFT) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 22 | #define PMF_IMPL_ID_SHIFT 24 |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 23 | #define PMF_IMPL_ID_MASK (U(0xFF) << PMF_IMPL_ID_SHIFT) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Flags passed to PMF_REGISTER_SERVICE |
| 27 | */ |
| 28 | #define PMF_STORE_ENABLE (1 << 0) |
| 29 | #define PMF_DUMP_ENABLE (1 << 1) |
| 30 | |
| 31 | /* |
| 32 | * Flags passed to PMF_GET_TIMESTAMP_XXX |
| 33 | * and PMF_CAPTURE_TIMESTAMP |
| 34 | */ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 35 | #define PMF_CACHE_MAINT (U(1) << 0) |
| 36 | #define PMF_NO_CACHE_MAINT U(0) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Defines for PMF SMC function ids. |
| 40 | */ |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 41 | #define PMF_SMC_GET_TIMESTAMP_32 U(0x82000010) |
| 42 | #define PMF_SMC_GET_TIMESTAMP_64 U(0xC2000010) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 43 | #define PMF_NUM_SMC_CALLS 2 |
| 44 | |
| 45 | /* |
| 46 | * The macros below are used to identify |
| 47 | * PMF calls from the SMC function ID. |
| 48 | */ |
Antonio Nino Diaz | bf170be | 2018-10-25 17:38:23 +0100 | [diff] [blame] | 49 | #define PMF_FID_MASK U(0xffe0) |
| 50 | #define PMF_FID_VALUE U(0) |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 51 | #define is_pmf_fid(_fid) (((_fid) & PMF_FID_MASK) == PMF_FID_VALUE) |
| 52 | |
| 53 | /* Following are the supported PMF service IDs */ |
| 54 | #define PMF_PSCI_STAT_SVC_ID 0 |
dp-arm | 3cac786 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 55 | #define PMF_RT_INSTR_SVC_ID 1 |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 56 | |
| 57 | #if ENABLE_PMF |
| 58 | /* |
| 59 | * Convenience macros for capturing time-stamp. |
| 60 | */ |
| 61 | #define PMF_DECLARE_CAPTURE_TIMESTAMP(_name) \ |
| 62 | void pmf_capture_timestamp_with_cache_maint_ ## _name( \ |
| 63 | unsigned int tid, \ |
| 64 | unsigned long long ts); \ |
| 65 | void pmf_capture_timestamp_ ## _name( \ |
| 66 | unsigned int tid, \ |
| 67 | unsigned long long ts); |
| 68 | |
| 69 | #define PMF_CAPTURE_TIMESTAMP(_name, _tid, _flags) \ |
| 70 | do { \ |
| 71 | unsigned long long ts = read_cntpct_el0(); \ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 72 | if (((_flags) & PMF_CACHE_MAINT) != 0U) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 73 | pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), ts);\ |
| 74 | else \ |
| 75 | pmf_capture_timestamp_ ## _name((_tid), ts); \ |
| 76 | } while (0) |
| 77 | |
| 78 | #define PMF_CAPTURE_AND_GET_TIMESTAMP(_name, _tid, _flags, _tsval) \ |
| 79 | do { \ |
| 80 | (_tsval) = read_cntpct_el0(); \ |
| 81 | CASSERT(sizeof(_tsval) == sizeof(unsigned long long), invalid_tsval_size);\ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 82 | if (((_flags) & PMF_CACHE_MAINT) != 0U) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 83 | pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), (_tsval));\ |
| 84 | else \ |
| 85 | pmf_capture_timestamp_ ## _name((_tid), (_tsval));\ |
| 86 | } while (0) |
| 87 | |
| 88 | #define PMF_WRITE_TIMESTAMP(_name, _tid, _flags, _wrval) \ |
| 89 | do { \ |
| 90 | CASSERT(sizeof(_wrval) == sizeof(unsigned long long), invalid_wrval_size);\ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 91 | if (((_flags) & PMF_CACHE_MAINT) != 0U) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 92 | pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), (_wrval));\ |
| 93 | else \ |
| 94 | pmf_capture_timestamp_ ## _name((_tid), (_wrval));\ |
| 95 | } while (0) |
| 96 | |
| 97 | /* |
| 98 | * Convenience macros for retrieving time-stamp. |
| 99 | */ |
| 100 | #define PMF_DECLARE_GET_TIMESTAMP(_name) \ |
| 101 | unsigned long long pmf_get_timestamp_by_index_ ## _name(\ |
| 102 | unsigned int tid, \ |
| 103 | unsigned int cpuid, \ |
| 104 | unsigned int flags); \ |
| 105 | unsigned long long pmf_get_timestamp_by_mpidr_ ## _name(\ |
| 106 | unsigned int tid, \ |
| 107 | u_register_t mpidr, \ |
| 108 | unsigned int flags); |
| 109 | |
| 110 | #define PMF_GET_TIMESTAMP_BY_MPIDR(_name, _tid, _mpidr, _flags, _tsval)\ |
| 111 | _tsval = pmf_get_timestamp_by_mpidr_ ## _name(_tid, _mpidr, _flags) |
| 112 | |
| 113 | #define PMF_GET_TIMESTAMP_BY_INDEX(_name, _tid, _cpuid, _flags, _tsval)\ |
| 114 | _tsval = pmf_get_timestamp_by_index_ ## _name(_tid, _cpuid, _flags) |
| 115 | |
| 116 | /* Convenience macros to register a PMF service.*/ |
| 117 | /* |
| 118 | * This macro is used to register a PMF Service. It allocates PMF memory |
| 119 | * and defines default service-specific PMF functions. |
| 120 | */ |
| 121 | #define PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags) \ |
| 122 | PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _totalid) \ |
| 123 | PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \ |
| 124 | PMF_DEFINE_GET_TIMESTAMP(_name) |
| 125 | |
| 126 | /* |
| 127 | * This macro is used to register a PMF service, including an |
| 128 | * SMC interface to that service. |
| 129 | */ |
| 130 | #define PMF_REGISTER_SERVICE_SMC(_name, _svcid, _totalid, _flags)\ |
| 131 | PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags) \ |
| 132 | PMF_DEFINE_SERVICE_DESC(_name, PMF_ARM_TIF_IMPL_ID, \ |
| 133 | _svcid, _totalid, NULL, \ |
| 134 | pmf_get_timestamp_by_mpidr_ ## _name) |
| 135 | |
| 136 | /* |
| 137 | * This macro is used to register a PMF service that has an SMC interface |
| 138 | * but provides its own service-specific PMF functions. |
| 139 | */ |
| 140 | #define PMF_REGISTER_SERVICE_SMC_OWN(_name, _implid, _svcid, _totalid, \ |
| 141 | _init, _getts) \ |
| 142 | PMF_DEFINE_SERVICE_DESC(_name, _implid, _svcid, _totalid, \ |
| 143 | _init, _getts) |
| 144 | |
| 145 | #else |
| 146 | |
| 147 | #define PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags) |
| 148 | #define PMF_REGISTER_SERVICE_SMC(_name, _svcid, _totalid, _flags) |
| 149 | #define PMF_REGISTER_SERVICE_SMC_OWN(_name, _implid, _svcid, _totalid, \ |
| 150 | _init, _getts) |
| 151 | #define PMF_DECLARE_CAPTURE_TIMESTAMP(_name) |
| 152 | #define PMF_DECLARE_GET_TIMESTAMP(_name) |
| 153 | #define PMF_CAPTURE_TIMESTAMP(_name, _tid, _flags) |
| 154 | #define PMF_GET_TIMESTAMP_BY_MPIDR(_name, _tid, _mpidr, _flags, _tsval) |
| 155 | #define PMF_GET_TIMESTAMP_BY_INDEX(_name, _tid, _cpuid, _flags, _tsval) |
| 156 | |
| 157 | #endif /* ENABLE_PMF */ |
| 158 | |
| 159 | /******************************************************************************* |
| 160 | * Function & variable prototypes |
| 161 | ******************************************************************************/ |
| 162 | /* PMF common functions */ |
| 163 | int pmf_get_timestamp_smc(unsigned int tid, |
| 164 | u_register_t mpidr, |
| 165 | unsigned int flags, |
Roberto Vargas | 777dd43 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 166 | unsigned long long *ts_value); |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 167 | int pmf_setup(void); |
| 168 | uintptr_t pmf_smc_handler(unsigned int smc_fid, |
| 169 | u_register_t x1, |
| 170 | u_register_t x2, |
| 171 | u_register_t x3, |
| 172 | u_register_t x4, |
| 173 | void *cookie, |
| 174 | void *handle, |
| 175 | u_register_t flags); |
| 176 | |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 177 | #endif /* PMF_H */ |