| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * arch/sh/mm/cache-sh2.c | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2002 Paul Mundt | 
| Yoshinori Sato | cce2d45 | 2008-08-04 16:33:47 +0900 | [diff] [blame] | 5 | * Copyright (C) 2008 Yoshinori Sato | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * | 
|  | 7 | * Released under the terms of the GNU GPL v2.0. | 
|  | 8 | */ | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 9 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> | 
|  | 11 | #include <linux/mm.h> | 
|  | 12 |  | 
|  | 13 | #include <asm/cache.h> | 
|  | 14 | #include <asm/addrspace.h> | 
|  | 15 | #include <asm/processor.h> | 
|  | 16 | #include <asm/cacheflush.h> | 
|  | 17 | #include <asm/io.h> | 
|  | 18 |  | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 19 | void __flush_wback_region(void *start, int size) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 21 | unsigned long v; | 
|  | 22 | unsigned long begin, end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 24 | begin = (unsigned long)start & ~(L1_CACHE_BYTES-1); | 
|  | 25 | end = ((unsigned long)start + size + L1_CACHE_BYTES-1) | 
|  | 26 | & ~(L1_CACHE_BYTES-1); | 
|  | 27 | for (v = begin; v < end; v+=L1_CACHE_BYTES) { | 
| Yoshinori Sato | cce2d45 | 2008-08-04 16:33:47 +0900 | [diff] [blame] | 28 | unsigned long addr = CACHE_OC_ADDRESS_ARRAY | (v & 0x00000ff0); | 
|  | 29 | int way; | 
|  | 30 | for (way = 0; way < 4; way++) { | 
|  | 31 | unsigned long data =  ctrl_inl(addr | (way << 12)); | 
|  | 32 | if ((data & CACHE_PHYSADDR_MASK) == (v & CACHE_PHYSADDR_MASK)) { | 
|  | 33 | data &= ~SH_CACHE_UPDATED; | 
|  | 34 | ctrl_outl(data, addr | (way << 12)); | 
|  | 35 | } | 
|  | 36 | } | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 37 | } | 
|  | 38 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 |  | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 40 | void __flush_purge_region(void *start, int size) | 
|  | 41 | { | 
|  | 42 | unsigned long v; | 
|  | 43 | unsigned long begin, end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 |  | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 45 | begin = (unsigned long)start & ~(L1_CACHE_BYTES-1); | 
|  | 46 | end = ((unsigned long)start + size + L1_CACHE_BYTES-1) | 
|  | 47 | & ~(L1_CACHE_BYTES-1); | 
| Yoshinori Sato | cce2d45 | 2008-08-04 16:33:47 +0900 | [diff] [blame] | 48 |  | 
|  | 49 | for (v = begin; v < end; v+=L1_CACHE_BYTES) | 
|  | 50 | ctrl_outl((v & CACHE_PHYSADDR_MASK), | 
|  | 51 | CACHE_OC_ADDRESS_ARRAY | (v & 0x00000ff0) | 0x00000008); | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 52 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 54 | void __flush_invalidate_region(void *start, int size) | 
|  | 55 | { | 
| Yoshinori Sato | cce2d45 | 2008-08-04 16:33:47 +0900 | [diff] [blame] | 56 | #ifdef CONFIG_CACHE_WRITEBACK | 
|  | 57 | /* | 
|  | 58 | * SH-2 does not support individual line invalidation, only a | 
|  | 59 | * global invalidate. | 
|  | 60 | */ | 
|  | 61 | unsigned long ccr; | 
|  | 62 | unsigned long flags; | 
|  | 63 | local_irq_save(flags); | 
|  | 64 | jump_to_uncached(); | 
|  | 65 |  | 
|  | 66 | ccr = ctrl_inl(CCR); | 
|  | 67 | ccr |= CCR_CACHE_INVALIDATE; | 
|  | 68 | ctrl_outl(ccr, CCR); | 
|  | 69 |  | 
|  | 70 | back_to_cached(); | 
|  | 71 | local_irq_restore(flags); | 
|  | 72 | #else | 
| Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 73 | unsigned long v; | 
|  | 74 | unsigned long begin, end; | 
|  | 75 |  | 
|  | 76 | begin = (unsigned long)start & ~(L1_CACHE_BYTES-1); | 
|  | 77 | end = ((unsigned long)start + size + L1_CACHE_BYTES-1) | 
|  | 78 | & ~(L1_CACHE_BYTES-1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 |  | 
| Yoshinori Sato | cce2d45 | 2008-08-04 16:33:47 +0900 | [diff] [blame] | 80 | for (v = begin; v < end; v+=L1_CACHE_BYTES) | 
|  | 81 | ctrl_outl((v & CACHE_PHYSADDR_MASK), | 
|  | 82 | CACHE_OC_ADDRESS_ARRAY | (v & 0x00000ff0) | 0x00000008); | 
|  | 83 | #endif | 
|  | 84 | } |