From 3a7517f8fc751e8ace814f7b1b62176a876e502f Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Tue, 3 Sep 2024 20:38:07 +0800 Subject: [PATCH] feat: kernel/plat/irq: add inital dispatch support --- kernel/src/plat/irq.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/kernel/src/plat/irq.rs b/kernel/src/plat/irq.rs index 3a0d42e..acd80fd 100644 --- a/kernel/src/plat/irq.rs +++ b/kernel/src/plat/irq.rs @@ -1,6 +1,7 @@ use super::utils::generate_driver; use crate::drivers::irq::IrqPlic; use crate::objects::*; +use log::{error, warn}; use spin::{lazy::Lazy, Mutex}; const IRQ_NUM: usize = 32; @@ -63,6 +64,36 @@ impl IrqManager { } pub fn dispatch(&mut self) { - todo!("forward to endpoint cap"); + let irq = IRQ_DRIVER.lock().claim(); + if irq.is_none() { + warn!("[IrqManager] No pending IRQ found"); + return; + } + + let irq = irq.unwrap(); + if irq >= IRQ_NUM { + error!("[IrqManager] Invalid IRQ number: {}", irq); + IRQ_DRIVER.lock().disable(irq); + IRQ_DRIVER.lock().complete(irq); + return; + } + + match self.state[irq] { + IrqState::Inactive => { + warn!("[IrqManager] Received disabled IRQ: {}", irq); + IRQ_DRIVER.lock().disable(irq); + }, + IrqState::Signal => { + // TODO: send signal via endpoint + warn!("[IrqManager] Undelivered IRQ: {}", irq); + IRQ_DRIVER.lock().disable(irq); + }, + IrqState::Ipi => { + todo!("Kernel: NO SMP support now"); + }, + IrqState::Reserved => error!("[IrqManager] Received unhandled reserved IRQ: {}", irq), + } + + IRQ_DRIVER.lock().complete(irq); } }