sc-mips.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /*
  17. * MIPS32/MIPS64 L2 cache handling
  18. */
  19. /*
  20. * Writeback and invalidate the secondary cache before DMA.
  21. */
  22. static void mips_sc_wback_inv(unsigned long addr, unsigned long size)
  23. {
  24. blast_scache_range(addr, addr + size);
  25. }
  26. /*
  27. * Invalidate the secondary cache before DMA.
  28. */
  29. static void mips_sc_inv(unsigned long addr, unsigned long size)
  30. {
  31. unsigned long lsize = cpu_scache_line_size();
  32. unsigned long almask = ~(lsize - 1);
  33. cache_op(Hit_Writeback_Inv_SD, addr & almask);
  34. cache_op(Hit_Writeback_Inv_SD, (addr + size - 1) & almask);
  35. blast_inv_scache_range(addr, addr + size);
  36. }
  37. static void mips_sc_enable(void)
  38. {
  39. /* L2 cache is permanently enabled */
  40. }
  41. static void mips_sc_disable(void)
  42. {
  43. /* L2 cache is permanently enabled */
  44. }
  45. static struct bcache_ops mips_sc_ops = {
  46. .bc_enable = mips_sc_enable,
  47. .bc_disable = mips_sc_disable,
  48. .bc_wback_inv = mips_sc_wback_inv,
  49. .bc_inv = mips_sc_inv
  50. };
  51. /*
  52. * Check if the L2 cache controller is activated on a particular platform.
  53. * MTI's L2 controller and the L2 cache controller of Broadcom's BMIPS
  54. * cores both use c0_config2's bit 12 as "L2 Bypass" bit, that is the
  55. * cache being disabled. However there is no guarantee for this to be
  56. * true on all platforms. In an act of stupidity the spec defined bits
  57. * 12..15 as implementation defined so below function will eventually have
  58. * to be replaced by a platform specific probe.
  59. */
  60. static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
  61. {
  62. unsigned int config2 = read_c0_config2();
  63. unsigned int tmp;
  64. /* Check the bypass bit (L2B) */
  65. switch (current_cpu_type()) {
  66. case CPU_34K:
  67. case CPU_74K:
  68. case CPU_1004K:
  69. case CPU_1074K:
  70. case CPU_INTERAPTIV:
  71. case CPU_PROAPTIV:
  72. case CPU_P5600:
  73. case CPU_BMIPS5000:
  74. case CPU_QEMU_GENERIC:
  75. if (config2 & (1 << 12))
  76. return 0;
  77. }
  78. tmp = (config2 >> 4) & 0x0f;
  79. if (0 < tmp && tmp <= 7)
  80. c->scache.linesz = 2 << tmp;
  81. else
  82. return 0;
  83. return 1;
  84. }
  85. static inline int __init mips_sc_probe(void)
  86. {
  87. struct cpuinfo_mips *c = &current_cpu_data;
  88. unsigned int config1, config2;
  89. unsigned int tmp;
  90. /* Mark as not present until probe completed */
  91. c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
  92. /* Ignore anything but MIPSxx processors */
  93. if (!(c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M32R2 |
  94. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R1 |
  95. MIPS_CPU_ISA_M64R2 | MIPS_CPU_ISA_M64R6)))
  96. return 0;
  97. /* Does this MIPS32/MIPS64 CPU have a config2 register? */
  98. config1 = read_c0_config1();
  99. if (!(config1 & MIPS_CONF_M))
  100. return 0;
  101. config2 = read_c0_config2();
  102. if (!mips_sc_is_activated(c))
  103. return 0;
  104. tmp = (config2 >> 8) & 0x0f;
  105. if (0 <= tmp && tmp <= 7)
  106. c->scache.sets = 64 << tmp;
  107. else
  108. return 0;
  109. tmp = (config2 >> 0) & 0x0f;
  110. if (0 <= tmp && tmp <= 7)
  111. c->scache.ways = tmp + 1;
  112. else
  113. return 0;
  114. c->scache.waysize = c->scache.sets * c->scache.linesz;
  115. c->scache.waybit = __ffs(c->scache.waysize);
  116. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  117. return 1;
  118. }
  119. int mips_sc_init(void)
  120. {
  121. int found = mips_sc_probe();
  122. if (found) {
  123. mips_sc_enable();
  124. bcops = &mips_sc_ops;
  125. }
  126. return found;
  127. }