cache-sh3.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * arch/sh/mm/cache-sh3.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2002 Paul Mundt
  6. *
  7. * Released under the terms of the GNU GPL v2.0.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/mman.h>
  11. #include <linux/mm.h>
  12. #include <linux/threads.h>
  13. #include <asm/addrspace.h>
  14. #include <asm/page.h>
  15. #include <asm/pgtable.h>
  16. #include <asm/processor.h>
  17. #include <asm/cache.h>
  18. #include <asm/io.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/pgalloc.h>
  21. #include <asm/mmu_context.h>
  22. #include <asm/cacheflush.h>
  23. /*
  24. * Write back the dirty D-caches, but not invalidate them.
  25. *
  26. * Is this really worth it, or should we just alias this routine
  27. * to __flush_purge_region too?
  28. *
  29. * START: Virtual Address (U0, P1, or P3)
  30. * SIZE: Size of the region.
  31. */
  32. static void sh3__flush_wback_region(void *start, int size)
  33. {
  34. unsigned long v, j;
  35. unsigned long begin, end;
  36. unsigned long flags;
  37. begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
  38. end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
  39. & ~(L1_CACHE_BYTES-1);
  40. for (v = begin; v < end; v+=L1_CACHE_BYTES) {
  41. unsigned long addrstart = CACHE_OC_ADDRESS_ARRAY;
  42. for (j = 0; j < current_cpu_data.dcache.ways; j++) {
  43. unsigned long data, addr, p;
  44. p = __pa(v);
  45. addr = addrstart | (v & current_cpu_data.dcache.entry_mask);
  46. local_irq_save(flags);
  47. data = __raw_readl(addr);
  48. if ((data & CACHE_PHYSADDR_MASK) ==
  49. (p & CACHE_PHYSADDR_MASK)) {
  50. data &= ~SH_CACHE_UPDATED;
  51. __raw_writel(data, addr);
  52. local_irq_restore(flags);
  53. break;
  54. }
  55. local_irq_restore(flags);
  56. addrstart += current_cpu_data.dcache.way_incr;
  57. }
  58. }
  59. }
  60. /*
  61. * Write back the dirty D-caches and invalidate them.
  62. *
  63. * START: Virtual Address (U0, P1, or P3)
  64. * SIZE: Size of the region.
  65. */
  66. static void sh3__flush_purge_region(void *start, int size)
  67. {
  68. unsigned long v;
  69. unsigned long begin, end;
  70. begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
  71. end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
  72. & ~(L1_CACHE_BYTES-1);
  73. for (v = begin; v < end; v+=L1_CACHE_BYTES) {
  74. unsigned long data, addr;
  75. data = (v & 0xfffffc00); /* _Virtual_ address, ~U, ~V */
  76. addr = CACHE_OC_ADDRESS_ARRAY |
  77. (v & current_cpu_data.dcache.entry_mask) | SH_CACHE_ASSOC;
  78. __raw_writel(data, addr);
  79. }
  80. }
  81. void __init sh3_cache_init(void)
  82. {
  83. __flush_wback_region = sh3__flush_wback_region;
  84. __flush_purge_region = sh3__flush_purge_region;
  85. /*
  86. * No write back please
  87. *
  88. * Except I don't think there's any way to avoid the writeback.
  89. * So we just alias it to sh3__flush_purge_region(). dwmw2.
  90. */
  91. __flush_invalidate_region = sh3__flush_purge_region;
  92. }