cache.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * (C) Copyright 2007 Michal Simek
  3. *
  4. * Michal SIMEK <monstr@monstr.eu>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.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. MSRSET(0x20);
  30. }
  31. void icache_disable(void) {
  32. /* we are not generate ICACHE size -> flush whole cache */
  33. flush_cache(0, 32768);
  34. MSRCLR(0x20);
  35. }
  36. void dcache_enable (void) {
  37. MSRSET(0x80);
  38. }
  39. void dcache_disable(void) {
  40. #ifdef XILINX_USE_DCACHE
  41. flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
  42. #endif
  43. MSRCLR(0x80);
  44. }
  45. void flush_cache (ulong addr, ulong size)
  46. {
  47. int i;
  48. for (i = 0; i < size; i += 4)
  49. asm volatile (
  50. #ifdef CONFIG_ICACHE
  51. "wic %0, r0;"
  52. #endif
  53. "nop;"
  54. #ifdef CONFIG_DCACHE
  55. "wdc.flush %0, r0;"
  56. #endif
  57. "nop;"
  58. :
  59. : "r" (addr + i)
  60. : "memory");
  61. }