v850e2_cache.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * arch/v850/kernel/v850e2_cache.c -- Cache control for V850E2 cache
  3. * memories
  4. *
  5. * Copyright (C) 2003 NEC Electronics Corporation
  6. * Copyright (C) 2003 Miles Bader <miles@gnu.org>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General
  9. * Public License. See the file COPYING in the main directory of this
  10. * archive for more details.
  11. *
  12. * Written by Miles Bader <miles@gnu.org>
  13. */
  14. #include <linux/mm.h>
  15. #include <asm/v850e2_cache.h>
  16. /* Cache operations we can do. The encoding corresponds directly to the
  17. value we need to write into the COPR register. */
  18. enum cache_op {
  19. OP_SYNC_IF_DIRTY = V850E2_CACHE_COPR_CFC(0), /* 000 */
  20. OP_SYNC_IF_VALID = V850E2_CACHE_COPR_CFC(1), /* 001 */
  21. OP_SYNC_IF_VALID_AND_CLEAR = V850E2_CACHE_COPR_CFC(3), /* 011 */
  22. OP_WAY_CLEAR = V850E2_CACHE_COPR_CFC(4), /* 100 */
  23. OP_FILL = V850E2_CACHE_COPR_CFC(5), /* 101 */
  24. OP_CLEAR = V850E2_CACHE_COPR_CFC(6), /* 110 */
  25. OP_CREATE_DIRTY = V850E2_CACHE_COPR_CFC(7) /* 111 */
  26. };
  27. /* Which cache to use. This encoding also corresponds directly to the
  28. value we need to write into the COPR register. */
  29. enum cache {
  30. ICACHE = 0,
  31. DCACHE = V850E2_CACHE_COPR_LBSL
  32. };
  33. /* Returns ADDR rounded down to the beginning of its cache-line. */
  34. #define CACHE_LINE_ADDR(addr) \
  35. ((addr) & ~(V850E2_CACHE_LINE_SIZE - 1))
  36. /* Returns END_ADDR rounded up to the `limit' of its cache-line. */
  37. #define CACHE_LINE_END_ADDR(end_addr) \
  38. CACHE_LINE_ADDR(end_addr + (V850E2_CACHE_LINE_SIZE - 1))
  39. /* Low-level cache ops. */
  40. /* Apply cache-op OP to all entries in CACHE. */
  41. static inline void cache_op_all (enum cache_op op, enum cache cache)
  42. {
  43. int cmd = op | cache | V850E2_CACHE_COPR_WSLE | V850E2_CACHE_COPR_STRT;
  44. if (op != OP_WAY_CLEAR) {
  45. /* The WAY_CLEAR operation does the whole way, but other
  46. ops take begin-index and count params; we just indicate
  47. the entire cache. */
  48. V850E2_CACHE_CADL = 0;
  49. V850E2_CACHE_CADH = 0;
  50. V850E2_CACHE_CCNT = V850E2_CACHE_WAY_SIZE - 1;
  51. }
  52. V850E2_CACHE_COPR = cmd | V850E2_CACHE_COPR_WSL(0); /* way 0 */
  53. V850E2_CACHE_COPR = cmd | V850E2_CACHE_COPR_WSL(1); /* way 1 */
  54. V850E2_CACHE_COPR = cmd | V850E2_CACHE_COPR_WSL(2); /* way 2 */
  55. V850E2_CACHE_COPR = cmd | V850E2_CACHE_COPR_WSL(3); /* way 3 */
  56. }
  57. /* Apply cache-op OP to all entries in CACHE covering addresses ADDR
  58. through ADDR+LEN. */
  59. static inline void cache_op_range (enum cache_op op, u32 addr, u32 len,
  60. enum cache cache)
  61. {
  62. u32 start = CACHE_LINE_ADDR (addr);
  63. u32 end = CACHE_LINE_END_ADDR (addr + len);
  64. u32 num_lines = (end - start) >> V850E2_CACHE_LINE_SIZE_BITS;
  65. V850E2_CACHE_CADL = start & 0xFFFF;
  66. V850E2_CACHE_CADH = start >> 16;
  67. V850E2_CACHE_CCNT = num_lines - 1;
  68. V850E2_CACHE_COPR = op | cache | V850E2_CACHE_COPR_STRT;
  69. }
  70. /* High-level ops. */
  71. static void cache_exec_after_store_all (void)
  72. {
  73. cache_op_all (OP_SYNC_IF_DIRTY, DCACHE);
  74. cache_op_all (OP_WAY_CLEAR, ICACHE);
  75. }
  76. static void cache_exec_after_store_range (u32 start, u32 len)
  77. {
  78. cache_op_range (OP_SYNC_IF_DIRTY, start, len, DCACHE);
  79. cache_op_range (OP_CLEAR, start, len, ICACHE);
  80. }
  81. /* Exported functions. */
  82. void flush_icache (void)
  83. {
  84. cache_exec_after_store_all ();
  85. }
  86. void flush_icache_range (unsigned long start, unsigned long end)
  87. {
  88. cache_exec_after_store_range (start, end - start);
  89. }
  90. void flush_icache_page (struct vm_area_struct *vma, struct page *page)
  91. {
  92. cache_exec_after_store_range (page_to_virt (page), PAGE_SIZE);
  93. }
  94. void flush_icache_user_range (struct vm_area_struct *vma, struct page *page,
  95. unsigned long addr, int len)
  96. {
  97. cache_exec_after_store_range (addr, len);
  98. }
  99. void flush_cache_sigtramp (unsigned long addr)
  100. {
  101. /* For the exact size, see signal.c, but 16 bytes should be enough. */
  102. cache_exec_after_store_range (addr, 16);
  103. }