aarch64_cpu/registers/
hcr_el2.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//
3// Copyright (c) 2018-2023 by the author(s)
4//
5// Author(s):
6//   - Andre Richter <andre.o.richter@gmail.com>
7//   - Bradley Landherr <landhb@users.noreply.github.com>
8//   - Javier Alvarez <javier.alvarez@allthingsembedded.com>
9
10//! Hypervisor Configuration Register - EL2
11//!
12//! Provides configuration controls for virtualization, including defining
13//! whether various Non-secure operations are trapped to EL2.
14
15use tock_registers::{
16    interfaces::{Readable, Writeable},
17    register_bitfields,
18};
19
20register_bitfields! {u64,
21    pub HCR_EL2 [
22        /// When FEAT_S2FWB is implemented Forced Write-back changes the combined cachability of stage1
23        /// and stage2 attributes
24        FWB OFFSET(46) NUMBITS(1) [
25           /// Stage2 memory type and cacheability attributes are in bits[5:2] of the stage2 PTE
26           Disabled = 0,
27           /// Stage1 memory type can be overridden by Stage2 descriptor
28           Enabled = 1,
29        ],
30
31        /// Controls the use of instructions related to Pointer Authentication:
32        ///
33        ///   - In EL0, when HCR_EL2.TGE==0 or HCR_EL2.E2H==0, and the associated SCTLR_EL1.En<N><M>==1.
34        ///   - In EL1, the associated SCTLR_EL1.En<N><M>==1.
35        ///
36        /// Traps are reported using EC syndrome value 0x09. The Pointer Authentication instructions
37        /// trapped are:
38        ///
39        /// `AUTDA`, `AUTDB`, `AUTDZA`, `AUTDZB`, `AUTIA`, `AUTIA1716`, `AUTIASP`, `AUTIAZ`, `AUTIB`, `AUTIB1716`,
40        /// `AUTIBSP`, `AUTIBZ`, `AUTIZA`, `AUTIZB`, `PACGA`, `PACDA`, `PACDB`, `PACDZA`, `PACDZB`, `PACIA`,
41        /// `PACIA1716`, `PACIASP`, `PACIAZ`, `PACIB`, `PACIB1716`, `PACIBSP`, `PACIBZ`, `PACIZA`, `PACIZB`,
42        /// `RETAA`, `RETAB`, `BRAA`, `BRAB`, `BLRAA`, `BLRAB`, `BRAAZ`, `BRABZ`, `BLRAAZ`, `BLRABZ`,
43        /// `ERETAA`, `ERETAB`, `LDRAA`, and `LDRAB`.
44        API   OFFSET(41) NUMBITS(1) [
45            EnableTrapPointerAuthInstToEl2 = 0,
46            DisableTrapPointerAuthInstToEl2 = 1
47        ],
48
49        /// Trap registers holding "key" values for Pointer Authentication. Traps accesses to the
50        /// following registers from EL1 to EL2, when EL2 is enabled in the current Security state,
51        /// reported using EC syndrome value 0x18:
52        ///
53        /// `APIAKeyLo_EL1`, `APIAKeyHi_EL1`, `APIBKeyLo_EL1`, `APIBKeyHi_EL1`, `APDAKeyLo_EL1`,
54        /// `APDAKeyHi_EL1`, `APDBKeyLo_EL1`, `APDBKeyHi_EL1`, `APGAKeyLo_EL1`, and `APGAKeyHi_EL1`.
55        APK   OFFSET(40) NUMBITS(1) [
56            EnableTrapPointerAuthKeyRegsToEl2 = 0,
57            DisableTrapPointerAuthKeyRegsToEl2 = 1,
58        ],
59
60        /// Route synchronous External abort exceptions to EL2.
61        ///   if 0: This control does not cause exceptions to be routed from EL0 and EL1 to EL2.
62        ///   if 1: Route synchronous External abort exceptions from EL0 and EL1 to EL2, when EL2 is
63        ///         enabled in the current Security state, if not routed to EL3.
64        TEA   OFFSET(37) NUMBITS(1) [
65            DisableTrapSyncExtAbortsToEl2 = 0,
66            EnableTrapSyncExtAbortsToEl2 = 1,
67        ],
68
69        /// Trap accesses of Error Record registers. Enables a trap to EL2 on accesses of
70        /// Error Record registers.
71        ///
72        /// 0 Accesses of the specified Error Record registers are not trapped by this mechanism.
73        /// 1 Accesses of the specified Error Record registers at EL1 are trapped to EL2,
74        ///   unless the instruction generates a higher priority exception.
75        TERR  OFFSET(36) NUMBITS(1) [],
76
77        /// Trap LOR registers. Traps Non-secure EL1 accesses to LORSA_EL1, LOREA_EL1, LORN_EL1,
78        /// LORC_EL1, and LORID_EL1 registers to EL2.
79        ///
80        /// 0 This control does not cause any instructions to be trapped.
81        /// 1 Non-secure EL1 accesses to the LOR registers are trapped to EL2.
82        TLOR  OFFSET(35) NUMBITS(1) [],
83
84        /// EL2 Host. Enables a configuration where a Host Operating System is running in EL2, and
85        /// the Host Operating System's applications are running in EL0.
86        E2H   OFFSET(34) NUMBITS(1) [
87            DisableOsAtEl2 = 0,
88            EnableOsAtEl2 = 1
89        ],
90
91        /// Execution state control for lower Exception levels:
92        ///
93        /// 0 Lower levels are all AArch32.
94        /// 1 The Execution state for EL1 is AArch64. The Execution state for EL0 is determined by
95        ///   the current value of PSTATE.nRW when executing at EL0.
96        ///
97        /// If all lower Exception levels cannot use AArch32 then this bit is RAO/WI.
98        ///
99        /// In an implementation that includes EL3, when SCR_EL3.NS==0, the PE behaves as if this
100        /// bit has the same value as the SCR_EL3.RW bit for all purposes other than a direct read
101        /// or write access of HCR_EL2.
102        ///
103        /// The RW bit is permitted to be cached in a TLB.
104        ///
105        /// When ARMv8.1-VHE is implemented, and the value of HCR_EL2.{E2H, TGE} is {1, 1}, this
106        /// field behaves as 1 for all purposes other than a direct read of the value of this bit.
107        RW   OFFSET(31) NUMBITS(1) [
108            AllLowerELsAreAarch32 = 0,
109            EL1IsAarch64 = 1
110        ],
111
112        /// Trap General Exceptions, from EL0.
113        ///
114        /// If enabled:
115        ///   - When EL2 is not enabled in the current Security state, this control has no effect on
116        ///     execution at EL0.
117        ///
118        ///   - When EL2 is enabled in the current Security state, in all cases:
119        ///
120        ///       - All exceptions that would be routed to EL1 are routed to EL2.
121        ///       - If EL1 is using AArch64, the SCTLR_EL1.M field is treated as being 0 for all
122        ///         purposes other than returning the result of a direct read of SCTLR_EL1.
123        ///       - If EL1 is using AArch32, the SCTLR.M field is treated as being 0 for all
124        ///         purposes other than returning the result of a direct read of SCTLR.
125        ///       - All virtual interrupts are disabled.
126        ///       - Any IMPLEMENTATION DEFINED mechanisms for signaling virtual interrupts are
127        ///         disabled.
128        ///       - An exception return to EL1 is treated as an illegal exception return.
129        ///       - The MDCR_EL2.{TDRA, TDOSA, TDA, TDE} fields are treated as being 1 for all
130        ///         purposes other than returning the result of a direct read of MDCR_EL2.
131        ///
132        ///   - In addition, when EL2 is enabled in the current Security state, if:
133        ///
134        ///       - HCR_EL2.E2H is 0, the Effective values of the HCR_EL2.{FMO, IMO, AMO} fields
135        ///         are 1.
136        ///       - HCR_EL2.E2H is 1, the Effective values of the HCR_EL2.{FMO, IMO, AMO} fields
137        ///         are 0.
138        ///
139        ///   - For further information on the behavior of this bit when E2H is 1, see 'Behavior of
140        ///     HCR_EL2.E2H'.
141        TGE   OFFSET(27) NUMBITS(1) [
142            DisableTrapGeneralExceptionsToEl2 = 0,
143            EnableTrapGeneralExceptionsToEl2 = 1,
144        ],
145
146        /// Trap data or unified cache maintenance instructions that operate by Set/Way.
147        /// Traps execution of those cache maintenance instructions at EL1 to EL2, when
148        /// EL2 is enabled in the current Security state.
149        ///
150        /// 0 This control does not cause any instructions to be trapped.
151        /// 1 Execution of the specified instructions is trapped to EL2, when EL2 is enabled
152        /// in the current Security state.
153        TSW   OFFSET(22) NUMBITS(1) [],
154
155        /// Trap Auxiliary Control Registers. Traps EL1 accesses to the Auxiliary Control Registers
156        /// to EL2, when EL2 is enabled in the current Security state
157        ///
158        /// 0 This control does not cause any instructions to be trapped.
159        /// 1 EL1 accesses to the specified registers are trapped to EL2, when EL2 is enabled in the
160        ///   current Security state.
161        TACR  OFFSET(21) NUMBITS(1) [],
162
163        /// Trap IMPLEMENTATION DEFINED functionality. Traps EL1 accesses to the encodings reserved
164        /// for IMPLEMENTATION DEFINED functionality to EL2, when EL2 is enabled in the current
165        /// Security state
166        ///
167        /// 0 This control does not cause any instructions to be trapped.
168        /// 1 EL1 accesses to or execution of the specified encodings reserved for IMPLEMENTATION
169        /// DEFINED functionality are trapped to EL2, when EL2 is enabled in the current Security
170        /// state.
171        TIDCP OFFSET(20) NUMBITS(1) [],
172
173        /// Trap ID group 3. Traps EL1 reads of group 3 ID registers to EL2, when EL2 is enabled
174        /// in the current Security state.
175        ///
176        /// 0 This control does not cause any instructions to be trapped.
177        /// 1 The specified EL1 read accesses to ID group 3 registers are trapped to EL2, when EL2
178        /// is enabled in the current Security state.
179        TID3  OFFSET(18) NUMBITS(1) [],
180
181        /// Trap SMC instructions. Traps EL1 execution of SMC instructions to EL2, when EL2 is
182        /// enabled in the current Security state.
183        ///
184        /// If execution is in AArch64 state, the trap is reported using EC syndrome value 0x17.
185        ///
186        /// HCR_EL2.TSC traps execution of the SMC instruction. It is not a routing control for
187        /// the SMC exception. Trap exceptions and SMC exceptions have different preferred return
188        /// addresses.
189        ///
190        /// If disabled, this control does not cause any instructions to be trapped.
191        ///
192        /// If enabled:
193        ///   - If EL3 is implemented, then any attempt to execute an SMC instruction at EL1 is
194        ///     trapped to EL2, when EL2 is enabled in the current Security state, regardless of
195        ///     the value of SCR_EL3.SMD.
196        ///   - If EL3 is not implemented, FEAT_NV is implemented, and HCR_EL2.NV is 1, then any
197        ///     attempt to execute an SMC instruction at EL1 using AArch64 is trapped to EL2,
198        ///     when EL2 is enabled in the current Security state.
199        ///   - If EL3 is not implemented, and either FEAT_NV is not implemented or HCR_EL2.NV is 0,
200        ///     then it is IMPLEMENTATION DEFINED whether:
201        ///       - Any attempt to execute an SMC instruction at EL1 is trapped to EL2, when EL2 is
202        ///         enabled in the current Security state.
203        ///       - Any attempt to execute an SMC instruction is UNDEFINED.
204        ///
205        /// SMC instructions are UNDEFINED at EL0.
206        ///
207        /// If EL3 is not implemented, and either FEAT_NV is not implemented or HCR_EL2.NV is 0,
208        /// then it is IMPLEMENTATION DEFINED whether this bit is:
209        ///   - RES0.
210        ///   - Implemented with the functionality as described in HCR_EL2.TSC.
211        ///
212        /// When HCR_EL2.TGE is 1, the PE ignores the value of this field for all purposes other
213        /// than a direct read of this field.
214        TSC   OFFSET(19) NUMBITS(1) [
215            DisableTrapEl1SmcToEl2 = 0,
216            EnableTrapEl1SmcToEl2 = 1,
217        ],
218
219        /// Default Cacheability.
220        ///
221        /// 0 This control has no effect on the Non-secure EL1&0 translation regime.
222        ///
223        /// 1 In Non-secure state:
224        ///   - When EL1 is using AArch64, the PE behaves as if the value of the SCTLR_EL1.M field
225        ///     is 0 for all purposes other than returning the value of a direct read of SCTLR_EL1.
226        ///
227        ///   - When EL1 is using AArch32, the PE behaves as if the value of the SCTLR.M field is 0
228        ///     for all purposes other than returning the value of a direct read of SCTLR.
229        ///
230        ///   - The PE behaves as if the value of the HCR_EL2.VM field is 1 for all purposes other
231        ///     than returning the value of a direct read of HCR_EL2.
232        ///
233        ///   - The memory type produced by stage 1 of the EL1&0 translation regime is Normal
234        ///     Non-Shareable, Inner Write-Back Read-Allocate Write-Allocate, Outer Write-Back
235        ///     Read-Allocate Write-Allocate.
236        ///
237        /// This field has no effect on the EL2, EL2&0, and EL3 translation regimes.
238        ///
239        /// This field is permitted to be cached in a TLB.
240        ///
241        /// In an implementation that includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
242        /// as if this field is 0 for all purposes other than a direct read or write access of
243        /// HCR_EL2.
244        ///
245        /// When ARMv8.1-VHE is implemented, and the value of HCR_EL2.{E2H, TGE} is {1, 1}, this
246        /// field behaves as 0 for all purposes other than a direct read of the value of this field.
247        DC   OFFSET(12) NUMBITS(1) [],
248
249        /// Barrier Shareability upgrade. This field determines the minimum shareability domain that
250        /// is applied to any barrier instruction executed from EL1 or EL0.
251        BSU  OFFSET(10) NUMBITS(2) [
252            NoEffect = 0b00,
253            InnerShareable = 0b01,
254            OuterShareable = 0b10,
255            FullSystem = 0b11
256        ],
257
258        /// Force broadcast. Causes the following instructions to be broadcast within the Inner
259        /// Shareable domain when executed from EL1.
260        ///
261        /// 0 This field has no effect on the operation of the specified instructions.
262        /// 1 When one of the specified instruction is executed at EL1, the instruction is broadcast
263        /// within the Inner Shareable shareability domain.
264        FB    OFFSET(9) NUMBITS(1) [],
265
266        /// Physical SError interrupt routing.
267        ///   - If bit is 1 when executing at any Exception level, and EL2 is enabled in the current
268        ///     Security state:
269        ///     - Physical SError interrupts are taken to EL2, unless they are routed to EL3.
270        ///     - When the value of HCR_EL2.TGE is 0, then virtual SError interrupts are enabled.
271        AMO   OFFSET(5) NUMBITS(1) [],
272
273        /// Physical IRQ Routing.
274        ///
275        /// If this bit is 0:
276        ///   - When executing at Exception levels below EL2, and EL2 is enabled in the current
277        ///     Security state:
278        ///     - When the value of HCR_EL2.TGE is 0, Physical IRQ interrupts are not taken to EL2.
279        ///     - When the value of HCR_EL2.TGE is 1, Physical IRQ interrupts are taken to EL2
280        ///       unless they are routed to EL3.
281        ///     - Virtual IRQ interrupts are disabled.
282        ///
283        /// If this bit is 1:
284        ///   - When executing at any Exception level, and EL2 is enabled in the current Security
285        ///     state:
286        ///     - Physical IRQ interrupts are taken to EL2, unless they are routed to EL3.
287        ///     - When the value of HCR_EL2.TGE is 0, then Virtual IRQ interrupts are enabled.
288        ///
289        /// If EL2 is enabled in the current Security state, and the value of HCR_EL2.TGE is 1:
290        ///   - Regardless of the value of the IMO bit, physical IRQ Interrupts target EL2 unless
291        ///     they are routed to EL3.
292        ///   - When FEAT_VHE is not implemented, or if HCR_EL2.E2H is 0, this field behaves as 1
293        ///     for all purposes other than a direct read of the value of this bit.
294        ///   - When FEAT_VHE is implemented and HCR_EL2.E2H is 1, this field behaves as 0 for all
295        ///     purposes other than a direct read of the value of this bit.
296        ///
297        /// For more information, see 'Asynchronous exception routing'.
298        IMO   OFFSET(4) NUMBITS(1) [
299            DisableVirtualIRQ = 0,
300            EnableVirtualIRQ = 1,
301        ],
302
303        /// Physical FIQ Routing.
304        /// If this bit is 0:
305        ///   - When executing at Exception levels below EL2, and EL2 is enabled in the current
306        ///     Security state:
307        ///     - When the value of HCR_EL2.TGE is 0, Physical FIQ interrupts are not taken to EL2.
308        ///     - When the value of HCR_EL2.TGE is 1, Physical FIQ interrupts are taken to EL2
309        ///       unless they are routed to EL3.
310        ///     - Virtual FIQ interrupts are disabled.
311        ///
312        /// If this bit is 1:
313        ///   - When executing at any Exception level, and EL2 is enabled in the current Security
314        ///     state:
315        ///     - Physical FIQ interrupts are taken to EL2, unless they are routed to EL3.
316        ///     - When HCR_EL2.TGE is 0, then Virtual FIQ interrupts are enabled.
317        ///
318        /// If EL2 is enabled in the current Security state and the value of HCR_EL2.TGE is 1:
319        ///   - Regardless of the value of the FMO bit, physical FIQ Interrupts target EL2 unless
320        ///     they are routed to EL3.
321        ///   - When FEAT_VHE is not implemented, or if HCR_EL2.E2H is 0, this field behaves as 1
322        ///     for all purposes other than a direct read of the value of this bit.
323        ///   - When FEAT_VHE is implemented and HCR_EL2.E2H is 1, this field behaves as 0 for all
324        ///     purposes other than a direct read of the value of this bit.
325        ///
326        /// For more information, see 'Asynchronous exception routing'.
327        FMO   OFFSET(3) NUMBITS(1) [
328            DisableVirtualFIQ = 0,
329            EnableVirtualFIQ = 1,
330        ],
331
332        /// Set/Way Invalidation Override. Causes Non-secure EL1 execution of the data cache
333        /// invalidate by set/way instructions to perform a data cache clean and invalidate by
334        /// set/way:
335        ///
336        /// 0 This control has no effect on the operation of data cache invalidate by set/way
337        ///   instructions.
338        ///
339        /// 1 Data cache invalidate by set/way instructions perform a data cache clean and
340        ///   invalidate by set/way.
341        ///
342        /// When the value of this bit is 1:
343        ///
344        /// AArch32: DCISW performs the same invalidation as a DCCISW instruction.
345        ///
346        /// AArch64: DC ISW performs the same invalidation as a DC CISW instruction.
347        ///
348        /// This bit can be implemented as RES 1.
349        ///
350        /// In an implementation that includes EL3, when the value of SCR_EL3.NS is 0 the PE behaves
351        /// as if this field is 0 for all purposes other than a direct read or write access of
352        /// HCR_EL2.
353        ///
354        /// When HCR_EL2.TGE is 1, the PE ignores the value of this field for all purposes other
355        /// than a direct read of this field.
356        SWIO OFFSET(1) NUMBITS(1) [],
357
358        /// Virtualization enable. Enables stage 2 address translation for the EL1&0 translation regime,
359        /// when EL2 is enabled in the current Security state. The possible values are:
360        ///
361        /// 0    EL1&0 stage 2 address translation disabled.
362        /// 1    EL1&0 stage 2 address translation enabled.
363        ///
364        /// When the value of this bit is 1, data cache invalidate instructions executed at EL1 perform
365        /// a data cache clean and invalidate. For the invalidate by set/way instruction this behavior
366        /// applies regardless of the value of the HCR_EL2.SWIO bit.
367        ///
368        /// This bit is permitted to be cached in a TLB.
369        ///
370        /// When ARMv8.1-VHE is implemented, and the value of HCR_EL2.{E2H, TGE} is {1, 1}, this
371        /// field behaves as 0 for all purposes other than a direct read of the value of this field.
372        VM OFFSET(0) NUMBITS(1) [
373            Disable = 0,
374            Enable = 1
375        ]
376    ]
377}
378
379pub struct Reg;
380
381impl Readable for Reg {
382    type T = u64;
383    type R = HCR_EL2::Register;
384
385    sys_coproc_read_raw!(u64, "HCR_EL2", "x");
386}
387
388impl Writeable for Reg {
389    type T = u64;
390    type R = HCR_EL2::Register;
391
392    sys_coproc_write_raw!(u64, "HCR_EL2", "x");
393}
394
395pub const HCR_EL2: Reg = Reg {};