cache.c 936 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <cpu_func.h>
  8. #include <asm/cache.h>
  9. #include <watchdog.h>
  10. void flush_cache(ulong start_addr, ulong size)
  11. {
  12. #ifndef CONFIG_5xx
  13. ulong addr, start, end;
  14. start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
  15. end = start_addr + size - 1;
  16. for (addr = start; (addr <= end) && (addr >= start);
  17. addr += CONFIG_SYS_CACHELINE_SIZE) {
  18. asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
  19. WATCHDOG_RESET();
  20. }
  21. /* wait for all dcbst to complete on bus */
  22. asm volatile("sync" : : : "memory");
  23. for (addr = start; (addr <= end) && (addr >= start);
  24. addr += CONFIG_SYS_CACHELINE_SIZE) {
  25. asm volatile("icbi 0,%0" : : "r" (addr) : "memory");
  26. WATCHDOG_RESET();
  27. }
  28. asm volatile("sync" : : : "memory");
  29. /* flush prefetch queue */
  30. asm volatile("isync" : : : "memory");
  31. #endif
  32. }