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 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/processor.h> 16 #include <asm/cache.h> 17 #include <asm/io.h> 18 #include <linux/uaccess.h> 19 #include <asm/pgalloc.h> 20 #include <asm/mmu_context.h> 21 #include <asm/cacheflush.h> 22 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 33 static void sh3__flush_wback_region(void *start, int size) 34 { 35 unsigned long v, j; 36 unsigned long begin, end; 37 unsigned long flags; 38 39 begin = (unsigned long)start & ~(L1_CACHE_BYTES-1); 40 end = ((unsigned long)start + size + L1_CACHE_BYTES-1) 41 & ~(L1_CACHE_BYTES-1); 42 43 for (v = begin; v < end; v+=L1_CACHE_BYTES) { 44 unsigned long addrstart = CACHE_OC_ADDRESS_ARRAY; 45 for (j = 0; j < current_cpu_data.dcache.ways; j++) { 46 unsigned long data, addr, p; 47 48 p = __pa(v); 49 addr = addrstart | (v & current_cpu_data.dcache.entry_mask); 50 local_irq_save(flags); 51 data = __raw_readl(addr); 52 53 if ((data & CACHE_PHYSADDR_MASK) == 54 (p & CACHE_PHYSADDR_MASK)) { 55 data &= ~SH_CACHE_UPDATED; 56 __raw_writel(data, addr); 57 local_irq_restore(flags); 58 break; 59 } 60 local_irq_restore(flags); 61 addrstart += current_cpu_data.dcache.way_incr; 62 } 63 } 64 } 65 66 /* 67 * Write back the dirty D-caches and invalidate them. 68 * 69 * START: Virtual Address (U0, P1, or P3) 70 * SIZE: Size of the region. 71 */ 72 static void sh3__flush_purge_region(void *start, int size) 73 { 74 unsigned long v; 75 unsigned long begin, end; 76 77 begin = (unsigned long)start & ~(L1_CACHE_BYTES-1); 78 end = ((unsigned long)start + size + L1_CACHE_BYTES-1) 79 & ~(L1_CACHE_BYTES-1); 80 81 for (v = begin; v < end; v+=L1_CACHE_BYTES) { 82 unsigned long data, addr; 83 84 data = (v & 0xfffffc00); /* _Virtual_ address, ~U, ~V */ 85 addr = CACHE_OC_ADDRESS_ARRAY | 86 (v & current_cpu_data.dcache.entry_mask) | SH_CACHE_ASSOC; 87 __raw_writel(data, addr); 88 } 89 } 90 91 void __init sh3_cache_init(void) 92 { 93 __flush_wback_region = sh3__flush_wback_region; 94 __flush_purge_region = sh3__flush_purge_region; 95 96 /* 97 * No write back please 98 * 99 * Except I don't think there's any way to avoid the writeback. 100 * So we just alias it to sh3__flush_purge_region(). dwmw2. 101 */ 102 __flush_invalidate_region = sh3__flush_purge_region; 103 } 104