blob: 0dc4ebf694383a361c7fc4c7b35ea75203810969 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Aneesh V960f5c02011-06-16 23:30:47 +00002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
Aneesh V960f5c02011-06-16 23:30:47 +00006 */
7#include <linux/types.h>
8#include <common.h>
9#include <asm/armv7.h>
10#include <asm/utils.h>
11
Hans de Goedeba3bf9b2016-04-09 13:53:49 +020012#define ARMV7_DCACHE_INVAL_RANGE 1
13#define ARMV7_DCACHE_CLEAN_INVAL_RANGE 2
Aneesh V960f5c02011-06-16 23:30:47 +000014
Trevor Woerner43ec7e02019-05-03 09:41:00 -040015#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Hans de Goede076e8412016-04-09 13:53:48 +020016
17/* Asm functions from cache_v7_asm.S */
18void v7_flush_dcache_all(void);
Hans de Goedeba3bf9b2016-04-09 13:53:49 +020019void v7_invalidate_dcache_all(void);
Hans de Goede076e8412016-04-09 13:53:48 +020020
Aneesh V960f5c02011-06-16 23:30:47 +000021static u32 get_ccsidr(void)
22{
23 u32 ccsidr;
24
25 /* Read current CP15 Cache Size ID Register */
26 asm volatile ("mrc p15, 1, %0, c0, c0, 0" : "=r" (ccsidr));
27 return ccsidr;
28}
29
Thierry Reding0c597382014-08-26 17:34:20 +020030static void v7_dcache_clean_inval_range(u32 start, u32 stop, u32 line_len)
Aneesh V960f5c02011-06-16 23:30:47 +000031{
32 u32 mva;
33
34 /* Align start to cache line boundary */
35 start &= ~(line_len - 1);
36 for (mva = start; mva < stop; mva = mva + line_len) {
37 /* DCCIMVAC - Clean & Invalidate data cache by MVA to PoC */
38 asm volatile ("mcr p15, 0, %0, c7, c14, 1" : : "r" (mva));
39 }
40}
41
42static void v7_dcache_inval_range(u32 start, u32 stop, u32 line_len)
43{
44 u32 mva;
45
Simon Glassb7ba9572016-06-19 19:43:02 -060046 if (!check_cache_range(start, stop))
47 return;
Aneesh V960f5c02011-06-16 23:30:47 +000048
49 for (mva = start; mva < stop; mva = mva + line_len) {
50 /* DCIMVAC - Invalidate data cache by MVA to PoC */
51 asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (mva));
52 }
53}
54
55static void v7_dcache_maint_range(u32 start, u32 stop, u32 range_op)
56{
57 u32 line_len, ccsidr;
58
59 ccsidr = get_ccsidr();
60 line_len = ((ccsidr & CCSIDR_LINE_SIZE_MASK) >>
61 CCSIDR_LINE_SIZE_OFFSET) + 2;
62 /* Converting from words to bytes */
63 line_len += 2;
64 /* converting from log2(linelen) to linelen */
65 line_len = 1 << line_len;
66
67 switch (range_op) {
68 case ARMV7_DCACHE_CLEAN_INVAL_RANGE:
69 v7_dcache_clean_inval_range(start, stop, line_len);
70 break;
71 case ARMV7_DCACHE_INVAL_RANGE:
72 v7_dcache_inval_range(start, stop, line_len);
73 break;
74 }
75
Aneesh V517912b2011-08-11 04:35:44 +000076 /* DSB to make sure the operation is complete */
Tom Rini3b787ef2016-08-01 18:54:53 -040077 dsb();
Aneesh V960f5c02011-06-16 23:30:47 +000078}
79
80/* Invalidate TLB */
81static void v7_inval_tlb(void)
82{
83 /* Invalidate entire unified TLB */
84 asm volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0));
85 /* Invalidate entire data TLB */
86 asm volatile ("mcr p15, 0, %0, c8, c6, 0" : : "r" (0));
87 /* Invalidate entire instruction TLB */
88 asm volatile ("mcr p15, 0, %0, c8, c5, 0" : : "r" (0));
89 /* Full system DSB - make sure that the invalidation is complete */
Tom Rini3b787ef2016-08-01 18:54:53 -040090 dsb();
Aneesh V960f5c02011-06-16 23:30:47 +000091 /* Full system ISB - make sure the instruction stream sees it */
Tom Rini3b787ef2016-08-01 18:54:53 -040092 isb();
Aneesh V960f5c02011-06-16 23:30:47 +000093}
94
95void invalidate_dcache_all(void)
96{
Hans de Goedeba3bf9b2016-04-09 13:53:49 +020097 v7_invalidate_dcache_all();
Aneesh V960f5c02011-06-16 23:30:47 +000098
99 v7_outer_cache_inval_all();
100}
101
102/*
103 * Performs a clean & invalidation of the entire data cache
104 * at all levels
105 */
106void flush_dcache_all(void)
107{
Hans de Goede076e8412016-04-09 13:53:48 +0200108 v7_flush_dcache_all();
Aneesh V960f5c02011-06-16 23:30:47 +0000109
110 v7_outer_cache_flush_all();
111}
112
113/*
114 * Invalidates range in all levels of D-cache/unified cache used:
115 * Affects the range [start, stop - 1]
116 */
117void invalidate_dcache_range(unsigned long start, unsigned long stop)
118{
Marek Vasutc28ad232015-07-27 22:34:17 +0200119 check_cache_range(start, stop);
120
Aneesh V960f5c02011-06-16 23:30:47 +0000121 v7_dcache_maint_range(start, stop, ARMV7_DCACHE_INVAL_RANGE);
122
123 v7_outer_cache_inval_range(start, stop);
124}
125
126/*
127 * Flush range(clean & invalidate) from all levels of D-cache/unified
128 * cache used:
129 * Affects the range [start, stop - 1]
130 */
131void flush_dcache_range(unsigned long start, unsigned long stop)
132{
Marek Vasutc28ad232015-07-27 22:34:17 +0200133 check_cache_range(start, stop);
134
Aneesh V960f5c02011-06-16 23:30:47 +0000135 v7_dcache_maint_range(start, stop, ARMV7_DCACHE_CLEAN_INVAL_RANGE);
136
137 v7_outer_cache_flush_range(start, stop);
138}
139
140void arm_init_before_mmu(void)
141{
142 v7_outer_cache_enable();
143 invalidate_dcache_all();
144 v7_inval_tlb();
145}
146
Simon Glassa4f20792012-10-17 13:24:53 +0000147void mmu_page_table_flush(unsigned long start, unsigned long stop)
148{
149 flush_dcache_range(start, stop);
150 v7_inval_tlb();
151}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400152#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Aneesh V960f5c02011-06-16 23:30:47 +0000153void invalidate_dcache_all(void)
154{
155}
156
157void flush_dcache_all(void)
158{
159}
160
Daniel Allred4631f7d2016-06-27 09:19:16 -0500161void invalidate_dcache_range(unsigned long start, unsigned long stop)
162{
163}
164
165void flush_dcache_range(unsigned long start, unsigned long stop)
166{
167}
168
Aneesh V960f5c02011-06-16 23:30:47 +0000169void arm_init_before_mmu(void)
170{
171}
172
Simon Glassa4f20792012-10-17 13:24:53 +0000173void mmu_page_table_flush(unsigned long start, unsigned long stop)
174{
175}
176
R Sricharan06396c12013-03-04 20:04:45 +0000177void arm_init_domains(void)
178{
179}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400180#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Aneesh V960f5c02011-06-16 23:30:47 +0000181
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400182#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Aneesh V960f5c02011-06-16 23:30:47 +0000183/* Invalidate entire I-cache and branch predictor array */
184void invalidate_icache_all(void)
185{
186 /*
187 * Invalidate all instruction caches to PoU.
188 * Also flushes branch target cache.
189 */
190 asm volatile ("mcr p15, 0, %0, c7, c5, 0" : : "r" (0));
191
192 /* Invalidate entire branch predictor array */
193 asm volatile ("mcr p15, 0, %0, c7, c5, 6" : : "r" (0));
194
195 /* Full system DSB - make sure that the invalidation is complete */
Tom Rini3b787ef2016-08-01 18:54:53 -0400196 dsb();
Aneesh V960f5c02011-06-16 23:30:47 +0000197
198 /* ISB - make sure the instruction stream sees it */
Tom Rini3b787ef2016-08-01 18:54:53 -0400199 isb();
Aneesh V960f5c02011-06-16 23:30:47 +0000200}
201#else
202void invalidate_icache_all(void)
203{
204}
205#endif
206
Jeroen Hofsteed7460772014-06-23 22:07:04 +0200207/* Stub implementations for outer cache operations */
208__weak void v7_outer_cache_enable(void) {}
209__weak void v7_outer_cache_disable(void) {}
210__weak void v7_outer_cache_flush_all(void) {}
211__weak void v7_outer_cache_inval_all(void) {}
212__weak void v7_outer_cache_flush_range(u32 start, u32 end) {}
213__weak void v7_outer_cache_inval_range(u32 start, u32 end) {}