blob: ceefda838cab11e770a1d3204f853139b5bbc428 [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
Per Åstrand0fd65ce2021-03-11 10:25:18 +01002 * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02003 *
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
Anton Moberg61da4d32020-12-22 16:00:31 +010028#include "ethosu_driver.h"
29
Kristofer Jonsson537c71c2020-05-05 14:17:22 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020034/*****************************************************************************
35 * Defines
36 *****************************************************************************/
37
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020038#define ETHOSU_PMU_NCOUNTERS 4
39
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020040#define ETHOSU_PMU_CNT1_Msk (1UL << 0)
41#define ETHOSU_PMU_CNT2_Msk (1UL << 1)
42#define ETHOSU_PMU_CNT3_Msk (1UL << 2)
43#define ETHOSU_PMU_CNT4_Msk (1UL << 3)
44#define ETHOSU_PMU_CCNT_Msk (1UL << 31)
45
46/*****************************************************************************
47 * Types
48 *****************************************************************************/
49
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020050/** \brief HW Supported ETHOSU PMU Events
51 *
52 * Note: These values are symbolic. Actual HW-values may change. I.e. always use API
53 * to set/get actual event-type value.
54 * */
55enum ethosu_pmu_event_type
56{
Diqing Zhong25e2c812020-04-27 13:47:25 +020057 ETHOSU_PMU_NO_EVENT = 0,
58 ETHOSU_PMU_CYCLE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020059 ETHOSU_PMU_NPU_IDLE,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020060 ETHOSU_PMU_CC_STALLED_ON_BLOCKDEP,
61 ETHOSU_PMU_CC_STALLED_ON_SHRAM_RECONFIG,
Douglas Troha2407e962020-06-15 14:31:45 +020062 ETHOSU_PMU_NPU_ACTIVE,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020063 ETHOSU_PMU_MAC_ACTIVE,
64 ETHOSU_PMU_MAC_ACTIVE_8BIT,
65 ETHOSU_PMU_MAC_ACTIVE_16BIT,
66 ETHOSU_PMU_MAC_DPU_ACTIVE,
67 ETHOSU_PMU_MAC_STALLED_BY_WD_ACC,
68 ETHOSU_PMU_MAC_STALLED_BY_WD,
69 ETHOSU_PMU_MAC_STALLED_BY_ACC,
70 ETHOSU_PMU_MAC_STALLED_BY_IB,
Diqing Zhong25e2c812020-04-27 13:47:25 +020071 ETHOSU_PMU_MAC_ACTIVE_32BIT,
Douglas Trohaf6a85da2020-05-11 11:45:28 +020072 ETHOSU_PMU_MAC_STALLED_BY_INT_W,
73 ETHOSU_PMU_MAC_STALLED_BY_INT_ACC,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020074 ETHOSU_PMU_AO_ACTIVE,
75 ETHOSU_PMU_AO_ACTIVE_8BIT,
76 ETHOSU_PMU_AO_ACTIVE_16BIT,
77 ETHOSU_PMU_AO_STALLED_BY_OFMP_OB,
78 ETHOSU_PMU_AO_STALLED_BY_OFMP,
79 ETHOSU_PMU_AO_STALLED_BY_OB,
80 ETHOSU_PMU_AO_STALLED_BY_ACC_IB,
81 ETHOSU_PMU_AO_STALLED_BY_ACC,
82 ETHOSU_PMU_AO_STALLED_BY_IB,
83 ETHOSU_PMU_WD_ACTIVE,
84 ETHOSU_PMU_WD_STALLED,
85 ETHOSU_PMU_WD_STALLED_BY_WS,
86 ETHOSU_PMU_WD_STALLED_BY_WD_BUF,
87 ETHOSU_PMU_WD_PARSE_ACTIVE,
88 ETHOSU_PMU_WD_PARSE_STALLED,
89 ETHOSU_PMU_WD_PARSE_STALLED_IN,
90 ETHOSU_PMU_WD_PARSE_STALLED_OUT,
Diqing Zhong25e2c812020-04-27 13:47:25 +020091 ETHOSU_PMU_WD_TRANS_WS,
92 ETHOSU_PMU_WD_TRANS_WB,
93 ETHOSU_PMU_WD_TRANS_DW0,
94 ETHOSU_PMU_WD_TRANS_DW1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020095 ETHOSU_PMU_AXI0_RD_TRANS_ACCEPTED,
96 ETHOSU_PMU_AXI0_RD_TRANS_COMPLETED,
97 ETHOSU_PMU_AXI0_RD_DATA_BEAT_RECEIVED,
98 ETHOSU_PMU_AXI0_RD_TRAN_REQ_STALLED,
99 ETHOSU_PMU_AXI0_WR_TRANS_ACCEPTED,
100 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_M,
101 ETHOSU_PMU_AXI0_WR_TRANS_COMPLETED_S,
102 ETHOSU_PMU_AXI0_WR_DATA_BEAT_WRITTEN,
103 ETHOSU_PMU_AXI0_WR_TRAN_REQ_STALLED,
104 ETHOSU_PMU_AXI0_WR_DATA_BEAT_STALLED,
105 ETHOSU_PMU_AXI0_ENABLED_CYCLES,
106 ETHOSU_PMU_AXI0_RD_STALL_LIMIT,
107 ETHOSU_PMU_AXI0_WR_STALL_LIMIT,
108 ETHOSU_PMU_AXI1_RD_TRANS_ACCEPTED,
109 ETHOSU_PMU_AXI1_RD_TRANS_COMPLETED,
110 ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED,
111 ETHOSU_PMU_AXI1_RD_TRAN_REQ_STALLED,
112 ETHOSU_PMU_AXI1_WR_TRANS_ACCEPTED,
113 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_M,
114 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_S,
115 ETHOSU_PMU_AXI1_WR_DATA_BEAT_WRITTEN,
116 ETHOSU_PMU_AXI1_WR_TRAN_REQ_STALLED,
117 ETHOSU_PMU_AXI1_WR_DATA_BEAT_STALLED,
118 ETHOSU_PMU_AXI1_ENABLED_CYCLES,
119 ETHOSU_PMU_AXI1_RD_STALL_LIMIT,
120 ETHOSU_PMU_AXI1_WR_STALL_LIMIT,
121 ETHOSU_PMU_AXI_LATENCY_ANY,
122 ETHOSU_PMU_AXI_LATENCY_32,
123 ETHOSU_PMU_AXI_LATENCY_64,
124 ETHOSU_PMU_AXI_LATENCY_128,
125 ETHOSU_PMU_AXI_LATENCY_256,
126 ETHOSU_PMU_AXI_LATENCY_512,
127 ETHOSU_PMU_AXI_LATENCY_1024,
Stefan Nannessone2e70242020-08-19 16:01:29 +0200128 ETHOSU_PMU_ECC_DMA,
129 ETHOSU_PMU_ECC_SB0,
130 ETHOSU_PMU_ECC_SB1,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200131
132 ETHOSU_PMU_SENTINEL // End-marker (not event)
133};
134
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200135/*****************************************************************************
136 * Functions
137 *****************************************************************************/
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200138
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200139/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200140 * \brief Enable the PMU
141 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200142void ETHOSU_PMU_Enable(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200143
144/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200145 * \brief Disable the PMU
146 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200147void ETHOSU_PMU_Disable(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200148
149/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200150 * \brief Set event to count for PMU eventer counter
151 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
152 * \param [in] type Event to count
153 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200154void ETHOSU_PMU_Set_EVTYPER(struct ethosu_driver *drv, uint32_t num, enum ethosu_pmu_event_type type);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200155
156/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200157 * \brief Get event to count for PMU eventer counter
158 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
159 * \return type Event to count
160 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200161enum ethosu_pmu_event_type ETHOSU_PMU_Get_EVTYPER(struct ethosu_driver *drv, uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200162
163/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200164 * \brief Reset cycle counter
165 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200166void ETHOSU_PMU_CYCCNT_Reset(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200167
168/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200169 * \brief Reset all event counters
170 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200171void ETHOSU_PMU_EVCNTR_ALL_Reset(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200172
173/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200174 * \brief Enable counters
175 * \param [in] mask Counters to enable
176 * \note Enables one or more of the following:
177 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
178 * - cycle counter (bit 31)
179 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200180void ETHOSU_PMU_CNTR_Enable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200181
182/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200183 * \brief Disable counters
184 * \param [in] mask Counters to disable
185 * \note Disables one or more of the following:
186 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
187 * - cycle counter (bit 31)
188 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200189void ETHOSU_PMU_CNTR_Disable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200190
191/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200192 * \brief Determine counters activation
193 *
194 * \return Event count
195 * \param [in] mask Counters to enable
196 * \return a bitmask where bit-set means:
197 * - event counters activated (bit 0-ETHOSU_PMU_NCOUNTERS)
198 * - cycle counter activate (bit 31)
199 * \note ETHOSU specific. Usage breaks CMSIS complience
200 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200201uint32_t ETHOSU_PMU_CNTR_Status(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200202
203/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200204 * \brief Read cycle counter (64 bit)
205 * \return Cycle count
206 * \note Two HW 32-bit registers that can increment independently in-between reads.
207 * To work-around raciness yet still avoid turning
208 * off the event both are read as one value twice. If the latter read
209 * is not greater than the former, it means overflow of LSW without
210 * incrementing MSW has occurred, in which case the former value is used.
211 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200212uint64_t ETHOSU_PMU_Get_CCNTR(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200213
214/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200215 * \brief Set cycle counter (64 bit)
216 * \param [in] val Conter value
217 * \note Two HW 32-bit registers that can increment independently in-between reads.
218 * To work-around raciness, counter is temporary disabled if enabled.
219 * \note ETHOSU specific. Usage breaks CMSIS complience
220 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200221void ETHOSU_PMU_Set_CCNTR(struct ethosu_driver *drv, uint64_t val);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200222
223/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200224 * \brief Read event counter
225 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
226 * \return Event count
227 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200228uint32_t ETHOSU_PMU_Get_EVCNTR(struct ethosu_driver *drv, uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200229
230/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200231 * \brief Set event counter value
232 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
233 * \param [in] val Conter value
234 * \note ETHOSU specific. Usage breaks CMSIS complience
235 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200236void ETHOSU_PMU_Set_EVCNTR(struct ethosu_driver *drv, uint32_t num, uint32_t val);
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200237
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200238/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200239 * \brief Read counter overflow status
240 * \return Counter overflow status bits for the following:
241 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS))
242 * - cycle counter (bit 31)
243 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200244uint32_t ETHOSU_PMU_Get_CNTR_OVS(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200245
246/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200247 * \brief Clear counter overflow status
248 * \param [in] mask Counter overflow status bits to clear
249 * \note Clears overflow status bits for one or more of the following:
250 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
251 * - cycle counter (bit 31)
252 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200253void ETHOSU_PMU_Set_CNTR_OVS(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200254
255/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200256 * \brief Enable counter overflow interrupt request
257 * \param [in] mask Counter overflow interrupt request bits to set
258 * \note Sets 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 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200262void ETHOSU_PMU_Set_CNTR_IRQ_Enable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200263
264/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200265 * \brief Disable counter overflow interrupt request
266 * \param [in] mask Counter overflow interrupt request bits to clear
267 * \note Clears overflow interrupt request bits for one or more of the following:
268 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
269 * - cycle counter (bit 31)
270 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200271void ETHOSU_PMU_Set_CNTR_IRQ_Disable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200272
273/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200274 * \brief Get counters overflow interrupt request stiinings
275 * \return mask Counter overflow interrupt request bits
276 * \note Sets overflow interrupt request bits for one or more of the following:
277 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
278 * - cycle counter (bit 31)
279 * \note ETHOSU specific. Usage breaks CMSIS compliance
280 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200281uint32_t ETHOSU_PMU_Get_IRQ_Enable(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200282
283/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200284 * \brief Software increment event counter
285 * \param [in] mask Counters to increment
286 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
287 * - cycle counter (bit 31)
288 * \note Software increment bits for one or more event counters.
289 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200290void ETHOSU_PMU_CNTR_Increment(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200291
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200292/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200293 * \brief Set start event number for the cycle counter
Per Åstrand0fd65ce2021-03-11 10:25:18 +0100294 * \param [in] start_event Event to trigger start of the cycle counter
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200295 * \note Sets the event number that starts the cycle counter.
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200296 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200297void ETHOSU_PMU_PMCCNTR_CFG_Set_Start_Event(struct ethosu_driver *drv, enum ethosu_pmu_event_type 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
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200302 * \note Sets the event number that stops the cycle counter.
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200303 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200304void ETHOSU_PMU_PMCCNTR_CFG_Set_Stop_Event(struct ethosu_driver *drv, enum ethosu_pmu_event_type stop_event);
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200305
Kristofer Jonsson537c71c2020-05-05 14:17:22 +0200306#ifdef __cplusplus
307}
308#endif
309
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200310#endif /* PMU_ETHOSU_H */