11//! Code for managing HPRBAR (*Hyp Protection Region Base Address Register*)
22
3+ use arbitrary_int:: u26;
4+
35use crate :: register:: { SysReg , SysRegRead , SysRegWrite } ;
46
7+ /// Shareability for an MPU Region
8+ #[ derive( Debug , PartialEq , Eq ) ]
9+ #[ bitbybit:: bitenum( u2, exhaustive = true ) ]
10+ pub enum Shareability {
11+ /// Non-shareable
12+ NonShareable = 0b00 ,
13+ /// Reserved
14+ Reserved = 0b01 ,
15+ /// Outer-Shareable
16+ OuterShareable = 0b10 ,
17+ /// Inner-Shareable
18+ InnerShareable = 0b11 ,
19+ }
20+
21+ /// Access Permissions for an MPU Region
22+ #[ derive( Debug , PartialEq , Eq ) ]
23+ #[ bitbybit:: bitenum( u2, exhaustive = true ) ]
24+ pub enum AccessPerms {
25+ /// Read-Write at EL2, No access at EL1/0
26+ ReadWriteNoEL10 = 0b00 ,
27+ /// Read-Write at EL2, EL1, and EL0
28+ ReadWrite = 0b01 ,
29+ /// Read-Only at EL2, No access at EL1/0
30+ ReadOnlyNoEL10 = 0b10 ,
31+ /// Read-Only at EL2, EL1, and EL0
32+ ReadOnly = 0b11 ,
33+ }
34+
535/// HPRBAR (*Hyp Protection Region Base Address Register*)
6- pub struct Hprbar ( pub u32 ) ;
36+ #[ bitbybit:: bitfield( u32 ) ]
37+ pub struct Hprbar {
38+ /// Base Address
39+ #[ bits( 6 ..=31 , rw) ]
40+ base : u26 ,
41+ /// Shareability
42+ #[ bits( 3 ..=4 , rw) ]
43+ shareability : Shareability ,
44+ /// Access Permissions
45+ #[ bits( 1 ..=2 , rw) ]
46+ access_perms : AccessPerms ,
47+ /// Execute Never
48+ #[ bits( 0 ..=0 , rw) ]
49+ nx : bool ,
50+ }
51+
752impl SysReg for Hprbar {
853 const CP : u32 = 15 ;
954 const CRN : u32 = 6 ;
@@ -16,20 +61,16 @@ impl Hprbar {
1661 #[ inline]
1762 /// Reads HPRBAR (*Hyp Protection Region Base Address Register*)
1863 pub fn read ( ) -> Hprbar {
19- unsafe { Self ( <Self as SysRegRead >:: read_raw ( ) ) }
64+ unsafe { Self :: new_with_raw_value ( <Self as SysRegRead >:: read_raw ( ) ) }
2065 }
2166}
2267impl crate :: register:: SysRegWrite for Hprbar { }
2368impl Hprbar {
2469 #[ inline]
2570 /// Writes HPRBAR (*Hyp Protection Region Base Address Register*)
26- ///
27- /// # Safety
28- ///
29- /// Ensure that this value is appropriate for this register
30- pub unsafe fn write ( value : Self ) {
71+ pub fn write ( value : Self ) {
3172 unsafe {
32- <Self as SysRegWrite >:: write_raw ( value. 0 ) ;
73+ <Self as SysRegWrite >:: write_raw ( value. raw_value ( ) ) ;
3374 }
3475 }
3576}
0 commit comments