fix: driver-sys MsiAllocation type chain — alloc_cpu_id + u32 irq

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.
This commit is contained in:
2026-05-04 19:14:28 +01:00
parent fd27fe3396
commit 9bc3f24a98
@@ -288,6 +288,18 @@ fn read_cpu_count() -> Result<u8> {
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<Self> {
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()))
}