sc-mips.c 3.3 KB

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