Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 2 | /* |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002 |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | 3cb9c37 | 2023-10-12 19:03:56 -0400 | [diff] [blame] | 7 | #include <config.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 9 | #include <asm/immap.h> |
| 10 | #include <asm/cache.h> |
Ilias Apalodimas | e9e1865 | 2025-02-20 15:54:42 +0200 | [diff] [blame^] | 11 | #include <linux/errno.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 12 | |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 13 | volatile int *cf_icache_status = (int *)ICACHE_STATUS; |
| 14 | volatile int *cf_dcache_status = (int *)DCACHE_STATUS; |
| 15 | |
| 16 | void flush_cache(ulong start_addr, ulong size) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 17 | { |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 18 | /* Must be implemented for all M68k processors with copy-back data cache */ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 19 | } |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 20 | |
| 21 | int icache_status(void) |
| 22 | { |
| 23 | return *cf_icache_status; |
| 24 | } |
| 25 | |
| 26 | int dcache_status(void) |
| 27 | { |
| 28 | return *cf_dcache_status; |
| 29 | } |
| 30 | |
| 31 | void icache_enable(void) |
| 32 | { |
Tom Rini | f8628fa | 2024-06-19 15:27:54 -0600 | [diff] [blame] | 33 | invalidate_icache_all(); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 34 | |
| 35 | *cf_icache_status = 1; |
| 36 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 37 | #if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 38 | __asm__ __volatile__("movec %0, %%acr2"::"r"(CFG_SYS_CACHE_ACR2)); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 39 | __asm__ __volatile__("movec %0, %%acr3"::"r"(CFG_SYS_CACHE_ACR3)); |
| 40 | #if defined(CFG_CF_V4E) |
| 41 | __asm__ __volatile__("movec %0, %%acr6"::"r"(CFG_SYS_CACHE_ACR6)); |
| 42 | __asm__ __volatile__("movec %0, %%acr7"::"r"(CFG_SYS_CACHE_ACR7)); |
Angelo Dureghello | 8ddcf38 | 2017-05-31 21:32:48 +0200 | [diff] [blame] | 43 | #endif |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 44 | #else |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 45 | __asm__ __volatile__("movec %0, %%acr0"::"r"(CFG_SYS_CACHE_ACR0)); |
| 46 | __asm__ __volatile__("movec %0, %%acr1"::"r"(CFG_SYS_CACHE_ACR1)); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 47 | #endif |
| 48 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 49 | __asm__ __volatile__("movec %0, %%cacr"::"r"(CFG_SYS_CACHE_ICACR)); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void icache_disable(void) |
| 53 | { |
| 54 | u32 temp = 0; |
| 55 | |
| 56 | *cf_icache_status = 0; |
Tom Rini | f8628fa | 2024-06-19 15:27:54 -0600 | [diff] [blame] | 57 | invalidate_icache_all(); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 58 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 59 | #if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 60 | __asm__ __volatile__("movec %0, %%acr2"::"r"(temp)); |
| 61 | __asm__ __volatile__("movec %0, %%acr3"::"r"(temp)); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 62 | #if defined(CFG_CF_V4E) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 63 | __asm__ __volatile__("movec %0, %%acr6"::"r"(temp)); |
| 64 | __asm__ __volatile__("movec %0, %%acr7"::"r"(temp)); |
Angelo Dureghello | 8ddcf38 | 2017-05-31 21:32:48 +0200 | [diff] [blame] | 65 | #endif |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 66 | #else |
| 67 | __asm__ __volatile__("movec %0, %%acr0"::"r"(temp)); |
| 68 | __asm__ __volatile__("movec %0, %%acr1"::"r"(temp)); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 69 | #endif |
| 70 | } |
| 71 | |
Tom Rini | f8628fa | 2024-06-19 15:27:54 -0600 | [diff] [blame] | 72 | void invalidate_icache_all(void) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 73 | { |
| 74 | u32 temp; |
| 75 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 76 | temp = CFG_SYS_ICACHE_INV; |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 77 | if (*cf_icache_status) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 78 | temp |= CFG_SYS_CACHE_ICACR; |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 79 | |
| 80 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 81 | } |
| 82 | |
| 83 | /* |
Tom Rini | 7ab2f5f | 2021-05-14 21:34:10 -0400 | [diff] [blame] | 84 | * data cache only for ColdFire V4 such as MCF5445x |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 85 | * the dcache will be dummy in ColdFire V2 and V3 |
| 86 | */ |
| 87 | void dcache_enable(void) |
| 88 | { |
| 89 | dcache_invalid(); |
| 90 | *cf_dcache_status = 1; |
| 91 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 92 | #if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 93 | __asm__ __volatile__("movec %0, %%acr0"::"r"(CFG_SYS_CACHE_ACR0)); |
| 94 | __asm__ __volatile__("movec %0, %%acr1"::"r"(CFG_SYS_CACHE_ACR1)); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 95 | #if defined(CFG_CF_V4E) |
| 96 | __asm__ __volatile__("movec %0, %%acr4"::"r"(CFG_SYS_CACHE_ACR4)); |
| 97 | __asm__ __volatile__("movec %0, %%acr5"::"r"(CFG_SYS_CACHE_ACR5)); |
Angelo Dureghello | 8ddcf38 | 2017-05-31 21:32:48 +0200 | [diff] [blame] | 98 | #endif |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 99 | #endif |
| 100 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 101 | __asm__ __volatile__("movec %0, %%cacr"::"r"(CFG_SYS_CACHE_DCACR)); |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void dcache_disable(void) |
| 105 | { |
| 106 | u32 temp = 0; |
| 107 | |
| 108 | *cf_dcache_status = 0; |
| 109 | dcache_invalid(); |
| 110 | |
| 111 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 112 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 113 | #if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 114 | __asm__ __volatile__("movec %0, %%acr0"::"r"(temp)); |
| 115 | __asm__ __volatile__("movec %0, %%acr1"::"r"(temp)); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 116 | #if defined(CFG_CF_V4E) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 117 | __asm__ __volatile__("movec %0, %%acr4"::"r"(temp)); |
| 118 | __asm__ __volatile__("movec %0, %%acr5"::"r"(temp)); |
Angelo Dureghello | 8ddcf38 | 2017-05-31 21:32:48 +0200 | [diff] [blame] | 119 | #endif |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 120 | #endif |
| 121 | } |
| 122 | |
| 123 | void dcache_invalid(void) |
| 124 | { |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 125 | #if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E) |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 126 | u32 temp; |
| 127 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 128 | temp = CFG_SYS_DCACHE_INV; |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 129 | if (*cf_dcache_status) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 130 | temp |= CFG_SYS_CACHE_DCACR; |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 131 | if (*cf_icache_status) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 132 | temp |= CFG_SYS_CACHE_ICACR; |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 133 | |
| 134 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 135 | #endif |
| 136 | } |
Wu, Josh | 22f483c | 2015-07-27 11:40:15 +0800 | [diff] [blame] | 137 | |
Tom Rini | 8bcc53a | 2024-06-19 15:27:53 -0600 | [diff] [blame] | 138 | /* |
| 139 | * Default implementation: |
| 140 | * do a range flush for the entire range |
| 141 | */ |
| 142 | __weak void flush_dcache_all(void) |
| 143 | { |
| 144 | flush_dcache_range(0, ~0); |
| 145 | } |
| 146 | |
Wu, Josh | 22f483c | 2015-07-27 11:40:15 +0800 | [diff] [blame] | 147 | __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 148 | { |
| 149 | /* An empty stub, real implementation should be in platform code */ |
| 150 | } |
| 151 | __weak void flush_dcache_range(unsigned long start, unsigned long stop) |
| 152 | { |
| 153 | /* An empty stub, real implementation should be in platform code */ |
| 154 | } |
Ilias Apalodimas | e9e1865 | 2025-02-20 15:54:42 +0200 | [diff] [blame^] | 155 | |
| 156 | int __weak pgprot_set_attrs(phys_addr_t addr, size_t size, enum pgprot_attrs perm) |
| 157 | { |
| 158 | return -ENOSYS; |
| 159 | } |