cache.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024/11/26 zdtyuiop4444 The first version
  9. */
  10. #ifndef __CACHE_H__
  11. #define __CACHE_H__
  12. #include <rthw.h>
  13. #define L1_CACHE_BYTES 64
  14. #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
  15. /*
  16. * dcache.ipa rs1 (invalidate)
  17. * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
  18. * 0000001 01010 rs1 000 00000 0001011
  19. *
  20. * dcache.cpa rs1 (clean)
  21. * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
  22. * 0000001 01001 rs1 000 00000 0001011
  23. *
  24. * dcache.cipa rs1 (clean then invalidate)
  25. * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
  26. * 0000001 01011 rs1 000 00000 0001011
  27. *
  28. * icache.ipa rs1 (invalidate)
  29. * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
  30. * 0000001 11000 rs1 000 00000 0001011
  31. *
  32. * sync.s
  33. * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
  34. * 0000000 11001 00000 000 00000 0001011
  35. */
  36. #define DCACHE_IPA_A0 ".long 0x02a5000b"
  37. #define DCACHE_CPA_A0 ".long 0x0295000b"
  38. #define DCACHE_CIPA_A0 ".long 0x02b5000b"
  39. #define ICACHE_IPA_A0 ".long 0x0385000b"
  40. #define SYNC_S ".long 0x0190000b"
  41. #define CACHE_OP_RANGE(OP, start, size) \
  42. register unsigned long i asm("a0") = start & ~(L1_CACHE_BYTES - 1); \
  43. for (; i < ALIGN(start + size, L1_CACHE_BYTES); i += L1_CACHE_BYTES) \
  44. __asm__ __volatile__(OP); \
  45. __asm__ __volatile__(SYNC_S)
  46. #endif /* __CACHE_H__ */