cpu-feature-registers.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. ARM64 CPU Feature Registers
  2. ===========================
  3. Author: Suzuki K Poulose <suzuki.poulose@arm.com>
  4. This file describes the ABI for exporting the AArch64 CPU ID/feature
  5. registers to userspace. The availability of this ABI is advertised
  6. via the HWCAP_CPUID in HWCAPs.
  7. 1. Motivation
  8. ---------------
  9. The ARM architecture defines a set of feature registers, which describe
  10. the capabilities of the CPU/system. Access to these system registers is
  11. restricted from EL0 and there is no reliable way for an application to
  12. extract this information to make better decisions at runtime. There is
  13. limited information available to the application via HWCAPs, however
  14. there are some issues with their usage.
  15. a) Any change to the HWCAPs requires an update to userspace (e.g libc)
  16. to detect the new changes, which can take a long time to appear in
  17. distributions. Exposing the registers allows applications to get the
  18. information without requiring updates to the toolchains.
  19. b) Access to HWCAPs is sometimes limited (e.g prior to libc, or
  20. when ld is initialised at startup time).
  21. c) HWCAPs cannot represent non-boolean information effectively. The
  22. architecture defines a canonical format for representing features
  23. in the ID registers; this is well defined and is capable of
  24. representing all valid architecture variations.
  25. 2. Requirements
  26. -----------------
  27. a) Safety :
  28. Applications should be able to use the information provided by the
  29. infrastructure to run safely across the system. This has greater
  30. implications on a system with heterogeneous CPUs.
  31. The infrastructure exports a value that is safe across all the
  32. available CPU on the system.
  33. e.g, If at least one CPU doesn't implement CRC32 instructions, while
  34. others do, we should report that the CRC32 is not implemented.
  35. Otherwise an application could crash when scheduled on the CPU
  36. which doesn't support CRC32.
  37. b) Security :
  38. Applications should only be able to receive information that is
  39. relevant to the normal operation in userspace. Hence, some of the
  40. fields are masked out(i.e, made invisible) and their values are set to
  41. indicate the feature is 'not supported'. See Section 4 for the list
  42. of visible features. Also, the kernel may manipulate the fields
  43. based on what it supports. e.g, If FP is not supported by the
  44. kernel, the values could indicate that the FP is not available
  45. (even when the CPU provides it).
  46. c) Implementation Defined Features
  47. The infrastructure doesn't expose any register which is
  48. IMPLEMENTATION DEFINED as per ARMv8-A Architecture.
  49. d) CPU Identification :
  50. MIDR_EL1 is exposed to help identify the processor. On a
  51. heterogeneous system, this could be racy (just like getcpu()). The
  52. process could be migrated to another CPU by the time it uses the
  53. register value, unless the CPU affinity is set. Hence, there is no
  54. guarantee that the value reflects the processor that it is
  55. currently executing on. The REVIDR is not exposed due to this
  56. constraint, as REVIDR makes sense only in conjunction with the
  57. MIDR. Alternately, MIDR_EL1 and REVIDR_EL1 are exposed via sysfs
  58. at:
  59. /sys/devices/system/cpu/cpu$ID/regs/identification/
  60. \- midr
  61. \- revidr
  62. 3. Implementation
  63. --------------------
  64. The infrastructure is built on the emulation of the 'MRS' instruction.
  65. Accessing a restricted system register from an application generates an
  66. exception and ends up in SIGILL being delivered to the process.
  67. The infrastructure hooks into the exception handler and emulates the
  68. operation if the source belongs to the supported system register space.
  69. The infrastructure emulates only the following system register space:
  70. Op0=3, Op1=0, CRn=0, CRm=0,4,5,6,7
  71. (See Table C5-6 'System instruction encodings for non-Debug System
  72. register accesses' in ARMv8 ARM DDI 0487A.h, for the list of
  73. registers).
  74. The following rules are applied to the value returned by the
  75. infrastructure:
  76. a) The value of an 'IMPLEMENTATION DEFINED' field is set to 0.
  77. b) The value of a reserved field is populated with the reserved
  78. value as defined by the architecture.
  79. c) The value of a 'visible' field holds the system wide safe value
  80. for the particular feature (except for MIDR_EL1, see section 4).
  81. d) All other fields (i.e, invisible fields) are set to indicate
  82. the feature is missing (as defined by the architecture).
  83. 4. List of registers with visible features
  84. -------------------------------------------
  85. 1) ID_AA64ISAR0_EL1 - Instruction Set Attribute Register 0
  86. x--------------------------------------------------x
  87. | Name | bits | visible |
  88. |--------------------------------------------------|
  89. | TS | [55-52] | y |
  90. |--------------------------------------------------|
  91. | FHM | [51-48] | y |
  92. |--------------------------------------------------|
  93. | DP | [47-44] | y |
  94. |--------------------------------------------------|
  95. | SM4 | [43-40] | y |
  96. |--------------------------------------------------|
  97. | SM3 | [39-36] | y |
  98. |--------------------------------------------------|
  99. | SHA3 | [35-32] | y |
  100. |--------------------------------------------------|
  101. | RDM | [31-28] | y |
  102. |--------------------------------------------------|
  103. | ATOMICS | [23-20] | y |
  104. |--------------------------------------------------|
  105. | CRC32 | [19-16] | y |
  106. |--------------------------------------------------|
  107. | SHA2 | [15-12] | y |
  108. |--------------------------------------------------|
  109. | SHA1 | [11-8] | y |
  110. |--------------------------------------------------|
  111. | AES | [7-4] | y |
  112. x--------------------------------------------------x
  113. 2) ID_AA64PFR0_EL1 - Processor Feature Register 0
  114. x--------------------------------------------------x
  115. | Name | bits | visible |
  116. |--------------------------------------------------|
  117. | DIT | [51-48] | y |
  118. |--------------------------------------------------|
  119. | SVE | [35-32] | y |
  120. |--------------------------------------------------|
  121. | GIC | [27-24] | n |
  122. |--------------------------------------------------|
  123. | AdvSIMD | [23-20] | y |
  124. |--------------------------------------------------|
  125. | FP | [19-16] | y |
  126. |--------------------------------------------------|
  127. | EL3 | [15-12] | n |
  128. |--------------------------------------------------|
  129. | EL2 | [11-8] | n |
  130. |--------------------------------------------------|
  131. | EL1 | [7-4] | n |
  132. |--------------------------------------------------|
  133. | EL0 | [3-0] | n |
  134. x--------------------------------------------------x
  135. 3) MIDR_EL1 - Main ID Register
  136. x--------------------------------------------------x
  137. | Name | bits | visible |
  138. |--------------------------------------------------|
  139. | Implementer | [31-24] | y |
  140. |--------------------------------------------------|
  141. | Variant | [23-20] | y |
  142. |--------------------------------------------------|
  143. | Architecture | [19-16] | y |
  144. |--------------------------------------------------|
  145. | PartNum | [15-4] | y |
  146. |--------------------------------------------------|
  147. | Revision | [3-0] | y |
  148. x--------------------------------------------------x
  149. NOTE: The 'visible' fields of MIDR_EL1 will contain the value
  150. as available on the CPU where it is fetched and is not a system
  151. wide safe value.
  152. 4) ID_AA64ISAR1_EL1 - Instruction set attribute register 1
  153. x--------------------------------------------------x
  154. | Name | bits | visible |
  155. |--------------------------------------------------|
  156. | LRCPC | [23-20] | y |
  157. |--------------------------------------------------|
  158. | FCMA | [19-16] | y |
  159. |--------------------------------------------------|
  160. | JSCVT | [15-12] | y |
  161. |--------------------------------------------------|
  162. | DPB | [3-0] | y |
  163. x--------------------------------------------------x
  164. 5) ID_AA64MMFR2_EL1 - Memory model feature register 2
  165. x--------------------------------------------------x
  166. | Name | bits | visible |
  167. |--------------------------------------------------|
  168. | AT | [35-32] | y |
  169. x--------------------------------------------------x
  170. Appendix I: Example
  171. ---------------------------
  172. /*
  173. * Sample program to demonstrate the MRS emulation ABI.
  174. *
  175. * Copyright (C) 2015-2016, ARM Ltd
  176. *
  177. * Author: Suzuki K Poulose <suzuki.poulose@arm.com>
  178. *
  179. * This program is free software; you can redistribute it and/or modify
  180. * it under the terms of the GNU General Public License version 2 as
  181. * published by the Free Software Foundation.
  182. *
  183. * This program is distributed in the hope that it will be useful,
  184. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  185. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  186. * GNU General Public License for more details.
  187. * This program is free software; you can redistribute it and/or modify
  188. * it under the terms of the GNU General Public License version 2 as
  189. * published by the Free Software Foundation.
  190. *
  191. * This program is distributed in the hope that it will be useful,
  192. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  193. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  194. * GNU General Public License for more details.
  195. */
  196. #include <asm/hwcap.h>
  197. #include <stdio.h>
  198. #include <sys/auxv.h>
  199. #define get_cpu_ftr(id) ({ \
  200. unsigned long __val; \
  201. asm("mrs %0, "#id : "=r" (__val)); \
  202. printf("%-20s: 0x%016lx\n", #id, __val); \
  203. })
  204. int main(void)
  205. {
  206. if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
  207. fputs("CPUID registers unavailable\n", stderr);
  208. return 1;
  209. }
  210. get_cpu_ftr(ID_AA64ISAR0_EL1);
  211. get_cpu_ftr(ID_AA64ISAR1_EL1);
  212. get_cpu_ftr(ID_AA64MMFR0_EL1);
  213. get_cpu_ftr(ID_AA64MMFR1_EL1);
  214. get_cpu_ftr(ID_AA64PFR0_EL1);
  215. get_cpu_ftr(ID_AA64PFR1_EL1);
  216. get_cpu_ftr(ID_AA64DFR0_EL1);
  217. get_cpu_ftr(ID_AA64DFR1_EL1);
  218. get_cpu_ftr(MIDR_EL1);
  219. get_cpu_ftr(MPIDR_EL1);
  220. get_cpu_ftr(REVIDR_EL1);
  221. #if 0
  222. /* Unexposed register access causes SIGILL */
  223. get_cpu_ftr(ID_MMFR0_EL1);
  224. #endif
  225. return 0;
  226. }