From 9bc3f24a98e38955cbb4d8301c30b21b05a735d7 Mon Sep 17 00:00:00 2001 From: Vasilito Date: Mon, 4 May 2026 19:14:28 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20driver-sys=20MsiAllocation=20type=20chai?= =?UTF-8?q?n=20=E2=80=94=20alloc=5Fcpu=5Fid=20+=20u32=20irq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing alloc_cpu_id() function (atomic round-robin CPU selection). Fix type chain: MsiAllocation.irq u8→u32 to match allocate_irq_vector return type. irq_set_affinity accepts u32 irq for consistency. Verified: driver-sys compiles on Linux (x86_64-unknown-linux-gnu). Full redbear-mini image builds and boots in QEMU. --- .../redox-driver-sys/source/src/irq.rs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/local/recipes/drivers/redox-driver-sys/source/src/irq.rs b/local/recipes/drivers/redox-driver-sys/source/src/irq.rs index 08dfdcde..2ff9d2de 100644 --- a/local/recipes/drivers/redox-driver-sys/source/src/irq.rs +++ b/local/recipes/drivers/redox-driver-sys/source/src/irq.rs @@ -288,6 +288,18 @@ fn read_cpu_count() -> Result { Ok(buf[0].max(1)) } +#[cfg(target_os = "redox")] +fn alloc_cpu_id() -> u8 { + match read_cpu_count() { + Ok(n) if n > 0 => { + use std::sync::atomic::{AtomicU8, Ordering}; + static NEXT: AtomicU8 = AtomicU8::new(0); + NEXT.fetch_add(1, Ordering::Relaxed) % n + } + _ => 0, + } +} + #[cfg(target_os = "redox")] fn allocate_irq_vector(cpu_id: u8) -> Result<(u32, File)> { let dir = format!("/scheme/irq/cpu-{cpu_id:02x}"); @@ -431,7 +443,7 @@ mod tests { /// Standard MSI (non-X) interrupt allocation. /// For devices that support MSI but not MSI-X. pub struct MsiAllocation { - pub irq: u8, + pub irq: u32, pub fd: crate::pci::IrqFd, pub vector_count: u8, } @@ -439,7 +451,7 @@ pub struct MsiAllocation { impl MsiAllocation { #[cfg(target_os = "redox")] pub fn request(multiple_message_capable: u8, requested: u8) -> Result { - let cpu_id = alloc_cpu_id(0); + let cpu_id = alloc_cpu_id(); let count = requested.min(1u8 << multiple_message_capable); let (irq, fd) = allocate_irq_vector(cpu_id)?; log::info!("redox-driver-sys: allocated MSI vector -> irq {} on cpu {}", irq, cpu_id); @@ -455,7 +467,7 @@ impl MsiAllocation { /// Set IRQ affinity to a specific CPU. /// Returns true if the affinity was successfully changed. #[cfg(target_os = "redox")] -pub fn irq_set_affinity(irq: u8, cpu_id: u32) -> Result<()> { +pub fn irq_set_affinity(irq: u32, cpu_id: u32) -> Result<()> { use std::io::Write; let path = format!("/scheme/irq/{}/affinity", irq); let mut f = std::fs::OpenOptions::new().write(true).open(&path) @@ -465,6 +477,6 @@ pub fn irq_set_affinity(irq: u8, cpu_id: u32) -> Result<()> { } #[cfg(not(target_os = "redox"))] -pub fn irq_set_affinity(_irq: u8, _cpu_id: u32) -> Result<()> { +pub fn irq_set_affinity(_irq: u32, _cpu_id: u32) -> Result<()> { Err(DriverError::Irq("IRQ affinity is only available on target_os=redox".into())) }