Advance firmware and IOMMU support

Red Bear OS Team
This commit is contained in:
2026-04-16 12:43:50 +01:00
parent f44940a562
commit 35193bb32d
6 changed files with 130 additions and 46 deletions
@@ -92,15 +92,6 @@ impl AmdViUnit {
})?;
self.mmio = Some(MmioMapping { region });
let control_initial = self.mmio_read32(offsets::CONTROL)?;
let status_initial = self.mmio_read32(offsets::STATUS)?;
info!(
"amd-vi: unit {} initial control={:#x} status={:#x}",
self.info.unit_id(),
control_initial,
status_initial
);
self.disable_unit()?;
let device_table = DeviceTable::new().map_err(|err| err.to_string())?;
@@ -126,12 +117,6 @@ impl AmdViUnit {
if ext & ext_feature::NX_SUP != 0 {
control_value |= control::NX_EN;
}
let control_before = self.mmio_read32(offsets::CONTROL)?;
info!(
"amd-vi: unit {} control register before enable write = {:#x}",
self.info.unit_id(),
control_before
);
self.mmio_write32(offsets::CONTROL, control_value)?;
self.mmio_write32(offsets::CONTROL, control_value | control::IOMMU_ENABLE)?;
@@ -218,8 +203,10 @@ impl AmdViUnit {
}
fn wait_for_running(&self, expected: bool) -> Result<(), String> {
let expected_mask = status::CMDBUF_RUN | status::EVT_RUN;
for _ in 0..100_000 {
let running = self.mmio_read32(offsets::STATUS)? & status::IOMMU_RUNNING != 0;
let status = self.mmio_read32(offsets::STATUS)?;
let running = (status & expected_mask) == expected_mask;
if running == expected {
return Ok(());
}
@@ -227,8 +214,10 @@ impl AmdViUnit {
}
Err(format!(
"timed out waiting for AMD-Vi unit {} running={expected}",
self.info.unit_id()
"timed out waiting for AMD-Vi unit {} running={expected} (status={:#x}, expected_mask={:#x})",
self.info.unit_id(),
self.mmio_read32(offsets::STATUS).unwrap_or_default(),
expected_mask,
))
}
@@ -7,7 +7,7 @@ use redox_driver_sys::dma::DmaBuffer;
pub const DEVICE_TABLE_ENTRIES: usize = 65_536;
pub const DTE_SIZE: usize = 32;
const DEVICE_TABLE_BYTES: usize = DEVICE_TABLE_ENTRIES * DTE_SIZE;
pub const DEVICE_TABLE_BYTES: usize = DEVICE_TABLE_ENTRIES * DTE_SIZE;
const DTE_VALID_BIT: u64 = 1 << 0;
const DTE_TRANSLATION_VALID_BIT: u64 = 1 << 1;
@@ -27,7 +27,7 @@ pub mod control {
pub const EVENT_LOG_EN: u32 = 1 << 2;
pub const EVENT_INT_EN: u32 = 1 << 3;
pub const COM_WAIT_INT_EN: u32 = 1 << 4;
pub const CMD_BUF_EN: u32 = 1 << 5;
pub const CMD_BUF_EN: u32 = 1 << 12;
pub const PPR_LOG_EN: u32 = 1 << 6;
pub const PPR_INT_EN: u32 = 1 << 7;
pub const PPR_EN: u32 = 1 << 8;
@@ -46,12 +46,14 @@ pub mod control {
}
pub mod status {
pub const IOMMU_RUNNING: u32 = 1 << 0;
pub const EVENT_OVERFLOW: u32 = 1 << 1;
pub const EVENT_LOG_INT: u32 = 1 << 2;
pub const COM_WAIT_INT: u32 = 1 << 3;
pub const PPR_OVERFLOW: u32 = 1 << 4;
pub const PPR_INT: u32 = 1 << 5;
pub const EVENT_OVERFLOW: u32 = 1 << 0;
pub const EVENT_LOG_INT: u32 = 1 << 1;
pub const COM_WAIT_INT: u32 = 1 << 2;
pub const EVT_RUN: u32 = 1 << 3;
pub const CMDBUF_RUN: u32 = 1 << 4;
pub const PPR_LOG_OVERFLOW: u32 = 1 << 5;
pub const PPR_LOG_INT: u32 = 1 << 6;
pub const PPR_RUN: u32 = 1 << 7;
}
pub mod ext_feature {