aarch64/irq.rs
1use aarch64_cpu::registers::DAIF;
2use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
3
4/// Enable interrupts
5#[inline]
6pub fn enable() {
7 DAIF.modify(DAIF::A::Masked + DAIF::I::Masked + DAIF::F::Masked);
8}
9
10/// Disable interrupts
11#[inline]
12pub fn disable() {
13 DAIF.modify(DAIF::A::Unmasked + DAIF::I::Unmasked + DAIF::F::Unmasked);
14}
15
16/// Disable IRQs (nested)
17///
18/// Disable all IRQs when unsure if IRQs were enabled at all.
19/// This function together with nested_enable can be used
20/// in situations when interrupts shouldn't be activated if they
21/// were not activated before calling this function.
22#[inline]
23pub fn nested_disable() -> u64 {
24 let bits = DAIF.get();
25 disable();
26 bits
27}
28
29/// Enable all IRQs (nested)
30///
31/// Can be used in conjunction with nested_disable() to only enable
32/// interrupts again if they were enabled before.
33#[inline]
34pub fn nested_enable(bits: u64) {
35 DAIF.set(bits);
36}