sc-mips.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/system.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. unsigned long sc_lsize = cpu_scache_line_size();
  25. unsigned long end, a;
  26. pr_debug("mips_sc_wback_inv[%08lx,%08lx]", addr, size);
  27. /* Catch bad driver code */
  28. BUG_ON(size == 0);
  29. a = addr & ~(sc_lsize - 1);
  30. end = (addr + size - 1) & ~(sc_lsize - 1);
  31. while (1) {
  32. flush_scache_line(a); /* Hit_Writeback_Inv_SD */
  33. if (a == end)
  34. break;
  35. a += sc_lsize;
  36. }
  37. }
  38. /*
  39. * Invalidate the secondary cache before DMA.
  40. */
  41. static void mips_sc_inv(unsigned long addr, unsigned long size)
  42. {
  43. unsigned long sc_lsize = cpu_scache_line_size();
  44. unsigned long end, a;
  45. pr_debug("mips_sc_inv[%08lx,%08lx]", addr, size);
  46. /* Catch bad driver code */
  47. BUG_ON(size == 0);
  48. a = addr & ~(sc_lsize - 1);
  49. end = (addr + size - 1) & ~(sc_lsize - 1);
  50. while (1) {
  51. invalidate_scache_line(a); /* Hit_Invalidate_SD */
  52. if (a == end)
  53. break;
  54. a += sc_lsize;
  55. }
  56. }
  57. static void mips_sc_enable(void)
  58. {
  59. /* L2 cache is permanently enabled */
  60. }
  61. static void mips_sc_disable(void)
  62. {
  63. /* L2 cache is permanently enabled */
  64. }
  65. static struct bcache_ops mips_sc_ops = {
  66. .bc_enable = mips_sc_enable,
  67. .bc_disable = mips_sc_disable,
  68. .bc_wback_inv = mips_sc_wback_inv,
  69. .bc_inv = mips_sc_inv
  70. };
  71. static inline int __init mips_sc_probe(void)
  72. {
  73. struct cpuinfo_mips *c = &current_cpu_data;
  74. unsigned int config1, config2;
  75. unsigned int tmp;
  76. /* Mark as not present until probe completed */
  77. c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
  78. /* Ignore anything but MIPSxx processors */
  79. if (c->isa_level != MIPS_CPU_ISA_M32R1 &&
  80. c->isa_level != MIPS_CPU_ISA_M32R2 &&
  81. c->isa_level != MIPS_CPU_ISA_M64R1 &&
  82. c->isa_level != MIPS_CPU_ISA_M64R2)
  83. return 0;
  84. /* Does this MIPS32/MIPS64 CPU have a config2 register? */
  85. config1 = read_c0_config1();
  86. if (!(config1 & MIPS_CONF_M))
  87. return 0;
  88. config2 = read_c0_config2();
  89. tmp = (config2 >> 4) & 0x0f;
  90. if (0 < tmp && tmp <= 7)
  91. c->scache.linesz = 2 << tmp;
  92. else
  93. return 0;
  94. tmp = (config2 >> 8) & 0x0f;
  95. if (0 <= tmp && tmp <= 7)
  96. c->scache.sets = 64 << tmp;
  97. else
  98. return 0;
  99. tmp = (config2 >> 0) & 0x0f;
  100. if (0 <= tmp && tmp <= 7)
  101. c->scache.ways = tmp + 1;
  102. else
  103. return 0;
  104. c->scache.waysize = c->scache.sets * c->scache.linesz;
  105. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  106. return 1;
  107. }
  108. int __init mips_sc_init(void)
  109. {
  110. int found = mips_sc_probe ();
  111. if (found) {
  112. mips_sc_enable();
  113. bcops = &mips_sc_ops;
  114. }
  115. return found;
  116. }