blob: 41614e7de17d9d1c3e5fa2716b5224309b4a5011 [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 Jonsson537c71c2020-05-05 14:17:22 +020022#include <stdint.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020028#define ETHOSU_PMU_NCOUNTERS 4
29
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020030/** \brief HW Supported ETHOSU PMU Events
31 *
32 * Note: These values are symbolic. Actual HW-values may change. I.e. always use API
33 * to set/get actual event-type value.
34 * */
35enum ethosu_pmu_event_type
36{
Diqing Zhong25e2c812020-04-27 13:47:25 +020037 ETHOSU_PMU_NO_EVENT = 0,
38 ETHOSU_PMU_CYCLE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020039 ETHOSU_PMU_NPU_IDLE,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020040 ETHOSU_PMU_CC_STALLED_ON_BLOCKDEP,
41 ETHOSU_PMU_CC_STALLED_ON_SHRAM_RECONFIG,
Douglas Troha2407e962020-06-15 14:31:45 +020042 ETHOSU_PMU_NPU_ACTIVE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020043 ETHOSU_PMU_MAC_ACTIVE,
44 ETHOSU_PMU_MAC_ACTIVE_8BIT,
45 ETHOSU_PMU_MAC_ACTIVE_16BIT,
46 ETHOSU_PMU_MAC_DPU_ACTIVE,
47 ETHOSU_PMU_MAC_STALLED_BY_WD_ACC,
48 ETHOSU_PMU_MAC_STALLED_BY_WD,
49 ETHOSU_PMU_MAC_STALLED_BY_ACC,
50 ETHOSU_PMU_MAC_STALLED_BY_IB,
Diqing Zhong25e2c812020-04-27 13:47:25 +020051 ETHOSU_PMU_MAC_ACTIVE_32BIT,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020052 ETHOSU_PMU_MAC_STALLED_BY_INT_W,
53 ETHOSU_PMU_MAC_STALLED_BY_INT_ACC,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020054 ETHOSU_PMU_AO_ACTIVE,
55 ETHOSU_PMU_AO_ACTIVE_8BIT,
56 ETHOSU_PMU_AO_ACTIVE_16BIT,
57 ETHOSU_PMU_AO_STALLED_BY_OFMP_OB,
58 ETHOSU_PMU_AO_STALLED_BY_OFMP,
59 ETHOSU_PMU_AO_STALLED_BY_OB,
60 ETHOSU_PMU_AO_STALLED_BY_ACC_IB,
61 ETHOSU_PMU_AO_STALLED_BY_ACC,
62 ETHOSU_PMU_AO_STALLED_BY_IB,
63 ETHOSU_PMU_WD_ACTIVE,
64 ETHOSU_PMU_WD_STALLED,
65 ETHOSU_PMU_WD_STALLED_BY_WS,
66 ETHOSU_PMU_WD_STALLED_BY_WD_BUF,
67 ETHOSU_PMU_WD_PARSE_ACTIVE,
68 ETHOSU_PMU_WD_PARSE_STALLED,
69 ETHOSU_PMU_WD_PARSE_STALLED_IN,
70 ETHOSU_PMU_WD_PARSE_STALLED_OUT,
Diqing Zhong25e2c812020-04-27 13:47:25 +020071 ETHOSU_PMU_WD_TRANS_WS,
72 ETHOSU_PMU_WD_TRANS_WB,
73 ETHOSU_PMU_WD_TRANS_DW0,
74 ETHOSU_PMU_WD_TRANS_DW1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020075 ETHOSU_PMU_AXI0_RD_TRANS_ACCEPTED,
76 ETHOSU_PMU_AXI0_RD_TRANS_COMPLETED,
77 ETHOSU_PMU_AXI0_RD_DATA_BEAT_RECEIVED,
78 ETHOSU_PMU_AXI0_RD_TRAN_REQ_STALLED,
79 ETHOSU_PMU_AXI0_WR_TRANS_ACCEPTED,
80 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_M,
81 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_S,
82 ETHOSU_PMU_AXI0_WR_DATA_BEAT_WRITTEN,
83 ETHOSU_PMU_AXI0_WR_TRAN_REQ_STALLED,
84 ETHOSU_PMU_AXI0_WR_DATA_BEAT_STALLED,
85 ETHOSU_PMU_AXI0_ENABLED_CYCLES,
86 ETHOSU_PMU_AXI0_RD_STALL_LIMIT,
87 ETHOSU_PMU_AXI0_WR_STALL_LIMIT,
88 ETHOSU_PMU_AXI1_RD_TRANS_ACCEPTED,
89 ETHOSU_PMU_AXI1_RD_TRANS_COMPLETED,
90 ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED,
91 ETHOSU_PMU_AXI1_RD_TRAN_REQ_STALLED,
92 ETHOSU_PMU_AXI1_WR_TRANS_ACCEPTED,
93 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_M,
94 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_S,
95 ETHOSU_PMU_AXI1_WR_DATA_BEAT_WRITTEN,
96 ETHOSU_PMU_AXI1_WR_TRAN_REQ_STALLED,
97 ETHOSU_PMU_AXI1_WR_DATA_BEAT_STALLED,
98 ETHOSU_PMU_AXI1_ENABLED_CYCLES,
99 ETHOSU_PMU_AXI1_RD_STALL_LIMIT,
100 ETHOSU_PMU_AXI1_WR_STALL_LIMIT,
101 ETHOSU_PMU_AXI_LATENCY_ANY,
102 ETHOSU_PMU_AXI_LATENCY_32,
103 ETHOSU_PMU_AXI_LATENCY_64,
104 ETHOSU_PMU_AXI_LATENCY_128,
105 ETHOSU_PMU_AXI_LATENCY_256,
106 ETHOSU_PMU_AXI_LATENCY_512,
107 ETHOSU_PMU_AXI_LATENCY_1024,
108
109 ETHOSU_PMU_SENTINEL // End-marker (not event)
110};
111
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200112#define ETHOSU_PMU_CNT1_Msk (1UL << 0)
113#define ETHOSU_PMU_CNT2_Msk (1UL << 1)
114#define ETHOSU_PMU_CNT3_Msk (1UL << 2)
115#define ETHOSU_PMU_CNT4_Msk (1UL << 3)
116#define ETHOSU_PMU_CCNT_Msk (1UL << 31)
117
118/* Transpose functions between HW-event-type and event-id*/
119enum ethosu_pmu_event_type pmu_event_type(uint32_t);
120uint32_t pmu_event_value(enum ethosu_pmu_event_type);
121
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200122/* Initialize the PMU driver */
123void ethosu_pmu_driver_init(void);
124
Bhavik Pateldae5be02020-06-18 15:25:15 +0200125void ethosu_pmu_driver_exit(void);
126
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200127// CMSIS ref API
128/** \brief PMU Functions */
129
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200130/**
131 \brief Enable the PMU
132*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200133void ETHOSU_PMU_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200134
135/**
136 \brief Disable the PMU
137*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200138void ETHOSU_PMU_Disable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200139
140/**
141 \brief Set event to count for PMU eventer counter
142 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
143 \param [in] type Event to count
144*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200145void ETHOSU_PMU_Set_EVTYPER(uint32_t num, enum ethosu_pmu_event_type type);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200146
147/**
148 \brief Get event to count for PMU eventer counter
149 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
150 \return type Event to count
151*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200152enum ethosu_pmu_event_type ETHOSU_PMU_Get_EVTYPER(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200153
154/**
155 \brief Reset cycle counter
156*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200157void ETHOSU_PMU_CYCCNT_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200158
159/**
160 \brief Reset all event counters
161*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200162void ETHOSU_PMU_EVCNTR_ALL_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200163
164/**
165 \brief Enable counters
166 \param [in] mask Counters to enable
167 \note Enables one or more of the following:
168 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
169 - cycle counter (bit 31)
170*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200171void ETHOSU_PMU_CNTR_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200172
173/**
174 \brief Disable counters
175 \param [in] mask Counters to disable
176 \note Disables one or more of the following:
177 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
178 - cycle counter (bit 31)
179*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200180void ETHOSU_PMU_CNTR_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200181
182/**
183 \brief Determine counters activation
184
185 \return Event count
186 \param [in] mask Counters to enable
187 \return a bitmask where bit-set means:
188 - event counters activated (bit 0-ETHOSU_PMU_NCOUNTERS)
189 - cycle counter activate (bit 31)
190 \note ETHOSU specific. Usage breaks CMSIS complience
191*/
Bhavik Pateldae5be02020-06-18 15:25:15 +0200192uint32_t ETHOSU_PMU_CNTR_Status(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200193
194/**
195 \brief Read cycle counter (64 bit)
196 \return Cycle count
197 \note Two HW 32-bit registers that can increment independently in-between reads.
198 To work-around raciness yet still avoid turning
199 off the event both are read as one value twice. If the latter read
200 is not greater than the former, it means overflow of LSW without
201 incrementing MSW has occurred, in which case the former value is used.
202*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200203uint64_t ETHOSU_PMU_Get_CCNTR(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200204
205/**
206 \brief Set cycle counter (64 bit)
207 \param [in] val Conter value
208 \note Two HW 32-bit registers that can increment independently in-between reads.
209 To work-around raciness, counter is temporary disabled if enabled.
210 \note ETHOSU specific. Usage breaks CMSIS complience
211*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200212void ETHOSU_PMU_Set_CCNTR(uint64_t val);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200213
214/**
215 \brief Read event counter
216 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
217 \return Event count
218*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200219uint32_t ETHOSU_PMU_Get_EVCNTR(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200220
221/**
222 \brief Set event counter value
223 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
224 \param [in] val Conter value
225 \note ETHOSU specific. Usage breaks CMSIS complience
226*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200227void ETHOSU_PMU_Set_EVCNTR(uint32_t num, uint32_t val);
228
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200229/**
230 \brief Read counter overflow status
231 \return Counter overflow status bits for the following:
232 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS))
233 - cycle counter (bit 31)
234*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200235uint32_t ETHOSU_PMU_Get_CNTR_OVS(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200236
237/**
238 \brief Clear counter overflow status
239 \param [in] mask Counter overflow status bits to clear
240 \note Clears overflow status bits for one or more of the following:
241 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
242 - cycle counter (bit 31)
243*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200244void ETHOSU_PMU_Set_CNTR_OVS(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200245
246/**
247 \brief Enable counter overflow interrupt request
248 \param [in] mask Counter overflow interrupt request bits to set
249 \note Sets overflow interrupt request bits for one or more of the following:
250 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
251 - cycle counter (bit 31)
252*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200253void ETHOSU_PMU_Set_CNTR_IRQ_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200254
255/**
256 \brief Disable counter overflow interrupt request
257 \param [in] mask Counter overflow interrupt request bits to clear
258 \note Clears overflow interrupt request bits for one or more of the following:
259 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
260 - cycle counter (bit 31)
261*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200262void ETHOSU_PMU_Set_CNTR_IRQ_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200263
264/**
265 \brief Get counters overflow interrupt request stiinings
266 \return mask Counter overflow interrupt request bits
267 \note Sets overflow interrupt request bits for one or more of the following:
268 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
269 - cycle counter (bit 31)
Bhavik Pateldae5be02020-06-18 15:25:15 +0200270 \note ETHOSU specific. Usage breaks CMSIS compliance
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200271*/
Bhavik Pateldae5be02020-06-18 15:25:15 +0200272uint32_t ETHOSU_PMU_Get_IRQ_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200273
274/**
275 \brief Software increment event counter
276 \param [in] mask Counters to increment
277 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
278 - cycle counter (bit 31)
279 \note Software increment bits for one or more event counters.
280*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200281void ETHOSU_PMU_CNTR_Increment(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200282
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200283/**
284 \brief Set start event number for the cycle counter
285 \param [in] start_event Event number
286 - Start event (bits [9:0])
287 \note Sets the event number that starts the cycle counter.
288 - Event number in the range 0..1023
289*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200290void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(uint32_t start_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200291
292/**
293 \brief Set stop event number for the cycle counter
294 \param [in] stop_event Event number
295 - Stop event (bits [25:16])
296 \note Sets the event number that stops the cycle counter.
297 - Event number in the range 0..1023
298*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200299void ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event(uint32_t stop_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200300
Kristofer Jonsson537c71c2020-05-05 14:17:22 +0200301#ifdef __cplusplus
302}
303#endif
304
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200305#endif /* PMU_ETHOSU_H */