cortex_a/registers/
vttbr_el2.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//
3// Copyright (c) 2018-2022 by the author(s)
4//
5// Author(s):
6//   - KarimAllah Ahmed <karahmed@amazon.com>
7//   - Andre Richter <andre.o.richter@gmail.com>
8
9use tock_registers::{
10    interfaces::{Readable, Writeable},
11    register_bitfields,
12};
13
14register_bitfields! {u64,
15    pub VTTBR_EL2 [
16        /// An VMID for the translation table
17        ///
18        /// If the implementation only supports 8-bit VM IDs the top 8 bits are RES0
19        VMID  OFFSET(48) NUMBITS(16) [],
20
21        /// Translation table base address
22        BADDR OFFSET(1) NUMBITS(48) [],
23
24        /// Common not Private
25        CnP   OFFSET(0) NUMBITS(1) []
26    ]
27}
28
29pub struct Reg;
30
31impl Readable for Reg {
32    type T = u64;
33    type R = VTTBR_EL2::Register;
34
35    sys_coproc_read_raw!(u64, "VTTBR_EL2", "x");
36}
37
38impl Writeable for Reg {
39    type T = u64;
40    type R = VTTBR_EL2::Register;
41
42    sys_coproc_write_raw!(u64, "VTTBR_EL2", "x");
43}
44
45impl Reg {
46    #[inline(always)]
47    pub fn get_baddr(&self) -> u64 {
48        self.read(VTTBR_EL2::BADDR) << 1
49    }
50
51    #[inline(always)]
52    pub fn set_baddr(&self, addr: u64) {
53        self.write(VTTBR_EL2::BADDR.val(addr >> 1));
54    }
55}
56
57pub const VTTBR_EL2: Reg = Reg {};