v850e_cache.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * arch/v850/kernel/v850e_cache.c -- Cache control for V850E cache memories
  3. *
  4. * Copyright (C) 2003 NEC Electronics Corporation
  5. * Copyright (C) 2003 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. /* This file implements cache control for the rather simple cache used on
  14. some V850E CPUs, specifically the NB85E/TEG CPU-core and the V850E/ME2
  15. CPU. V850E2 processors have their own (better) cache
  16. implementation. */
  17. #include <asm/entry.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/v850e_cache.h>
  20. #define WAIT_UNTIL_CLEAR(value) while (value) {}
  21. /* Set caching params via the BHC and DCC registers. */
  22. void v850e_cache_enable (u16 bhc, u16 icc, u16 dcc)
  23. {
  24. unsigned long *r0_ram = (unsigned long *)R0_RAM_ADDR;
  25. register u16 bhc_val asm ("r6") = bhc;
  26. /* Read the instruction cache control register (ICC) and confirm
  27. that bits 0 and 1 (TCLR0, TCLR1) are all cleared. */
  28. WAIT_UNTIL_CLEAR (V850E_CACHE_ICC & 0x3);
  29. V850E_CACHE_ICC = icc;
  30. #ifdef V850E_CACHE_DCC
  31. /* Configure data-cache. */
  32. V850E_CACHE_DCC = dcc;
  33. #endif /* V850E_CACHE_DCC */
  34. /* Configure caching for various memory regions by writing the BHC
  35. register. The documentation says that an instruction _cannot_
  36. enable/disable caching for the memory region in which the
  37. instruction itself exists; to work around this, we store
  38. appropriate instructions into the on-chip RAM area (which is never
  39. cached), and briefly jump there to do the work. */
  40. #ifdef V850E_CACHE_WRITE_IBS
  41. *r0_ram++ = 0xf0720760; /* st.h r0, 0xfffff072[r0] */
  42. #endif
  43. *r0_ram++ = 0xf06a3760; /* st.h r6, 0xfffff06a[r0] */
  44. *r0_ram = 0x5640006b; /* jmp [r11] */
  45. asm ("mov hilo(1f), r11; jmp [%1]; 1:;"
  46. :: "r" (bhc_val), "r" (R0_RAM_ADDR) : "r11");
  47. }
  48. static void clear_icache (void)
  49. {
  50. /* 1. Read the instruction cache control register (ICC) and confirm
  51. that bits 0 and 1 (TCLR0, TCLR1) are all cleared. */
  52. WAIT_UNTIL_CLEAR (V850E_CACHE_ICC & 0x3);
  53. /* 2. Read the ICC register and confirm that bit 12 (LOCK0) is
  54. cleared. Bit 13 of the ICC register is always cleared. */
  55. WAIT_UNTIL_CLEAR (V850E_CACHE_ICC & 0x1000);
  56. /* 3. Set the TCLR0 and TCLR1 bits of the ICC register as follows,
  57. when clearing way 0 and way 1 at the same time:
  58. (a) Set the TCLR0 and TCLR1 bits.
  59. (b) Read the TCLR0 and TCLR1 bits to confirm that these bits
  60. are cleared.
  61. (c) Perform (a) and (b) above again. */
  62. V850E_CACHE_ICC |= 0x3;
  63. WAIT_UNTIL_CLEAR (V850E_CACHE_ICC & 0x3);
  64. #ifdef V850E_CACHE_REPEAT_ICC_WRITE
  65. /* Do it again. */
  66. V850E_CACHE_ICC |= 0x3;
  67. WAIT_UNTIL_CLEAR (V850E_CACHE_ICC & 0x3);
  68. #endif
  69. }
  70. #ifdef V850E_CACHE_DCC
  71. /* Flush or clear (or both) the data cache, depending on the value of FLAGS;
  72. the procedure is the same for both, just the control bits used differ (and
  73. both may be performed simultaneously). */
  74. static void dcache_op (unsigned short flags)
  75. {
  76. /* 1. Read the data cache control register (DCC) and confirm that bits
  77. 0, 1, 4, and 5 (DC00, DC01, DC04, DC05) are all cleared. */
  78. WAIT_UNTIL_CLEAR (V850E_CACHE_DCC & 0x33);
  79. /* 2. Clear DCC register bit 12 (DC12), bit 13 (DC13), or both
  80. depending on the way for which tags are to be cleared. */
  81. V850E_CACHE_DCC &= ~0xC000;
  82. /* 3. Set DCC register bit 0 (DC00), bit 1 (DC01) or both depending on
  83. the way for which tags are to be cleared.
  84. ...
  85. Set DCC register bit 4 (DC04), bit 5 (DC05), or both depending
  86. on the way to be data flushed. */
  87. V850E_CACHE_DCC |= flags;
  88. /* 4. Read DCC register bit DC00, DC01 [DC04, DC05], or both depending
  89. on the way for which tags were cleared [flushed] and confirm
  90. that that bit is cleared. */
  91. WAIT_UNTIL_CLEAR (V850E_CACHE_DCC & flags);
  92. }
  93. #endif /* V850E_CACHE_DCC */
  94. /* Flushes the contents of the dcache to memory. */
  95. static inline void flush_dcache (void)
  96. {
  97. #ifdef V850E_CACHE_DCC
  98. /* We only need to do something if in write-back mode. */
  99. if (V850E_CACHE_DCC & 0x0400)
  100. dcache_op (0x30);
  101. #endif /* V850E_CACHE_DCC */
  102. }
  103. /* Flushes the contents of the dcache to memory, and then clears it. */
  104. static inline void clear_dcache (void)
  105. {
  106. #ifdef V850E_CACHE_DCC
  107. /* We only need to do something if the dcache is enabled. */
  108. if (V850E_CACHE_DCC & 0x0C00)
  109. dcache_op (0x33);
  110. #endif /* V850E_CACHE_DCC */
  111. }
  112. /* Clears the dcache without flushing to memory first. */
  113. static inline void clear_dcache_no_flush (void)
  114. {
  115. #ifdef V850E_CACHE_DCC
  116. /* We only need to do something if the dcache is enabled. */
  117. if (V850E_CACHE_DCC & 0x0C00)
  118. dcache_op (0x3);
  119. #endif /* V850E_CACHE_DCC */
  120. }
  121. static inline void cache_exec_after_store (void)
  122. {
  123. flush_dcache ();
  124. clear_icache ();
  125. }
  126. /* Exported functions. */
  127. void flush_icache (void)
  128. {
  129. cache_exec_after_store ();
  130. }
  131. void flush_icache_range (unsigned long start, unsigned long end)
  132. {
  133. cache_exec_after_store ();
  134. }
  135. void flush_icache_page (struct vm_area_struct *vma, struct page *page)
  136. {
  137. cache_exec_after_store ();
  138. }
  139. void flush_icache_user_range (struct vm_area_struct *vma, struct page *page,
  140. unsigned long adr, int len)
  141. {
  142. cache_exec_after_store ();
  143. }
  144. void flush_cache_sigtramp (unsigned long addr)
  145. {
  146. cache_exec_after_store ();
  147. }