blob: 7eb5c09aafb71fc1294e50e8763ce820f483d84d [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,
Stefan Nannessone2e70242020-08-19 16:01:29 +0200108 ETHOSU_PMU_ECC_DMA,
109 ETHOSU_PMU_ECC_SB0,
110 ETHOSU_PMU_ECC_SB1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200111
112 ETHOSU_PMU_SENTINEL // End-marker (not event)
113};
114
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200115#define ETHOSU_PMU_CNT1_Msk (1UL << 0)
116#define ETHOSU_PMU_CNT2_Msk (1UL << 1)
117#define ETHOSU_PMU_CNT3_Msk (1UL << 2)
118#define ETHOSU_PMU_CNT4_Msk (1UL << 3)
119#define ETHOSU_PMU_CCNT_Msk (1UL << 31)
120
121/* Transpose functions between HW-event-type and event-id*/
122enum ethosu_pmu_event_type pmu_event_type(uint32_t);
123uint32_t pmu_event_value(enum ethosu_pmu_event_type);
124
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200125/* Initialize the PMU driver */
126void ethosu_pmu_driver_init(void);
127
Bhavik Pateldae5be02020-06-18 15:25:15 +0200128void ethosu_pmu_driver_exit(void);
129
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200130// CMSIS ref API
131/** \brief PMU Functions */
132
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200133/**
134 \brief Enable the PMU
135*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200136void ETHOSU_PMU_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200137
138/**
139 \brief Disable the PMU
140*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200141void ETHOSU_PMU_Disable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200142
143/**
144 \brief Set event to count for PMU eventer counter
145 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
146 \param [in] type Event to count
147*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200148void ETHOSU_PMU_Set_EVTYPER(uint32_t num, enum ethosu_pmu_event_type type);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200149
150/**
151 \brief Get event to count for PMU eventer counter
152 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
153 \return type Event to count
154*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200155enum ethosu_pmu_event_type ETHOSU_PMU_Get_EVTYPER(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200156
157/**
158 \brief Reset cycle counter
159*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200160void ETHOSU_PMU_CYCCNT_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200161
162/**
163 \brief Reset all event counters
164*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200165void ETHOSU_PMU_EVCNTR_ALL_Reset(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200166
167/**
168 \brief Enable counters
169 \param [in] mask Counters to enable
170 \note Enables one or more of the following:
171 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
172 - cycle counter (bit 31)
173*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200174void ETHOSU_PMU_CNTR_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200175
176/**
177 \brief Disable counters
178 \param [in] mask Counters to disable
179 \note Disables one or more of the following:
180 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
181 - cycle counter (bit 31)
182*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200183void ETHOSU_PMU_CNTR_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200184
185/**
186 \brief Determine counters activation
187
188 \return Event count
189 \param [in] mask Counters to enable
190 \return a bitmask where bit-set means:
191 - event counters activated (bit 0-ETHOSU_PMU_NCOUNTERS)
192 - cycle counter activate (bit 31)
193 \note ETHOSU specific. Usage breaks CMSIS complience
194*/
Bhavik Pateldae5be02020-06-18 15:25:15 +0200195uint32_t ETHOSU_PMU_CNTR_Status(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200196
197/**
198 \brief Read cycle counter (64 bit)
199 \return Cycle count
200 \note Two HW 32-bit registers that can increment independently in-between reads.
201 To work-around raciness yet still avoid turning
202 off the event both are read as one value twice. If the latter read
203 is not greater than the former, it means overflow of LSW without
204 incrementing MSW has occurred, in which case the former value is used.
205*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200206uint64_t ETHOSU_PMU_Get_CCNTR(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200207
208/**
209 \brief Set cycle counter (64 bit)
210 \param [in] val Conter value
211 \note Two HW 32-bit registers that can increment independently in-between reads.
212 To work-around raciness, counter is temporary disabled if enabled.
213 \note ETHOSU specific. Usage breaks CMSIS complience
214*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200215void ETHOSU_PMU_Set_CCNTR(uint64_t val);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200216
217/**
218 \brief Read event counter
219 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
220 \return Event count
221*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200222uint32_t ETHOSU_PMU_Get_EVCNTR(uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200223
224/**
225 \brief Set event counter value
226 \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
227 \param [in] val Conter value
228 \note ETHOSU specific. Usage breaks CMSIS complience
229*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200230void ETHOSU_PMU_Set_EVCNTR(uint32_t num, uint32_t val);
231
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200232/**
233 \brief Read counter overflow status
234 \return Counter overflow status bits for the following:
235 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS))
236 - cycle counter (bit 31)
237*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200238uint32_t ETHOSU_PMU_Get_CNTR_OVS(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200239
240/**
241 \brief Clear counter overflow status
242 \param [in] mask Counter overflow status bits to clear
243 \note Clears overflow status bits for one or more of the following:
244 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
245 - cycle counter (bit 31)
246*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200247void ETHOSU_PMU_Set_CNTR_OVS(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200248
249/**
250 \brief Enable counter overflow interrupt request
251 \param [in] mask Counter overflow interrupt request bits to set
252 \note Sets overflow interrupt request bits for one or more of the following:
253 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
254 - cycle counter (bit 31)
255*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200256void ETHOSU_PMU_Set_CNTR_IRQ_Enable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200257
258/**
259 \brief Disable counter overflow interrupt request
260 \param [in] mask Counter overflow interrupt request bits to clear
261 \note Clears overflow interrupt request bits for one or more of the following:
262 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
263 - cycle counter (bit 31)
264*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200265void ETHOSU_PMU_Set_CNTR_IRQ_Disable(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200266
267/**
268 \brief Get counters overflow interrupt request stiinings
269 \return mask Counter overflow interrupt request bits
270 \note Sets overflow interrupt request bits for one or more of the following:
271 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
272 - cycle counter (bit 31)
Bhavik Pateldae5be02020-06-18 15:25:15 +0200273 \note ETHOSU specific. Usage breaks CMSIS compliance
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200274*/
Bhavik Pateldae5be02020-06-18 15:25:15 +0200275uint32_t ETHOSU_PMU_Get_IRQ_Enable(void);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200276
277/**
278 \brief Software increment event counter
279 \param [in] mask Counters to increment
280 - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
281 - cycle counter (bit 31)
282 \note Software increment bits for one or more event counters.
283*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200284void ETHOSU_PMU_CNTR_Increment(uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200285
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200286/**
287 \brief Set start event number for the cycle counter
288 \param [in] start_event Event number
289 - Start event (bits [9:0])
290 \note Sets the event number that starts the cycle counter.
291 - Event number in the range 0..1023
292*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200293void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(uint32_t start_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200294
295/**
296 \brief Set stop event number for the cycle counter
297 \param [in] stop_event Event number
298 - Stop event (bits [25:16])
299 \note Sets the event number that stops the cycle counter.
300 - Event number in the range 0..1023
301*/
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200302void ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event(uint32_t stop_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200303
Kristofer Jonsson537c71c2020-05-05 14:17:22 +0200304#ifdef __cplusplus
305}
306#endif
307
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200308#endif /* PMU_ETHOSU_H */