Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PMF_HELPERS_H__ |
| 32 | #define __PMF_HELPERS_H__ |
| 33 | |
| 34 | #include <arch_helpers.h> |
| 35 | #include <assert.h> |
dp-arm | 3cac786 | 2016-09-19 11:18:44 +0100 | [diff] [blame] | 36 | #include <bl_common.h> |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 37 | #include <platform.h> |
| 38 | #include <pmf.h> |
| 39 | #include <stdint.h> |
| 40 | #include <stddef.h> |
| 41 | |
| 42 | /* |
| 43 | * Prototype for PMF service functions. |
| 44 | */ |
| 45 | typedef int (*pmf_svc_init_t)(void); |
| 46 | typedef unsigned long long (*pmf_svc_get_ts_t)(unsigned int tid, |
| 47 | u_register_t mpidr, |
| 48 | unsigned int flags); |
| 49 | |
| 50 | /* |
| 51 | * This is the definition of PMF service desc. |
| 52 | */ |
| 53 | typedef struct pmf_svc_desc { |
| 54 | /* Structure version information */ |
| 55 | param_header_t h; |
| 56 | |
| 57 | /* Name of the PMF service */ |
| 58 | const char *name; |
| 59 | |
| 60 | /* PMF service config: Implementer id, Service id and total id*/ |
| 61 | unsigned int svc_config; |
| 62 | |
| 63 | /* PMF service initialization handler */ |
| 64 | pmf_svc_init_t init; |
| 65 | |
| 66 | /* PMF service time-stamp retrieval handler */ |
| 67 | pmf_svc_get_ts_t get_ts; |
| 68 | } pmf_svc_desc_t; |
| 69 | |
| 70 | /* |
| 71 | * Convenience macro to allocate memory for a PMF service. |
| 72 | */ |
dp-arm | a97bd89 | 2016-08-15 10:35:54 +0100 | [diff] [blame] | 73 | #define PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _total_id) \ |
| 74 | unsigned long long pmf_ts_mem_ ## _name[_total_id] \ |
dp-arm | 8810e83 | 2016-09-09 11:39:09 +0100 | [diff] [blame] | 75 | __aligned(CACHE_WRITEBACK_GRANULE) \ |
| 76 | __section("pmf_timestamp_array") \ |
| 77 | __used; |
Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Convenience macro to validate tid index for the given TS array. |
| 81 | */ |
| 82 | #define PMF_VALIDATE_TID(_name, _tid) \ |
| 83 | assert((_tid & PMF_TID_MASK) < (ARRAY_SIZE(pmf_ts_mem_ ## _name))) |
| 84 | |
| 85 | /* |
| 86 | * Convenience macros for capturing time-stamp. |
| 87 | */ |
| 88 | #define PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \ |
| 89 | void pmf_capture_timestamp_ ## _name( \ |
| 90 | unsigned int tid, \ |
| 91 | unsigned long long ts) \ |
| 92 | { \ |
| 93 | CASSERT(_flags, select_proper_config); \ |
| 94 | PMF_VALIDATE_TID(_name, tid); \ |
| 95 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
| 96 | if ((_flags) & PMF_STORE_ENABLE) \ |
| 97 | __pmf_store_timestamp(base_addr, tid, ts); \ |
| 98 | if ((_flags) & PMF_DUMP_ENABLE) \ |
| 99 | __pmf_dump_timestamp(tid, ts); \ |
| 100 | } \ |
| 101 | void pmf_capture_timestamp_with_cache_maint_ ## _name( \ |
| 102 | unsigned int tid, \ |
| 103 | unsigned long long ts) \ |
| 104 | { \ |
| 105 | CASSERT(_flags, select_proper_config); \ |
| 106 | PMF_VALIDATE_TID(_name, tid); \ |
| 107 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
| 108 | if ((_flags) & PMF_STORE_ENABLE) \ |
| 109 | __pmf_store_timestamp_with_cache_maint(base_addr, tid, ts);\ |
| 110 | if ((_flags) & PMF_DUMP_ENABLE) \ |
| 111 | __pmf_dump_timestamp(tid, ts); \ |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Convenience macros for retrieving time-stamp. |
| 116 | */ |
| 117 | #define PMF_DEFINE_GET_TIMESTAMP(_name) \ |
| 118 | unsigned long long pmf_get_timestamp_by_index_ ## _name( \ |
| 119 | unsigned int tid, unsigned int cpuid, 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, cpuid, flags);\ |
| 124 | } \ |
| 125 | unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \ |
| 126 | unsigned int tid, u_register_t mpidr, unsigned int flags)\ |
| 127 | { \ |
| 128 | PMF_VALIDATE_TID(_name, tid); \ |
| 129 | uintptr_t base_addr = (uintptr_t) pmf_ts_mem_ ## _name; \ |
| 130 | return __pmf_get_timestamp(base_addr, tid, \ |
| 131 | plat_core_pos_by_mpidr(mpidr), flags); \ |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Convenience macro to register a PMF service. |
| 136 | * This is needed for services that require SMC handling. |
| 137 | */ |
| 138 | #define PMF_DEFINE_SERVICE_DESC(_name, _implid, _svcid, _totalid, \ |
| 139 | _init, _getts_by_mpidr) \ |
| 140 | static const pmf_svc_desc_t __pmf_desc_ ## _name \ |
| 141 | __section("pmf_svc_descs") __used = { \ |
| 142 | .h.type = PARAM_EP, \ |
| 143 | .h.version = VERSION_1, \ |
| 144 | .h.size = sizeof(pmf_svc_desc_t), \ |
| 145 | .h.attr = 0, \ |
| 146 | .name = #_name, \ |
| 147 | .svc_config = ((((_implid) << PMF_IMPL_ID_SHIFT) & \ |
| 148 | PMF_IMPL_ID_MASK) | \ |
| 149 | (((_svcid) << PMF_SVC_ID_SHIFT) & \ |
| 150 | PMF_SVC_ID_MASK) | \ |
| 151 | (((_totalid) << PMF_TID_SHIFT) & \ |
| 152 | PMF_TID_MASK)), \ |
| 153 | .init = _init, \ |
| 154 | .get_ts = _getts_by_mpidr \ |
| 155 | }; |
| 156 | |
| 157 | /* PMF internal functions */ |
| 158 | void __pmf_dump_timestamp(unsigned int tid, unsigned long long ts); |
| 159 | void __pmf_store_timestamp(uintptr_t base_addr, |
| 160 | unsigned int tid, |
| 161 | unsigned long long ts); |
| 162 | void __pmf_store_timestamp_with_cache_maint(uintptr_t base_addr, |
| 163 | unsigned int tid, |
| 164 | unsigned long long ts); |
| 165 | unsigned long long __pmf_get_timestamp(uintptr_t base_addr, |
| 166 | unsigned int tid, |
| 167 | unsigned int cpuid, |
| 168 | unsigned int flags); |
| 169 | #endif /* __PMF_HELPERS_H__ */ |