aarch32_cpu/register/
dccsw.rs

1//! DCCSW (*Clean Data or Unified Cache line by Set/Way.*)
2
3use arbitrary_int::u3;
4
5use crate::register::{SysReg, SysRegWrite};
6
7#[derive(Debug, Copy, Clone)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct Dccsw(pub u32);
11
12impl Dccsw {
13    /// Create DCCSW value for cache cleaning by set and way.
14    ///
15    /// ## Generics
16    ///
17    /// - A: log2(ASSOCIATIVITY) rounded up to the next integer if necessary. For example, a 4-way
18    ///   associative cache will have a value of 2 and a 8-way associative cache will have a value of
19    ///   3.
20    /// - N: log2(LINE LENGTH). For example, a 32-byte line length (4 words) will have a value of
21    ///   5.
22    #[inline]
23    pub const fn new<const A: usize, const N: usize>(way: u8, set: u16, level: u3) -> Self {
24        Self(super::dc_sw_ops::new::<A, N>(way, set, level))
25    }
26
27    /// Create DCCSW value for cache cleaning by set and way.
28    /// Returns [None] on invalid input.
29    ///
30    /// # Arguments
31    ///
32    /// - a: log2(ASSOCIATIVITY) rounded up to the next integer if necessary. For example, a 4-way
33    ///   associative cache will have a value of 2 and a 8-way associative cache will have a value of
34    ///   3.
35    /// - n: log2(LINE LENGTH). For example, a 32-byte line length (4 words) will have a value of
36    ///   5.
37    #[inline]
38    pub const fn new_with_offsets(a: usize, way: u8, n: usize, set: u16, level: u3) -> Self {
39        Self(super::dc_sw_ops::new_with_offsets(a, way, n, set, level))
40    }
41}
42
43impl SysReg for Dccsw {
44    const CP: u32 = 15;
45    const CRN: u32 = 7;
46    const OP1: u32 = 0;
47    const CRM: u32 = 10;
48    const OP2: u32 = 2;
49}
50
51impl crate::register::SysRegWrite for Dccsw {}
52
53impl Dccsw {
54    #[inline]
55    /// Writes DCCSW (*Clean Data or Unified Cache line by Set/Way.*)
56    ///
57    /// # Safety
58    ///
59    /// Ensure that this value is appropriate for this register
60    pub unsafe fn write(value: Self) {
61        unsafe {
62            <Self as SysRegWrite>::write_raw(value.0);
63        }
64    }
65}