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 ******************************************************************************/
54 #include "xil_cache.h"
55 #include "xil_testcache.h"
57 extern void xil_printf(const char *ctrl1, ...);
59 #define DATA_LENGTH 128
61 static u32 Data[DATA_LENGTH] __attribute__ ((aligned(32)));
64 * Perform DCache range related API test such as Xil_DCacheFlushRange and
65 * Xil_DCacheInvalidateRange. This test function writes a constant value
66 * to the Data array, flushes the range, writes a new value, then invalidates
67 * the corresponding range.
71 * - 0 is returned for a pass
72 * - -1 is returned for a failure
74 int Xil_TestDCacheRange(void)
81 xil_printf("-- Cache Range Test --\n\r");
84 for (Index = 0; Index < DATA_LENGTH; Index++)
85 Data[Index] = 0xA0A00505;
87 xil_printf(" initialize Data done:\r\n");
89 Xil_DCacheFlushRange((u32)Data, DATA_LENGTH * sizeof(u32));
91 xil_printf(" flush range done\r\n");
92 for (Index = 0; Index < DATA_LENGTH; Index++)
93 Data[Index] = Index + 3;
95 Xil_DCacheInvalidateRange((u32)Data, DATA_LENGTH * sizeof(u32));
97 xil_printf(" invalidate dcache range done\r\n");
101 for (Index = 0; Index < DATA_LENGTH; Index++) {
103 if (Value != 0xA0A00505) {
105 xil_printf("Data[%d] = %x\r\n", Index, Value);
111 xil_printf(" Invalidate worked\r\n");
114 xil_printf("Error: Invalidate dcache range not working\r\n");
117 xil_printf("-- Cache Range Test Complete --\r\n");
124 * Perform DCache all related API test such as Xil_DCacheFlush and
125 * Xil_DCacheInvalidate. This test function writes a constant value
126 * to the Data array, flushes the DCache, writes a new value, then invalidates
130 * - 0 is returned for a pass
131 * - -1 is returned for a failure
133 int Xil_TestDCacheAll(void)
139 xil_printf("-- Cache All Test --\n\r");
142 for (Index = 0; Index < DATA_LENGTH; Index++)
143 Data[Index] = 0x50500A0A;
145 xil_printf(" initialize Data done:\r\n");
149 xil_printf(" flush all done\r\n");
151 for (Index = 0; Index < DATA_LENGTH; Index++)
152 Data[Index] = Index + 3;
154 Xil_DCacheInvalidate();
156 xil_printf(" invalidate all done\r\n");
160 for (Index = 0; Index < DATA_LENGTH; Index++) {
162 if (Value != 0x50500A0A) {
164 xil_printf("Data[%d] = %x\r\n", Index, Value);
170 xil_printf(" Invalidate all worked\r\n");
173 xil_printf("Error: Invalidate dcache all not working\r\n");
176 xil_printf("-- DCache all Test Complete --\n\r");
184 * Perform Xil_ICacheInvalidateRange() on a few function pointers.
188 * - 0 is returned for a pass
189 * The function will hang if it fails.
191 int Xil_TestICacheRange(void)
194 Xil_ICacheInvalidateRange((u32)Xil_TestICacheRange, 1024);
195 Xil_ICacheInvalidateRange((u32)Xil_TestDCacheRange, 1024);
196 Xil_ICacheInvalidateRange((u32)Xil_TestDCacheAll, 1024);
198 xil_printf("-- Invalidate icache range done --\r\n");
204 * Perform Xil_ICacheInvalidate().
208 * - 0 is returned for a pass
209 * The function will hang if it fails.
211 int Xil_TestICacheAll(void)
213 Xil_ICacheInvalidate();
214 xil_printf("-- Invalidate icache all done --\r\n");