sc-mips.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. 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. static inline int __init mips_sc_probe(void)
  52. {
  53. struct cpuinfo_mips *c = &current_cpu_data;
  54. unsigned int config1, config2;
  55. unsigned int tmp;
  56. /* Mark as not present until probe completed */
  57. c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
  58. /* Ignore anything but MIPSxx processors */
  59. if (c->isa_level != MIPS_CPU_ISA_M32R1 &&
  60. c->isa_level != MIPS_CPU_ISA_M32R2 &&
  61. c->isa_level != MIPS_CPU_ISA_M64R1 &&
  62. c->isa_level != MIPS_CPU_ISA_M64R2)
  63. return 0;
  64. /* Does this MIPS32/MIPS64 CPU have a config2 register? */
  65. config1 = read_c0_config1();
  66. if (!(config1 & MIPS_CONF_M))
  67. return 0;
  68. config2 = read_c0_config2();
  69. tmp = (config2 >> 4) & 0x0f;
  70. if (0 < tmp && tmp <= 7)
  71. c->scache.linesz = 2 << tmp;
  72. else
  73. return 0;
  74. tmp = (config2 >> 8) & 0x0f;
  75. if (0 <= tmp && tmp <= 7)
  76. c->scache.sets = 64 << tmp;
  77. else
  78. return 0;
  79. tmp = (config2 >> 0) & 0x0f;
  80. if (0 <= tmp && tmp <= 7)
  81. c->scache.ways = tmp + 1;
  82. else
  83. return 0;
  84. c->scache.waysize = c->scache.sets * c->scache.linesz;
  85. c->scache.waybit = __ffs(c->scache.waysize);
  86. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  87. return 1;
  88. }
  89. int __cpuinit mips_sc_init(void)
  90. {
  91. int found = mips_sc_probe();
  92. if (found) {
  93. mips_sc_enable();
  94. bcops = &mips_sc_ops;
  95. }
  96. return found;
  97. }