sc-rm7k.c 3.9 KB

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