cache.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007 Michal Simek
  4. *
  5. * Michal SIMEK <monstr@monstr.eu>
  6. */
  7. #include <common.h>
  8. #include <asm/asm.h>
  9. int dcache_status (void)
  10. {
  11. int i = 0;
  12. int mask = 0x80;
  13. __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
  14. /* i&=0x80 */
  15. __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
  16. return i;
  17. }
  18. int icache_status (void)
  19. {
  20. int i = 0;
  21. int mask = 0x20;
  22. __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
  23. /* i&=0x20 */
  24. __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
  25. return i;
  26. }
  27. void icache_enable (void) {
  28. MSRSET(0x20);
  29. }
  30. void icache_disable(void) {
  31. /* we are not generate ICACHE size -> flush whole cache */
  32. flush_cache(0, 32768);
  33. MSRCLR(0x20);
  34. }
  35. void dcache_enable (void) {
  36. MSRSET(0x80);
  37. }
  38. void dcache_disable(void) {
  39. #ifdef XILINX_USE_DCACHE
  40. flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
  41. #endif
  42. MSRCLR(0x80);
  43. }
  44. void flush_cache (ulong addr, ulong size)
  45. {
  46. int i;
  47. for (i = 0; i < size; i += 4)
  48. asm volatile (
  49. #ifdef CONFIG_ICACHE
  50. "wic %0, r0;"
  51. #endif
  52. "nop;"
  53. #ifdef CONFIG_DCACHE
  54. "wdc.flush %0, r0;"
  55. #endif
  56. "nop;"
  57. :
  58. : "r" (addr + i)
  59. : "memory");
  60. }