1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *     Performance, Monitor, and Instrumentation HAL Interface.
9  */
10 
11 #ifndef MOD_PMI_H
12 #define MOD_PMI_H
13 
14 #include <fwk_id.h>
15 #include <fwk_macros.h>
16 #include <fwk_module_idx.h>
17 
18 #include <stdint.h>
19 
20 /*!
21  * \ingroup GroupModules
22  * \defgroup GroupPmi Performance and Instrumentation
23  *      module
24  * \{
25  */
26 
27 /*!
28  * \defgroup GroupPmiTypes Types
29  * \{
30  */
31 
32 /*!
33  * \brief PMI configuration data.
34  */
35 struct mod_pmi_driver_config {
36     /*! Identifier of the PMI driver */
37     fwk_id_t driver_id;
38 
39     /*! Identifier of the PMI driver api*/
40     fwk_id_t driver_api_id;
41 };
42 
43 /*!
44  * \}
45  */
46 
47 /*!
48  * \defgroup GroupPmiApis APIs
49  * \{
50  */
51 
52 /*!
53  * \brief PMI API.
54  */
55 struct mod_pmi_hal_api {
56     /*!
57      * \brief Start cycle counting
58      *
59      * \retval ::FWK_SUCCESS The operation succeeded.
60      * \return One of the standard framework error codes.
61      */
62     int (*start_cycle_count)(void);
63 
64     /*!
65      * \brief Stop cycle counting
66      *
67      * \retval ::FWK_SUCCESS The operation succeeded.
68      * \return One of the standard framework error codes.
69      */
70     int (*stop_cycle_count)(void);
71 
72     /*!
73      * \brief Get the current cycle count.
74      *
75      * \param[out] cycle_count  Value of the current cycle count
76      *
77      * \retval ::FWK_SUCCESS The operation succeeded.
78      * \return One of the standard framework error codes.
79      */
80 
81     int (*get_cycle_count)(uint64_t *cycle_count);
82 
83     /*!
84      * \brief Set the cycle count to cycle_count if supported
85      *
86      * \param[in] cycle_count Reset/Set value of the cycle count.
87      *
88      * \retval ::FWK_SUCCESS The operation succeeded.
89      * \return One of the standard framework error codes.
90      */
91     int (*set_cycle_count)(uint64_t cycle_count);
92 
93     /*!
94      * \brief Returns cycle count diff for 'end' and 'start'
95      *
96      * \details Since cycle count register can wrap around, it is important
97      *          to take care of this while calculating the difference between
98      *          'end' and 'start'. This call assumes 'end' wrapped around but
99      *          still less than the start value.
100      *
101      * \param[in] start start value of the cycle count
102      *
103      * \param[in] end end value of the cycle count
104      *
105      * \retval Difference between cycle count 'end' - 'start'
106      */
107     uint64_t (*cycle_count_diff)(uint64_t start, uint64_t end);
108 
109     /*!
110      * \brief Get current timestamp
111      *
112      * \retval Value of the current time
113      */
114     uint64_t (*get_current_time)(void);
115 };
116 
117 /*!
118  * \brief PMI Driver API.
119  */
120 struct mod_pmi_driver_api {
121     /*!
122      * \brief Start cycle counting
123      *
124      * \retval ::FWK_SUCCESS The operation succeeded.
125      * \return One of the standard framework error codes.
126      */
127     int (*start_cycle_count)(void);
128 
129     /*!
130      * \brief Stop cycle counting
131      *
132      * \retval ::FWK_SUCCESS The operation succeeded.
133      * \retval One of the standard framework error codes.
134      */
135     int (*stop_cycle_count)(void);
136 
137     /*!
138      * \brief Get the current cycle count.
139      *
140      * \param[out] cycle_count  Value of the current cycle count
141      * \return One of the standard framework error codes.
142      */
143     int (*get_cycle_count)(uint64_t *cycle_count);
144 
145     /*!
146      * \brief Set the cycle count to cycle_count if supported
147      *
148      * \param[in] cycle_count Reset/Set value of the cycle count.
149      * \return One of the standard framework error codes.
150      */
151     int (*set_cycle_count)(uint64_t cycle_count);
152 
153     /*!
154      * \brief Returns cycle count diff for 'end' and 'start'
155      *
156      * \details Since cycle count register can wrap around, it is important
157      *          to take care of this while calculating the difference between
158      *          'end' and 'start'. This call assumes 'end' wrapped around but
159      *          still less than the start value.
160      *
161      * \param[in] start start value of the cycle count
162      *
163      * \param[in] end end value of the cycle count
164      */
165     uint64_t (*cycle_count_diff)(uint64_t start, uint64_t end);
166 
167     /*!
168      * \brief Get current timestamp
169      *
170      * \retval Value of the current time
171      */
172     uint64_t (*get_current_time)(void);
173 };
174 
175 /*!
176  * \}
177  */
178 
179 /*!
180  * \defgroup GroupPmiIds Identifiers
181  * \{
182  */
183 
184 /*!
185  * \brief API indices.
186  */
187 enum mod_pmi_api_idx {
188     MOD_PMI_API_IDX_HAL, /*! API index for mod_pmi_api_id_pmi() */
189     MOD_PMI_API_IDX_COUNT /*! Number of defined APIs */
190 };
191 
192 /*! Module API identifier */
193 static const fwk_id_t mod_pmi_api_id_hal =
194     FWK_ID_API_INIT(FWK_MODULE_IDX_PMI, MOD_PMI_API_IDX_HAL);
195 
196 /*!
197  * \}
198  */
199 
200 /*!
201  * \}
202  */
203 
204 #endif /* MOD_PMI_H */
205