Extract IOMMU register operations

This commit is contained in:
Yuke Peng
2024-07-18 20:48:56 +08:00
committed by Tate, Hongliang Tian
parent 63b42bff73
commit 0bf3595964
4 changed files with 181 additions and 192 deletions

View File

@ -12,7 +12,7 @@ use spin::Once;
use trapframe::TrapFrame;
use volatile::{access::ReadWrite, Volatile};
use super::remapping::Capability;
use super::registers::Capability;
use crate::{mm::Vaddr, trap::IrqLine};
#[derive(Debug)]
@ -37,10 +37,13 @@ impl FaultEventRegisters {
///
/// User must ensure the base_register_vaddr is read from DRHD
unsafe fn new(base_register_vaddr: Vaddr) -> Self {
let capability = Volatile::new_read_only(&*((base_register_vaddr + 0x08) as *const u64));
let length = ((capability.read() & Capability::NFR.bits()) >> 40) + 1;
let capability_reg =
Volatile::new_read_only(&*((base_register_vaddr + 0x08) as *const u64));
let capability = Capability::new(capability_reg.read());
let length = capability.fault_recording_number() + 1;
let mut recordings = Vec::with_capacity(length as usize);
let offset = (capability.read() & 0x3_ff00_0000) >> 24;
let offset = capability.fault_recording_register_offset();
for i in 0..length {
recordings.push(Volatile::new(
&mut *((base_register_vaddr + 16 * (offset + i) as usize) as *mut u128),