@@ -15,43 +15,30 @@ use tock_registers::{
15
15
} ;
16
16
17
17
register_bitfields ! { u64 ,
18
- /// The representation of `CCSIDR_EL1` when `FEAT_CCIDX` is implemented.
19
- pub CCSIDR_EL1_WITH_FEAT_CCIDX [
18
+ pub CCSIDR_EL1 [
20
19
/// Number of sets in cache.
21
20
///
22
21
/// A value of 0 indicates 1 set in the cache. The number does not
23
22
/// necessarily have to be a power of 2.
24
- NumSets OFFSET ( 32 ) NUMBITS ( 24 ) [ ] ,
23
+ NumSetsWithCCIDX OFFSET ( 32 ) NUMBITS ( 24 ) [ ] ,
25
24
26
- /// Associativity of cache.
25
+ /// Number of sets in cache.
27
26
///
28
- /// A value of 0 indicates an associativity of 1 . The value does not
27
+ /// A value of 0 indicates 1 set in the cache . The number does not
29
28
/// necessarily have to be a power of 2.
30
- Associativity OFFSET ( 3 ) NUMBITS ( 21 ) [ ] ,
31
-
32
- /// Log2(Number of bytes in cache lline) - 4.
33
- ///
34
- /// **Examples:**
35
- ///
36
- /// - For a line length of 16 bytes: Log2(16) - 4 = 0. This is the minimum line length.
37
- ///
38
- /// - For a line length of 32 bytes: Log2(32) - 4 = 1.
39
- LineSize OFFSET ( 0 ) NUMBITS ( 3 ) [ ]
40
- ] ,
29
+ NumSetsWithoutCCIDX OFFSET ( 13 ) NUMBITS ( 15 ) [ ] ,
41
30
42
- /// The representation of `CCSIDR_EL1` otherwise.
43
- pub CCSIDR_EL1 [
44
- /// Number of sets in cache.
31
+ /// Associativity of cache.
45
32
///
46
- /// A value of 0 indicates 1 set in the cache . The number does not
33
+ /// A value of 0 indicates an associativity of 1 . The value does not
47
34
/// necessarily have to be a power of 2.
48
- NumSets OFFSET ( 13 ) NUMBITS ( 15 ) [ ] ,
35
+ AssociativityWithCCIDX OFFSET ( 3 ) NUMBITS ( 21 ) [ ] ,
49
36
50
37
/// Associativity of cache.
51
38
///
52
39
/// A value of 0 indicates an associativity of 1. The value does not
53
40
/// necessarily have to be a power of 2.
54
- Associativity OFFSET ( 3 ) NUMBITS ( 10 ) [ ] ,
41
+ AssociativityWithoutCCIDX OFFSET ( 3 ) NUMBITS ( 10 ) [ ] ,
55
42
56
43
/// Log2(Number of bytes in cache lline) - 4.
57
44
///
@@ -64,21 +51,55 @@ register_bitfields! {u64,
64
51
]
65
52
}
66
53
67
- pub struct RegWithFeatCcidx ;
68
- pub struct Reg ;
54
+ #[ inline( always) ]
55
+ fn has_feature_ccidx ( ) -> bool {
56
+ use crate :: registers:: ID_AA64MMFR2_EL1 ;
69
57
70
- impl Readable for RegWithFeatCcidx {
71
- type T = u64 ;
72
- type R = CCSIDR_EL1_WITH_FEAT_CCIDX :: Register ;
73
-
74
- sys_coproc_read_raw ! ( u64 , "CCSIDR_EL1" , "x" ) ;
58
+ ID_AA64MMFR2_EL1 . read ( ID_AA64MMFR2_EL1 :: CCIDX ) != 0
75
59
}
76
60
77
- impl Writeable for RegWithFeatCcidx {
78
- type T = u64 ;
79
- type R = CCSIDR_EL1_WITH_FEAT_CCIDX :: Register ;
61
+ pub struct Reg ;
80
62
81
- sys_coproc_write_raw ! ( u64 , "CCSIDR_EL1" , "x" ) ;
63
+ impl Reg {
64
+ /// Reads the [`CCSIDR_EL1`] `NumSets` field, selecting the correct
65
+ /// bit field by checking if the running CPU supports `CCIDX`.
66
+ #[ inline( always) ]
67
+ pub fn get_num_sets ( & self ) -> u64 {
68
+ match has_feature_ccidx ( ) {
69
+ true => self . read ( CCSIDR_EL1 :: NumSetsWithCCIDX ) ,
70
+ false => self . read ( CCSIDR_EL1 :: NumSetsWithoutCCIDX ) ,
71
+ }
72
+ }
73
+
74
+ /// Sets the [`CCSIDR_EL1`] `NumSets` field, selecting the correct
75
+ /// bit field by checking if the running CPU supports `CCIDX`.
76
+ #[ inline( always) ]
77
+ pub fn set_num_sets ( & self , value : u64 ) {
78
+ match has_feature_ccidx ( ) {
79
+ true => self . write ( CCSIDR_EL1 :: NumSetsWithCCIDX . val ( value) ) ,
80
+ false => self . write ( CCSIDR_EL1 :: NumSetsWithoutCCIDX . val ( value) ) ,
81
+ }
82
+ }
83
+
84
+ /// Reads the [`CCSIDR_EL1`] `Associativity` field, selecting the correct
85
+ /// bit field by checking if the running CPU supports `CCIDX`.
86
+ #[ inline( always) ]
87
+ pub fn get_associativity ( & self ) -> u64 {
88
+ match has_feature_ccidx ( ) {
89
+ true => self . read ( CCSIDR_EL1 :: AssociativityWithCCIDX ) ,
90
+ false => self . read ( CCSIDR_EL1 :: AssociativityWithoutCCIDX ) ,
91
+ }
92
+ }
93
+
94
+ /// Sets the [`CCSIDR_EL1`] `Associativity` field, selecting the correct
95
+ /// bit field by checking if the running CPU supports `CCIDX`.
96
+ #[ inline( always) ]
97
+ pub fn set_associativity ( & self , value : u64 ) {
98
+ match has_feature_ccidx ( ) {
99
+ true => self . write ( CCSIDR_EL1 :: AssociativityWithCCIDX . val ( value) ) ,
100
+ false => self . write ( CCSIDR_EL1 :: AssociativityWithoutCCIDX . val ( value) ) ,
101
+ }
102
+ }
82
103
}
83
104
84
105
impl Readable for Reg {
@@ -95,5 +116,4 @@ impl Writeable for Reg {
95
116
sys_coproc_write_raw ! ( u64 , "CCSIDR_EL1" , "x" ) ;
96
117
}
97
118
98
- pub const CCSIDR_EL1_WITH_FEAT_CCIDX : RegWithFeatCcidx = RegWithFeatCcidx ;
99
119
pub const CCSIDR_EL1 : Reg = Reg ;
0 commit comments