blob: 78d46eec297035fb4b693eeb738bc4f5393885a5 [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
2 * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020019#ifndef PMU_ETHOSU_H
20#define PMU_ETHOSU_H
21
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020022/*****************************************************************************
23 * Includes
24 *****************************************************************************/
25
Kristofer Jonsson537c71c2020-05-05 14:17:22 +020026#include <stdint.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020032/*****************************************************************************
33 * Defines
34 *****************************************************************************/
35
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020036#define ETHOSU_PMU_NCOUNTERS 4
37
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020038#define ETHOSU_PMU_CNT1_Msk (1UL << 0)
39#define ETHOSU_PMU_CNT2_Msk (1UL << 1)
40#define ETHOSU_PMU_CNT3_Msk (1UL << 2)
41#define ETHOSU_PMU_CNT4_Msk (1UL << 3)
42#define ETHOSU_PMU_CCNT_Msk (1UL << 31)
43
44/*****************************************************************************
45 * Types
46 *****************************************************************************/
47
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020048/** \brief HW Supported ETHOSU PMU Events
49 *
50 * Note: These values are symbolic. Actual HW-values may change. I.e. always use API
51 * to set/get actual event-type value.
52 * */
53enum ethosu_pmu_event_type
54{
Diqing Zhong25e2c812020-04-27 13:47:25 +020055 ETHOSU_PMU_NO_EVENT = 0,
56 ETHOSU_PMU_CYCLE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020057 ETHOSU_PMU_NPU_IDLE,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020058 ETHOSU_PMU_CC_STALLED_ON_BLOCKDEP,
59 ETHOSU_PMU_CC_STALLED_ON_SHRAM_RECONFIG,
Douglas Troha2407e962020-06-15 14:31:45 +020060 ETHOSU_PMU_NPU_ACTIVE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020061 ETHOSU_PMU_MAC_ACTIVE,
62 ETHOSU_PMU_MAC_ACTIVE_8BIT,
63 ETHOSU_PMU_MAC_ACTIVE_16BIT,
64 ETHOSU_PMU_MAC_DPU_ACTIVE,
65 ETHOSU_PMU_MAC_STALLED_BY_WD_ACC,
66 ETHOSU_PMU_MAC_STALLED_BY_WD,
67 ETHOSU_PMU_MAC_STALLED_BY_ACC,
68 ETHOSU_PMU_MAC_STALLED_BY_IB,
Diqing Zhong25e2c812020-04-27 13:47:25 +020069 ETHOSU_PMU_MAC_ACTIVE_32BIT,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020070 ETHOSU_PMU_MAC_STALLED_BY_INT_W,
71 ETHOSU_PMU_MAC_STALLED_BY_INT_ACC,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020072 ETHOSU_PMU_AO_ACTIVE,
73 ETHOSU_PMU_AO_ACTIVE_8BIT,
74 ETHOSU_PMU_AO_ACTIVE_16BIT,
75 ETHOSU_PMU_AO_STALLED_BY_OFMP_OB,
76 ETHOSU_PMU_AO_STALLED_BY_OFMP,
77 ETHOSU_PMU_AO_STALLED_BY_OB,
78 ETHOSU_PMU_AO_STALLED_BY_ACC_IB,
79 ETHOSU_PMU_AO_STALLED_BY_ACC,
80 ETHOSU_PMU_AO_STALLED_BY_IB,
81 ETHOSU_PMU_WD_ACTIVE,
82 ETHOSU_PMU_WD_STALLED,
83 ETHOSU_PMU_WD_STALLED_BY_WS,
84 ETHOSU_PMU_WD_STALLED_BY_WD_BUF,
85 ETHOSU_PMU_WD_PARSE_ACTIVE,
86 ETHOSU_PMU_WD_PARSE_STALLED,
87 ETHOSU_PMU_WD_PARSE_STALLED_IN,
88 ETHOSU_PMU_WD_PARSE_STALLED_OUT,
Diqing Zhong25e2c812020-04-27 13:47:25 +020089 ETHOSU_PMU_WD_TRANS_WS,
90 ETHOSU_PMU_WD_TRANS_WB,
91 ETHOSU_PMU_WD_TRANS_DW0,
92 ETHOSU_PMU_WD_TRANS_DW1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020093 ETHOSU_PMU_AXI0_RD_TRANS_ACCEPTED,
94 ETHOSU_PMU_AXI0_RD_TRANS_COMPLETED,
95 ETHOSU_PMU_AXI0_RD_DATA_BEAT_RECEIVED,
96 ETHOSU_PMU_AXI0_RD_TRAN_REQ_STALLED,
97 ETHOSU_PMU_AXI0_WR_TRANS_ACCEPTED,
98 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_M,
99 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_S,
100 ETHOSU_PMU_AXI0_WR_DATA_BEAT_WRITTEN,
101 ETHOSU_PMU_AXI0_WR_TRAN_REQ_STALLED,
102 ETHOSU_PMU_AXI0_WR_DATA_BEAT_STALLED,
103 ETHOSU_PMU_AXI0_ENABLED_CYCLES,
104 ETHOSU_PMU_AXI0_RD_STALL_LIMIT,
105 ETHOSU_PMU_AXI0_WR_STALL_LIMIT,
106 ETHOSU_PMU_AXI1_RD_TRANS_ACCEPTED,
107 ETHOSU_PMU_AXI1_RD_TRANS_COMPLETED,
108 ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED,
109 ETHOSU_PMU_AXI1_RD_TRAN_REQ_STALLED,
110 ETHOSU_PMU_AXI1_WR_TRANS_ACCEPTED,
111 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_M,
112 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_S,
113 ETHOSU_PMU_AXI1_WR_DATA_BEAT_WRITTEN,
114 ETHOSU_PMU_AXI1_WR_TRAN_REQ_STALLED,
115 ETHOSU_PMU_AXI1_WR_DATA_BEAT_STALLED,
116 ETHOSU_PMU_AXI1_ENABLED_CYCLES,
117 ETHOSU_PMU_AXI1_RD_STALL_LIMIT,
118 ETHOSU_PMU_AXI1_WR_STALL_LIMIT,
119 ETHOSU_PMU_AXI_LATENCY_ANY,
120 ETHOSU_PMU_AXI_LATENCY_32,
121 ETHOSU_PMU_AXI_LATENCY_64,
122 ETHOSU_PMU_AXI_LATENCY_128,
123 ETHOSU_PMU_AXI_LATENCY_256,
124 ETHOSU_PMU_AXI_LATENCY_512,
125 ETHOSU_PMU_AXI_LATENCY_1024,
Stefan Nannessone2e70242020-08-19 16:01:29 +0200126 ETHOSU_PMU_ECC_DMA,
127 ETHOSU_PMU_ECC_SB0,
128 ETHOSU_PMU_ECC_SB1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200129
130 ETHOSU_PMU_SENTINEL // End-marker (not event)
131};
132
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200133/*****************************************************************************
134 * Functions
135 *****************************************************************************/
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200136
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200137/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200138 * \brief Enable the PMU
139 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200140void ETHOSU_PMU_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200141
142/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200143 * \brief Disable the PMU
144 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200145void ETHOSU_PMU_Disable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200146
147/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200148 * \brief Set event to count for PMU eventer counter
149 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
150 * \param [in] type Event to count
151 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200152void ETHOSU_PMU_Set_EVTYPER(uint32_t num, enum ethosu_pmu_event_type type);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200153
154/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200155 * \brief Get event to count for PMU eventer counter
156 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
157 * \return type Event to count
158 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200159enum ethosu_pmu_event_type ETHOSU_PMU_Get_EVTYPER(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200160
161/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200162 * \brief Reset cycle counter
163 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200164void ETHOSU_PMU_CYCCNT_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200165
166/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200167 * \brief Reset all event counters
168 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200169void ETHOSU_PMU_EVCNTR_ALL_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200170
171/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200172 * \brief Enable counters
173 * \param [in] mask Counters to enable
174 * \note Enables one or more of the following:
175 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
176 * - cycle counter (bit 31)
177 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200178void ETHOSU_PMU_CNTR_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200179
180/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200181 * \brief Disable counters
182 * \param [in] mask Counters to disable
183 * \note Disables one or more of the following:
184 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
185 * - cycle counter (bit 31)
186 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200187void ETHOSU_PMU_CNTR_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200188
189/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200190 * \brief Determine counters activation
191 *
192 * \return Event count
193 * \param [in] mask Counters to enable
194 * \return a bitmask where bit-set means:
195 * - event counters activated (bit 0-ETHOSU_PMU_NCOUNTERS)
196 * - cycle counter activate (bit 31)
197 * \note ETHOSU specific. Usage breaks CMSIS complience
198 */
Bhavik Pateldae5be02020-06-18 15:25:15 +0200199uint32_t ETHOSU_PMU_CNTR_Status(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200200
201/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200202 * \brief Read cycle counter (64 bit)
203 * \return Cycle count
204 * \note Two HW 32-bit registers that can increment independently in-between reads.
205 * To work-around raciness yet still avoid turning
206 * off the event both are read as one value twice. If the latter read
207 * is not greater than the former, it means overflow of LSW without
208 * incrementing MSW has occurred, in which case the former value is used.
209 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200210uint64_t ETHOSU_PMU_Get_CCNTR(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200211
212/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200213 * \brief Set cycle counter (64 bit)
214 * \param [in] val Conter value
215 * \note Two HW 32-bit registers that can increment independently in-between reads.
216 * To work-around raciness, counter is temporary disabled if enabled.
217 * \note ETHOSU specific. Usage breaks CMSIS complience
218 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200219void ETHOSU_PMU_Set_CCNTR(uint64_t val);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200220
221/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200222 * \brief Read event counter
223 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
224 * \return Event count
225 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200226uint32_t ETHOSU_PMU_Get_EVCNTR(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200227
228/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200229 * \brief Set event counter value
230 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
231 * \param [in] val Conter value
232 * \note ETHOSU specific. Usage breaks CMSIS complience
233 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200234void ETHOSU_PMU_Set_EVCNTR(uint32_t num, uint32_t val);
235
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200236/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200237 * \brief Read counter overflow status
238 * \return Counter overflow status bits for the following:
239 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS))
240 * - cycle counter (bit 31)
241 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200242uint32_t ETHOSU_PMU_Get_CNTR_OVS(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200243
244/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200245 * \brief Clear counter overflow status
246 * \param [in] mask Counter overflow status bits to clear
247 * \note Clears overflow status bits for one or more of the following:
248 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
249 * - cycle counter (bit 31)
250 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200251void ETHOSU_PMU_Set_CNTR_OVS(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200252
253/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200254 * \brief Enable counter overflow interrupt request
255 * \param [in] mask Counter overflow interrupt request bits to set
256 * \note Sets overflow interrupt request bits for one or more of the following:
257 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
258 * - cycle counter (bit 31)
259 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200260void ETHOSU_PMU_Set_CNTR_IRQ_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200261
262/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200263 * \brief Disable counter overflow interrupt request
264 * \param [in] mask Counter overflow interrupt request bits to clear
265 * \note Clears overflow interrupt request bits for one or more of the following:
266 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
267 * - cycle counter (bit 31)
268 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200269void ETHOSU_PMU_Set_CNTR_IRQ_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200270
271/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200272 * \brief Get counters overflow interrupt request stiinings
273 * \return mask Counter overflow interrupt request bits
274 * \note Sets overflow interrupt request bits for one or more of the following:
275 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
276 * - cycle counter (bit 31)
277 * \note ETHOSU specific. Usage breaks CMSIS compliance
278 */
Bhavik Pateldae5be02020-06-18 15:25:15 +0200279uint32_t ETHOSU_PMU_Get_IRQ_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200280
281/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200282 * \brief Software increment event counter
283 * \param [in] mask Counters to increment
284 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
285 * - cycle counter (bit 31)
286 * \note Software increment bits for one or more event counters.
287 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200288void ETHOSU_PMU_CNTR_Increment(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200289
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200290/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200291 * \brief Set start event number for the cycle counter
292 * \param [in] start_event Event number
293 * - Start event (bits [9:0])
294 * \note Sets the event number that starts the cycle counter.
295 * - Event number in the range 0..1023
296 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200297void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(uint32_t start_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200298
299/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200300 * \brief Set stop event number for the cycle counter
301 * \param [in] stop_event Event number
302 * - Stop event (bits [25:16])
303 * \note Sets the event number that stops the cycle counter.
304 * - Event number in the range 0..1023
305 */
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200306void ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event(uint32_t stop_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200307
Kristofer Jonsson537c71c2020-05-05 14:17:22 +0200308#ifdef __cplusplus
309}
310#endif
311
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200312#endif /* PMU_ETHOSU_H */