sysreg.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Macros for accessing system registers with older binutils.
  3. *
  4. * Copyright (C) 2014 ARM Ltd.
  5. * Author: Catalin Marinas <catalin.marinas@arm.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_SYSREG_H
  20. #define __ASM_SYSREG_H
  21. #include <asm/opcodes.h>
  22. /*
  23. * ARMv8 ARM reserves the following encoding for system registers:
  24. * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
  25. * C5.2, version:ARM DDI 0487A.f)
  26. * [20-19] : Op0
  27. * [18-16] : Op1
  28. * [15-12] : CRn
  29. * [11-8] : CRm
  30. * [7-5] : Op2
  31. */
  32. #define sys_reg(op0, op1, crn, crm, op2) \
  33. ((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5))
  34. #define SYS_MIDR_EL1 sys_reg(3, 0, 0, 0, 0)
  35. #define SYS_MPIDR_EL1 sys_reg(3, 0, 0, 0, 5)
  36. #define SYS_REVIDR_EL1 sys_reg(3, 0, 0, 0, 6)
  37. #define SYS_ID_PFR0_EL1 sys_reg(3, 0, 0, 1, 0)
  38. #define SYS_ID_PFR1_EL1 sys_reg(3, 0, 0, 1, 1)
  39. #define SYS_ID_DFR0_EL1 sys_reg(3, 0, 0, 1, 2)
  40. #define SYS_ID_MMFR0_EL1 sys_reg(3, 0, 0, 1, 4)
  41. #define SYS_ID_MMFR1_EL1 sys_reg(3, 0, 0, 1, 5)
  42. #define SYS_ID_MMFR2_EL1 sys_reg(3, 0, 0, 1, 6)
  43. #define SYS_ID_MMFR3_EL1 sys_reg(3, 0, 0, 1, 7)
  44. #define SYS_ID_ISAR0_EL1 sys_reg(3, 0, 0, 2, 0)
  45. #define SYS_ID_ISAR1_EL1 sys_reg(3, 0, 0, 2, 1)
  46. #define SYS_ID_ISAR2_EL1 sys_reg(3, 0, 0, 2, 2)
  47. #define SYS_ID_ISAR3_EL1 sys_reg(3, 0, 0, 2, 3)
  48. #define SYS_ID_ISAR4_EL1 sys_reg(3, 0, 0, 2, 4)
  49. #define SYS_ID_ISAR5_EL1 sys_reg(3, 0, 0, 2, 5)
  50. #define SYS_ID_MMFR4_EL1 sys_reg(3, 0, 0, 2, 6)
  51. #define SYS_MVFR0_EL1 sys_reg(3, 0, 0, 3, 0)
  52. #define SYS_MVFR1_EL1 sys_reg(3, 0, 0, 3, 1)
  53. #define SYS_MVFR2_EL1 sys_reg(3, 0, 0, 3, 2)
  54. #define SYS_ID_AA64PFR0_EL1 sys_reg(3, 0, 0, 4, 0)
  55. #define SYS_ID_AA64PFR1_EL1 sys_reg(3, 0, 0, 4, 1)
  56. #define SYS_ID_AA64DFR0_EL1 sys_reg(3, 0, 0, 5, 0)
  57. #define SYS_ID_AA64DFR1_EL1 sys_reg(3, 0, 0, 5, 1)
  58. #define SYS_ID_AA64ISAR0_EL1 sys_reg(3, 0, 0, 6, 0)
  59. #define SYS_ID_AA64ISAR1_EL1 sys_reg(3, 0, 0, 6, 1)
  60. #define SYS_ID_AA64MMFR0_EL1 sys_reg(3, 0, 0, 7, 0)
  61. #define SYS_ID_AA64MMFR1_EL1 sys_reg(3, 0, 0, 7, 1)
  62. #define SYS_CNTFRQ_EL0 sys_reg(3, 3, 14, 0, 0)
  63. #define SYS_CTR_EL0 sys_reg(3, 3, 0, 0, 1)
  64. #define SYS_DCZID_EL0 sys_reg(3, 3, 0, 0, 7)
  65. #define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4)
  66. #define SET_PSTATE_PAN(x) __inst_arm(0xd5000000 | REG_PSTATE_PAN_IMM |\
  67. (!!x)<<8 | 0x1f)
  68. /* SCTLR_EL1 */
  69. #define SCTLR_EL1_CP15BEN (0x1 << 5)
  70. #define SCTLR_EL1_SED (0x1 << 8)
  71. #define SCTLR_EL1_SPAN (0x1 << 23)
  72. /* id_aa64isar0 */
  73. #define ID_AA64ISAR0_RDM_SHIFT 28
  74. #define ID_AA64ISAR0_ATOMICS_SHIFT 20
  75. #define ID_AA64ISAR0_CRC32_SHIFT 16
  76. #define ID_AA64ISAR0_SHA2_SHIFT 12
  77. #define ID_AA64ISAR0_SHA1_SHIFT 8
  78. #define ID_AA64ISAR0_AES_SHIFT 4
  79. /* id_aa64pfr0 */
  80. #define ID_AA64PFR0_GIC_SHIFT 24
  81. #define ID_AA64PFR0_ASIMD_SHIFT 20
  82. #define ID_AA64PFR0_FP_SHIFT 16
  83. #define ID_AA64PFR0_EL3_SHIFT 12
  84. #define ID_AA64PFR0_EL2_SHIFT 8
  85. #define ID_AA64PFR0_EL1_SHIFT 4
  86. #define ID_AA64PFR0_EL0_SHIFT 0
  87. #define ID_AA64PFR0_FP_NI 0xf
  88. #define ID_AA64PFR0_FP_SUPPORTED 0x0
  89. #define ID_AA64PFR0_ASIMD_NI 0xf
  90. #define ID_AA64PFR0_ASIMD_SUPPORTED 0x0
  91. #define ID_AA64PFR0_EL1_64BIT_ONLY 0x1
  92. #define ID_AA64PFR0_EL0_64BIT_ONLY 0x1
  93. #define ID_AA64PFR0_EL0_32BIT_64BIT 0x2
  94. /* id_aa64mmfr0 */
  95. #define ID_AA64MMFR0_TGRAN4_SHIFT 28
  96. #define ID_AA64MMFR0_TGRAN64_SHIFT 24
  97. #define ID_AA64MMFR0_TGRAN16_SHIFT 20
  98. #define ID_AA64MMFR0_BIGENDEL0_SHIFT 16
  99. #define ID_AA64MMFR0_SNSMEM_SHIFT 12
  100. #define ID_AA64MMFR0_BIGENDEL_SHIFT 8
  101. #define ID_AA64MMFR0_ASID_SHIFT 4
  102. #define ID_AA64MMFR0_PARANGE_SHIFT 0
  103. #define ID_AA64MMFR0_TGRAN4_NI 0xf
  104. #define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
  105. #define ID_AA64MMFR0_TGRAN64_NI 0xf
  106. #define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
  107. #define ID_AA64MMFR0_TGRAN16_NI 0x0
  108. #define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
  109. /* id_aa64mmfr1 */
  110. #define ID_AA64MMFR1_PAN_SHIFT 20
  111. #define ID_AA64MMFR1_LOR_SHIFT 16
  112. #define ID_AA64MMFR1_HPD_SHIFT 12
  113. #define ID_AA64MMFR1_VHE_SHIFT 8
  114. #define ID_AA64MMFR1_VMIDBITS_SHIFT 4
  115. #define ID_AA64MMFR1_HADBS_SHIFT 0
  116. /* id_aa64dfr0 */
  117. #define ID_AA64DFR0_CTX_CMPS_SHIFT 28
  118. #define ID_AA64DFR0_WRPS_SHIFT 20
  119. #define ID_AA64DFR0_BRPS_SHIFT 12
  120. #define ID_AA64DFR0_PMUVER_SHIFT 8
  121. #define ID_AA64DFR0_TRACEVER_SHIFT 4
  122. #define ID_AA64DFR0_DEBUGVER_SHIFT 0
  123. #define ID_ISAR5_RDM_SHIFT 24
  124. #define ID_ISAR5_CRC32_SHIFT 16
  125. #define ID_ISAR5_SHA2_SHIFT 12
  126. #define ID_ISAR5_SHA1_SHIFT 8
  127. #define ID_ISAR5_AES_SHIFT 4
  128. #define ID_ISAR5_SEVL_SHIFT 0
  129. #define MVFR0_FPROUND_SHIFT 28
  130. #define MVFR0_FPSHVEC_SHIFT 24
  131. #define MVFR0_FPSQRT_SHIFT 20
  132. #define MVFR0_FPDIVIDE_SHIFT 16
  133. #define MVFR0_FPTRAP_SHIFT 12
  134. #define MVFR0_FPDP_SHIFT 8
  135. #define MVFR0_FPSP_SHIFT 4
  136. #define MVFR0_SIMD_SHIFT 0
  137. #define MVFR1_SIMDFMAC_SHIFT 28
  138. #define MVFR1_FPHP_SHIFT 24
  139. #define MVFR1_SIMDHP_SHIFT 20
  140. #define MVFR1_SIMDSP_SHIFT 16
  141. #define MVFR1_SIMDINT_SHIFT 12
  142. #define MVFR1_SIMDLS_SHIFT 8
  143. #define MVFR1_FPDNAN_SHIFT 4
  144. #define MVFR1_FPFTZ_SHIFT 0
  145. #define ID_AA64MMFR0_TGRAN4_SHIFT 28
  146. #define ID_AA64MMFR0_TGRAN64_SHIFT 24
  147. #define ID_AA64MMFR0_TGRAN16_SHIFT 20
  148. #define ID_AA64MMFR0_TGRAN4_NI 0xf
  149. #define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
  150. #define ID_AA64MMFR0_TGRAN64_NI 0xf
  151. #define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
  152. #define ID_AA64MMFR0_TGRAN16_NI 0x0
  153. #define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
  154. #if defined(CONFIG_ARM64_4K_PAGES)
  155. #define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN4_SHIFT
  156. #define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN4_SUPPORTED
  157. #elif defined(CONFIG_ARM64_16K_PAGES)
  158. #define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN16_SHIFT
  159. #define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN16_SUPPORTED
  160. #elif defined(CONFIG_ARM64_64K_PAGES)
  161. #define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN64_SHIFT
  162. #define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN64_SUPPORTED
  163. #endif
  164. #ifdef __ASSEMBLY__
  165. .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
  166. .equ __reg_num_x\num, \num
  167. .endr
  168. .equ __reg_num_xzr, 31
  169. .macro mrs_s, rt, sreg
  170. .inst 0xd5200000|(\sreg)|(__reg_num_\rt)
  171. .endm
  172. .macro msr_s, sreg, rt
  173. .inst 0xd5000000|(\sreg)|(__reg_num_\rt)
  174. .endm
  175. #else
  176. asm(
  177. " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n"
  178. " .equ __reg_num_x\\num, \\num\n"
  179. " .endr\n"
  180. " .equ __reg_num_xzr, 31\n"
  181. "\n"
  182. " .macro mrs_s, rt, sreg\n"
  183. " .inst 0xd5200000|(\\sreg)|(__reg_num_\\rt)\n"
  184. " .endm\n"
  185. "\n"
  186. " .macro msr_s, sreg, rt\n"
  187. " .inst 0xd5000000|(\\sreg)|(__reg_num_\\rt)\n"
  188. " .endm\n"
  189. );
  190. static inline void config_sctlr_el1(u32 clear, u32 set)
  191. {
  192. u32 val;
  193. asm volatile("mrs %0, sctlr_el1" : "=r" (val));
  194. val &= ~clear;
  195. val |= set;
  196. asm volatile("msr sctlr_el1, %0" : : "r" (val));
  197. }
  198. #endif
  199. #endif /* __ASM_SYSREG_H */