blob: 18ef0a5598ea87ad1c8ae058416063b826b5b1e9 [file] [log] [blame]
Yatharth Kochar9518d022016-03-11 14:20:19 +00001/*
Roberto Vargas777dd432018-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_H
8#define PMF_H
Yatharth Kochar9518d022016-03-11 14:20:19 +00009
10#include <cassert.h>
11#include <pmf_helpers.h>
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010012#include <utils_def.h>
Yatharth Kochar9518d022016-03-11 14:20:19 +000013
14/*
15 * Constants used for/by PMF services.
16 */
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010017#define PMF_ARM_TIF_IMPL_ID U(0x41)
Yatharth Kochar9518d022016-03-11 14:20:19 +000018#define PMF_TID_SHIFT 0
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010019#define PMF_TID_MASK (U(0xFF) << PMF_TID_SHIFT)
Yatharth Kochar9518d022016-03-11 14:20:19 +000020#define PMF_SVC_ID_SHIFT 10
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010021#define PMF_SVC_ID_MASK (U(0x3F) << PMF_SVC_ID_SHIFT)
Yatharth Kochar9518d022016-03-11 14:20:19 +000022#define PMF_IMPL_ID_SHIFT 24
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010023#define PMF_IMPL_ID_MASK (U(0xFF) << PMF_IMPL_ID_SHIFT)
Yatharth Kochar9518d022016-03-11 14:20:19 +000024
25/*
26 * Flags passed to PMF_REGISTER_SERVICE
27 */
28#define PMF_STORE_ENABLE (1 << 0)
29#define PMF_DUMP_ENABLE (1 << 1)
30
31/*
32 * Flags passed to PMF_GET_TIMESTAMP_XXX
33 * and PMF_CAPTURE_TIMESTAMP
34 */
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010035#define PMF_CACHE_MAINT (U(1) << 0)
36#define PMF_NO_CACHE_MAINT U(0)
Yatharth Kochar9518d022016-03-11 14:20:19 +000037
38/*
39 * Defines for PMF SMC function ids.
40 */
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010041#define PMF_SMC_GET_TIMESTAMP_32 U(0x82000010)
42#define PMF_SMC_GET_TIMESTAMP_64 U(0xC2000010)
Yatharth Kochar9518d022016-03-11 14:20:19 +000043#define PMF_NUM_SMC_CALLS 2
44
45/*
46 * The macros below are used to identify
47 * PMF calls from the SMC function ID.
48 */
Antonio Nino Diazbf170be2018-10-25 17:38:23 +010049#define PMF_FID_MASK U(0xffe0)
50#define PMF_FID_VALUE U(0)
Yatharth Kochar9518d022016-03-11 14:20:19 +000051#define is_pmf_fid(_fid) (((_fid) & PMF_FID_MASK) == PMF_FID_VALUE)
52
53/* Following are the supported PMF service IDs */
54#define PMF_PSCI_STAT_SVC_ID 0
dp-arm3cac7862016-09-19 11:18:44 +010055#define PMF_RT_INSTR_SVC_ID 1
Yatharth Kochar9518d022016-03-11 14:20:19 +000056
57#if ENABLE_PMF
58/*
59 * Convenience macros for capturing time-stamp.
60 */
61#define PMF_DECLARE_CAPTURE_TIMESTAMP(_name) \
62 void pmf_capture_timestamp_with_cache_maint_ ## _name( \
63 unsigned int tid, \
64 unsigned long long ts); \
65 void pmf_capture_timestamp_ ## _name( \
66 unsigned int tid, \
67 unsigned long long ts);
68
69#define PMF_CAPTURE_TIMESTAMP(_name, _tid, _flags) \
70 do { \
71 unsigned long long ts = read_cntpct_el0(); \
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010072 if (((_flags) & PMF_CACHE_MAINT) != 0U) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000073 pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), ts);\
74 else \
75 pmf_capture_timestamp_ ## _name((_tid), ts); \
76 } while (0)
77
78#define PMF_CAPTURE_AND_GET_TIMESTAMP(_name, _tid, _flags, _tsval) \
79 do { \
80 (_tsval) = read_cntpct_el0(); \
81 CASSERT(sizeof(_tsval) == sizeof(unsigned long long), invalid_tsval_size);\
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010082 if (((_flags) & PMF_CACHE_MAINT) != 0U) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000083 pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), (_tsval));\
84 else \
85 pmf_capture_timestamp_ ## _name((_tid), (_tsval));\
86 } while (0)
87
88#define PMF_WRITE_TIMESTAMP(_name, _tid, _flags, _wrval) \
89 do { \
90 CASSERT(sizeof(_wrval) == sizeof(unsigned long long), invalid_wrval_size);\
Antonio Nino Diaze89a4532018-07-18 13:26:25 +010091 if (((_flags) & PMF_CACHE_MAINT) != 0U) \
Yatharth Kochar9518d022016-03-11 14:20:19 +000092 pmf_capture_timestamp_with_cache_maint_ ## _name((_tid), (_wrval));\
93 else \
94 pmf_capture_timestamp_ ## _name((_tid), (_wrval));\
95 } while (0)
96
97/*
98 * Convenience macros for retrieving time-stamp.
99 */
100#define PMF_DECLARE_GET_TIMESTAMP(_name) \
101 unsigned long long pmf_get_timestamp_by_index_ ## _name(\
102 unsigned int tid, \
103 unsigned int cpuid, \
104 unsigned int flags); \
105 unsigned long long pmf_get_timestamp_by_mpidr_ ## _name(\
106 unsigned int tid, \
107 u_register_t mpidr, \
108 unsigned int flags);
109
110#define PMF_GET_TIMESTAMP_BY_MPIDR(_name, _tid, _mpidr, _flags, _tsval)\
111 _tsval = pmf_get_timestamp_by_mpidr_ ## _name(_tid, _mpidr, _flags)
112
113#define PMF_GET_TIMESTAMP_BY_INDEX(_name, _tid, _cpuid, _flags, _tsval)\
114 _tsval = pmf_get_timestamp_by_index_ ## _name(_tid, _cpuid, _flags)
115
116/* Convenience macros to register a PMF service.*/
117/*
118 * This macro is used to register a PMF Service. It allocates PMF memory
119 * and defines default service-specific PMF functions.
120 */
121#define PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags) \
122 PMF_ALLOCATE_TIMESTAMP_MEMORY(_name, _totalid) \
123 PMF_DEFINE_CAPTURE_TIMESTAMP(_name, _flags) \
124 PMF_DEFINE_GET_TIMESTAMP(_name)
125
126/*
127 * This macro is used to register a PMF service, including an
128 * SMC interface to that service.
129 */
130#define PMF_REGISTER_SERVICE_SMC(_name, _svcid, _totalid, _flags)\
131 PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags) \
132 PMF_DEFINE_SERVICE_DESC(_name, PMF_ARM_TIF_IMPL_ID, \
133 _svcid, _totalid, NULL, \
134 pmf_get_timestamp_by_mpidr_ ## _name)
135
136/*
137 * This macro is used to register a PMF service that has an SMC interface
138 * but provides its own service-specific PMF functions.
139 */
140#define PMF_REGISTER_SERVICE_SMC_OWN(_name, _implid, _svcid, _totalid, \
141 _init, _getts) \
142 PMF_DEFINE_SERVICE_DESC(_name, _implid, _svcid, _totalid, \
143 _init, _getts)
144
145#else
146
147#define PMF_REGISTER_SERVICE(_name, _svcid, _totalid, _flags)
148#define PMF_REGISTER_SERVICE_SMC(_name, _svcid, _totalid, _flags)
149#define PMF_REGISTER_SERVICE_SMC_OWN(_name, _implid, _svcid, _totalid, \
150 _init, _getts)
151#define PMF_DECLARE_CAPTURE_TIMESTAMP(_name)
152#define PMF_DECLARE_GET_TIMESTAMP(_name)
153#define PMF_CAPTURE_TIMESTAMP(_name, _tid, _flags)
154#define PMF_GET_TIMESTAMP_BY_MPIDR(_name, _tid, _mpidr, _flags, _tsval)
155#define PMF_GET_TIMESTAMP_BY_INDEX(_name, _tid, _cpuid, _flags, _tsval)
156
157#endif /* ENABLE_PMF */
158
159/*******************************************************************************
160 * Function & variable prototypes
161 ******************************************************************************/
162/* PMF common functions */
163int pmf_get_timestamp_smc(unsigned int tid,
164 u_register_t mpidr,
165 unsigned int flags,
Roberto Vargas777dd432018-02-12 12:36:17 +0000166 unsigned long long *ts_value);
Yatharth Kochar9518d022016-03-11 14:20:19 +0000167int pmf_setup(void);
168uintptr_t pmf_smc_handler(unsigned int smc_fid,
169 u_register_t x1,
170 u_register_t x2,
171 u_register_t x3,
172 u_register_t x4,
173 void *cookie,
174 void *handle,
175 u_register_t flags);
176
Antonio Nino Diaze89a4532018-07-18 13:26:25 +0100177#endif /* PMF_H */