Skip to main content

aarch32_cpu/register/hyp/
hactlr.rs

1//! Code for managing HACTRL (*Hyp Auxiliary Control Register*)
2
3use crate::register::{SysReg, SysRegRead, SysRegWrite};
4
5/// HACTRL (*Hyp Auxiliary Control Register*)
6#[bitbybit::bitfield(u32)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Hactlr {
9    /// Controls access to IMP_TESTR1 at EL0 and EL1
10    #[bits(15..=15, rw)]
11    testr1: bool,
12    /// Controls access to IMP_DCERR0, IMP_DCERR1, IMP_ICERR0, IMP_ICERR1,
13    /// IMP_TCMERR0, IMP_TCMERR1, IMP_FLASHERR0, and IMP_FLASHERR1 registers
14    #[bits(13..=13, rw)]
15    err: bool,
16    /// Controls access to IMP_INTMONR at EL1
17    #[bits(12..=12, rw)]
18    intmonr: bool,
19    /// Controls access to IMP_BUSTIMEOUTR at EL1
20    #[bits(10..=10, rw)]
21    bustimeoutr: bool,
22    /// Controls access to QOSR at EL1
23    #[bits(9..=9, rw)]
24    qosr: bool,
25    /// Controls access to IMP_PERIPHPREGIONR at EL1
26    #[bits(8..=8, rw)]
27    periphpregionr: bool,
28    /// Controls access to IMP_FLASHIFREGIONR at EL1
29    #[bits(7..=7, rw)]
30    flashifregionr: bool,
31    /// Controls access to CDBGDCI at EL1
32    #[bits(1..=1, rw)]
33    cdbgdci: bool,
34    /// IMP_CPUACTLR write access control
35    #[bits(0..=0, rw)]
36    cpuactlr: bool,
37}
38
39impl SysReg for Hactlr {
40    const CP: u32 = 15;
41    const CRN: u32 = 1;
42    const OP1: u32 = 4;
43    const CRM: u32 = 0;
44    const OP2: u32 = 1;
45}
46
47impl SysRegRead for Hactlr {}
48
49impl SysRegWrite for Hactlr {}
50
51impl Hactlr {
52    /// Read HACTRL (*Hyp Auxiliary Control Register*)
53    #[inline]
54    pub fn read() -> Hactlr {
55        Self::new_with_raw_value(<Self as SysRegRead>::read_raw())
56    }
57
58    /// Write HACTRL (*Hyp Auxiliary Control Register*)
59    #[inline]
60    pub fn write(value: Self) {
61        // Safety: Writing this register is atomic
62        unsafe {
63            <Self as SysRegWrite>::write_raw(value.raw_value());
64        }
65    }
66
67    /// Modify HACTRL (*Hyp Auxiliary Control Register*)
68    #[inline]
69    pub fn modify<F>(f: F)
70    where
71        F: FnOnce(&mut Self),
72    {
73        let mut value = Self::read();
74        f(&mut value);
75        Self::write(value);
76    }
77}
78
79impl core::fmt::Debug for Hactlr {
80    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81        write!(f, "HACTLR {{ CPUACTLR={}, CDBGDCI={}, FLASHIFREGIONR={}, PERIPHPREGIONR={}, QOSR={}, BUSTIMEOUTR={}, INTMONR={}, ERR={}, TESTR1={} }}",
82            self.cpuactlr() as u8,
83            self.cdbgdci() as u8,
84            self.flashifregionr() as u8,
85            self.periphpregionr() as u8,
86            self.qosr() as u8,
87            self.bustimeoutr() as u8,
88            self.intmonr() as u8,
89            self.err() as u8,
90            self.testr1() as u8
91        )
92    }
93}
94
95#[cfg(feature = "defmt")]
96impl defmt::Format for Hactlr {
97    fn format(&self, f: defmt::Formatter) {
98        defmt::write!(f, "HACTLR {{ CPUACTLR={0=0..1}, CDBGDCI={0=1..2}, FLASHIFREGIONR={0=7..8}, PERIPHPREGIONR={0=8..9}, QOSR={0=9..10}, BUSTIMEOUTR={0=10..11}, INTMONR={0=12..13}, ERR={0=13..14}, TESTR1={0=15..16} }}", self.raw_value())
99    }
100}