sc-rm7k.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. cache_op(Index_Store_Tag_SD, CKSEG0ADDR(i));
  76. }
  77. static __cpuinit void rm7k_sc_enable(void)
  78. {
  79. if (read_c0_config() & RM7K_CONF_SE)
  80. return;
  81. printk(KERN_INFO "Enabling secondary cache...\n");
  82. run_uncached(__rm7k_sc_enable);
  83. }
  84. static void rm7k_sc_disable(void)
  85. {
  86. clear_c0_config(RM7K_CONF_SE);
  87. }
  88. static struct bcache_ops rm7k_sc_ops = {
  89. .bc_enable = rm7k_sc_enable,
  90. .bc_disable = rm7k_sc_disable,
  91. .bc_wback_inv = rm7k_sc_wback_inv,
  92. .bc_inv = rm7k_sc_inv
  93. };
  94. void __cpuinit rm7k_sc_init(void)
  95. {
  96. struct cpuinfo_mips *c = &current_cpu_data;
  97. unsigned int config = read_c0_config();
  98. if ((config & RM7K_CONF_SC))
  99. return;
  100. c->scache.linesz = sc_lsize;
  101. c->scache.ways = 4;
  102. c->scache.waybit= __ffs(scache_size / c->scache.ways);
  103. c->scache.waysize = scache_size / c->scache.ways;
  104. c->scache.sets = scache_size / (c->scache.linesz * c->scache.ways);
  105. printk(KERN_INFO "Secondary cache size %dK, linesize %d bytes.\n",
  106. (scache_size >> 10), sc_lsize);
  107. if (!(config & RM7K_CONF_SE))
  108. rm7k_sc_enable();
  109. /*
  110. * While we're at it let's deal with the tertiary cache.
  111. */
  112. if (!(config & RM7K_CONF_TC)) {
  113. /*
  114. * We can't enable the L3 cache yet. There may be board-specific
  115. * magic necessary to turn it on, and blindly asking the CPU to
  116. * start using it would may give cache errors.
  117. *
  118. * Also, board-specific knowledge may allow us to use the
  119. * CACHE Flash_Invalidate_T instruction if the tag RAM supports
  120. * it, and may specify the size of the L3 cache so we don't have
  121. * to probe it.
  122. */
  123. printk(KERN_INFO "Tertiary cache present, %s enabled\n",
  124. (config & RM7K_CONF_TE) ? "already" : "not (yet)");
  125. if ((config & RM7K_CONF_TE))
  126. rm7k_tcache_enabled = 1;
  127. }
  128. bcops = &rm7k_sc_ops;
  129. }