u-boot/arch/powerpc/lib/cache.c

47 lines
1.1 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0+
2002-08-17 09:36:01 +00:00
/*
* (C) Copyright 2002
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#include <common.h>
#include <cpu_func.h>
#include <asm/cache.h>
#include <watchdog.h>
2021-04-21 09:16:03 +00:00
static ulong maybe_watchdog_reset(ulong flushed)
{
flushed += CONFIG_SYS_CACHELINE_SIZE;
if (flushed >= CONFIG_CACHE_FLUSH_WATCHDOG_THRESHOLD) {
schedule();
2021-04-21 09:16:03 +00:00
flushed = 0;
}
return flushed;
}
void flush_cache(ulong start_addr, ulong size)
2002-08-17 09:36:01 +00:00
{
ulong addr, start, end;
2021-04-21 09:16:03 +00:00
ulong flushed = 0;
2002-08-17 09:36:01 +00:00
start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
end = start_addr + size - 1;
2002-08-17 09:36:01 +00:00
for (addr = start; (addr <= end) && (addr >= start);
addr += CONFIG_SYS_CACHELINE_SIZE) {
asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
2021-04-21 09:16:03 +00:00
flushed = maybe_watchdog_reset(flushed);
2002-08-17 09:36:01 +00:00
}
/* wait for all dcbst to complete on bus */
asm volatile("sync" : : : "memory");
for (addr = start; (addr <= end) && (addr >= start);
addr += CONFIG_SYS_CACHELINE_SIZE) {
asm volatile("icbi 0,%0" : : "r" (addr) : "memory");
2021-04-21 09:16:03 +00:00
flushed = maybe_watchdog_reset(flushed);
}
asm volatile("sync" : : : "memory");
/* flush prefetch queue */
asm volatile("isync" : : : "memory");
2002-08-17 09:36:01 +00:00
}