sc-mips.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. blast_inv_scache_range(addr, addr + size);
  32. }
  33. static void mips_sc_enable(void)
  34. {
  35. /* L2 cache is permanently enabled */
  36. }
  37. static void mips_sc_disable(void)
  38. {
  39. /* L2 cache is permanently enabled */
  40. }
  41. static struct bcache_ops mips_sc_ops = {
  42. .bc_enable = mips_sc_enable,
  43. .bc_disable = mips_sc_disable,
  44. .bc_wback_inv = mips_sc_wback_inv,
  45. .bc_inv = mips_sc_inv
  46. };
  47. static inline int __init mips_sc_probe(void)
  48. {
  49. struct cpuinfo_mips *c = &current_cpu_data;
  50. unsigned int config1, config2;
  51. unsigned int tmp;
  52. /* Mark as not present until probe completed */
  53. c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
  54. /* Ignore anything but MIPSxx processors */
  55. if (c->isa_level != MIPS_CPU_ISA_M32R1 &&
  56. c->isa_level != MIPS_CPU_ISA_M32R2 &&
  57. c->isa_level != MIPS_CPU_ISA_M64R1 &&
  58. c->isa_level != MIPS_CPU_ISA_M64R2)
  59. return 0;
  60. /* Does this MIPS32/MIPS64 CPU have a config2 register? */
  61. config1 = read_c0_config1();
  62. if (!(config1 & MIPS_CONF_M))
  63. return 0;
  64. config2 = read_c0_config2();
  65. tmp = (config2 >> 4) & 0x0f;
  66. if (0 < tmp && tmp <= 7)
  67. c->scache.linesz = 2 << tmp;
  68. else
  69. return 0;
  70. tmp = (config2 >> 8) & 0x0f;
  71. if (0 <= tmp && tmp <= 7)
  72. c->scache.sets = 64 << tmp;
  73. else
  74. return 0;
  75. tmp = (config2 >> 0) & 0x0f;
  76. if (0 <= tmp && tmp <= 7)
  77. c->scache.ways = tmp + 1;
  78. else
  79. return 0;
  80. c->scache.waysize = c->scache.sets * c->scache.linesz;
  81. c->scache.waybit = __ffs(c->scache.waysize);
  82. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  83. return 1;
  84. }
  85. int __cpuinit mips_sc_init(void)
  86. {
  87. int found = mips_sc_probe();
  88. if (found) {
  89. mips_sc_enable();
  90. bcops = &mips_sc_ops;
  91. }
  92. return found;
  93. }