blob: e6798a7ce79abb8e9429fbf37d2a4b9dbc329f35 [file] [log] [blame]
Yatharth Kochar9518d022016-03-11 14:20:19 +00001/*
Roberto Vargas2ca18d92018-02-12 12:36:17 +00002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar9518d022016-03-11 14:20:19 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar9518d022016-03-11 14:20:19 +00005 */
6
Antonio Nino Diaze89a4532018-07-18 13:26:25 +01007#ifndef PMF_HELPERS_H
8#define PMF_HELPERS_H
Yatharth Kochar9518d022016-03-11 14:20:19 +00009
Yatharth Kochar9518d022016-03-11 14:20:19 +000010#include <assert.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000011#include <stddef.h>
Isla Mitchell99305012017-07-11 14:54:08 +010012#include <stdint.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000013
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <arch_helpers.h>
15#include <common/bl_common.h>
16#include <plat/common/platform.h>
17
Yatharth Kochar9518d022016-03-11 14:20:19 +000018/*
19 * Prototype for PMF service functions.
20 */
21typedef int (*pmf_svc_init_t)(void);
22typedef 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 */
29typedef 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 Vargas2ca18d92018-02-12 12:36:17 +000048 *
49 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
Yatharth Kochar9518d022016-03-11 14:20:19 +000050 */
dp-arma97bd892016-08-15 10:35:54 +010051#define PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _total_id) \
Roberto Vargas2ca18d92018-02-12 12:36:17 +000052 extern unsigned long long pmf_ts_mem_ ## _name[_total_id]; \
dp-arma97bd892016-08-15 10:35:54 +010053 unsigned long long pmf_ts_mem_ ## _name[_total_id] \
dp-arm8810e832016-09-09 11:39:09 +010054 __aligned(CACHE_WRITEBACK_GRANULE) \
55 __section("pmf_timestamp_array") \
56 __used;
Yatharth Kochar9518d022016-03-11 14:20:19 +000057
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 Vargas2ca18d92018-02-12 12:36:17 +000066 *
67 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
Yatharth Kochar9518d022016-03-11 14:20:19 +000068 */
69#define PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \
70 void pmf_capture_timestamp_ ## _name( \
71 unsigned int tid, \
Roberto Vargas2ca18d92018-02-12 12:36:17 +000072 unsigned long long ts); \
73 void pmf_capture_timestamp_ ## _name( \
74 unsigned int tid, \
Yatharth Kochar9518d022016-03-11 14:20:19 +000075 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 Diaze89a4532018-07-18 13:26:25 +010080 if (((_flags) & PMF_STORE_ENABLE) != 0) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000081 __pmf_store_timestamp(base_addr, tid, ts); \
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010082 if (((_flags) & PMF_DUMP_ENABLE) != 0) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000083 __pmf_dump_timestamp(tid, ts); \
84 } \
85 void pmf_capture_timestamp_with_cache_maint_ ## _name( \
86 unsigned int tid, \
Roberto Vargas2ca18d92018-02-12 12:36:17 +000087 unsigned long long ts); \
88 void pmf_capture_timestamp_with_cache_maint_ ## _name( \
89 unsigned int tid, \
Yatharth Kochar9518d022016-03-11 14:20:19 +000090 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 Diaze89a4532018-07-18 13:26:25 +010095 if (((_flags) & PMF_STORE_ENABLE) != 0) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000096 __pmf_store_timestamp_with_cache_maint(base_addr, tid, ts);\
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010097 if (((_flags) & PMF_DUMP_ENABLE) != 0) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000098 __pmf_dump_timestamp(tid, ts); \
99 }
100
101/*
102 * Convenience macros for retrieving time-stamp.
Roberto Vargas2ca18d92018-02-12 12:36:17 +0000103 *
104 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
Yatharth Kochar9518d022016-03-11 14:20:19 +0000105 */
106#define PMF_DEFINE_GET_TIMESTAMP(_name) \
107 unsigned long long pmf_get_timestamp_by_index_ ## _name( \
Roberto Vargas2ca18d92018-02-12 12:36:17 +0000108 unsigned int tid, unsigned int cpuid, unsigned int flags);\
109 unsigned long long pmf_get_timestamp_by_index_ ## _name( \
Yatharth Kochar9518d022016-03-11 14:20:19 +0000110 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 Vargas2ca18d92018-02-12 12:36:17 +0000117 unsigned int tid, u_register_t mpidr, unsigned int flags);\
118 unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \
Yatharth Kochar9518d022016-03-11 14:20:19 +0000119 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 */
151void __pmf_dump_timestamp(unsigned int tid, unsigned long long ts);
152void __pmf_store_timestamp(uintptr_t base_addr,
153 unsigned int tid,
154 unsigned long long ts);
155void __pmf_store_timestamp_with_cache_maint(uintptr_t base_addr,
156 unsigned int tid,
157 unsigned long long ts);
158unsigned long long __pmf_get_timestamp(uintptr_t base_addr,
159 unsigned int tid,
160 unsigned int cpuid,
161 unsigned int flags);
Antonio Nino Diaze89a4532018-07-18 13:26:25 +0100162#endif /* PMF_HELPERS_H */