mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-28 11:53:24 +00:00
Make ostd::trap::irq
public
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
751e0b2ebf
commit
b96c8f9ed2
@ -13,7 +13,10 @@ use component::{init_component, ComponentInitError};
|
|||||||
use lock::is_softirq_enabled;
|
use lock::is_softirq_enabled;
|
||||||
use ostd::{
|
use ostd::{
|
||||||
cpu_local_cell,
|
cpu_local_cell,
|
||||||
trap::{disable_local, register_bottom_half_handler, DisabledLocalIrqGuard},
|
trap::{
|
||||||
|
irq::{disable_local, DisabledLocalIrqGuard},
|
||||||
|
register_bottom_half_handler,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use ostd::{
|
|||||||
atomic_mode::{AsAtomicModeGuard, InAtomicMode},
|
atomic_mode::{AsAtomicModeGuard, InAtomicMode},
|
||||||
disable_preempt, DisabledPreemptGuard,
|
disable_preempt, DisabledPreemptGuard,
|
||||||
},
|
},
|
||||||
trap::{disable_local, in_interrupt_context},
|
trap::{in_interrupt_context, irq::disable_local},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::process_all_pending;
|
use crate::process_all_pending;
|
||||||
|
@ -131,7 +131,7 @@ fn do_schedule(
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
taskless_list
|
taskless_list
|
||||||
.get_with(&irq_guard)
|
.get_with(&irq_guard)
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
@ -158,7 +158,7 @@ fn taskless_softirq_handler(
|
|||||||
softirq_id: u8,
|
softirq_id: u8,
|
||||||
) {
|
) {
|
||||||
let mut processing_list = {
|
let mut processing_list = {
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
let guard = taskless_list.get_with(&irq_guard);
|
let guard = taskless_list.get_with(&irq_guard);
|
||||||
let mut list_mut = guard.borrow_mut();
|
let mut list_mut = guard.borrow_mut();
|
||||||
LinkedList::take(list_mut.deref_mut())
|
LinkedList::take(list_mut.deref_mut())
|
||||||
@ -170,7 +170,7 @@ fn taskless_softirq_handler(
|
|||||||
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
|
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
taskless_list
|
taskless_list
|
||||||
.get_with(&irq_guard)
|
.get_with(&irq_guard)
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -7,8 +7,8 @@ use log::info;
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use ostd::arch::kernel::MappedIrqLine;
|
use ostd::arch::kernel::MappedIrqLine;
|
||||||
#[cfg(target_arch = "riscv64")] // TODO: Add `MappedIrqLine` support for RISC-V.
|
#[cfg(target_arch = "riscv64")] // TODO: Add `MappedIrqLine` support for RISC-V.
|
||||||
use ostd::trap::IrqLine as MappedIrqLine;
|
use ostd::trap::irq::IrqLine as MappedIrqLine;
|
||||||
use ostd::{io::IoMem, mm::VmIoOnce, trap::IrqLine, Error, Result};
|
use ostd::{io::IoMem, mm::VmIoOnce, trap::irq::IrqLine, Error, Result};
|
||||||
|
|
||||||
/// A MMIO common device.
|
/// A MMIO common device.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -28,7 +28,7 @@ pub(super) fn init() {
|
|||||||
fn x86_probe() {
|
fn x86_probe() {
|
||||||
use common_device::{mmio_check_magic, mmio_read_device_id, MmioCommonDevice};
|
use common_device::{mmio_check_magic, mmio_read_device_id, MmioCommonDevice};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use ostd::{arch::kernel::IRQ_CHIP, io::IoMem, trap::IrqLine};
|
use ostd::{arch::kernel::IRQ_CHIP, io::IoMem, trap::irq::IrqLine};
|
||||||
|
|
||||||
// TODO: The correct method for detecting VirtIO-MMIO devices on x86_64 systems is to parse the
|
// TODO: The correct method for detecting VirtIO-MMIO devices on x86_64 systems is to parse the
|
||||||
// kernel command line if ACPI tables are absent [1], or the ACPI SSDT if ACPI tables are
|
// kernel command line if ACPI tables are absent [1], or the ACPI SSDT if ACPI tables are
|
||||||
|
@ -11,7 +11,7 @@ use ostd::{
|
|||||||
io::IoMem,
|
io::IoMem,
|
||||||
mm::{DmaCoherent, PAGE_SIZE},
|
mm::{DmaCoherent, PAGE_SIZE},
|
||||||
sync::RwLock,
|
sync::RwLock,
|
||||||
trap::IrqCallbackFunction,
|
trap::irq::IrqCallbackFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -8,7 +8,10 @@ use aster_util::safe_ptr::SafePtr;
|
|||||||
use ostd::{
|
use ostd::{
|
||||||
io::IoMem,
|
io::IoMem,
|
||||||
sync::RwLock,
|
sync::RwLock,
|
||||||
trap::{IrqCallbackFunction, IrqLine, TrapFrame},
|
trap::{
|
||||||
|
irq::{IrqCallbackFunction, IrqLine},
|
||||||
|
TrapFrame,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Multiplexing Irqs. The two interrupt types (configuration space change and queue interrupt)
|
/// Multiplexing Irqs. The two interrupt types (configuration space change and queue interrupt)
|
||||||
|
@ -9,7 +9,7 @@ use ostd::{
|
|||||||
bus::pci::cfg_space::Bar,
|
bus::pci::cfg_space::Bar,
|
||||||
io::IoMem,
|
io::IoMem,
|
||||||
mm::{DmaCoherent, PodOnce},
|
mm::{DmaCoherent, PodOnce},
|
||||||
trap::IrqCallbackFunction,
|
trap::irq::IrqCallbackFunction,
|
||||||
Pod,
|
Pod,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ use ostd::{
|
|||||||
},
|
},
|
||||||
io::IoMem,
|
io::IoMem,
|
||||||
mm::DmaCoherent,
|
mm::DmaCoherent,
|
||||||
trap::IrqCallbackFunction,
|
trap::irq::IrqCallbackFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{common_cfg::VirtioPciCommonCfg, msix::VirtioMsixManager};
|
use super::{common_cfg::VirtioPciCommonCfg, msix::VirtioMsixManager};
|
||||||
|
@ -12,7 +12,7 @@ use ostd::{
|
|||||||
},
|
},
|
||||||
io::IoMem,
|
io::IoMem,
|
||||||
mm::{DmaCoherent, HasDaddr, PAGE_SIZE},
|
mm::{DmaCoherent, HasDaddr, PAGE_SIZE},
|
||||||
trap::IrqCallbackFunction,
|
trap::irq::IrqCallbackFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use ostd::{bus::pci::capability::msix::CapabilityMsixData, trap::IrqLine};
|
use ostd::{bus::pci::capability::msix::CapabilityMsixData, trap::irq::IrqLine};
|
||||||
|
|
||||||
pub struct VirtioMsixManager {
|
pub struct VirtioMsixManager {
|
||||||
config_msix_vector: u16,
|
config_msix_vector: u16,
|
||||||
@ -20,7 +20,7 @@ impl VirtioMsixManager {
|
|||||||
pub fn new(mut msix: CapabilityMsixData) -> Self {
|
pub fn new(mut msix: CapabilityMsixData) -> Self {
|
||||||
let mut msix_vector_list: Vec<u16> = (0..msix.table_size()).collect();
|
let mut msix_vector_list: Vec<u16> = (0..msix.table_size()).collect();
|
||||||
for i in msix_vector_list.iter() {
|
for i in msix_vector_list.iter() {
|
||||||
let irq = ostd::trap::IrqLine::alloc().unwrap();
|
let irq = IrqLine::alloc().unwrap();
|
||||||
msix.set_interrupt_vector(irq, *i);
|
msix.set_interrupt_vector(irq, *i);
|
||||||
}
|
}
|
||||||
let config_msix_vector = msix_vector_list.pop().unwrap();
|
let config_msix_vector = msix_vector_list.pop().unwrap();
|
||||||
|
@ -16,7 +16,7 @@ use ostd::{
|
|||||||
},
|
},
|
||||||
AtomicCpuId, Task,
|
AtomicCpuId, Task,
|
||||||
},
|
},
|
||||||
trap::disable_local,
|
trap::irq::disable_local,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -7,7 +7,7 @@ use core::{alloc::Layout, cell::RefCell};
|
|||||||
use ostd::{
|
use ostd::{
|
||||||
cpu_local,
|
cpu_local,
|
||||||
mm::{Paddr, PAGE_SIZE},
|
mm::{Paddr, PAGE_SIZE},
|
||||||
trap::DisabledLocalIrqGuard,
|
trap::irq::DisabledLocalIrqGuard,
|
||||||
};
|
};
|
||||||
|
|
||||||
cpu_local! {
|
cpu_local! {
|
||||||
|
@ -64,7 +64,7 @@ pub struct FrameAllocator;
|
|||||||
|
|
||||||
impl GlobalFrameAllocator for FrameAllocator {
|
impl GlobalFrameAllocator for FrameAllocator {
|
||||||
fn alloc(&self, layout: Layout) -> Option<Paddr> {
|
fn alloc(&self, layout: Layout) -> Option<Paddr> {
|
||||||
let guard = trap::disable_local();
|
let guard = trap::irq::disable_local();
|
||||||
let res = cache::alloc(&guard, layout);
|
let res = cache::alloc(&guard, layout);
|
||||||
if res.is_some() {
|
if res.is_some() {
|
||||||
TOTAL_FREE_SIZE.sub(guard.current_cpu(), layout.size());
|
TOTAL_FREE_SIZE.sub(guard.current_cpu(), layout.size());
|
||||||
@ -73,13 +73,13 @@ impl GlobalFrameAllocator for FrameAllocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dealloc(&self, addr: Paddr, size: usize) {
|
fn dealloc(&self, addr: Paddr, size: usize) {
|
||||||
let guard = trap::disable_local();
|
let guard = trap::irq::disable_local();
|
||||||
TOTAL_FREE_SIZE.add(guard.current_cpu(), size);
|
TOTAL_FREE_SIZE.add(guard.current_cpu(), size);
|
||||||
cache::dealloc(&guard, addr, size);
|
cache::dealloc(&guard, addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_free_memory(&self, addr: Paddr, size: usize) {
|
fn add_free_memory(&self, addr: Paddr, size: usize) {
|
||||||
let guard = trap::disable_local();
|
let guard = trap::irq::disable_local();
|
||||||
TOTAL_FREE_SIZE.add(guard.current_cpu(), size);
|
TOTAL_FREE_SIZE.add(guard.current_cpu(), size);
|
||||||
pools::add_free_memory(&guard, addr, size);
|
pools::add_free_memory(&guard, addr, size);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use ostd::{
|
|||||||
cpu_local,
|
cpu_local,
|
||||||
mm::Paddr,
|
mm::Paddr,
|
||||||
sync::{LocalIrqDisabled, SpinLock, SpinLockGuard},
|
sync::{LocalIrqDisabled, SpinLock, SpinLockGuard},
|
||||||
trap::DisabledLocalIrqGuard,
|
trap::irq::DisabledLocalIrqGuard,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::chunk::{greater_order_of, lesser_order_of, size_of_order, split_to_chunks, BuddyOrder};
|
use crate::chunk::{greater_order_of, lesser_order_of, size_of_order, split_to_chunks, BuddyOrder};
|
||||||
|
@ -98,7 +98,7 @@ mod test {
|
|||||||
pub static FREE_SIZE_COUNTER: usize;
|
pub static FREE_SIZE_COUNTER: usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
let guard = trap::disable_local();
|
let guard = trap::irq::disable_local();
|
||||||
let cur_cpu = guard.current_cpu();
|
let cur_cpu = guard.current_cpu();
|
||||||
FREE_SIZE_COUNTER.add(cur_cpu, 10);
|
FREE_SIZE_COUNTER.add(cur_cpu, 10);
|
||||||
assert_eq!(FREE_SIZE_COUNTER.get(), 10);
|
assert_eq!(FREE_SIZE_COUNTER.get(), 10);
|
||||||
|
@ -296,7 +296,7 @@ impl GlobalHeapAllocator for HeapAllocator {
|
|||||||
return HeapSlot::alloc_large(layout.size().div_ceil(PAGE_SIZE) * PAGE_SIZE);
|
return HeapSlot::alloc_large(layout.size().div_ceil(PAGE_SIZE) * PAGE_SIZE);
|
||||||
};
|
};
|
||||||
|
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
let this_cache = LOCAL_POOL.get_with(&irq_guard);
|
let this_cache = LOCAL_POOL.get_with(&irq_guard);
|
||||||
let mut local_cache = this_cache.borrow_mut();
|
let mut local_cache = this_cache.borrow_mut();
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ impl GlobalHeapAllocator for HeapAllocator {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
let this_cache = LOCAL_POOL.get_with(&irq_guard);
|
let this_cache = LOCAL_POOL.get_with(&irq_guard);
|
||||||
let mut local_cache = this_cache.borrow_mut();
|
let mut local_cache = this_cache.borrow_mut();
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ fn main() {
|
|||||||
|
|
||||||
#[ostd::ktest::panic_handler]
|
#[ostd::ktest::panic_handler]
|
||||||
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
||||||
let _irq_guard = ostd::trap::disable_local();
|
let _irq_guard = ostd::trap::irq::disable_local();
|
||||||
|
|
||||||
use alloc::{boxed::Box, string::ToString};
|
use alloc::{boxed::Box, string::ToString};
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ pub(super) unsafe fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn handle_timer_interrupt() {
|
pub(super) fn handle_timer_interrupt() {
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
if irq_guard.current_cpu() == CpuId::bsp() {
|
if irq_guard.current_cpu() == CpuId::bsp() {
|
||||||
crate::timer::jiffies::ELAPSED.fetch_add(1, Ordering::Relaxed);
|
crate::timer::jiffies::ELAPSED.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use volatile::{access::ReadWrite, VolatileRef};
|
|||||||
use super::registers::Capability;
|
use super::registers::Capability;
|
||||||
use crate::{
|
use crate::{
|
||||||
sync::{LocalIrqDisabled, SpinLock},
|
sync::{LocalIrqDisabled, SpinLock},
|
||||||
trap::{IrqLine, TrapFrame},
|
trap::{irq::IrqLine, TrapFrame},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -76,7 +76,7 @@ impl super::Apic for X2Apic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn send_ipi(&self, icr: super::Icr) {
|
unsafe fn send_ipi(&self, icr: super::Icr) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
// SAFETY: These `rdmsr` and `wrmsr` instructions write the interrupt command to APIC and
|
// SAFETY: These `rdmsr` and `wrmsr` instructions write the interrupt command to APIC and
|
||||||
// wait for results. The caller guarantees it's safe to execute this interrupt command.
|
// wait for results. The caller guarantees it's safe to execute this interrupt command.
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -79,7 +79,7 @@ impl super::Apic for XApic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn send_ipi(&self, icr: super::Icr) {
|
unsafe fn send_ipi(&self, icr: super::Icr) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
self.write(xapic::XAPIC_ESR, 0);
|
self.write(xapic::XAPIC_ESR, 0);
|
||||||
// The upper 32 bits of ICR must be written into XAPIC_ICR1 first,
|
// The upper 32 bits of ICR must be written into XAPIC_ICR1 first,
|
||||||
// because writing into XAPIC_ICR0 will trigger the action of
|
// because writing into XAPIC_ICR0 will trigger the action of
|
||||||
|
@ -11,7 +11,7 @@ use volatile::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::if_tdx_enabled, io::IoMemAllocatorBuilder, mm::paddr_to_vaddr, trap::IrqLine, Error,
|
arch::if_tdx_enabled, io::IoMemAllocatorBuilder, mm::paddr_to_vaddr, trap::irq::IrqLine, Error,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use log::info;
|
|||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
use super::acpi::get_acpi_tables;
|
use super::acpi::get_acpi_tables;
|
||||||
use crate::{io::IoMemAllocatorBuilder, sync::SpinLock, trap::IrqLine, Error, Result};
|
use crate::{io::IoMemAllocatorBuilder, sync::SpinLock, trap::irq::IrqLine, Error, Result};
|
||||||
|
|
||||||
mod ioapic;
|
mod ioapic;
|
||||||
mod pic;
|
mod pic;
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
pit::{self, OperatingMode},
|
pit::{self, OperatingMode},
|
||||||
TIMER_FREQ,
|
TIMER_FREQ,
|
||||||
},
|
},
|
||||||
trap::{IrqLine, TrapFrame},
|
trap::{irq::IrqLine, TrapFrame},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The frequency of TSC(Hz)
|
/// The frequency of TSC(Hz)
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
tsc_freq,
|
tsc_freq,
|
||||||
},
|
},
|
||||||
task::disable_preempt,
|
task::disable_preempt,
|
||||||
trap::{IrqLine, TrapFrame},
|
trap::{irq::IrqLine, TrapFrame},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initializes APIC with TSC-deadline mode or periodic mode.
|
/// Initializes APIC with TSC-deadline mode or periodic mode.
|
||||||
|
@ -13,7 +13,7 @@ use volatile::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
arch::kernel::{acpi::get_acpi_tables, MappedIrqLine, IRQ_CHIP},
|
arch::kernel::{acpi::get_acpi_tables, MappedIrqLine, IRQ_CHIP},
|
||||||
mm::paddr_to_vaddr,
|
mm::paddr_to_vaddr,
|
||||||
trap::IrqLine,
|
trap::irq::IrqLine,
|
||||||
};
|
};
|
||||||
|
|
||||||
static HPET_INSTANCE: Once<Hpet> = Once::new();
|
static HPET_INSTANCE: Once<Hpet> = Once::new();
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||||||
arch::kernel,
|
arch::kernel,
|
||||||
cpu::{CpuId, PinCurrentCpu},
|
cpu::{CpuId, PinCurrentCpu},
|
||||||
timer::INTERRUPT_CALLBACKS,
|
timer::INTERRUPT_CALLBACKS,
|
||||||
trap::{self, IrqLine, TrapFrame},
|
trap::{self, irq::IrqLine, TrapFrame},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The timer frequency (Hz).
|
/// The timer frequency (Hz).
|
||||||
@ -61,7 +61,7 @@ pub(super) fn init_ap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn timer_callback(_: &TrapFrame) {
|
fn timer_callback(_: &TrapFrame) {
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
if irq_guard.current_cpu() == CpuId::bsp() {
|
if irq_guard.current_cpu() == CpuId::bsp() {
|
||||||
crate::timer::jiffies::ELAPSED.fetch_add(1, Ordering::SeqCst);
|
crate::timer::jiffies::ELAPSED.fetch_add(1, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use crate::{
|
|||||||
timer::TIMER_FREQ,
|
timer::TIMER_FREQ,
|
||||||
},
|
},
|
||||||
io::{sensitive_io_port, IoPort},
|
io::{sensitive_io_port, IoPort},
|
||||||
trap::IrqLine,
|
trap::irq::IrqLine,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// PIT Operating Mode.
|
/// PIT Operating Mode.
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||||||
device_info::PciDeviceLocation,
|
device_info::PciDeviceLocation,
|
||||||
},
|
},
|
||||||
mm::VmIoOnce,
|
mm::VmIoOnce,
|
||||||
trap::IrqLine,
|
trap::irq::IrqLine,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// MSI-X capability. It will set the BAR space it uses to be hidden.
|
/// MSI-X capability. It will set the BAR space it uses to be hidden.
|
||||||
|
@ -33,7 +33,7 @@ use crate::arch;
|
|||||||
/// // You can avoid this by disabling interrupts (and preemption, if needed).
|
/// // You can avoid this by disabling interrupts (and preemption, if needed).
|
||||||
/// println!("BAR VAL: {:?}", BAR.load());
|
/// println!("BAR VAL: {:?}", BAR.load());
|
||||||
///
|
///
|
||||||
/// let _irq_guard = ostd::trap::disable_local_irq();
|
/// let _irq_guard = ostd::trap::irq::disable_local_irq();
|
||||||
/// println!("1st FOO VAL: {:?}", FOO.load());
|
/// println!("1st FOO VAL: {:?}", FOO.load());
|
||||||
/// // No surprises here, the two accesses must result in the same value.
|
/// // No surprises here, the two accesses must result in the same value.
|
||||||
/// println!("2nd FOO VAL: {:?}", FOO.load());
|
/// println!("2nd FOO VAL: {:?}", FOO.load());
|
||||||
|
@ -10,7 +10,7 @@ use super::{AnyStorage, CpuLocal};
|
|||||||
use crate::{
|
use crate::{
|
||||||
cpu::{all_cpus, num_cpus, CpuId, PinCurrentCpu},
|
cpu::{all_cpus, num_cpus, CpuId, PinCurrentCpu},
|
||||||
mm::{paddr_to_vaddr, FrameAllocOptions, Segment, Vaddr, PAGE_SIZE},
|
mm::{paddr_to_vaddr, FrameAllocOptions, Segment, Vaddr, PAGE_SIZE},
|
||||||
trap::DisabledLocalIrqGuard,
|
trap::irq::DisabledLocalIrqGuard,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ use static_cpu_local::StaticStorage;
|
|||||||
use super::CpuId;
|
use super::CpuId;
|
||||||
use crate::{
|
use crate::{
|
||||||
mm::{frame::allocator, paddr_to_vaddr, Paddr, PAGE_SIZE},
|
mm::{frame::allocator, paddr_to_vaddr, Paddr, PAGE_SIZE},
|
||||||
trap::DisabledLocalIrqGuard,
|
trap::irq::DisabledLocalIrqGuard,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Dynamically-allocated CPU-local objects.
|
/// Dynamically-allocated CPU-local objects.
|
||||||
@ -324,7 +324,7 @@ mod test {
|
|||||||
crate::cpu_local! {
|
crate::cpu_local! {
|
||||||
static FOO: RefCell<usize> = RefCell::new(1);
|
static FOO: RefCell<usize> = RefCell::new(1);
|
||||||
}
|
}
|
||||||
let irq_guard = crate::trap::disable_local();
|
let irq_guard = crate::trap::irq::disable_local();
|
||||||
let foo_guard = FOO.get_with(&irq_guard);
|
let foo_guard = FOO.get_with(&irq_guard);
|
||||||
assert_eq!(*foo_guard.borrow(), 1);
|
assert_eq!(*foo_guard.borrow(), 1);
|
||||||
*foo_guard.borrow_mut() = 2;
|
*foo_guard.borrow_mut() = 2;
|
||||||
@ -337,7 +337,7 @@ mod test {
|
|||||||
crate::cpu_local_cell! {
|
crate::cpu_local_cell! {
|
||||||
static BAR: usize = 3;
|
static BAR: usize = 3;
|
||||||
}
|
}
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
assert_eq!(BAR.load(), 3);
|
assert_eq!(BAR.load(), 3);
|
||||||
BAR.store(4);
|
BAR.store(4);
|
||||||
assert_eq!(BAR.load(), 4);
|
assert_eq!(BAR.load(), 4);
|
||||||
|
@ -41,7 +41,7 @@ pub trait SingleInstructionAddAssign<Rhs = Self> {
|
|||||||
|
|
||||||
impl<T: num_traits::WrappingAdd + Copy> SingleInstructionAddAssign<T> for T {
|
impl<T: num_traits::WrappingAdd + Copy> SingleInstructionAddAssign<T> for T {
|
||||||
default unsafe fn add_assign(offset: *mut Self, rhs: T) {
|
default unsafe fn add_assign(offset: *mut Self, rhs: T) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let addr = (base + offset as usize) as *mut Self;
|
let addr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
@ -67,7 +67,7 @@ pub trait SingleInstructionSubAssign<Rhs = Self> {
|
|||||||
|
|
||||||
impl<T: num_traits::WrappingSub + Copy> SingleInstructionSubAssign<T> for T {
|
impl<T: num_traits::WrappingSub + Copy> SingleInstructionSubAssign<T> for T {
|
||||||
default unsafe fn sub_assign(offset: *mut Self, rhs: T) {
|
default unsafe fn sub_assign(offset: *mut Self, rhs: T) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let addr = (base + offset as usize) as *mut Self;
|
let addr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
@ -87,7 +87,7 @@ pub trait SingleInstructionBitOrAssign<Rhs = Self> {
|
|||||||
|
|
||||||
impl<T: core::ops::BitOr<Output = T> + Copy> SingleInstructionBitOrAssign<T> for T {
|
impl<T: core::ops::BitOr<Output = T> + Copy> SingleInstructionBitOrAssign<T> for T {
|
||||||
default unsafe fn bitor_assign(offset: *mut Self, rhs: T) {
|
default unsafe fn bitor_assign(offset: *mut Self, rhs: T) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let addr = (base + offset as usize) as *mut Self;
|
let addr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
@ -107,7 +107,7 @@ pub trait SingleInstructionBitAndAssign<Rhs = Self> {
|
|||||||
|
|
||||||
impl<T: core::ops::BitAnd<Output = T> + Copy> SingleInstructionBitAndAssign<T> for T {
|
impl<T: core::ops::BitAnd<Output = T> + Copy> SingleInstructionBitAndAssign<T> for T {
|
||||||
default unsafe fn bitand_assign(offset: *mut Self, rhs: T) {
|
default unsafe fn bitand_assign(offset: *mut Self, rhs: T) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let addr = (base + offset as usize) as *mut Self;
|
let addr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
@ -127,7 +127,7 @@ pub trait SingleInstructionBitXorAssign<Rhs = Self> {
|
|||||||
|
|
||||||
impl<T: core::ops::BitXor<Output = T> + Copy> SingleInstructionBitXorAssign<T> for T {
|
impl<T: core::ops::BitXor<Output = T> + Copy> SingleInstructionBitXorAssign<T> for T {
|
||||||
default unsafe fn bitxor_assign(offset: *mut Self, rhs: T) {
|
default unsafe fn bitxor_assign(offset: *mut Self, rhs: T) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let addr = (base + offset as usize) as *mut Self;
|
let addr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
@ -147,7 +147,7 @@ pub trait SingleInstructionLoad {
|
|||||||
|
|
||||||
impl<T: Copy> SingleInstructionLoad for T {
|
impl<T: Copy> SingleInstructionLoad for T {
|
||||||
default unsafe fn load(offset: *const Self) -> Self {
|
default unsafe fn load(offset: *const Self) -> Self {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let ptr = (base + offset as usize) as *const Self;
|
let ptr = (base + offset as usize) as *const Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
@ -167,7 +167,7 @@ pub trait SingleInstructionStore {
|
|||||||
|
|
||||||
impl<T: Copy> SingleInstructionStore for T {
|
impl<T: Copy> SingleInstructionStore for T {
|
||||||
default unsafe fn store(offset: *mut Self, val: Self) {
|
default unsafe fn store(offset: *mut Self, val: Self) {
|
||||||
let _guard = crate::trap::disable_local();
|
let _guard = crate::trap::irq::disable_local();
|
||||||
let base = crate::arch::cpu::local::get_base() as usize;
|
let base = crate::arch::cpu::local::get_base() as usize;
|
||||||
let ptr = (base + offset as usize) as *mut Self;
|
let ptr = (base + offset as usize) as *mut Self;
|
||||||
// SAFETY: Same as `add_assign`.
|
// SAFETY: Same as `add_assign`.
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use super::{AnyStorage, CpuLocal, __cpu_local_end, __cpu_local_start};
|
use super::{AnyStorage, CpuLocal, __cpu_local_end, __cpu_local_start};
|
||||||
use crate::{arch, cpu::CpuId, trap::DisabledLocalIrqGuard};
|
use crate::{arch, cpu::CpuId, trap::irq::DisabledLocalIrqGuard};
|
||||||
|
|
||||||
/// Defines a statically-allocated CPU-local variable.
|
/// Defines a statically-allocated CPU-local variable.
|
||||||
///
|
///
|
||||||
@ -33,7 +33,7 @@ use crate::{arch, cpu::CpuId, trap::DisabledLocalIrqGuard};
|
|||||||
/// let val_of_foo = ref_of_foo.load(Ordering::Relaxed);
|
/// let val_of_foo = ref_of_foo.load(Ordering::Relaxed);
|
||||||
/// println!("FOO VAL: {}", val_of_foo);
|
/// println!("FOO VAL: {}", val_of_foo);
|
||||||
///
|
///
|
||||||
/// let irq_guard = trap::disable_local();
|
/// let irq_guard = trap::irq::disable_local();
|
||||||
/// let bar_guard = BAR.get_with(&irq_guard);
|
/// let bar_guard = BAR.get_with(&irq_guard);
|
||||||
/// let val_of_bar = bar_guard.get();
|
/// let val_of_bar = bar_guard.get();
|
||||||
/// println!("BAR VAL: {}", val_of_bar);
|
/// println!("BAR VAL: {}", val_of_bar);
|
||||||
|
@ -77,7 +77,7 @@ impl<'a, G: PinCurrentCpu> TlbFlusher<'a, G> {
|
|||||||
/// function. But it may not be synchronous. Upon the return of this
|
/// function. But it may not be synchronous. Upon the return of this
|
||||||
/// function, the TLB entries may not be coherent.
|
/// function, the TLB entries may not be coherent.
|
||||||
pub fn dispatch_tlb_flush(&mut self) {
|
pub fn dispatch_tlb_flush(&mut self) {
|
||||||
let irq_guard = crate::trap::disable_local();
|
let irq_guard = crate::trap::irq::disable_local();
|
||||||
|
|
||||||
if self.ops_stack.is_empty() {
|
if self.ops_stack.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -28,7 +28,7 @@ use unwinding::abi::{
|
|||||||
#[linkage = "weak"]
|
#[linkage = "weak"]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn __ostd_panic_handler(info: &core::panic::PanicInfo) -> ! {
|
pub fn __ostd_panic_handler(info: &core::panic::PanicInfo) -> ! {
|
||||||
let _irq_guard = crate::trap::disable_local();
|
let _irq_guard = crate::trap::irq::disable_local();
|
||||||
|
|
||||||
crate::cpu_local_cell! {
|
crate::cpu_local_cell! {
|
||||||
static IN_PANIC: bool = false;
|
static IN_PANIC: bool = false;
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||||||
cpu::{CpuSet, PinCurrentCpu},
|
cpu::{CpuSet, PinCurrentCpu},
|
||||||
cpu_local,
|
cpu_local,
|
||||||
sync::SpinLock,
|
sync::SpinLock,
|
||||||
trap::{self, IrqLine, TrapFrame},
|
trap::{self, irq::IrqLine, TrapFrame},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Executes a function on other processors.
|
/// Executes a function on other processors.
|
||||||
@ -32,7 +32,7 @@ use crate::{
|
|||||||
/// The function `f` will be executed asynchronously on the target processors.
|
/// The function `f` will be executed asynchronously on the target processors.
|
||||||
/// However if called on the current processor, it will be synchronous.
|
/// However if called on the current processor, it will be synchronous.
|
||||||
pub fn inter_processor_call(targets: &CpuSet, f: fn()) {
|
pub fn inter_processor_call(targets: &CpuSet, f: fn()) {
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
let this_cpu_id = irq_guard.current_cpu();
|
let this_cpu_id = irq_guard.current_cpu();
|
||||||
|
|
||||||
let ipi_data = IPI_GLOBAL_DATA.get().unwrap();
|
let ipi_data = IPI_GLOBAL_DATA.get().unwrap();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
task::{atomic_mode::AsAtomicModeGuard, disable_preempt, DisabledPreemptGuard},
|
task::{atomic_mode::AsAtomicModeGuard, disable_preempt, DisabledPreemptGuard},
|
||||||
trap::{disable_local, DisabledLocalIrqGuard},
|
trap::irq::{disable_local, DisabledLocalIrqGuard},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A guardian that denotes the guard behavior for holding a spin-based lock.
|
/// A guardian that denotes the guard behavior for holding a spin-based lock.
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
FrameAllocOptions, PAGE_SIZE,
|
FrameAllocOptions, PAGE_SIZE,
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
trap::DisabledLocalIrqGuard,
|
trap::irq::DisabledLocalIrqGuard,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The kernel stack size of a task, specified in pages.
|
/// The kernel stack size of a task, specified in pages.
|
||||||
|
@ -4,7 +4,7 @@ use alloc::sync::Arc;
|
|||||||
use core::{ptr::NonNull, sync::atomic::Ordering};
|
use core::{ptr::NonNull, sync::atomic::Ordering};
|
||||||
|
|
||||||
use super::{context_switch, Task, TaskContext, POST_SCHEDULE_HANDLER};
|
use super::{context_switch, Task, TaskContext, POST_SCHEDULE_HANDLER};
|
||||||
use crate::{cpu_local_cell, trap::DisabledLocalIrqGuard};
|
use crate::{cpu_local_cell, trap::irq::DisabledLocalIrqGuard};
|
||||||
|
|
||||||
cpu_local_cell! {
|
cpu_local_cell! {
|
||||||
/// The `Arc<Task>` (casted by [`Arc::into_raw`]) that is the current task.
|
/// The `Arc<Task>` (casted by [`Arc::into_raw`]) that is the current task.
|
||||||
@ -43,7 +43,7 @@ pub(super) fn switch_to_task(next_task: Arc<Task>) {
|
|||||||
crate::sync::finish_grace_period();
|
crate::sync::finish_grace_period();
|
||||||
}
|
}
|
||||||
|
|
||||||
let irq_guard = crate::trap::disable_local();
|
let irq_guard = crate::trap::irq::disable_local();
|
||||||
|
|
||||||
let current_task_ptr = CURRENT_TASK_PTR.load();
|
let current_task_ptr = CURRENT_TASK_PTR.load();
|
||||||
let current_task_ctx_ptr = if !current_task_ptr.is_null() {
|
let current_task_ctx_ptr = if !current_task_ptr.is_null() {
|
||||||
|
@ -22,7 +22,7 @@ pub fn register_callback<F>(func: F)
|
|||||||
where
|
where
|
||||||
F: Fn() + Sync + Send + 'static,
|
F: Fn() + Sync + Send + 'static,
|
||||||
{
|
{
|
||||||
let irq_guard = trap::disable_local();
|
let irq_guard = trap::irq::disable_local();
|
||||||
INTERRUPT_CALLBACKS
|
INTERRUPT_CALLBACKS
|
||||||
.get_with(&irq_guard)
|
.get_with(&irq_guard)
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
use super::{disable_local, irq::process_top_half, DisabledLocalIrqGuard};
|
use super::irq::{disable_local, process_top_half, DisabledLocalIrqGuard};
|
||||||
use crate::{cpu_local_cell, task::disable_preempt, trap::TrapFrame};
|
use crate::{cpu_local_cell, task::disable_preempt, trap::TrapFrame};
|
||||||
|
|
||||||
static BOTTOM_HALF_HANDLER: Once<fn(DisabledLocalIrqGuard) -> DisabledLocalIrqGuard> = Once::new();
|
static BOTTOM_HALF_HANDLER: Once<fn(DisabledLocalIrqGuard) -> DisabledLocalIrqGuard> = Once::new();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
//! IRQ line and IRQ guards.
|
||||||
|
|
||||||
use core::{fmt::Debug, ops::Deref};
|
use core::{fmt::Debug, ops::Deref};
|
||||||
|
|
||||||
use id_alloc::IdAlloc;
|
use id_alloc::IdAlloc;
|
||||||
@ -141,6 +143,7 @@ fn get_or_init_allocator() -> &'static SpinLock<IdAlloc> {
|
|||||||
/// A handle for an allocated IRQ line.
|
/// A handle for an allocated IRQ line.
|
||||||
///
|
///
|
||||||
/// When the handle is dropped, the IRQ line will be released automatically.
|
/// When the handle is dropped, the IRQ line will be released automatically.
|
||||||
|
#[must_use]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct InnerHandle {
|
struct InnerHandle {
|
||||||
index: u8,
|
index: u8,
|
||||||
@ -204,10 +207,10 @@ pub(super) fn process_top_half(trap_frame: &TrapFrame, irq_num: usize) {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use ostd::irq;
|
/// use ostd::trap;
|
||||||
///
|
///
|
||||||
/// {
|
/// {
|
||||||
/// let _ = irq::disable_local();
|
/// let _ = trap::irq::disable_local();
|
||||||
/// todo!("do something when irqs are disabled");
|
/// todo!("do something when irqs are disabled");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
//! Handles trap across kernel and user space.
|
//! Handles trap across kernel and user space.
|
||||||
|
|
||||||
mod handler;
|
mod handler;
|
||||||
mod irq;
|
pub mod irq;
|
||||||
|
|
||||||
|
pub(crate) use handler::call_irq_callback_functions;
|
||||||
pub use handler::{in_interrupt_context, register_bottom_half_handler};
|
pub use handler::{in_interrupt_context, register_bottom_half_handler};
|
||||||
|
|
||||||
pub(crate) use self::handler::call_irq_callback_functions;
|
|
||||||
pub use self::irq::{disable_local, DisabledLocalIrqGuard, IrqCallbackFunction, IrqLine};
|
|
||||||
pub use crate::arch::trap::TrapFrame;
|
pub use crate::arch::trap::TrapFrame;
|
||||||
|
Reference in New Issue
Block a user