1 /******************************************************************************
3 * Copyright (C) 2014 - 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This file contains APIs for configuring and controlling the Cortex-R5
38 * Performance Monitor Events. For more information about the event counters,
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -----------------------------------------------
46 * 5.00 pkp 02/10/14 Initial version
49 ******************************************************************************/
51 /***************************** Include Files *********************************/
53 #include "xpm_counter.h"
55 /************************** Constant Definitions ****************************/
57 /**************************** Type Definitions ******************************/
59 typedef const u32 PmcrEventCfg32[XPM_CTRCOUNT];
61 /***************** Macros (Inline Functions) Definitions ********************/
63 /************************** Variable Definitions *****************************/
67 /************************** Function Prototypes ******************************/
69 void Xpm_DisableEventCounters(void);
70 void Xpm_EnableEventCounters (void);
71 void Xpm_ResetEventCounters (void);
73 /******************************************************************************/
75 /****************************************************************************/
78 * This function disables the Cortex R5 event counters.
86 *****************************************************************************/
87 void Xpm_DisableEventCounters(void)
89 /* Disable the event counters */
90 mtcp(XREG_CP15_COUNT_ENABLE_CLR, 0x3f);
93 /****************************************************************************/
96 * This function enables the Cortex R5 event counters.
104 *****************************************************************************/
105 void Xpm_EnableEventCounters(void)
107 /* Enable the event counters */
108 mtcp(XREG_CP15_COUNT_ENABLE_SET, 0x3f);
111 /****************************************************************************/
114 * This function resets the Cortex R5 event counters.
122 *****************************************************************************/
123 void Xpm_ResetEventCounters(void)
128 Reg = mfcp(XREG_CP15_PERF_MONITOR_CTRL);
130 { register u32 C15Reg __asm(XREG_CP15_PERF_MONITOR_CTRL);
133 Reg |= (1U << 2U); /* reset event counters */
134 mtcp(XREG_CP15_PERF_MONITOR_CTRL, Reg);
137 /****************************************************************************/
140 * This function configures the Cortex R5 event counters controller, with the
141 * event codes, in a configuration selected by the user and enables the counters.
143 * @param PmcrCfg is configuration value based on which the event counters
145 * Use XPM_CNTRCFG* values defined in xpm_counter.h.
151 *****************************************************************************/
152 void Xpm_SetEvents(s32 PmcrCfg)
155 static PmcrEventCfg32 PmcrEvents[] = {
158 XPM_EVENT_INSRFETCH_CACHEREFILL,
159 XPM_EVENT_INSTRFECT_TLBREFILL,
160 XPM_EVENT_DATA_CACHEREFILL,
161 XPM_EVENT_DATA_CACHEACCESS,
162 XPM_EVENT_DATA_TLBREFILL
165 XPM_EVENT_DATA_READS,
166 XPM_EVENT_DATA_WRITE,
168 XPM_EVENT_EXCEPRETURN,
169 XPM_EVENT_CHANGECONTEXT,
170 XPM_EVENT_SW_CHANGEPC
173 XPM_EVENT_IMMEDBRANCH,
174 XPM_EVENT_UNALIGNEDACCESS,
175 XPM_EVENT_BRANCHMISS,
176 XPM_EVENT_CLOCKCYCLES,
177 XPM_EVENT_BRANCHPREDICT,
178 XPM_EVENT_JAVABYTECODE
181 XPM_EVENT_SWJAVABYTECODE,
182 XPM_EVENT_JAVABACKBRANCH,
183 XPM_EVENT_COHERLINEMISS,
184 XPM_EVENT_COHERLINEHIT,
185 XPM_EVENT_INSTRSTALL,
189 XPM_EVENT_MAINTLBSTALL,
193 XPM_EVENT_NODISPATCH,
197 XPM_EVENT_INSTRRENAME,
198 XPM_EVENT_PREDICTFUNCRET,
202 XPM_EVENT_FLOATRENAME
205 XPM_EVENT_NEONRENAME,
207 XPM_EVENT_WRITESTALL,
208 XPM_EVENT_INSTRTLBSTALL,
209 XPM_EVENT_DATATLBSTALL,
210 XPM_EVENT_INSTR_uTLBSTALL
213 XPM_EVENT_DATA_uTLBSTALL,
238 XPM_EVENT_INSRFETCH_CACHEREFILL,
239 XPM_EVENT_INSTRFECT_TLBREFILL,
240 XPM_EVENT_DATA_CACHEREFILL,
241 XPM_EVENT_DATA_CACHEACCESS,
242 XPM_EVENT_DATA_TLBREFILL
245 const u32 *ptr = PmcrEvents[PmcrCfg];
247 Xpm_DisableEventCounters();
249 for(Counter = 0U; Counter < XPM_CTRCOUNT; Counter++) {
251 /* Selecet event counter */
252 mtcp(XREG_CP15_EVENT_CNTR_SEL, Counter);
255 mtcp(XREG_CP15_EVENT_TYPE_SEL, ptr[Counter]);
258 Xpm_ResetEventCounters();
259 Xpm_EnableEventCounters();
262 /****************************************************************************/
265 * This function disables the event counters and returns the counter values.
267 * @param PmCtrValue is a pointer to an array of type u32 PmCtrValue[6].
268 * It is an output parameter which is used to return the PM
275 *****************************************************************************/
276 void Xpm_GetEventCounters(u32 *PmCtrValue)
280 Xpm_DisableEventCounters();
282 for(Counter = 0U; Counter < XPM_CTRCOUNT; Counter++) {
284 mtcp(XREG_CP15_EVENT_CNTR_SEL, Counter);
286 PmCtrValue[Counter] = mfcp(XREG_CP15_PERF_MONITOR_COUNT);
288 { register u32 Cp15Reg __asm(XREG_CP15_PERF_MONITOR_COUNT);
289 PmCtrValue[Counter] = Cp15Reg; }