blob: b717130bedfe84337f0754f0e6cef91f739599ef [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
Kristofer Jonsson4e53fee2022-09-29 12:03:36 +02002 * SPDX-FileCopyrightText: Copyright 2019-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
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,
Jonny Svärd16836652021-11-18 12:14:21 +0100108 ETHOSU_PMU_AXI_LATENCY_ANY,
109 ETHOSU_PMU_AXI_LATENCY_32,
110 ETHOSU_PMU_AXI_LATENCY_64,
111 ETHOSU_PMU_AXI_LATENCY_128,
112 ETHOSU_PMU_AXI_LATENCY_256,
113 ETHOSU_PMU_AXI_LATENCY_512,
114 ETHOSU_PMU_AXI_LATENCY_1024,
115 ETHOSU_PMU_ECC_DMA,
116 ETHOSU_PMU_ECC_SB0,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200117 ETHOSU_PMU_AXI1_RD_TRANS_ACCEPTED,
118 ETHOSU_PMU_AXI1_RD_TRANS_COMPLETED,
119 ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED,
120 ETHOSU_PMU_AXI1_RD_TRAN_REQ_STALLED,
121 ETHOSU_PMU_AXI1_WR_TRANS_ACCEPTED,
122 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_M,
123 ETHOSU_PMU_AXI1_WR_TRANS_COMPLETED_S,
124 ETHOSU_PMU_AXI1_WR_DATA_BEAT_WRITTEN,
125 ETHOSU_PMU_AXI1_WR_TRAN_REQ_STALLED,
126 ETHOSU_PMU_AXI1_WR_DATA_BEAT_STALLED,
127 ETHOSU_PMU_AXI1_ENABLED_CYCLES,
128 ETHOSU_PMU_AXI1_RD_STALL_LIMIT,
129 ETHOSU_PMU_AXI1_WR_STALL_LIMIT,
Stefan Nannessone2e70242020-08-19 16:01:29 +0200130 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/**
Jonny Svärd20ce37f2021-12-17 17:00:57 +0100157 * \brief Get number of PMU event counters
158 * \return Number of event counters
159 */
160uint32_t ETHOSU_PMU_Get_NumEventCounters(void);
161
162/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200163 * \brief Get event to count for PMU eventer counter
164 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS) to configure
165 * \return type Event to count
166 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200167enum ethosu_pmu_event_type ETHOSU_PMU_Get_EVTYPER(struct ethosu_driver *drv, uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200168
169/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200170 * \brief Reset cycle counter
171 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200172void ETHOSU_PMU_CYCCNT_Reset(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200173
174/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200175 * \brief Reset all event counters
176 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200177void ETHOSU_PMU_EVCNTR_ALL_Reset(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200178
179/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200180 * \brief Enable counters
181 * \param [in] mask Counters to enable
182 * \note Enables one or more of the following:
183 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
184 * - cycle counter (bit 31)
185 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200186void ETHOSU_PMU_CNTR_Enable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200187
188/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200189 * \brief Disable counters
190 * \param [in] mask Counters to disable
191 * \note Disables one or more of the following:
192 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
193 * - cycle counter (bit 31)
194 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200195void ETHOSU_PMU_CNTR_Disable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200196
197/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200198 * \brief Determine counters activation
199 *
200 * \return Event count
201 * \param [in] mask Counters to enable
202 * \return a bitmask where bit-set means:
203 * - event counters activated (bit 0-ETHOSU_PMU_NCOUNTERS)
204 * - cycle counter activate (bit 31)
205 * \note ETHOSU specific. Usage breaks CMSIS complience
206 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200207uint32_t ETHOSU_PMU_CNTR_Status(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200208
209/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200210 * \brief Read cycle counter (64 bit)
211 * \return Cycle count
212 * \note Two HW 32-bit registers that can increment independently in-between reads.
213 * To work-around raciness yet still avoid turning
214 * off the event both are read as one value twice. If the latter read
215 * is not greater than the former, it means overflow of LSW without
216 * incrementing MSW has occurred, in which case the former value is used.
217 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200218uint64_t ETHOSU_PMU_Get_CCNTR(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200219
220/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200221 * \brief Set cycle counter (64 bit)
222 * \param [in] val Conter value
223 * \note Two HW 32-bit registers that can increment independently in-between reads.
224 * To work-around raciness, counter is temporary disabled if enabled.
225 * \note ETHOSU specific. Usage breaks CMSIS complience
226 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200227void ETHOSU_PMU_Set_CCNTR(struct ethosu_driver *drv, uint64_t val);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200228
229/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200230 * \brief Read event counter
231 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
232 * \return Event count
233 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200234uint32_t ETHOSU_PMU_Get_EVCNTR(struct ethosu_driver *drv, uint32_t num);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200235
236/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200237 * \brief Set event counter value
238 * \param [in] num Event counter (0-ETHOSU_PMU_NCOUNTERS)
239 * \param [in] val Conter value
240 * \note ETHOSU specific. Usage breaks CMSIS complience
241 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200242void ETHOSU_PMU_Set_EVCNTR(struct ethosu_driver *drv, uint32_t num, uint32_t val);
Bhavik Patel8e32b0b2020-06-23 13:48:25 +0200243
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200244/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200245 * \brief Read counter overflow status
246 * \return Counter overflow status bits for the following:
247 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS))
248 * - cycle counter (bit 31)
249 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200250uint32_t ETHOSU_PMU_Get_CNTR_OVS(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200251
252/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200253 * \brief Clear counter overflow status
254 * \param [in] mask Counter overflow status bits to clear
255 * \note Clears overflow status bits for one or more of the following:
256 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
257 * - cycle counter (bit 31)
258 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200259void ETHOSU_PMU_Set_CNTR_OVS(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200260
261/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200262 * \brief Enable counter overflow interrupt request
263 * \param [in] mask Counter overflow interrupt request bits to set
264 * \note Sets overflow interrupt request bits for one or more of the following:
265 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
266 * - cycle counter (bit 31)
267 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200268void ETHOSU_PMU_Set_CNTR_IRQ_Enable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200269
270/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200271 * \brief Disable counter overflow interrupt request
272 * \param [in] mask Counter overflow interrupt request bits to clear
273 * \note Clears overflow interrupt request bits for one or more of the following:
274 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
275 * - cycle counter (bit 31)
276 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200277void ETHOSU_PMU_Set_CNTR_IRQ_Disable(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200278
279/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200280 * \brief Get counters overflow interrupt request stiinings
281 * \return mask Counter overflow interrupt request bits
282 * \note Sets overflow interrupt request bits for one or more of the following:
283 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
284 * - cycle counter (bit 31)
285 * \note ETHOSU specific. Usage breaks CMSIS compliance
286 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200287uint32_t ETHOSU_PMU_Get_IRQ_Enable(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200288
289/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200290 * \brief Software increment event counter
291 * \param [in] mask Counters to increment
292 * - event counters (bit 0-ETHOSU_PMU_NCOUNTERS)
293 * - cycle counter (bit 31)
294 * \note Software increment bits for one or more event counters.
295 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200296void ETHOSU_PMU_CNTR_Increment(struct ethosu_driver *drv, uint32_t mask);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200297
Bhavik Patel4e8dbf52020-06-15 10:09:28 +0200298/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200299 * \brief Set start event number for the cycle counter
Per Åstrand0fd65ce2021-03-11 10:25:18 +0100300 * \param [in] start_event Event to trigger start of the cycle counter
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200301 * \note Sets the event number that starts the cycle counter.
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200302 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200303void 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 +0200304
305/**
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200306 * \brief Set stop event number for the cycle counter
307 * \param [in] stop_event Event number
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200308 * \note Sets the event number that stops the cycle counter.
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +0200309 */
Anton Mobergc6fd88e2021-05-03 17:00:33 +0200310void 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 +0200311
Kristofer Jonsson4e53fee2022-09-29 12:03:36 +0200312/**
313 * \brief Read qread register
314 */
315uint32_t ETHOSU_PMU_Get_QREAD(struct ethosu_driver *drv);
316
317/**
318 * \brief Read status register
319 */
320uint32_t ETHOSU_PMU_Get_STATUS(struct ethosu_driver *drv);
321
Kristofer Jonsson537c71c2020-05-05 14:17:22 +0200322#ifdef __cplusplus
323}
324#endif
325
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200326#endif /* PMU_ETHOSU_H */