/FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/standalone_v6_6/src/xil_testcache.c

https://gitlab.com/21mece13/FreeRTOS · C · 371 lines · 229 code · 47 blank · 95 comment · 28 complexity · 988402b04a23c6dfcf64b546a411d2bf MD5 · raw file

  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. * This file contain functions that all operate on HAL.
  51. *
  52. ******************************************************************************/
  53. #ifdef __ARM__
  54. #include "xil_cache.h"
  55. #include "xil_testcache.h"
  56. #include "xil_types.h"
  57. #include "xpseudo_asm.h"
  58. #ifdef __aarch64__
  59. #include "xreg_cortexa53.h"
  60. #else
  61. #include "xreg_cortexr5.h"
  62. #endif
  63. #include "xil_types.h"
  64. extern void xil_printf(const char8 *ctrl1, ...);
  65. #define DATA_LENGTH 128
  66. #ifdef __aarch64__
  67. static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(64)));
  68. #else
  69. static INTPTR Data[DATA_LENGTH] __attribute__ ((aligned(32)));
  70. #endif
  71. /*****************************************************************************/
  72. /**
  73. *
  74. * @brief Perform DCache range related API test such as Xil_DCacheFlushRange
  75. * and Xil_DCacheInvalidateRange. This test function writes a constant
  76. * value to the Data array, flushes the range, writes a new value, then
  77. * invalidates the corresponding range.
  78. * @param None
  79. *
  80. * @return
  81. * - -1 is returned for a failure
  82. * - 0 is returned for a pass
  83. *
  84. *****************************************************************************/
  85. s32 Xil_TestDCacheRange(void)
  86. {
  87. s32 Index;
  88. s32 Status = 0;
  89. u32 CtrlReg;
  90. INTPTR Value;
  91. xil_printf("-- Cache Range Test --\n\r");
  92. for (Index = 0; Index < DATA_LENGTH; Index++)
  93. Data[Index] = 0xA0A00505;
  94. xil_printf(" initialize Data done:\r\n");
  95. Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
  96. xil_printf(" flush range done\r\n");
  97. dsb();
  98. #ifdef __aarch64__
  99. CtrlReg = mfcp(SCTLR_EL3);
  100. CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
  101. mtcp(SCTLR_EL3,CtrlReg);
  102. #else
  103. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  104. CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
  105. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  106. #endif
  107. dsb();
  108. Status = 0;
  109. for (Index = 0; Index < DATA_LENGTH; Index++) {
  110. Value = Data[Index];
  111. if (Value != 0xA0A00505) {
  112. Status = -1;
  113. xil_printf("Data[%d] = %x\r\n", Index, Value);
  114. break;
  115. }
  116. }
  117. if (!Status) {
  118. xil_printf(" Flush worked\r\n");
  119. }
  120. else {
  121. xil_printf("Error: flush dcache range not working\r\n");
  122. }
  123. dsb();
  124. #ifdef __aarch64__
  125. CtrlReg = mfcp(SCTLR_EL3);
  126. CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
  127. mtcp(SCTLR_EL3,CtrlReg);
  128. #else
  129. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  130. CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
  131. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  132. #endif
  133. dsb();
  134. for (Index = 0; Index < DATA_LENGTH; Index++)
  135. Data[Index] = 0xA0A0C505;
  136. Xil_DCacheFlushRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
  137. for (Index = 0; Index < DATA_LENGTH; Index++)
  138. Data[Index] = Index + 3;
  139. Xil_DCacheInvalidateRange((INTPTR)Data, DATA_LENGTH * sizeof(INTPTR));
  140. xil_printf(" invalidate dcache range done\r\n");
  141. dsb();
  142. #ifdef __aarch64__
  143. CtrlReg = mfcp(SCTLR_EL3);
  144. CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
  145. mtcp(SCTLR_EL3,CtrlReg);
  146. #else
  147. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  148. CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
  149. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  150. #endif
  151. dsb();
  152. for (Index = 0; Index < DATA_LENGTH; Index++)
  153. Data[Index] = 0xA0A0A05;
  154. dsb();
  155. #ifdef __aarch64__
  156. CtrlReg = mfcp(SCTLR_EL3);
  157. CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
  158. mtcp(SCTLR_EL3,CtrlReg);
  159. #else
  160. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  161. CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
  162. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  163. #endif
  164. dsb();
  165. Status = 0;
  166. for (Index = 0; Index < DATA_LENGTH; Index++) {
  167. Value = Data[Index];
  168. if (Value != 0xA0A0A05) {
  169. Status = -1;
  170. xil_printf("Data[%d] = %x\r\n", Index, Value);
  171. break;
  172. }
  173. }
  174. if (!Status) {
  175. xil_printf(" Invalidate worked\r\n");
  176. }
  177. else {
  178. xil_printf("Error: Invalidate dcache range not working\r\n");
  179. }
  180. xil_printf("-- Cache Range Test Complete --\r\n");
  181. return Status;
  182. }
  183. /*****************************************************************************/
  184. /**
  185. * @brief Perform DCache all related API test such as Xil_DCacheFlush and
  186. * Xil_DCacheInvalidate. This test function writes a constant value
  187. * to the Data array, flushes the DCache, writes a new value,
  188. * then invalidates the DCache.
  189. *
  190. * @return
  191. * - 0 is returned for a pass
  192. * - -1 is returned for a failure
  193. *****************************************************************************/
  194. s32 Xil_TestDCacheAll(void)
  195. {
  196. s32 Index;
  197. s32 Status;
  198. INTPTR Value;
  199. u32 CtrlReg;
  200. xil_printf("-- Cache All Test --\n\r");
  201. for (Index = 0; Index < DATA_LENGTH; Index++)
  202. Data[Index] = 0x50500A0A;
  203. xil_printf(" initialize Data done:\r\n");
  204. Xil_DCacheFlush();
  205. xil_printf(" flush all done\r\n");
  206. dsb();
  207. #ifdef __aarch64__
  208. CtrlReg = mfcp(SCTLR_EL3);
  209. CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
  210. mtcp(SCTLR_EL3,CtrlReg);
  211. #else
  212. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  213. CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
  214. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  215. #endif
  216. dsb();
  217. Status = 0;
  218. for (Index = 0; Index < DATA_LENGTH; Index++) {
  219. Value = Data[Index];
  220. if (Value != 0x50500A0A) {
  221. Status = -1;
  222. xil_printf("Data[%d] = %x\r\n", Index, Value);
  223. break;
  224. }
  225. }
  226. if (!Status) {
  227. xil_printf(" Flush all worked\r\n");
  228. }
  229. else {
  230. xil_printf("Error: Flush dcache all not working\r\n");
  231. }
  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. for (Index = 0; Index < DATA_LENGTH; Index++)
  244. Data[Index] = 0x505FFA0A;
  245. Xil_DCacheFlush();
  246. for (Index = 0; Index < DATA_LENGTH; Index++)
  247. Data[Index] = Index + 3;
  248. Xil_DCacheInvalidate();
  249. xil_printf(" invalidate all done\r\n");
  250. dsb();
  251. #ifdef __aarch64__
  252. CtrlReg = mfcp(SCTLR_EL3);
  253. CtrlReg &= ~(XREG_CONTROL_DCACHE_BIT);
  254. mtcp(SCTLR_EL3,CtrlReg);
  255. #else
  256. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  257. CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
  258. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  259. #endif
  260. dsb();
  261. for (Index = 0; Index < DATA_LENGTH; Index++)
  262. Data[Index] = 0x50CFA0A;
  263. dsb();
  264. #ifdef __aarch64__
  265. CtrlReg = mfcp(SCTLR_EL3);
  266. CtrlReg |= (XREG_CONTROL_DCACHE_BIT);
  267. mtcp(SCTLR_EL3,CtrlReg);
  268. #else
  269. CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
  270. CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
  271. mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
  272. #endif
  273. dsb();
  274. Status = 0;
  275. for (Index = 0; Index < DATA_LENGTH; Index++) {
  276. Value = Data[Index];
  277. if (Value != 0x50CFA0A) {
  278. Status = -1;
  279. xil_printf("Data[%d] = %x\r\n", Index, Value);
  280. break;
  281. }
  282. }
  283. if (!Status) {
  284. xil_printf(" Invalidate all worked\r\n");
  285. }
  286. else {
  287. xil_printf("Error: Invalidate dcache all not working\r\n");
  288. }
  289. xil_printf("-- DCache all Test Complete --\n\r");
  290. return Status;
  291. }
  292. /*****************************************************************************/
  293. /**
  294. * @brief Perform Xil_ICacheInvalidateRange() on a few function pointers.
  295. *
  296. * @return
  297. * - 0 is returned for a pass
  298. * @note
  299. * The function will hang if it fails.
  300. *****************************************************************************/
  301. s32 Xil_TestICacheRange(void)
  302. {
  303. Xil_ICacheInvalidateRange((INTPTR)Xil_TestICacheRange, 1024);
  304. Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheRange, 1024);
  305. Xil_ICacheInvalidateRange((INTPTR)Xil_TestDCacheAll, 1024);
  306. xil_printf("-- Invalidate icache range done --\r\n");
  307. return 0;
  308. }
  309. /*****************************************************************************/
  310. /**
  311. * @brief Perform Xil_ICacheInvalidate() on a few function pointers.
  312. *
  313. * @return
  314. * - 0 is returned for a pass
  315. * @note
  316. * The function will hang if it fails.
  317. *****************************************************************************/
  318. s32 Xil_TestICacheAll(void)
  319. {
  320. Xil_ICacheInvalidate();
  321. xil_printf("-- Invalidate icache all done --\r\n");
  322. return 0;
  323. }
  324. #endif