cache.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <cpu_func.h>
  9. #include <asm/asm.h>
  10. int dcache_status(void)
  11. {
  12. int i = 0;
  13. int mask = 0x80;
  14. __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
  15. /* i&=0x80 */
  16. __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
  17. return i;
  18. }
  19. int icache_status(void)
  20. {
  21. int i = 0;
  22. int mask = 0x20;
  23. __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
  24. /* i&=0x20 */
  25. __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
  26. return i;
  27. }
  28. void icache_enable(void)
  29. {
  30. MSRSET(0x20);
  31. }
  32. void icache_disable(void)
  33. {
  34. /* we are not generate ICACHE size -> flush whole cache */
  35. flush_cache(0, 32768);
  36. MSRCLR(0x20);
  37. }
  38. void dcache_enable(void)
  39. {
  40. MSRSET(0x80);
  41. }
  42. void dcache_disable(void)
  43. {
  44. #ifdef XILINX_USE_DCACHE
  45. flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
  46. #endif
  47. MSRCLR(0x80);
  48. }
  49. void flush_cache(ulong addr, ulong size)
  50. {
  51. int i;
  52. for (i = 0; i < size; i += 4)
  53. asm volatile (
  54. #ifdef CONFIG_ICACHE
  55. "wic %0, r0;"
  56. #endif
  57. "nop;"
  58. #ifdef CONFIG_DCACHE
  59. "wdc.flush %0, r0;"
  60. #endif
  61. "nop;"
  62. :
  63. : "r" (addr + i)
  64. : "memory");
  65. }