wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Stefan Roese | 9b94ac6 | 2007-10-31 17:55:58 +0100 | [diff] [blame] | 9 | #include <asm/cache.h> |
Yuri Tikhonov | 138105e | 2008-04-29 13:32:45 +0200 | [diff] [blame] | 10 | #include <watchdog.h> |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 11 | |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 12 | void flush_cache(ulong start_addr, ulong size) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 13 | { |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 14 | #ifndef CONFIG_5xx |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 15 | ulong addr, start, end; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 16 | |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 17 | start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1); |
| 18 | end = start_addr + size - 1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 19 | |
Kumar Gala | bced7cc | 2009-02-06 08:08:06 -0600 | [diff] [blame] | 20 | for (addr = start; (addr <= end) && (addr >= start); |
| 21 | addr += CONFIG_SYS_CACHELINE_SIZE) { |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 22 | asm volatile("dcbst 0,%0" : : "r" (addr) : "memory"); |
| 23 | WATCHDOG_RESET(); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 24 | } |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 25 | /* wait for all dcbst to complete on bus */ |
| 26 | asm volatile("sync" : : : "memory"); |
| 27 | |
Kumar Gala | bced7cc | 2009-02-06 08:08:06 -0600 | [diff] [blame] | 28 | for (addr = start; (addr <= end) && (addr >= start); |
| 29 | addr += CONFIG_SYS_CACHELINE_SIZE) { |
Dave Liu | e39cd81 | 2008-12-05 15:36:14 +0800 | [diff] [blame] | 30 | asm volatile("icbi 0,%0" : : "r" (addr) : "memory"); |
| 31 | WATCHDOG_RESET(); |
| 32 | } |
| 33 | asm volatile("sync" : : : "memory"); |
| 34 | /* flush prefetch queue */ |
| 35 | asm volatile("isync" : : : "memory"); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 36 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 37 | } |