blob: 829ad6ccab4812bf8fec7511dd7c9b0d23f57c0e [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
7#ifndef __PMF_HELPERS_H__
8#define __PMF_HELPERS_H__
9
10#include <arch_helpers.h>
11#include <assert.h>
dp-arm3cac7862016-09-19 11:18:44 +010012#include <bl_common.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000013#include <platform.h>
14#include <pmf.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000015#include <stddef.h>
Isla Mitchell99305012017-07-11 14:54:08 +010016#include <stdint.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000017
18/*
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; \
80 if ((_flags) & PMF_STORE_ENABLE) \
81 __pmf_store_timestamp(base_addr, tid, ts); \
82 if ((_flags) & PMF_DUMP_ENABLE) \
83 __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; \
95 if ((_flags) & PMF_STORE_ENABLE) \
96 __pmf_store_timestamp_with_cache_maint(base_addr, tid, ts);\
97 if ((_flags) & PMF_DUMP_ENABLE) \
98 __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);
162#endif /* __PMF_HELPERS_H__ */