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 Denk1a459662013-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 Roese9b94ac62007-10-31 17:55:58 +01009#include <asm/cache.h>
Yuri Tikhonov138105e2008-04-29 13:32:45 +020010#include <watchdog.h>
wdenk0db5bca2003-03-31 17:27:09 +000011
Dave Liue39cd812008-12-05 15:36:14 +080012void flush_cache(ulong start_addr, ulong size)
wdenkaffae2b2002-08-17 09:36:01 +000013{
wdenk0db5bca2003-03-31 17:27:09 +000014#ifndef CONFIG_5xx
Dave Liue39cd812008-12-05 15:36:14 +080015 ulong addr, start, end;
wdenkaffae2b2002-08-17 09:36:01 +000016
Dave Liue39cd812008-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 Galabced7cc2009-02-06 08:08:06 -060020 for (addr = start; (addr <= end) && (addr >= start);
21 addr += CONFIG_SYS_CACHELINE_SIZE) {
Dave Liue39cd812008-12-05 15:36:14 +080022 asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
23 WATCHDOG_RESET();
wdenkaffae2b2002-08-17 09:36:01 +000024 }
Dave Liue39cd812008-12-05 15:36:14 +080025 /* wait for all dcbst to complete on bus */
26 asm volatile("sync" : : : "memory");
27
Kumar Galabced7cc2009-02-06 08:08:06 -060028 for (addr = start; (addr <= end) && (addr >= start);
29 addr += CONFIG_SYS_CACHELINE_SIZE) {
Dave Liue39cd812008-12-05 15:36:14 +080030 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");
wdenk0db5bca2003-03-31 17:27:09 +000036#endif
wdenkaffae2b2002-08-17 09:36:01 +000037}