cache.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * (C) Copyright 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Author: Igor Lisitsin <igor@emcraft.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. /* Cache test
  27. *
  28. * This test verifies the CPU data and instruction cache using
  29. * several test scenarios.
  30. */
  31. #ifdef CONFIG_POST
  32. #include <post.h>
  33. #if CONFIG_POST & CFG_POST_CACHE
  34. #include <asm/mmu.h>
  35. #include <watchdog.h>
  36. #define CACHE_POST_SIZE 1024
  37. void program_tlb(u32 phys_addr, u32 virt_addr, u32 size, u32 tlb_word2_i_value);
  38. int cache_post_test1 (int tlb, void *p, int size);
  39. int cache_post_test2 (int tlb, void *p, int size);
  40. int cache_post_test3 (int tlb, void *p, int size);
  41. int cache_post_test4 (int tlb, void *p, int size);
  42. int cache_post_test5 (int tlb, void *p, int size);
  43. int cache_post_test6 (int tlb, void *p, int size);
  44. static int tlb = -1; /* index to the victim TLB entry */
  45. #ifdef CONFIG_440
  46. static unsigned char testarea[CACHE_POST_SIZE]
  47. __attribute__((__aligned__(CACHE_POST_SIZE)));
  48. #endif
  49. int cache_post_test (int flags)
  50. {
  51. void* virt = (void*)CFG_POST_CACHE_ADDR;
  52. int ints;
  53. int res = 0;
  54. /*
  55. * All 44x variants deal with cache management differently
  56. * because they have the address translation always enabled.
  57. * The 40x ppc's don't use address translation in U-Boot at all,
  58. * so we have to distinguish here between 40x and 44x.
  59. */
  60. #ifdef CONFIG_440
  61. int word0, i;
  62. if (tlb < 0) {
  63. /*
  64. * Allocate a new TLB entry, since we are going to modify
  65. * the write-through and caching inhibited storage attributes.
  66. */
  67. program_tlb((u32)testarea, (u32)virt,
  68. CACHE_POST_SIZE, TLB_WORD2_I_ENABLE);
  69. /* Find the TLB entry */
  70. for (i = 0;; i++) {
  71. if (i >= PPC4XX_TLB_SIZE) {
  72. printf ("Failed to program tlb entry\n");
  73. return -1;
  74. }
  75. word0 = mftlb1(i);
  76. if (TLB_WORD0_EPN_DECODE(word0) == (u32)virt) {
  77. tlb = i;
  78. break;
  79. }
  80. }
  81. }
  82. #endif
  83. ints = disable_interrupts ();
  84. WATCHDOG_RESET ();
  85. if (res == 0)
  86. res = cache_post_test1 (tlb, virt, CACHE_POST_SIZE);
  87. WATCHDOG_RESET ();
  88. if (res == 0)
  89. res = cache_post_test2 (tlb, virt, CACHE_POST_SIZE);
  90. WATCHDOG_RESET ();
  91. if (res == 0)
  92. res = cache_post_test3 (tlb, virt, CACHE_POST_SIZE);
  93. WATCHDOG_RESET ();
  94. if (res == 0)
  95. res = cache_post_test4 (tlb, virt, CACHE_POST_SIZE);
  96. WATCHDOG_RESET ();
  97. if (res == 0)
  98. res = cache_post_test5 (tlb, virt, CACHE_POST_SIZE);
  99. WATCHDOG_RESET ();
  100. if (res == 0)
  101. res = cache_post_test6 (tlb, virt, CACHE_POST_SIZE);
  102. if (ints)
  103. enable_interrupts ();
  104. return res;
  105. }
  106. #endif /* CONFIG_POST & CFG_POST_CACHE */
  107. #endif /* CONFIG_POST */