Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 1 | /* |
Roberto Vargas | 2ca18d9 | 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_HELPERS_H |
| 8 | #define PMF_HELPERS_H |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <assert.h> |
dp-arm | 3cac786 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 12 | #include <bl_common.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 13 | #include <platform.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 14 | #include <stddef.h> |
Isla Mitchell | 9930501 | 2017-07-11 14:54:08 +0100 | [diff] [blame] | 15 | #include <stdint.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * Prototype for PMF service functions. |
| 19 | */ |
| 20 | typedef int (*pmf_svc_init_t)(void); |
| 21 | typedef unsigned long long (*pmf_svc_get_ts_t)(unsigned int tid, |
| 22 | u_register_t mpidr, |
| 23 | unsigned int flags); |
| 24 | |
| 25 | /* |
| 26 | * This is the definition of PMF service desc. |
| 27 | */ |
| 28 | typedef struct pmf_svc_desc { |
| 29 | /* Structure version information */ |
| 30 | param_header_t h; |
| 31 | |
| 32 | /* Name of the PMF service */ |
| 33 | const char *name; |
| 34 | |
| 35 | /* PMF service config: Implementer id, Service id and total id*/ |
| 36 | unsigned int svc_config; |
| 37 | |
| 38 | /* PMF service initialization handler */ |
| 39 | pmf_svc_init_t init; |
| 40 | |
| 41 | /* PMF service time-stamp retrieval handler */ |
| 42 | pmf_svc_get_ts_t get_ts; |
| 43 | } pmf_svc_desc_t; |
| 44 | |
| 45 | /* |
| 46 | * Convenience macro to allocate memory for a PMF service. |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 47 | * |
| 48 | * The extern declaration is there to satisfy MISRA C-2012 rule 8.4. |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 49 | */ |
dp-arm | a97bd89 | 2016-08-15 10:35:54 +0100 | [diff] [blame] | 50 | #define PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _total_id) \ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 51 | extern unsigned long long pmf_ts_mem_ ## _name[_total_id]; \ |
dp-arm | a97bd89 | 2016-08-15 10:35:54 +0100 | [diff] [blame] | 52 | unsigned long long pmf_ts_mem_ ## _name[_total_id] \ |
dp-arm | 8810e83 | 2016-09-09 11:39:09 +0100 | [diff] [blame] | 53 | __aligned(CACHE_WRITEBACK_GRANULE) \ |
| 54 | __section("pmf_timestamp_array") \ |
| 55 | __used; |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * Convenience macro to validate tid index for the given TS array. |
| 59 | */ |
| 60 | #define PMF_VALIDATE_TID(_name, _tid) \ |
| 61 | assert((_tid & PMF_TID_MASK) < (ARRAY_SIZE(pmf_ts_mem_ ## _name))) |
| 62 | |
| 63 | /* |
| 64 | * Convenience macros for capturing time-stamp. |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 65 | * |
| 66 | * The extern declaration is there to satisfy MISRA C-2012 rule 8.4. |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 67 | */ |
| 68 | #define PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \ |
| 69 | void pmf_capture_timestamp_ ## _name( \ |
| 70 | unsigned int tid, \ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 71 | unsigned long long ts); \ |
| 72 | void pmf_capture_timestamp_ ## _name( \ |
| 73 | unsigned int tid, \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 74 | unsigned long long ts) \ |
| 75 | { \ |
| 76 | CASSERT(_flags, select_proper_config); \ |
| 77 | PMF_VALIDATE_TID(_name, tid); \ |
| 78 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 79 | if (((_flags) & PMF_STORE_ENABLE) != 0) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 80 | __pmf_store_timestamp(base_addr, tid, ts); \ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 81 | if (((_flags) & PMF_DUMP_ENABLE) != 0) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 82 | __pmf_dump_timestamp(tid, ts); \ |
| 83 | } \ |
| 84 | void pmf_capture_timestamp_with_cache_maint_ ## _name( \ |
| 85 | unsigned int tid, \ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 86 | unsigned long long ts); \ |
| 87 | void pmf_capture_timestamp_with_cache_maint_ ## _name( \ |
| 88 | unsigned int tid, \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 89 | unsigned long long ts) \ |
| 90 | { \ |
| 91 | CASSERT(_flags, select_proper_config); \ |
| 92 | PMF_VALIDATE_TID(_name, tid); \ |
| 93 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 94 | if (((_flags) & PMF_STORE_ENABLE) != 0) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 95 | __pmf_store_timestamp_with_cache_maint(base_addr, tid, ts);\ |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 96 | if (((_flags) & PMF_DUMP_ENABLE) != 0) \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 97 | __pmf_dump_timestamp(tid, ts); \ |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Convenience macros for retrieving time-stamp. |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 102 | * |
| 103 | * The extern declaration is there to satisfy MISRA C-2012 rule 8.4. |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 104 | */ |
| 105 | #define PMF_DEFINE_GET_TIMESTAMP(_name) \ |
| 106 | unsigned long long pmf_get_timestamp_by_index_ ## _name( \ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 107 | unsigned int tid, unsigned int cpuid, unsigned int flags);\ |
| 108 | unsigned long long pmf_get_timestamp_by_index_ ## _name( \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 109 | unsigned int tid, unsigned int cpuid, unsigned int flags)\ |
| 110 | { \ |
| 111 | PMF_VALIDATE_TID(_name, tid); \ |
| 112 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
| 113 | return __pmf_get_timestamp(base_addr, tid, cpuid, flags);\ |
| 114 | } \ |
| 115 | unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 116 | unsigned int tid, u_register_t mpidr, unsigned int flags);\ |
| 117 | unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \ |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 118 | unsigned int tid, u_register_t mpidr, unsigned int flags)\ |
| 119 | { \ |
| 120 | PMF_VALIDATE_TID(_name, tid); \ |
| 121 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
| 122 | return __pmf_get_timestamp(base_addr, tid, \ |
| 123 | plat_core_pos_by_mpidr(mpidr), flags); \ |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Convenience macro to register a PMF service. |
| 128 | * This is needed for services that require SMC handling. |
| 129 | */ |
| 130 | #define PMF_DEFINE_SERVICE_DESC(_name, _implid, _svcid, _totalid, \ |
| 131 | _init, _getts_by_mpidr) \ |
| 132 | static const pmf_svc_desc_t __pmf_desc_ ## _name \ |
| 133 | __section("pmf_svc_descs") __used = { \ |
| 134 | .h.type = PARAM_EP, \ |
| 135 | .h.version = VERSION_1, \ |
| 136 | .h.size = sizeof(pmf_svc_desc_t), \ |
| 137 | .h.attr = 0, \ |
| 138 | .name = #_name, \ |
| 139 | .svc_config = ((((_implid) << PMF_IMPL_ID_SHIFT) & \ |
| 140 | PMF_IMPL_ID_MASK) | \ |
| 141 | (((_svcid) << PMF_SVC_ID_SHIFT) & \ |
| 142 | PMF_SVC_ID_MASK) | \ |
| 143 | (((_totalid) << PMF_TID_SHIFT) & \ |
| 144 | PMF_TID_MASK)), \ |
| 145 | .init = _init, \ |
| 146 | .get_ts = _getts_by_mpidr \ |
| 147 | }; |
| 148 | |
| 149 | /* PMF internal functions */ |
| 150 | void __pmf_dump_timestamp(unsigned int tid, unsigned long long ts); |
| 151 | void __pmf_store_timestamp(uintptr_t base_addr, |
| 152 | unsigned int tid, |
| 153 | unsigned long long ts); |
| 154 | void __pmf_store_timestamp_with_cache_maint(uintptr_t base_addr, |
| 155 | unsigned int tid, |
| 156 | unsigned long long ts); |
| 157 | unsigned long long __pmf_get_timestamp(uintptr_t base_addr, |
| 158 | unsigned int tid, |
| 159 | unsigned int cpuid, |
| 160 | unsigned int flags); |
Antonio Nino Diaz | e89a453 | 2018-07-18 13:26:25 +0100 | [diff] [blame] | 161 | #endif /* PMF_HELPERS_H */ |