Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Stefan Roese | eff3a0a | 2007-10-31 17:55:58 +0100 | [diff] [blame] | 8 | #include <asm/cache.h> |
Yuri Tikhonov | 18db5a6 | 2008-04-29 13:32:45 +0200 | [diff] [blame] | 9 | #include <watchdog.h> |
wdenk | 359733b | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 10 | |
Rasmus Villemoes | dc32275 | 2021-04-21 11:16:03 +0200 | [diff] [blame] | 11 | static ulong maybe_watchdog_reset(ulong flushed) |
| 12 | { |
| 13 | flushed += CONFIG_SYS_CACHELINE_SIZE; |
| 14 | if (flushed >= CONFIG_CACHE_FLUSH_WATCHDOG_THRESHOLD) { |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 15 | schedule(); |
Rasmus Villemoes | dc32275 | 2021-04-21 11:16:03 +0200 | [diff] [blame] | 16 | flushed = 0; |
| 17 | } |
| 18 | return flushed; |
| 19 | } |
| 20 | |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 21 | void flush_cache(ulong start_addr, ulong size) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 22 | { |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 23 | ulong addr, start, end; |
Rasmus Villemoes | dc32275 | 2021-04-21 11:16:03 +0200 | [diff] [blame] | 24 | ulong flushed = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 25 | |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 26 | start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1); |
| 27 | end = start_addr + size - 1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 28 | |
Kumar Gala | 3b967ae | 2009-02-06 08:08:06 -0600 | [diff] [blame] | 29 | for (addr = start; (addr <= end) && (addr >= start); |
| 30 | addr += CONFIG_SYS_CACHELINE_SIZE) { |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 31 | asm volatile("dcbst 0,%0" : : "r" (addr) : "memory"); |
Rasmus Villemoes | dc32275 | 2021-04-21 11:16:03 +0200 | [diff] [blame] | 32 | flushed = maybe_watchdog_reset(flushed); |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 33 | } |
| 34 | /* wait for all dcbst to complete on bus */ |
| 35 | asm volatile("sync" : : : "memory"); |
| 36 | |
Kumar Gala | 3b967ae | 2009-02-06 08:08:06 -0600 | [diff] [blame] | 37 | for (addr = start; (addr <= end) && (addr >= start); |
| 38 | addr += CONFIG_SYS_CACHELINE_SIZE) { |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 39 | asm volatile("icbi 0,%0" : : "r" (addr) : "memory"); |
Rasmus Villemoes | dc32275 | 2021-04-21 11:16:03 +0200 | [diff] [blame] | 40 | flushed = maybe_watchdog_reset(flushed); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 41 | } |
Dave Liu | 06ed90b | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 42 | asm volatile("sync" : : : "memory"); |
| 43 | /* flush prefetch queue */ |
| 44 | asm volatile("isync" : : : "memory"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 45 | } |