cache.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * (C) Copyright 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Author: Igor Lisitsin <igor@emcraft.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. /* Cache test
  11. *
  12. * This test verifies the CPU data and instruction cache using
  13. * several test scenarios.
  14. */
  15. #include <post.h>
  16. #if CONFIG_POST & CONFIG_SYS_POST_CACHE
  17. #include <asm/mmu.h>
  18. #include <watchdog.h>
  19. #define CACHE_POST_SIZE 1024
  20. int cache_post_test1 (int tlb, void *p, int size);
  21. int cache_post_test2 (int tlb, void *p, int size);
  22. int cache_post_test3 (int tlb, void *p, int size);
  23. int cache_post_test4 (int tlb, void *p, int size);
  24. int cache_post_test5 (int tlb, void *p, int size);
  25. int cache_post_test6 (int tlb, void *p, int size);
  26. #ifdef CONFIG_440
  27. static unsigned char testarea[CACHE_POST_SIZE]
  28. __attribute__((__aligned__(CACHE_POST_SIZE)));
  29. #endif
  30. int cache_post_test (int flags)
  31. {
  32. void *virt = (void *)CONFIG_SYS_POST_CACHE_ADDR;
  33. int ints;
  34. int res = 0;
  35. int tlb = -1; /* index to the victim TLB entry */
  36. /*
  37. * All 44x variants deal with cache management differently
  38. * because they have the address translation always enabled.
  39. * The 40x ppc's don't use address translation in U-Boot at all,
  40. * so we have to distinguish here between 40x and 44x.
  41. */
  42. #ifdef CONFIG_440
  43. int word0, i;
  44. /*
  45. * Allocate a new TLB entry, since we are going to modify
  46. * the write-through and caching inhibited storage attributes.
  47. */
  48. program_tlb((u32)testarea, (u32)virt, CACHE_POST_SIZE,
  49. TLB_WORD2_I_ENABLE);
  50. /* Find the TLB entry */
  51. for (i = 0;; i++) {
  52. if (i >= PPC4XX_TLB_SIZE) {
  53. printf ("Failed to program tlb entry\n");
  54. return -1;
  55. }
  56. word0 = mftlb1(i);
  57. if (TLB_WORD0_EPN_DECODE(word0) == (u32)virt) {
  58. tlb = i;
  59. break;
  60. }
  61. }
  62. #endif
  63. ints = disable_interrupts ();
  64. WATCHDOG_RESET ();
  65. if (res == 0)
  66. res = cache_post_test1 (tlb, virt, CACHE_POST_SIZE);
  67. WATCHDOG_RESET ();
  68. if (res == 0)
  69. res = cache_post_test2 (tlb, virt, CACHE_POST_SIZE);
  70. WATCHDOG_RESET ();
  71. if (res == 0)
  72. res = cache_post_test3 (tlb, virt, CACHE_POST_SIZE);
  73. WATCHDOG_RESET ();
  74. if (res == 0)
  75. res = cache_post_test4 (tlb, virt, CACHE_POST_SIZE);
  76. WATCHDOG_RESET ();
  77. if (res == 0)
  78. res = cache_post_test5 (tlb, virt, CACHE_POST_SIZE);
  79. WATCHDOG_RESET ();
  80. if (res == 0)
  81. res = cache_post_test6 (tlb, virt, CACHE_POST_SIZE);
  82. if (ints)
  83. enable_interrupts ();
  84. #ifdef CONFIG_440
  85. remove_tlb((u32)virt, CACHE_POST_SIZE);
  86. #endif
  87. return res;
  88. }
  89. #endif /* CONFIG_POST & CONFIG_SYS_POST_CACHE */