blob: 3c3c470bbbda91c4403b1ddbb51d540feb2d8966 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkaffae2b2002-08-17 09:36:01 +00005 */
6
7#include <common.h>
Simon Glass63334482019-11-14 12:57:39 -07008#include <cpu_func.h>
Stefan Roeseeff3a0a2007-10-31 17:55:58 +01009#include <asm/cache.h>
Yuri Tikhonov18db5a62008-04-29 13:32:45 +020010#include <watchdog.h>
wdenk359733b2003-03-31 17:27:09 +000011
Dave Liu06ed90b2008-12-05 15:36:14 +080012void flush_cache(ulong start_addr, ulong size)
wdenkaffae2b2002-08-17 09:36:01 +000013{
wdenk359733b2003-03-31 17:27:09 +000014#ifndef CONFIG_5xx
Dave Liu06ed90b2008-12-05 15:36:14 +080015 ulong addr, start, end;
wdenkaffae2b2002-08-17 09:36:01 +000016
Dave Liu06ed90b2008-12-05 15:36:14 +080017 start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
18 end = start_addr + size - 1;
wdenkaffae2b2002-08-17 09:36:01 +000019
Kumar Gala3b967ae2009-02-06 08:08:06 -060020 for (addr = start; (addr <= end) && (addr >= start);
21 addr += CONFIG_SYS_CACHELINE_SIZE) {
Dave Liu06ed90b2008-12-05 15:36:14 +080022 asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
23 WATCHDOG_RESET();
24 }
25 /* wait for all dcbst to complete on bus */
26 asm volatile("sync" : : : "memory");
27
Kumar Gala3b967ae2009-02-06 08:08:06 -060028 for (addr = start; (addr <= end) && (addr >= start);
29 addr += CONFIG_SYS_CACHELINE_SIZE) {
Dave Liu06ed90b2008-12-05 15:36:14 +080030 asm volatile("icbi 0,%0" : : "r" (addr) : "memory");
31 WATCHDOG_RESET();
wdenkaffae2b2002-08-17 09:36:01 +000032 }
Dave Liu06ed90b2008-12-05 15:36:14 +080033 asm volatile("sync" : : : "memory");
34 /* flush prefetch queue */
35 asm volatile("isync" : : : "memory");
wdenk359733b2003-03-31 17:27:09 +000036#endif
wdenkaffae2b2002-08-17 09:36:01 +000037}