]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v5_4/src/xil_testcache.c
Completely re-generate the Zynq 7000 demo using the 2016.1 SDK tools.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v5_4 / src / xil_testcache.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 2015 Xilinx, Inc. All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xil_testcache.c
36 *
37 * Contains utility functions to test cache.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
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
46 *                                     cache line.
47 * </pre>
48 *
49 * @note
50 *
51 * This file contain functions that all operate on HAL.
52 *
53 ******************************************************************************/
54 #ifdef __ARM__
55 #include "xil_cache.h"
56 #include "xil_testcache.h"
57 #include "xil_types.h"
58 #include "xpseudo_asm.h"
59 #ifdef __aarch64__
60 #include "xreg_cortexa53.h"
61 #else
62 #include "xreg_cortexr5.h"
63 #endif
64
65 #include "xil_types.h"
66
67 extern void xil_printf(const char8 *ctrl1, ...);
68
69 #define DATA_LENGTH 128
70
71 #ifdef __aarch64__
72 static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(64)));
73 #else
74 static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(32)));
75 #endif
76
77 /**
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.
82 *
83 * @return
84 *
85 *     - 0 is returned for a pass
86 *     - -1 is returned for a failure
87 */
88 s32 Xil_TestDCacheRange(void)
89 {
90         s32 Index;
91         s32 Status = 0;
92         u32 CtrlReg;
93         INTPTR Value;
94
95         xil_printf("-- Cache Range Test --\n\r");
96
97         for (Index = 0; Index < DATA_LENGTH; Index++)
98                 Data[Index] = 0xA0A00505;
99
100         xil_printf("    initialize Data done:\r\n");
101
102         Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
103
104         xil_printf("    flush range done\r\n");
105
106         dsb();
107         #ifdef __aarch64__
108                         CtrlReg = mfcp(SCTLR_EL3);
109                         CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
110                         mtcp(SCTLR_EL3,CtrlReg);
111         #else
112                         CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
113                         CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
114                         mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
115         #endif
116         dsb();
117
118         Status = 0;
119
120         for (Index = 0; Index < DATA_LENGTH; Index++) {
121                 Value = Data[Index];
122                 if (Value != 0xA0A00505) {
123                         Status = -1;
124                         xil_printf("Data[%d] = %x\r\n", Index, Value);
125                         break;
126                 }
127         }
128
129         if (!Status) {
130                 xil_printf("    Flush worked\r\n");
131         }
132         else {
133                 xil_printf("Error: flush dcache range not working\r\n");
134         }
135         dsb();
136         #ifdef __aarch64__
137                         CtrlReg = mfcp(SCTLR_EL3);
138                         CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
139                         mtcp(SCTLR_EL3,CtrlReg);
140                 #else
141                         CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
142                         CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
143                         mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
144                 #endif
145         dsb();
146         for (Index = 0; Index < DATA_LENGTH; Index++)
147                 Data[Index] = 0xA0A0C505;
148
149
150
151         Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
152
153         for (Index = 0; Index < DATA_LENGTH; Index++)
154                 Data[Index] = Index + 3;
155
156         Xil_DCacheInvalidateRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
157
158         xil_printf("    invalidate dcache range done\r\n");
159         dsb();
160         #ifdef __aarch64__
161                         CtrlReg = mfcp(SCTLR_EL3);
162                         CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
163                         mtcp(SCTLR_EL3,CtrlReg);
164         #else
165                         CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
166                         CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
167                         mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
168         #endif
169         dsb();
170         for (Index = 0; Index < DATA_LENGTH; Index++)
171                 Data[Index] = 0xA0A0A05;
172         dsb();
173         #ifdef __aarch64__
174                         CtrlReg = mfcp(SCTLR_EL3);
175                         CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
176                         mtcp(SCTLR_EL3,CtrlReg);
177         #else
178                         CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
179                         CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
180                         mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
181         #endif
182         dsb();
183
184         Status = 0;
185
186         for (Index = 0; Index < DATA_LENGTH; Index++) {
187                 Value = Data[Index];
188                 if (Value != 0xA0A0A05) {
189                         Status = -1;
190                         xil_printf("Data[%d] = %x\r\n", Index, Value);
191                         break;
192                 }
193         }
194
195
196         if (!Status) {
197                 xil_printf("    Invalidate worked\r\n");
198         }
199         else {
200                 xil_printf("Error: Invalidate dcache range not working\r\n");
201         }
202         xil_printf("-- Cache Range Test Complete --\r\n");
203         return Status;
204
205 }
206
207 /**
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
211 * the DCache.
212 *
213 * @return
214 *     - 0 is returned for a pass
215 *     - -1 is returned for a failure
216 */
217 s32 Xil_TestDCacheAll(void)
218 {
219         s32 Index;
220         s32 Status;
221         INTPTR Value;
222         u32 CtrlReg;
223
224         xil_printf("-- Cache All Test --\n\r");
225
226         for (Index = 0; Index < DATA_LENGTH; Index++)
227                 Data[Index] = 0x50500A0A;
228         xil_printf("    initialize Data done:\r\n");
229
230         Xil_DCacheFlush();
231         xil_printf("    flush all done\r\n");
232         dsb();
233         #ifdef __aarch64__
234                 CtrlReg = mfcp(SCTLR_EL3);
235                 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
236                 mtcp(SCTLR_EL3,CtrlReg);
237         #else
238                 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
239                 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
240                 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
241         #endif
242         dsb();
243         Status = 0;
244
245         for (Index = 0; Index < DATA_LENGTH; Index++) {
246                 Value = Data[Index];
247
248                 if (Value != 0x50500A0A) {
249                         Status = -1;
250                         xil_printf("Data[%d] = %x\r\n", Index, Value);
251                         break;
252                 }
253         }
254
255         if (!Status) {
256                 xil_printf("    Flush all worked\r\n");
257         }
258         else {
259                 xil_printf("Error: Flush dcache all not working\r\n");
260         }
261         dsb();
262         #ifdef __aarch64__
263                 CtrlReg = mfcp(SCTLR_EL3);
264                 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
265                 mtcp(SCTLR_EL3,CtrlReg);
266         #else
267                 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
268                         CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
269                         mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
270         #endif
271         dsb();
272         for (Index = 0; Index < DATA_LENGTH; Index++)
273                 Data[Index] = 0x505FFA0A;
274
275         Xil_DCacheFlush();
276
277
278         for (Index = 0; Index < DATA_LENGTH; Index++)
279                 Data[Index] = Index + 3;
280
281         Xil_DCacheInvalidate();
282
283         xil_printf("    invalidate all done\r\n");
284         dsb();
285         #ifdef __aarch64__
286                 CtrlReg = mfcp(SCTLR_EL3);
287                 CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
288                 mtcp(SCTLR_EL3,CtrlReg);
289         #else
290                 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
291                 CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
292                 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
293         #endif
294         dsb();
295         for (Index = 0; Index < DATA_LENGTH; Index++)
296                 Data[Index] = 0x50CFA0A;
297         dsb();
298         #ifdef __aarch64__
299                 CtrlReg = mfcp(SCTLR_EL3);
300                 CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
301                 mtcp(SCTLR_EL3,CtrlReg);
302         #else
303                 CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
304                 CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
305                 mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
306         #endif
307         dsb();
308         Status = 0;
309
310         for (Index = 0; Index < DATA_LENGTH; Index++) {
311                 Value = Data[Index];
312                 if (Value != 0x50CFA0A) {
313                         Status = -1;
314                         xil_printf("Data[%d] = %x\r\n", Index, Value);
315                         break;
316                 }
317         }
318
319         if (!Status) {
320                 xil_printf("    Invalidate all worked\r\n");
321         }
322         else {
323                         xil_printf("Error: Invalidate dcache all not working\r\n");
324         }
325
326         xil_printf("-- DCache all Test Complete --\n\r");
327
328         return Status;
329 }
330
331
332 /**
333 * Perform Xil_ICacheInvalidateRange() on a few function pointers.
334 *
335 * @return
336 *
337 *     - 0 is returned for a pass
338 *     The function will hang if it fails.
339 */
340 s32 Xil_TestICacheRange(void)
341 {
342
343         Xil_ICacheInvalidateRange((INTPTR)Xil_TestICacheRange, 1024);
344         Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheRange, 1024);
345         Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheAll, 1024);
346
347         xil_printf("-- Invalidate icache range done --\r\n");
348
349         return 0;
350 }
351
352 /**
353 * Perform Xil_ICacheInvalidate().
354 *
355 * @return
356 *
357 *     - 0 is returned for a pass
358 *     The function will hang if it fails.
359 */
360 s32 Xil_TestICacheAll(void)
361 {
362         Xil_ICacheInvalidate();
363         xil_printf("-- Invalidate icache all done --\r\n");
364         return 0;
365 }
366 #endif