1
1
//! Code for managing HPRBAR (*Hyp Protection Region Base Address Register*)
2
2
3
+ use arbitrary_int:: u26;
4
+
3
5
use crate :: register:: { SysReg , SysRegRead , SysRegWrite } ;
4
6
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
+
5
35
/// 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
+
7
52
impl SysReg for Hprbar {
8
53
const CP : u32 = 15 ;
9
54
const CRN : u32 = 6 ;
@@ -16,20 +61,16 @@ impl Hprbar {
16
61
#[ inline]
17
62
/// Reads HPRBAR (*Hyp Protection Region Base Address Register*)
18
63
pub fn read ( ) -> Hprbar {
19
- unsafe { Self ( <Self as SysRegRead >:: read_raw ( ) ) }
64
+ unsafe { Self :: new_with_raw_value ( <Self as SysRegRead >:: read_raw ( ) ) }
20
65
}
21
66
}
22
67
impl crate :: register:: SysRegWrite for Hprbar { }
23
68
impl Hprbar {
24
69
#[ inline]
25
70
/// 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 ) {
31
72
unsafe {
32
- <Self as SysRegWrite >:: write_raw ( value. 0 ) ;
73
+ <Self as SysRegWrite >:: write_raw ( value. raw_value ( ) ) ;
33
74
}
34
75
}
35
76
}
0 commit comments