cpu-feature-registers.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. ===========================
  2. ARM64 CPU Feature Registers
  3. ===========================
  4. Author: Suzuki K Poulose <suzuki.poulose@arm.com>
  5. This file describes the ABI for exporting the AArch64 CPU ID/feature
  6. registers to userspace. The availability of this ABI is advertised
  7. via the HWCAP_CPUID in HWCAPs.
  8. 1. Motivation
  9. -------------
  10. The ARM architecture defines a set of feature registers, which describe
  11. the capabilities of the CPU/system. Access to these system registers is
  12. restricted from EL0 and there is no reliable way for an application to
  13. extract this information to make better decisions at runtime. There is
  14. limited information available to the application via HWCAPs, however
  15. there are some issues with their usage.
  16. a) Any change to the HWCAPs requires an update to userspace (e.g libc)
  17. to detect the new changes, which can take a long time to appear in
  18. distributions. Exposing the registers allows applications to get the
  19. information without requiring updates to the toolchains.
  20. b) Access to HWCAPs is sometimes limited (e.g prior to libc, or
  21. when ld is initialised at startup time).
  22. c) HWCAPs cannot represent non-boolean information effectively. The
  23. architecture defines a canonical format for representing features
  24. in the ID registers; this is well defined and is capable of
  25. representing all valid architecture variations.
  26. 2. Requirements
  27. ---------------
  28. a) Safety:
  29. Applications should be able to use the information provided by the
  30. infrastructure to run safely across the system. This has greater
  31. implications on a system with heterogeneous CPUs.
  32. The infrastructure exports a value that is safe across all the
  33. available CPU on the system.
  34. e.g, If at least one CPU doesn't implement CRC32 instructions, while
  35. others do, we should report that the CRC32 is not implemented.
  36. Otherwise an application could crash when scheduled on the CPU
  37. which doesn't support CRC32.
  38. b) Security:
  39. Applications should only be able to receive information that is
  40. relevant to the normal operation in userspace. Hence, some of the
  41. fields are masked out(i.e, made invisible) and their values are set to
  42. indicate the feature is 'not supported'. See Section 4 for the list
  43. of visible features. Also, the kernel may manipulate the fields
  44. based on what it supports. e.g, If FP is not supported by the
  45. kernel, the values could indicate that the FP is not available
  46. (even when the CPU provides it).
  47. c) Implementation Defined Features
  48. The infrastructure doesn't expose any register which is
  49. IMPLEMENTATION DEFINED as per ARMv8-A Architecture.
  50. d) CPU Identification:
  51. MIDR_EL1 is exposed to help identify the processor. On a
  52. heterogeneous system, this could be racy (just like getcpu()). The
  53. process could be migrated to another CPU by the time it uses the
  54. register value, unless the CPU affinity is set. Hence, there is no
  55. guarantee that the value reflects the processor that it is
  56. currently executing on. REVIDR and AIDR are not exposed due to this
  57. constraint, as these registers only make sense in conjunction with
  58. the MIDR. Alternately, MIDR_EL1, REVIDR_EL1, and AIDR_EL1 are exposed
  59. via sysfs at::
  60. /sys/devices/system/cpu/cpu$ID/regs/identification/
  61. \- midr_el1
  62. \- revidr_el1
  63. \- aidr_el1
  64. 3. Implementation
  65. --------------------
  66. The infrastructure is built on the emulation of the 'MRS' instruction.
  67. Accessing a restricted system register from an application generates an
  68. exception and ends up in SIGILL being delivered to the process.
  69. The infrastructure hooks into the exception handler and emulates the
  70. operation if the source belongs to the supported system register space.
  71. The infrastructure emulates only the following system register space::
  72. Op0=3, Op1=0, CRn=0, CRm=0,2,3,4,5,6,7
  73. (See Table C5-6 'System instruction encodings for non-Debug System
  74. register accesses' in ARMv8 ARM DDI 0487A.h, for the list of
  75. registers).
  76. The following rules are applied to the value returned by the
  77. infrastructure:
  78. a) The value of an 'IMPLEMENTATION DEFINED' field is set to 0.
  79. b) The value of a reserved field is populated with the reserved
  80. value as defined by the architecture.
  81. c) The value of a 'visible' field holds the system wide safe value
  82. for the particular feature (except for MIDR_EL1, see section 4).
  83. d) All other fields (i.e, invisible fields) are set to indicate
  84. the feature is missing (as defined by the architecture).
  85. 4. List of registers with visible features
  86. -------------------------------------------
  87. 1) ID_AA64ISAR0_EL1 - Instruction Set Attribute Register 0
  88. +------------------------------+---------+---------+
  89. | Name | bits | visible |
  90. +------------------------------+---------+---------+
  91. | RNDR | [63-60] | y |
  92. +------------------------------+---------+---------+
  93. | TS | [55-52] | y |
  94. +------------------------------+---------+---------+
  95. | FHM | [51-48] | y |
  96. +------------------------------+---------+---------+
  97. | DP | [47-44] | y |
  98. +------------------------------+---------+---------+
  99. | SM4 | [43-40] | y |
  100. +------------------------------+---------+---------+
  101. | SM3 | [39-36] | y |
  102. +------------------------------+---------+---------+
  103. | SHA3 | [35-32] | y |
  104. +------------------------------+---------+---------+
  105. | RDM | [31-28] | y |
  106. +------------------------------+---------+---------+
  107. | ATOMICS | [23-20] | y |
  108. +------------------------------+---------+---------+
  109. | CRC32 | [19-16] | y |
  110. +------------------------------+---------+---------+
  111. | SHA2 | [15-12] | y |
  112. +------------------------------+---------+---------+
  113. | SHA1 | [11-8] | y |
  114. +------------------------------+---------+---------+
  115. | AES | [7-4] | y |
  116. +------------------------------+---------+---------+
  117. 2) ID_AA64PFR0_EL1 - Processor Feature Register 0
  118. +------------------------------+---------+---------+
  119. | Name | bits | visible |
  120. +------------------------------+---------+---------+
  121. | DIT | [51-48] | y |
  122. +------------------------------+---------+---------+
  123. | MPAM | [43-40] | n |
  124. +------------------------------+---------+---------+
  125. | SVE | [35-32] | y |
  126. +------------------------------+---------+---------+
  127. | GIC | [27-24] | n |
  128. +------------------------------+---------+---------+
  129. | AdvSIMD | [23-20] | y |
  130. +------------------------------+---------+---------+
  131. | FP | [19-16] | y |
  132. +------------------------------+---------+---------+
  133. | EL3 | [15-12] | n |
  134. +------------------------------+---------+---------+
  135. | EL2 | [11-8] | n |
  136. +------------------------------+---------+---------+
  137. | EL1 | [7-4] | n |
  138. +------------------------------+---------+---------+
  139. | EL0 | [3-0] | n |
  140. +------------------------------+---------+---------+
  141. 3) ID_AA64PFR1_EL1 - Processor Feature Register 1
  142. +------------------------------+---------+---------+
  143. | Name | bits | visible |
  144. +------------------------------+---------+---------+
  145. | SME | [27-24] | y |
  146. +------------------------------+---------+---------+
  147. | MTE | [11-8] | y |
  148. +------------------------------+---------+---------+
  149. | SSBS | [7-4] | y |
  150. +------------------------------+---------+---------+
  151. | BT | [3-0] | y |
  152. +------------------------------+---------+---------+
  153. 4) MIDR_EL1 - Main ID Register
  154. +------------------------------+---------+---------+
  155. | Name | bits | visible |
  156. +------------------------------+---------+---------+
  157. | Implementer | [31-24] | y |
  158. +------------------------------+---------+---------+
  159. | Variant | [23-20] | y |
  160. +------------------------------+---------+---------+
  161. | Architecture | [19-16] | y |
  162. +------------------------------+---------+---------+
  163. | PartNum | [15-4] | y |
  164. +------------------------------+---------+---------+
  165. | Revision | [3-0] | y |
  166. +------------------------------+---------+---------+
  167. NOTE: The 'visible' fields of MIDR_EL1 will contain the value
  168. as available on the CPU where it is fetched and is not a system
  169. wide safe value.
  170. 5) ID_AA64ISAR1_EL1 - Instruction set attribute register 1
  171. +------------------------------+---------+---------+
  172. | Name | bits | visible |
  173. +------------------------------+---------+---------+
  174. | I8MM | [55-52] | y |
  175. +------------------------------+---------+---------+
  176. | DGH | [51-48] | y |
  177. +------------------------------+---------+---------+
  178. | BF16 | [47-44] | y |
  179. +------------------------------+---------+---------+
  180. | SB | [39-36] | y |
  181. +------------------------------+---------+---------+
  182. | FRINTTS | [35-32] | y |
  183. +------------------------------+---------+---------+
  184. | GPI | [31-28] | y |
  185. +------------------------------+---------+---------+
  186. | GPA | [27-24] | y |
  187. +------------------------------+---------+---------+
  188. | LRCPC | [23-20] | y |
  189. +------------------------------+---------+---------+
  190. | FCMA | [19-16] | y |
  191. +------------------------------+---------+---------+
  192. | JSCVT | [15-12] | y |
  193. +------------------------------+---------+---------+
  194. | API | [11-8] | y |
  195. +------------------------------+---------+---------+
  196. | APA | [7-4] | y |
  197. +------------------------------+---------+---------+
  198. | DPB | [3-0] | y |
  199. +------------------------------+---------+---------+
  200. 6) ID_AA64MMFR0_EL1 - Memory model feature register 0
  201. +------------------------------+---------+---------+
  202. | Name | bits | visible |
  203. +------------------------------+---------+---------+
  204. | ECV | [63-60] | y |
  205. +------------------------------+---------+---------+
  206. 7) ID_AA64MMFR2_EL1 - Memory model feature register 2
  207. +------------------------------+---------+---------+
  208. | Name | bits | visible |
  209. +------------------------------+---------+---------+
  210. | AT | [35-32] | y |
  211. +------------------------------+---------+---------+
  212. 8) ID_AA64ZFR0_EL1 - SVE feature ID register 0
  213. +------------------------------+---------+---------+
  214. | Name | bits | visible |
  215. +------------------------------+---------+---------+
  216. | F64MM | [59-56] | y |
  217. +------------------------------+---------+---------+
  218. | F32MM | [55-52] | y |
  219. +------------------------------+---------+---------+
  220. | I8MM | [47-44] | y |
  221. +------------------------------+---------+---------+
  222. | SM4 | [43-40] | y |
  223. +------------------------------+---------+---------+
  224. | SHA3 | [35-32] | y |
  225. +------------------------------+---------+---------+
  226. | B16B16 | [27-24] | y |
  227. +------------------------------+---------+---------+
  228. | BF16 | [23-20] | y |
  229. +------------------------------+---------+---------+
  230. | BitPerm | [19-16] | y |
  231. +------------------------------+---------+---------+
  232. | AES | [7-4] | y |
  233. +------------------------------+---------+---------+
  234. | SVEVer | [3-0] | y |
  235. +------------------------------+---------+---------+
  236. 8) ID_AA64MMFR1_EL1 - Memory model feature register 1
  237. +------------------------------+---------+---------+
  238. | Name | bits | visible |
  239. +------------------------------+---------+---------+
  240. | AFP | [47-44] | y |
  241. +------------------------------+---------+---------+
  242. 9) ID_AA64ISAR2_EL1 - Instruction set attribute register 2
  243. +------------------------------+---------+---------+
  244. | Name | bits | visible |
  245. +------------------------------+---------+---------+
  246. | CSSC | [55-52] | y |
  247. +------------------------------+---------+---------+
  248. | RPRFM | [51-48] | y |
  249. +------------------------------+---------+---------+
  250. | BC | [23-20] | y |
  251. +------------------------------+---------+---------+
  252. | MOPS | [19-16] | y |
  253. +------------------------------+---------+---------+
  254. | APA3 | [15-12] | y |
  255. +------------------------------+---------+---------+
  256. | GPA3 | [11-8] | y |
  257. +------------------------------+---------+---------+
  258. | RPRES | [7-4] | y |
  259. +------------------------------+---------+---------+
  260. | WFXT | [3-0] | y |
  261. +------------------------------+---------+---------+
  262. 10) MVFR0_EL1 - AArch32 Media and VFP Feature Register 0
  263. +------------------------------+---------+---------+
  264. | Name | bits | visible |
  265. +------------------------------+---------+---------+
  266. | FPDP | [11-8] | y |
  267. +------------------------------+---------+---------+
  268. 11) MVFR1_EL1 - AArch32 Media and VFP Feature Register 1
  269. +------------------------------+---------+---------+
  270. | Name | bits | visible |
  271. +------------------------------+---------+---------+
  272. | SIMDFMAC | [31-28] | y |
  273. +------------------------------+---------+---------+
  274. | SIMDSP | [19-16] | y |
  275. +------------------------------+---------+---------+
  276. | SIMDInt | [15-12] | y |
  277. +------------------------------+---------+---------+
  278. | SIMDLS | [11-8] | y |
  279. +------------------------------+---------+---------+
  280. 12) ID_ISAR5_EL1 - AArch32 Instruction Set Attribute Register 5
  281. +------------------------------+---------+---------+
  282. | Name | bits | visible |
  283. +------------------------------+---------+---------+
  284. | CRC32 | [19-16] | y |
  285. +------------------------------+---------+---------+
  286. | SHA2 | [15-12] | y |
  287. +------------------------------+---------+---------+
  288. | SHA1 | [11-8] | y |
  289. +------------------------------+---------+---------+
  290. | AES | [7-4] | y |
  291. +------------------------------+---------+---------+
  292. Appendix I: Example
  293. -------------------
  294. ::
  295. /*
  296. * Sample program to demonstrate the MRS emulation ABI.
  297. *
  298. * Copyright (C) 2015-2016, ARM Ltd
  299. *
  300. * Author: Suzuki K Poulose <suzuki.poulose@arm.com>
  301. *
  302. * This program is free software; you can redistribute it and/or modify
  303. * it under the terms of the GNU General Public License version 2 as
  304. * published by the Free Software Foundation.
  305. *
  306. * This program is distributed in the hope that it will be useful,
  307. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  308. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  309. * GNU General Public License for more details.
  310. * This program is free software; you can redistribute it and/or modify
  311. * it under the terms of the GNU General Public License version 2 as
  312. * published by the Free Software Foundation.
  313. *
  314. * This program is distributed in the hope that it will be useful,
  315. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  316. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  317. * GNU General Public License for more details.
  318. */
  319. #include <asm/hwcap.h>
  320. #include <stdio.h>
  321. #include <sys/auxv.h>
  322. #define get_cpu_ftr(id) ({ \
  323. unsigned long __val; \
  324. asm("mrs %0, "#id : "=r" (__val)); \
  325. printf("%-20s: 0x%016lx\n", #id, __val); \
  326. })
  327. int main(void)
  328. {
  329. if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
  330. fputs("CPUID registers unavailable\n", stderr);
  331. return 1;
  332. }
  333. get_cpu_ftr(ID_AA64ISAR0_EL1);
  334. get_cpu_ftr(ID_AA64ISAR1_EL1);
  335. get_cpu_ftr(ID_AA64MMFR0_EL1);
  336. get_cpu_ftr(ID_AA64MMFR1_EL1);
  337. get_cpu_ftr(ID_AA64PFR0_EL1);
  338. get_cpu_ftr(ID_AA64PFR1_EL1);
  339. get_cpu_ftr(ID_AA64DFR0_EL1);
  340. get_cpu_ftr(ID_AA64DFR1_EL1);
  341. get_cpu_ftr(MIDR_EL1);
  342. get_cpu_ftr(MPIDR_EL1);
  343. get_cpu_ftr(REVIDR_EL1);
  344. #if 0
  345. /* Unexposed register access causes SIGILL */
  346. get_cpu_ftr(ID_MMFR0_EL1);
  347. #endif
  348. return 0;
  349. }