sc-mips.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2006 Chris Dearman (chris@mips.com),
  3. */
  4. #include <linux/init.h>
  5. #include <linux/kernel.h>
  6. #include <linux/sched.h>
  7. #include <linux/mm.h>
  8. #include <asm/cpu-type.h>
  9. #include <asm/mipsregs.h>
  10. #include <asm/bcache.h>
  11. #include <asm/cacheops.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/mmu_context.h>
  15. #include <asm/r4kcache.h>
  16. #include <asm/mips-cm.h>
  17. /*
  18. * MIPS32/MIPS64 L2 cache handling
  19. */
  20. /*
  21. * Writeback and invalidate the secondary cache before DMA.
  22. */
  23. static void mips_sc_wback_inv(unsigned long addr, unsigned long size)
  24. {
  25. blast_scache_range(addr, addr + size);
  26. }
  27. /*
  28. * Invalidate the secondary cache before DMA.
  29. */
  30. static void mips_sc_inv(unsigned long addr, unsigned long size)
  31. {
  32. unsigned long lsize = cpu_scache_line_size();
  33. unsigned long almask = ~(lsize - 1);
  34. cache_op(Hit_Writeback_Inv_SD, addr & almask);
  35. cache_op(Hit_Writeback_Inv_SD, (addr + size - 1) & almask);
  36. blast_inv_scache_range(addr, addr + size);
  37. }
  38. static void mips_sc_enable(void)
  39. {
  40. /* L2 cache is permanently enabled */
  41. }
  42. static void mips_sc_disable(void)
  43. {
  44. /* L2 cache is permanently enabled */
  45. }
  46. static struct bcache_ops mips_sc_ops = {
  47. .bc_enable = mips_sc_enable,
  48. .bc_disable = mips_sc_disable,
  49. .bc_wback_inv = mips_sc_wback_inv,
  50. .bc_inv = mips_sc_inv
  51. };
  52. /*
  53. * Check if the L2 cache controller is activated on a particular platform.
  54. * MTI's L2 controller and the L2 cache controller of Broadcom's BMIPS
  55. * cores both use c0_config2's bit 12 as "L2 Bypass" bit, that is the
  56. * cache being disabled. However there is no guarantee for this to be
  57. * true on all platforms. In an act of stupidity the spec defined bits
  58. * 12..15 as implementation defined so below function will eventually have
  59. * to be replaced by a platform specific probe.
  60. */
  61. static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
  62. {
  63. unsigned int config2 = read_c0_config2();
  64. unsigned int tmp;
  65. /* Check the bypass bit (L2B) */
  66. switch (current_cpu_type()) {
  67. case CPU_34K:
  68. case CPU_74K:
  69. case CPU_1004K:
  70. case CPU_1074K:
  71. case CPU_INTERAPTIV:
  72. case CPU_PROAPTIV:
  73. case CPU_P5600:
  74. case CPU_BMIPS5000:
  75. case CPU_QEMU_GENERIC:
  76. if (config2 & (1 << 12))
  77. return 0;
  78. }
  79. tmp = (config2 >> 4) & 0x0f;
  80. if (0 < tmp && tmp <= 7)
  81. c->scache.linesz = 2 << tmp;
  82. else
  83. return 0;
  84. return 1;
  85. }
  86. static int __init mips_sc_probe_cm3(void)
  87. {
  88. struct cpuinfo_mips *c = &current_cpu_data;
  89. unsigned long cfg = read_gcr_l2_config();
  90. unsigned long sets, line_sz, assoc;
  91. if (cfg & CM_GCR_L2_CONFIG_BYPASS_MSK)
  92. return 0;
  93. sets = cfg & CM_GCR_L2_CONFIG_SET_SIZE_MSK;
  94. sets >>= CM_GCR_L2_CONFIG_SET_SIZE_SHF;
  95. c->scache.sets = 64 << sets;
  96. line_sz = cfg & CM_GCR_L2_CONFIG_LINE_SIZE_MSK;
  97. line_sz >>= CM_GCR_L2_CONFIG_LINE_SIZE_SHF;
  98. c->scache.linesz = 2 << line_sz;
  99. assoc = cfg & CM_GCR_L2_CONFIG_ASSOC_MSK;
  100. assoc >>= CM_GCR_L2_CONFIG_ASSOC_SHF;
  101. c->scache.ways = assoc + 1;
  102. c->scache.waysize = c->scache.sets * c->scache.linesz;
  103. c->scache.waybit = __ffs(c->scache.waysize);
  104. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  105. return 1;
  106. }
  107. void __weak platform_early_l2_init(void)
  108. {
  109. }
  110. static inline int __init mips_sc_probe(void)
  111. {
  112. struct cpuinfo_mips *c = &current_cpu_data;
  113. unsigned int config1, config2;
  114. unsigned int tmp;
  115. /* Mark as not present until probe completed */
  116. c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
  117. /*
  118. * Do we need some platform specific probing before
  119. * we configure L2?
  120. */
  121. platform_early_l2_init();
  122. if (mips_cm_revision() >= CM_REV_CM3)
  123. return mips_sc_probe_cm3();
  124. /* Ignore anything but MIPSxx processors */
  125. if (!(c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M32R2 |
  126. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R1 |
  127. MIPS_CPU_ISA_M64R2 | MIPS_CPU_ISA_M64R6)))
  128. return 0;
  129. /* Does this MIPS32/MIPS64 CPU have a config2 register? */
  130. config1 = read_c0_config1();
  131. if (!(config1 & MIPS_CONF_M))
  132. return 0;
  133. config2 = read_c0_config2();
  134. if (!mips_sc_is_activated(c))
  135. return 0;
  136. tmp = (config2 >> 8) & 0x0f;
  137. if (0 <= tmp && tmp <= 7)
  138. c->scache.sets = 64 << tmp;
  139. else
  140. return 0;
  141. tmp = (config2 >> 0) & 0x0f;
  142. if (0 <= tmp && tmp <= 7)
  143. c->scache.ways = tmp + 1;
  144. else
  145. return 0;
  146. c->scache.waysize = c->scache.sets * c->scache.linesz;
  147. c->scache.waybit = __ffs(c->scache.waysize);
  148. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  149. return 1;
  150. }
  151. int mips_sc_init(void)
  152. {
  153. int found = mips_sc_probe();
  154. if (found) {
  155. mips_sc_enable();
  156. bcops = &mips_sc_ops;
  157. }
  158. return found;
  159. }