1 /******************************************************************************
3 * Copyright (C) 2011 - 2014 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 /*****************************************************************************/
35 * @file xl2cc_counter.c
37 * This file contains APIs for configuring and controlling the event counters
38 * in PL310 L2 cache controller. For more information about the event counters,
39 * see xl2cc_counter.h.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -----------------------------------------------
46 * 1.00a sdm 07/11/11 First release
47 * 3.07a asa 08/30/12 Updated for CR 675636 to provide the L2 Base Address
51 ******************************************************************************/
53 /***************************** Include Files *********************************/
56 #include "xparameters_ps.h"
57 #include "xl2cc_counter.h"
60 /************************** Constant Definitions ****************************/
62 /**************************** Type Definitions ******************************/
64 /***************** Macros (Inline Functions) Definitions ********************/
66 /************************** Variable Definitions *****************************/
68 /************************** Function Prototypes ******************************/
70 void XL2cc_EventCtrReset(void);
72 /******************************************************************************/
74 /****************************************************************************/
77 * This function initializes the event counters in L2 Cache controller with a
78 * set of event codes specified by the user.
80 * @param Event0 is the event code for counter 0.
81 * @param Event1 is the event code for counter 1.
82 * Use the event codes defined by XL2CC_* in xl2cc_counter.h.
88 *****************************************************************************/
89 void XL2cc_EventCtrInit(int Event0, int Event1)
92 /* Write event code into cnt1 cfg reg */
93 *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT1_CTRL_OFFSET)) = (Event1 << 2);
95 /* Write event code into cnt0 cfg reg */
96 *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT0_CTRL_OFFSET)) = (Event0 << 2);
99 XL2cc_EventCtrReset();
102 /****************************************************************************/
105 * This function starts the event counters in L2 Cache controller.
113 *****************************************************************************/
114 void XL2cc_EventCtrStart(void)
116 XL2cc_EventCtrReset();
119 *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET)) = 1;
122 /****************************************************************************/
125 * This function disables the event counters in L2 Cache controller, saves the
126 * counter values and resets the counters.
128 * @param EveCtr0 is an output parameter which is used to return the value
129 * in event counter 0.
130 * EveCtr1 is an output parameter which is used to return the value
131 * in event counter 1.
137 *****************************************************************************/
138 void XL2cc_EventCtrStop(u32 *EveCtr0, u32 *EveCtr1)
140 /* Disable counter */
141 *((volatile u32*) (XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET)) = 0;
143 /* Save counter values */
144 *EveCtr1 = *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT1_VAL_OFFSET));
145 *EveCtr0 = *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT0_VAL_OFFSET));
147 XL2cc_EventCtrReset();
150 /****************************************************************************/
153 * This function resets the event counters in L2 Cache controller.
161 *****************************************************************************/
162 void XL2cc_EventCtrReset(void)
164 *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET)) = 0x6;