cache.h 1.7 KB

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