sc-rm7k.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * sc-rm7k.c: RM7000 cache management functions.
  3. *
  4. * Copyright (C) 1997, 2001, 2003, 2004 Ralf Baechle (ralf@linux-mips.org)
  5. */
  6. #undef DEBUG
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mm.h>
  10. #include <asm/addrspace.h>
  11. #include <asm/bcache.h>
  12. #include <asm/cacheops.h>
  13. #include <asm/mipsregs.h>
  14. #include <asm/processor.h>
  15. #include <asm/cacheflush.h> /* for run_uncached() */
  16. /* Primary cache parameters. */
  17. #define sc_lsize 32
  18. #define tc_pagesize (32*128)
  19. /* Secondary cache parameters. */
  20. #define scache_size (256*1024) /* Fixed to 256KiB on RM7000 */
  21. extern unsigned long icache_way_size, dcache_way_size;
  22. #include <asm/r4kcache.h>
  23. int rm7k_tcache_enabled;
  24. /*
  25. * Writeback and invalidate the primary cache dcache before DMA.
  26. * (XXX These need to be fixed ...)
  27. */
  28. static void rm7k_sc_wback_inv(unsigned long addr, unsigned long size)
  29. {
  30. unsigned long end, a;
  31. pr_debug("rm7k_sc_wback_inv[%08lx,%08lx]", addr, size);
  32. /* Catch bad driver code */
  33. BUG_ON(size == 0);
  34. a = addr & ~(sc_lsize - 1);
  35. end = (addr + size - 1) & ~(sc_lsize - 1);
  36. while (1) {
  37. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  38. if (a == end)
  39. break;
  40. a += sc_lsize;
  41. }
  42. if (!rm7k_tcache_enabled)
  43. return;
  44. a = addr & ~(tc_pagesize - 1);
  45. end = (addr + size - 1) & ~(tc_pagesize - 1);
  46. while(1) {
  47. invalidate_tcache_page(a); /* Page_Invalidate_T */
  48. if (a == end)
  49. break;
  50. a += tc_pagesize;
  51. }
  52. }
  53. static void rm7k_sc_inv(unsigned long addr, unsigned long size)
  54. {
  55. unsigned long end, a;
  56. pr_debug("rm7k_sc_inv[%08lx,%08lx]", addr, size);
  57. /* Catch bad driver code */
  58. BUG_ON(size == 0);
  59. a = addr & ~(sc_lsize - 1);
  60. end = (addr + size - 1) & ~(sc_lsize - 1);
  61. while (1) {
  62. invalidate_scache_line(a); /* Hit_Invalidate_SD */
  63. if (a == end)
  64. break;
  65. a += sc_lsize;
  66. }
  67. if (!rm7k_tcache_enabled)
  68. return;
  69. a = addr & ~(tc_pagesize - 1);
  70. end = (addr + size - 1) & ~(tc_pagesize - 1);
  71. while(1) {
  72. invalidate_tcache_page(a); /* Page_Invalidate_T */
  73. if (a == end)
  74. break;
  75. a += tc_pagesize;
  76. }
  77. }
  78. /*
  79. * This function is executed in uncached address space.
  80. */
  81. static __init void __rm7k_sc_enable(void)
  82. {
  83. int i;
  84. set_c0_config(RM7K_CONF_SE);
  85. write_c0_taglo(0);
  86. write_c0_taghi(0);
  87. for (i = 0; i < scache_size; i += sc_lsize) {
  88. __asm__ __volatile__ (
  89. ".set noreorder\n\t"
  90. ".set mips3\n\t"
  91. "cache %1, (%0)\n\t"
  92. ".set mips0\n\t"
  93. ".set reorder"
  94. :
  95. : "r" (CKSEG0ADDR(i)), "i" (Index_Store_Tag_SD));
  96. }
  97. }
  98. static __init void rm7k_sc_enable(void)
  99. {
  100. if (read_c0_config() & RM7K_CONF_SE)
  101. return;
  102. printk(KERN_INFO "Enabling secondary cache...\n");
  103. run_uncached(__rm7k_sc_enable);
  104. }
  105. static void rm7k_sc_disable(void)
  106. {
  107. clear_c0_config(RM7K_CONF_SE);
  108. }
  109. struct bcache_ops rm7k_sc_ops = {
  110. .bc_enable = rm7k_sc_enable,
  111. .bc_disable = rm7k_sc_disable,
  112. .bc_wback_inv = rm7k_sc_wback_inv,
  113. .bc_inv = rm7k_sc_inv
  114. };
  115. void __init rm7k_sc_init(void)
  116. {
  117. unsigned int config = read_c0_config();
  118. if ((config & RM7K_CONF_SC))
  119. return;
  120. printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n",
  121. (scache_size >> 10), sc_lsize);
  122. if (!(config & RM7K_CONF_SE))
  123. rm7k_sc_enable();
  124. /*
  125. * While we're at it let's deal with the tertiary cache.
  126. */
  127. if (!(config & RM7K_CONF_TC)) {
  128. /*
  129. * We can't enable the L3 cache yet. There may be board-specific
  130. * magic necessary to turn it on, and blindly asking the CPU to
  131. * start using it would may give cache errors.
  132. *
  133. * Also, board-specific knowledge may allow us to use the
  134. * CACHE Flash_Invalidate_T instruction if the tag RAM supports
  135. * it, and may specify the size of the L3 cache so we don't have
  136. * to probe it.
  137. */
  138. printk(KERN_INFO "Tertiary cache present, %s enabled\n",
  139. (config & RM7K_CONF_TE) ? "already" : "not (yet)");
  140. if ((config & RM7K_CONF_TE))
  141. rm7k_tcache_enabled = 1;
  142. }
  143. bcops = &rm7k_sc_ops;
  144. }