2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
14 #include <arch_helpers.h>
15 #include <common/bl_common.h>
16 #include <plat/common/platform.h>
19 * Prototype for PMF service functions.
21 typedef int (*pmf_svc_init_t
)(void);
22 typedef unsigned long long (*pmf_svc_get_ts_t
)(unsigned int tid
,
27 * This is the definition of PMF service desc.
29 typedef struct pmf_svc_desc
{
30 /* Structure version information */
33 /* Name of the PMF service */
36 /* PMF service config: Implementer id, Service id and total id*/
37 unsigned int svc_config
;
39 /* PMF service initialization handler */
42 /* PMF service time-stamp retrieval handler */
43 pmf_svc_get_ts_t get_ts
;
47 * Convenience macro to allocate memory for a PMF service.
49 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
51 #define PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _total_id) \
52 extern unsigned long long pmf_ts_mem_ ## _name[_total_id]; \
53 unsigned long long pmf_ts_mem_ ## _name[_total_id] \
54 __aligned(CACHE_WRITEBACK_GRANULE) \
55 __section("pmf_timestamp_array") \
59 * Convenience macro to validate tid index for the given TS array.
61 #define PMF_VALIDATE_TID(_name, _tid) \
62 assert((_tid & PMF_TID_MASK) < (ARRAY_SIZE(pmf_ts_mem_ ## _name)))
65 * Convenience macros for capturing time-stamp.
67 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
69 #define PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \
70 void pmf_capture_timestamp_ ## _name( \
72 unsigned long long ts); \
73 void pmf_capture_timestamp_ ## _name( \
75 unsigned long long ts) \
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) != 0) \
81 __pmf_store_timestamp(base_addr, tid, ts); \
82 if (((_flags) & PMF_DUMP_ENABLE) != 0) \
83 __pmf_dump_timestamp(tid, ts); \
85 void pmf_capture_timestamp_with_cache_maint_ ## _name( \
87 unsigned long long ts); \
88 void pmf_capture_timestamp_with_cache_maint_ ## _name( \
90 unsigned long long ts) \
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) != 0) \
96 __pmf_store_timestamp_with_cache_maint(base_addr, tid, ts);\
97 if (((_flags) & PMF_DUMP_ENABLE) != 0) \
98 __pmf_dump_timestamp(tid, ts); \
102 * Convenience macros for retrieving time-stamp.
104 * The extern declaration is there to satisfy MISRA C-2012 rule 8.4.
106 #define PMF_DEFINE_GET_TIMESTAMP(_name) \
107 unsigned long long pmf_get_timestamp_by_index_ ## _name( \
108 unsigned int tid, unsigned int cpuid, unsigned int flags);\
109 unsigned long long pmf_get_timestamp_by_index_ ## _name( \
110 unsigned int tid, unsigned int cpuid, unsigned int flags)\
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);\
116 unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \
117 unsigned int tid, u_register_t mpidr, unsigned int flags);\
118 unsigned long long pmf_get_timestamp_by_mpidr_ ## _name( \
119 unsigned int tid, u_register_t mpidr, unsigned int flags)\
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); \
128 * Convenience macro to register a PMF service.
129 * This is needed for services that require SMC handling.
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), \
140 .svc_config = ((((_implid) << PMF_IMPL_ID_SHIFT) & \
141 PMF_IMPL_ID_MASK) | \
142 (((_svcid) << PMF_SVC_ID_SHIFT) & \
144 (((_totalid) << PMF_TID_SHIFT) & \
147 .get_ts = _getts_by_mpidr \
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
,
154 unsigned long long ts
);
155 void __pmf_store_timestamp_with_cache_maint(uintptr_t base_addr
,
157 unsigned long long ts
);
158 unsigned long long __pmf_get_timestamp(uintptr_t base_addr
,
162 #endif /* PMF_HELPERS_H */