l2_cache.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef L2_CACHE_H
  4. #define L2_CACHE_H
  5. /* CCTL_CMD_OP */
  6. #define L2_CA_CONF_OFF 0x0
  7. #define L2_IF_CONF_OFF 0x4
  8. #define L2CC_SETUP_OFF 0x8
  9. #define L2CC_PROT_OFF 0xC
  10. #define L2CC_CTRL_OFF 0x10
  11. #define L2_INT_EN_OFF 0x20
  12. #define L2_STA_OFF 0x24
  13. #define RDERR_ADDR_OFF 0x28
  14. #define WRERR_ADDR_OFF 0x2c
  15. #define EVDPTERR_ADDR_OFF 0x30
  16. #define IMPL3ERR_ADDR_OFF 0x34
  17. #define L2_CNT0_CTRL_OFF 0x40
  18. #define L2_EVNT_CNT0_OFF 0x44
  19. #define L2_CNT1_CTRL_OFF 0x48
  20. #define L2_EVNT_CNT1_OFF 0x4c
  21. #define L2_CCTL_CMD_OFF 0x60
  22. #define L2_CCTL_STATUS_OFF 0x64
  23. #define L2_LINE_TAG_OFF 0x68
  24. #define L2_LINE_DPT_OFF 0x70
  25. #define CCTL_CMD_L2_IX_INVAL 0x0
  26. #define CCTL_CMD_L2_PA_INVAL 0x1
  27. #define CCTL_CMD_L2_IX_WB 0x2
  28. #define CCTL_CMD_L2_PA_WB 0x3
  29. #define CCTL_CMD_L2_PA_WBINVAL 0x5
  30. #define CCTL_CMD_L2_SYNC 0xa
  31. /* CCTL_CMD_TYPE */
  32. #define CCTL_SINGLE_CMD 0
  33. #define CCTL_BLOCK_CMD 0x10
  34. #define CCTL_ALL_CMD 0x10
  35. /******************************************************************************
  36. * L2_CA_CONF (Cache architecture configuration)
  37. *****************************************************************************/
  38. #define L2_CA_CONF_offL2SET 0
  39. #define L2_CA_CONF_offL2WAY 4
  40. #define L2_CA_CONF_offL2CLSZ 8
  41. #define L2_CA_CONF_offL2DW 11
  42. #define L2_CA_CONF_offL2PT 14
  43. #define L2_CA_CONF_offL2VER 16
  44. #define L2_CA_CONF_mskL2SET (0xFUL << L2_CA_CONF_offL2SET)
  45. #define L2_CA_CONF_mskL2WAY (0xFUL << L2_CA_CONF_offL2WAY)
  46. #define L2_CA_CONF_mskL2CLSZ (0x7UL << L2_CA_CONF_offL2CLSZ)
  47. #define L2_CA_CONF_mskL2DW (0x7UL << L2_CA_CONF_offL2DW)
  48. #define L2_CA_CONF_mskL2PT (0x3UL << L2_CA_CONF_offL2PT)
  49. #define L2_CA_CONF_mskL2VER (0xFFFFUL << L2_CA_CONF_offL2VER)
  50. /******************************************************************************
  51. * L2CC_SETUP (L2CC Setup register)
  52. *****************************************************************************/
  53. #define L2CC_SETUP_offPART 0
  54. #define L2CC_SETUP_mskPART (0x3UL << L2CC_SETUP_offPART)
  55. #define L2CC_SETUP_offDDLATC 4
  56. #define L2CC_SETUP_mskDDLATC (0x3UL << L2CC_SETUP_offDDLATC)
  57. #define L2CC_SETUP_offTDLATC 8
  58. #define L2CC_SETUP_mskTDLATC (0x3UL << L2CC_SETUP_offTDLATC)
  59. /******************************************************************************
  60. * L2CC_PROT (L2CC Protect register)
  61. *****************************************************************************/
  62. #define L2CC_PROT_offMRWEN 31
  63. #define L2CC_PROT_mskMRWEN (0x1UL << L2CC_PROT_offMRWEN)
  64. /******************************************************************************
  65. * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
  66. *****************************************************************************/
  67. #define L2CC_CTRL_offEN 31
  68. #define L2CC_CTRL_mskEN (0x1UL << L2CC_CTRL_offEN)
  69. /******************************************************************************
  70. * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
  71. *****************************************************************************/
  72. #define L2_CCTL_STATUS_offCMD_COMP 31
  73. #define L2_CCTL_STATUS_mskCMD_COMP (0x1 << L2_CCTL_STATUS_offCMD_COMP)
  74. extern void __iomem *atl2c_base;
  75. #include <linux/smp.h>
  76. #include <asm/io.h>
  77. #include <asm/bitfield.h>
  78. #define L2C_R_REG(offset) readl(atl2c_base + offset)
  79. #define L2C_W_REG(offset, value) writel(value, atl2c_base + offset)
  80. #define L2_CMD_RDY() \
  81. do{;}while((L2C_R_REG(L2_CCTL_STATUS_OFF) & L2_CCTL_STATUS_mskCMD_COMP) == 0)
  82. static inline unsigned long L2_CACHE_SET(void)
  83. {
  84. return 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >>
  85. L2_CA_CONF_offL2SET);
  86. }
  87. static inline unsigned long L2_CACHE_WAY(void)
  88. {
  89. return 1 +
  90. ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >>
  91. L2_CA_CONF_offL2WAY);
  92. }
  93. static inline unsigned long L2_CACHE_LINE_SIZE(void)
  94. {
  95. return 4 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >>
  96. L2_CA_CONF_offL2CLSZ);
  97. }
  98. static inline unsigned long GET_L2CC_CTRL_CPU(unsigned long cpu)
  99. {
  100. if (cpu == smp_processor_id())
  101. return L2C_R_REG(L2CC_CTRL_OFF);
  102. return L2C_R_REG(L2CC_CTRL_OFF + (cpu << 8));
  103. }
  104. static inline void SET_L2CC_CTRL_CPU(unsigned long cpu, unsigned long val)
  105. {
  106. if (cpu == smp_processor_id())
  107. L2C_W_REG(L2CC_CTRL_OFF, val);
  108. else
  109. L2C_W_REG(L2CC_CTRL_OFF + (cpu << 8), val);
  110. }
  111. static inline unsigned long GET_L2CC_STATUS_CPU(unsigned long cpu)
  112. {
  113. if (cpu == smp_processor_id())
  114. return L2C_R_REG(L2_CCTL_STATUS_OFF);
  115. return L2C_R_REG(L2_CCTL_STATUS_OFF + (cpu << 8));
  116. }
  117. #endif