blob: 0b85dd9dd3a7df0ae97e37da5228328bf0c4a5ac [file] [log] [blame]
Paul Mundt81742522009-08-04 18:06:01 +09001#include <linux/mm.h>
2#include <asm/mmu_context.h>
Paul Mundtf03c4862012-03-30 19:29:57 +09003#include <asm/cache_insns.h>
Paul Mundt81742522009-08-04 18:06:01 +09004#include <asm/cacheflush.h>
David Howellse839ca52012-03-28 18:30:03 +01005#include <asm/traps.h>
Paul Mundt81742522009-08-04 18:06:01 +09006
7/*
8 * Write back the dirty D-caches, but not invalidate them.
9 *
10 * START: Virtual Address (U0, P1, or P3)
11 * SIZE: Size of the region.
12 */
Paul Mundt37443ef2009-08-15 12:29:49 +090013static void sh4__flush_wback_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090014{
Paul Mundt43bc61d2009-08-15 01:57:36 +090015 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090016
Paul Mundt43bc61d2009-08-15 01:57:36 +090017 aligned_start = register_align(start);
18 v = aligned_start & ~(L1_CACHE_BYTES-1);
19 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090020 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090021 cnt = (end - v) / L1_CACHE_BYTES;
22
23 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090024 __ocbwb(v); v += L1_CACHE_BYTES;
25 __ocbwb(v); v += L1_CACHE_BYTES;
26 __ocbwb(v); v += L1_CACHE_BYTES;
27 __ocbwb(v); v += L1_CACHE_BYTES;
28 __ocbwb(v); v += L1_CACHE_BYTES;
29 __ocbwb(v); v += L1_CACHE_BYTES;
30 __ocbwb(v); v += L1_CACHE_BYTES;
31 __ocbwb(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090032 cnt -= 8;
33 }
34
35 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +090036 __ocbwb(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090037 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +090038 }
39}
40
41/*
42 * Write back the dirty D-caches and invalidate them.
43 *
44 * START: Virtual Address (U0, P1, or P3)
45 * SIZE: Size of the region.
46 */
Paul Mundt37443ef2009-08-15 12:29:49 +090047static void sh4__flush_purge_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090048{
Paul Mundt43bc61d2009-08-15 01:57:36 +090049 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090050
Paul Mundt43bc61d2009-08-15 01:57:36 +090051 aligned_start = register_align(start);
52 v = aligned_start & ~(L1_CACHE_BYTES-1);
53 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090054 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090055 cnt = (end - v) / L1_CACHE_BYTES;
56
57 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090058 __ocbp(v); v += L1_CACHE_BYTES;
59 __ocbp(v); v += L1_CACHE_BYTES;
60 __ocbp(v); v += L1_CACHE_BYTES;
61 __ocbp(v); v += L1_CACHE_BYTES;
62 __ocbp(v); v += L1_CACHE_BYTES;
63 __ocbp(v); v += L1_CACHE_BYTES;
64 __ocbp(v); v += L1_CACHE_BYTES;
65 __ocbp(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090066 cnt -= 8;
67 }
68 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +090069 __ocbp(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090070 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +090071 }
72}
73
74/*
75 * No write back please
76 */
Paul Mundt37443ef2009-08-15 12:29:49 +090077static void sh4__flush_invalidate_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090078{
Paul Mundt43bc61d2009-08-15 01:57:36 +090079 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090080
Paul Mundt43bc61d2009-08-15 01:57:36 +090081 aligned_start = register_align(start);
82 v = aligned_start & ~(L1_CACHE_BYTES-1);
83 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090084 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090085 cnt = (end - v) / L1_CACHE_BYTES;
86
87 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090088 __ocbi(v); v += L1_CACHE_BYTES;
89 __ocbi(v); v += L1_CACHE_BYTES;
90 __ocbi(v); v += L1_CACHE_BYTES;
91 __ocbi(v); v += L1_CACHE_BYTES;
92 __ocbi(v); v += L1_CACHE_BYTES;
93 __ocbi(v); v += L1_CACHE_BYTES;
94 __ocbi(v); v += L1_CACHE_BYTES;
95 __ocbi(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090096 cnt -= 8;
97 }
98
99 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +0900100 __ocbi(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +0900101 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +0900102 }
103}
Paul Mundt37443ef2009-08-15 12:29:49 +0900104
105void __init sh4__flush_region_init(void)
106{
107 __flush_wback_region = sh4__flush_wback_region;
108 __flush_invalidate_region = sh4__flush_invalidate_region;
109 __flush_purge_region = sh4__flush_purge_region;
110}