blob: 8b8ef89721041bb3ecae009bee4b8395399eb758 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Paul Mundt81742522009-08-04 18:06:01 +09002#include <linux/mm.h>
3#include <asm/mmu_context.h>
Paul Mundtf03c4862012-03-30 19:29:57 +09004#include <asm/cache_insns.h>
Paul Mundt81742522009-08-04 18:06:01 +09005#include <asm/cacheflush.h>
David Howellse839ca52012-03-28 18:30:03 +01006#include <asm/traps.h>
Paul Mundt81742522009-08-04 18:06:01 +09007
8/*
9 * Write back the dirty D-caches, but not invalidate them.
10 *
11 * START: Virtual Address (U0, P1, or P3)
12 * SIZE: Size of the region.
13 */
Paul Mundt37443ef2009-08-15 12:29:49 +090014static void sh4__flush_wback_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090015{
Paul Mundt43bc61d2009-08-15 01:57:36 +090016 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090017
Paul Mundt43bc61d2009-08-15 01:57:36 +090018 aligned_start = register_align(start);
19 v = aligned_start & ~(L1_CACHE_BYTES-1);
20 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090021 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090022 cnt = (end - v) / L1_CACHE_BYTES;
23
24 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090025 __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;
32 __ocbwb(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090033 cnt -= 8;
34 }
35
36 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +090037 __ocbwb(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090038 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +090039 }
40}
41
42/*
43 * Write back the dirty D-caches and invalidate them.
44 *
45 * START: Virtual Address (U0, P1, or P3)
46 * SIZE: Size of the region.
47 */
Paul Mundt37443ef2009-08-15 12:29:49 +090048static void sh4__flush_purge_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090049{
Paul Mundt43bc61d2009-08-15 01:57:36 +090050 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090051
Paul Mundt43bc61d2009-08-15 01:57:36 +090052 aligned_start = register_align(start);
53 v = aligned_start & ~(L1_CACHE_BYTES-1);
54 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090055 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090056 cnt = (end - v) / L1_CACHE_BYTES;
57
58 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090059 __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;
66 __ocbp(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090067 cnt -= 8;
68 }
69 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +090070 __ocbp(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090071 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +090072 }
73}
74
75/*
76 * No write back please
77 */
Paul Mundt37443ef2009-08-15 12:29:49 +090078static void sh4__flush_invalidate_region(void *start, int size)
Paul Mundt81742522009-08-04 18:06:01 +090079{
Paul Mundt43bc61d2009-08-15 01:57:36 +090080 reg_size_t aligned_start, v, cnt, end;
Paul Mundt81742522009-08-04 18:06:01 +090081
Paul Mundt43bc61d2009-08-15 01:57:36 +090082 aligned_start = register_align(start);
83 v = aligned_start & ~(L1_CACHE_BYTES-1);
84 end = (aligned_start + size + L1_CACHE_BYTES-1)
Paul Mundt81742522009-08-04 18:06:01 +090085 & ~(L1_CACHE_BYTES-1);
Paul Mundt0837f522009-08-04 18:09:54 +090086 cnt = (end - v) / L1_CACHE_BYTES;
87
88 while (cnt >= 8) {
Paul Mundt94ecd222009-08-16 01:50:17 +090089 __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;
96 __ocbi(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +090097 cnt -= 8;
98 }
99
100 while (cnt) {
Paul Mundt94ecd222009-08-16 01:50:17 +0900101 __ocbi(v); v += L1_CACHE_BYTES;
Paul Mundt0837f522009-08-04 18:09:54 +0900102 cnt--;
Paul Mundt81742522009-08-04 18:06:01 +0900103 }
104}
Paul Mundt37443ef2009-08-15 12:29:49 +0900105
106void __init sh4__flush_region_init(void)
107{
108 __flush_wback_region = sh4__flush_wback_region;
109 __flush_invalidate_region = sh4__flush_invalidate_region;
110 __flush_purge_region = sh4__flush_purge_region;
111}