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