Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit c6f8932

Browse files
vbe0201andre-richter
authored andcommitted
Add CCSIDR_EL1 getters/setters with respect to CCIDX availability
1 parent d6dfc21 commit c6f8932

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

src/registers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod ttbr1_el1;
6161
mod vbar_el1;
6262
mod vbar_el2;
6363

64-
pub use ccsidr_el1::{CCSIDR_EL1, CCSIDR_EL1_WITH_FEAT_CCIDX};
64+
pub use ccsidr_el1::CCSIDR_EL1;
6565
pub use clidr_el1::CLIDR_EL1;
6666
pub use cntfrq_el0::CNTFRQ_EL0;
6767
pub use cnthctl_el2::CNTHCTL_EL2;

src/registers/ccsidr_el1.rs

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,30 @@ use tock_registers::{
1515
};
1616

1717
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 [
2019
/// Number of sets in cache.
2120
///
2221
/// A value of 0 indicates 1 set in the cache. The number does not
2322
/// necessarily have to be a power of 2.
24-
NumSets OFFSET(32) NUMBITS(24) [],
23+
NumSetsWithCCIDX OFFSET(32) NUMBITS(24) [],
2524

26-
/// Associativity of cache.
25+
/// Number of sets in cache.
2726
///
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
2928
/// 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) [],
4130

42-
/// The representation of `CCSIDR_EL1` otherwise.
43-
pub CCSIDR_EL1 [
44-
/// Number of sets in cache.
31+
/// Associativity of cache.
4532
///
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
4734
/// necessarily have to be a power of 2.
48-
NumSets OFFSET(13) NUMBITS(15) [],
35+
AssociativityWithCCIDX OFFSET(3) NUMBITS(21) [],
4936

5037
/// Associativity of cache.
5138
///
5239
/// A value of 0 indicates an associativity of 1. The value does not
5340
/// necessarily have to be a power of 2.
54-
Associativity OFFSET(3) NUMBITS(10) [],
41+
AssociativityWithoutCCIDX OFFSET(3) NUMBITS(10) [],
5542

5643
/// Log2(Number of bytes in cache lline) - 4.
5744
///
@@ -64,21 +51,55 @@ register_bitfields! {u64,
6451
]
6552
}
6653

67-
pub struct RegWithFeatCcidx;
68-
pub struct Reg;
54+
#[inline(always)]
55+
fn has_feature_ccidx() -> bool {
56+
use crate::registers::ID_AA64MMFR2_EL1;
6957

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
7559
}
7660

77-
impl Writeable for RegWithFeatCcidx {
78-
type T = u64;
79-
type R = CCSIDR_EL1_WITH_FEAT_CCIDX::Register;
61+
pub struct Reg;
8062

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+
}
82103
}
83104

84105
impl Readable for Reg {
@@ -95,5 +116,4 @@ impl Writeable for Reg {
95116
sys_coproc_write_raw!(u64, "CCSIDR_EL1", "x");
96117
}
97118

98-
pub const CCSIDR_EL1_WITH_FEAT_CCIDX: RegWithFeatCcidx = RegWithFeatCcidx;
99119
pub const CCSIDR_EL1: Reg = Reg;

0 commit comments

Comments
 (0)