From 787d77fcbdbb60a533a4c527ef65609d8549c8da Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 27 Feb 2023 20:37:01 +0800 Subject: [PATCH] kernel: implement FreeInterrupt This syscall is the opposite of ClaimInterrupt. Signed-off-by: Sean Cross --- kernel/src/irq.rs | 16 ++++++++++++++++ kernel/src/syscall.rs | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/src/irq.rs b/kernel/src/irq.rs index 81fc8a103..5df96608e 100644 --- a/kernel/src/irq.rs +++ b/kernel/src/irq.rs @@ -81,6 +81,22 @@ pub fn interrupt_claim( } } +pub fn interrupt_free(irq: usize, pid: PID) -> Result<(), xous_kernel::Error> { + // Unsafe is required since we're accessing a static mut array. + // However, we disable interrupts to prevent contention on this array. + unsafe { + if irq > IRQ_HANDLERS.len() { + Err(xous_kernel::Error::InterruptNotFound) + } else if !IRQ_HANDLERS[irq].map(|f| f.0 == pid).unwrap_or(false) { + Err(xous_kernel::Error::InterruptNotFound) + } else { + arch::irq::disable_irq(irq).unwrap(); + IRQ_HANDLERS[irq] = None; + Ok(()) + } + } +} + /// Iterate through the IRQ handlers and remove any handler that exists /// for the given PID. pub fn release_interrupts_for_pid(pid: PID) { diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 541b5ba00..1b2024049 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -3,7 +3,7 @@ use crate::arch; use crate::arch::process::Process as ArchProcess; -use crate::irq::interrupt_claim; +use crate::irq::{interrupt_claim, interrupt_free}; use crate::mem::{MemoryManager, PAGE_SIZE}; use crate::server::{SenderID, WaitingMessage}; use crate::services::SystemServices; @@ -954,6 +954,9 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR interrupt_claim(no, pid as definitions::PID, callback, arg) .map(|_| xous_kernel::Result::Ok) } + SysCall::FreeInterrupt(no) => { + interrupt_free(no, pid as definitions::PID).map(|_| xous_kernel::Result::Ok) + } SysCall::Yield => do_yield(pid, tid), SysCall::ReturnToParent(_pid, _cpuid) => { unsafe {