cache.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2011 Andes Technology Corporation
  4. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  5. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  6. */
  7. #ifndef _ASM_CACHE_H
  8. #define _ASM_CACHE_H
  9. /* cache */
  10. int icache_status(void);
  11. void icache_enable(void);
  12. void icache_disable(void);
  13. int dcache_status(void);
  14. void dcache_enable(void);
  15. void dcache_disable(void);
  16. void cache_flush(void);
  17. #define DEFINE_GET_SYS_REG(reg) \
  18. static inline unsigned long GET_##reg(void) \
  19. { \
  20. unsigned long val; \
  21. __asm__ volatile ( \
  22. "mfsr %0, $"#reg : "=&r" (val) : : "memory" \
  23. ); \
  24. return val; \
  25. }
  26. enum cache_t {ICACHE, DCACHE};
  27. DEFINE_GET_SYS_REG(ICM_CFG);
  28. DEFINE_GET_SYS_REG(DCM_CFG);
  29. /* I-cache sets (# of cache lines) per way */
  30. #define ICM_CFG_OFF_ISET 0
  31. /* I-cache ways */
  32. #define ICM_CFG_OFF_IWAY 3
  33. #define ICM_CFG_MSK_ISET (0x7 << ICM_CFG_OFF_ISET)
  34. #define ICM_CFG_MSK_IWAY (0x7 << ICM_CFG_OFF_IWAY)
  35. /* D-cache sets (# of cache lines) per way */
  36. #define DCM_CFG_OFF_DSET 0
  37. /* D-cache ways */
  38. #define DCM_CFG_OFF_DWAY 3
  39. #define DCM_CFG_MSK_DSET (0x7 << DCM_CFG_OFF_DSET)
  40. #define DCM_CFG_MSK_DWAY (0x7 << DCM_CFG_OFF_DWAY)
  41. /* I-cache line size */
  42. #define ICM_CFG_OFF_ISZ 6
  43. #define ICM_CFG_MSK_ISZ (0x7UL << ICM_CFG_OFF_ISZ)
  44. /* D-cache line size */
  45. #define DCM_CFG_OFF_DSZ 6
  46. #define DCM_CFG_MSK_DSZ (0x7UL << DCM_CFG_OFF_DSZ)
  47. /*
  48. * The current upper bound for NDS32 L1 data cache line sizes is 32 bytes.
  49. * We use that value for aligning DMA buffers unless the board config has
  50. * specified an alternate cache line size.
  51. */
  52. #ifdef CONFIG_SYS_CACHELINE_SIZE
  53. #define ARCH_DMA_MINALIGN CONFIG_SYS_CACHELINE_SIZE
  54. #else
  55. #define ARCH_DMA_MINALIGN 32
  56. #endif
  57. #endif /* _ASM_CACHE_H */