1 /******************************************************************************
3 * Copyright (C) 2009 - 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 xil_testcache.c
37 * Contains utility functions to test cache.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -------------------------------------------------------
44 * 1.00a hbm 07/28/09 Initial release
45 * 4.1 asa 05/09/14 Ensured that the address uses for cache test is aligned
51 * This file contain functions that all operate on HAL.
53 ******************************************************************************/
55 #include "xil_cache.h"
56 #include "xil_testcache.h"
57 #include "xil_types.h"
58 #include "xpseudo_asm.h"
60 #include "xreg_cortexa53.h"
62 #include "xreg_cortexr5.h"
65 #include "xil_types.h"
67 extern void xil_printf(const char8 *ctrl1, ...);
69 #define DATA_LENGTH 128
72 static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(64)));
74 static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(32)));
78 * Perform DCache range related API test such as Xil_DCacheFlushRange and
79 * Xil_DCacheInvalidateRange. This test function writes a constant value
80 * to the Data array, flushes the range, writes a new value, then invalidates
81 * the corresponding range.
85 * - 0 is returned for a pass
86 * - -1 is returned for a failure
88 s32 Xil_TestDCacheRange(void)
95 xil_printf("-- Cache Range Test --\n\r");
97 for (Index = 0; Index < DATA_LENGTH; Index++)
98 Data[Index] = 0xA0A00505;
100 xil_printf(" initialize Data done:\r\n");
102 Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
104 xil_printf(" flush range done\r\n");
108 CtrlReg = mfcp(SCTLR_EL3);
109 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
110 mtcp(SCTLR_EL3,CtrlReg);
112 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
113 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
114 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
120 for (Index = 0; Index < DATA_LENGTH; Index++) {
122 if (Value != 0xA0A00505) {
124 xil_printf("Data[%d] = %x\r\n", Index, Value);
130 xil_printf(" Flush worked\r\n");
133 xil_printf("Error: flush dcache range not working\r\n");
137 CtrlReg = mfcp(SCTLR_EL3);
138 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
139 mtcp(SCTLR_EL3,CtrlReg);
141 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
142 CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
143 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
146 for (Index = 0; Index < DATA_LENGTH; Index++)
147 Data[Index] = 0xA0A0C505;
151 Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
153 for (Index = 0; Index < DATA_LENGTH; Index++)
154 Data[Index] = Index + 3;
156 Xil_DCacheInvalidateRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
158 xil_printf(" invalidate dcache range done\r\n");
161 CtrlReg = mfcp(SCTLR_EL3);
162 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
163 mtcp(SCTLR_EL3,CtrlReg);
165 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
166 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
167 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
170 for (Index = 0; Index < DATA_LENGTH; Index++)
171 Data[Index] = 0xA0A0A05;
174 CtrlReg = mfcp(SCTLR_EL3);
175 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
176 mtcp(SCTLR_EL3,CtrlReg);
178 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
179 CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
180 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
186 for (Index = 0; Index < DATA_LENGTH; Index++) {
188 if (Value != 0xA0A0A05) {
190 xil_printf("Data[%d] = %x\r\n", Index, Value);
197 xil_printf(" Invalidate worked\r\n");
200 xil_printf("Error: Invalidate dcache range not working\r\n");
202 xil_printf("-- Cache Range Test Complete --\r\n");
208 * Perform DCache all related API test such as Xil_DCacheFlush and
209 * Xil_DCacheInvalidate. This test function writes a constant value
210 * to the Data array, flushes the DCache, writes a new value, then invalidates
214 * - 0 is returned for a pass
215 * - -1 is returned for a failure
217 s32 Xil_TestDCacheAll(void)
224 xil_printf("-- Cache All Test --\n\r");
226 for (Index = 0; Index < DATA_LENGTH; Index++)
227 Data[Index] = 0x50500A0A;
228 xil_printf(" initialize Data done:\r\n");
231 xil_printf(" flush all done\r\n");
234 CtrlReg = mfcp(SCTLR_EL3);
235 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
236 mtcp(SCTLR_EL3,CtrlReg);
238 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
239 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
240 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
245 for (Index = 0; Index < DATA_LENGTH; Index++) {
248 if (Value != 0x50500A0A) {
250 xil_printf("Data[%d] = %x\r\n", Index, Value);
256 xil_printf(" Flush all worked\r\n");
259 xil_printf("Error: Flush dcache all not working\r\n");
263 CtrlReg = mfcp(SCTLR_EL3);
264 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
265 mtcp(SCTLR_EL3,CtrlReg);
267 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
268 CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
269 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
272 for (Index = 0; Index < DATA_LENGTH; Index++)
273 Data[Index] = 0x505FFA0A;
278 for (Index = 0; Index < DATA_LENGTH; Index++)
279 Data[Index] = Index + 3;
281 Xil_DCacheInvalidate();
283 xil_printf(" invalidate all done\r\n");
286 CtrlReg = mfcp(SCTLR_EL3);
287 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
288 mtcp(SCTLR_EL3,CtrlReg);
290 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
291 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
292 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
295 for (Index = 0; Index < DATA_LENGTH; Index++)
296 Data[Index] = 0x50CFA0A;
299 CtrlReg = mfcp(SCTLR_EL3);
300 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
301 mtcp(SCTLR_EL3,CtrlReg);
303 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
304 CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
305 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
310 for (Index = 0; Index < DATA_LENGTH; Index++) {
312 if (Value != 0x50CFA0A) {
314 xil_printf("Data[%d] = %x\r\n", Index, Value);
320 xil_printf(" Invalidate all worked\r\n");
323 xil_printf("Error: Invalidate dcache all not working\r\n");
326 xil_printf("-- DCache all Test Complete --\n\r");
333 * Perform Xil_ICacheInvalidateRange() on a few function pointers.
337 * - 0 is returned for a pass
338 * The function will hang if it fails.
340 s32 Xil_TestICacheRange(void)
343 Xil_ICacheInvalidateRange((INTPTR)Xil_TestICacheRange, 1024);
344 Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheRange, 1024);
345 Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheAll, 1024);
347 xil_printf("-- Invalidate icache range done --\r\n");
353 * Perform Xil_ICacheInvalidate().
357 * - 0 is returned for a pass
358 * The function will hang if it fails.
360 s32 Xil_TestICacheAll(void)
362 Xil_ICacheInvalidate();
363 xil_printf("-- Invalidate icache all done --\r\n");