blob: 8fc87d3aac470d57870da5f52d4f30c39dd8f07d [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00006 */
7
8#include <common.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}