cache-sh3.c 2.5 KB

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