Skip to content

Commit

Permalink
Implement set_interrupt for aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
PandaZ3D committed Jan 19, 2024
1 parent 794cb8f commit f384373
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
42 changes: 28 additions & 14 deletions src/kernel/src/arch/aarch64/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use twizzler_abi::{
kso::{InterruptAllocateOptions, InterruptPriority},
};

use crate::interrupt::{DynamicInterrupt, Destination};
use crate::{
interrupt::{DynamicInterrupt, Destination, TriggerMode, PinPolarity},
processor::current_processor,
};
use crate::machine::interrupt::INTERRUPT_CONTROLLER;

use super::exception::{
Expand Down Expand Up @@ -135,7 +138,7 @@ pub(super) fn irq_exception_handler(_ctx: &mut ExceptionContext) {
// call timer interrupt handler
cntp_interrupt_handler();
},
_ => panic!("unknown reason!")
_ => panic!("unknown irq number! {}", irq_number)
}
// signal the GIC that we have serviced the IRQ
INTERRUPT_CONTROLLER.finish_active_interrupt(irq_number);
Expand Down Expand Up @@ -176,22 +179,33 @@ pub fn init_interrupts() {
// in the future we should not use logging until mm us up
emerglogln!("[arch::interrupt] initializing interrupts");

let cpu = current_processor();

// initialize interrupt controller
INTERRUPT_CONTROLLER.configure();
if cpu.is_bsp() {
INTERRUPT_CONTROLLER.configure_global();
}
INTERRUPT_CONTROLLER.configure_local();

// enable this CPU to recieve interrupts from the timer
// by configuring the interrupt controller to route
// the timer's interrupt to us
INTERRUPT_CONTROLLER.enable_interrupt(PhysicalTimer::INTERRUPT_ID);
INTERRUPT_CONTROLLER.route_interrupt(
PhysicalTimer::INTERRUPT_ID,
cpu.id,
);
}

// in crate::arch::aarch64
// pub fn set_interrupt(
// _num: u32,
// _masked: bool,
// _trigger: TriggerMode,
// _polarity: PinPolarity,
// _destination: Destination,
// ) {
// todo!();
// }
pub fn set_interrupt(
num: u32,
_masked: bool,
_trigger: TriggerMode,
_polarity: PinPolarity,
destination: Destination,
) {
match destination {
Destination::Bsp => INTERRUPT_CONTROLLER.route_interrupt(num, current_processor().bsp_id()),
_ => todo!("routing interrupt: {:?}", destination)
}
INTERRUPT_CONTROLLER.enable_interrupt(num);
}
13 changes: 1 addition & 12 deletions src/kernel/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use twizzler_abi::syscall::TimeSpan;

use crate::{
clock::Nanoseconds,
interrupt::{Destination, PinPolarity, TriggerMode},
BootInfo,
syscall::SyscallContext,
};
Expand All @@ -26,7 +25,7 @@ pub mod thread;
mod start;

pub use address::{VirtAddr, PhysAddr};
pub use interrupt::{send_ipi, init_interrupts};
pub use interrupt::{send_ipi, init_interrupts, set_interrupt};
pub use start::BootInfoSystemTable;

pub fn init<B: BootInfo>(boot_info: &B) {
Expand Down Expand Up @@ -85,16 +84,6 @@ pub fn init_secondary() {
// - configure the local CPU interrupt controller interface
}

pub fn set_interrupt(
_num: u32,
_masked: bool,
_trigger: TriggerMode,
_polarity: PinPolarity,
_destination: Destination,
) {
todo!();
}

pub fn start_clock(_statclock_hz: u64, _stat_cb: fn(Nanoseconds)) {
// TODO: implement support for the stat clock
}
Expand Down
12 changes: 8 additions & 4 deletions src/kernel/src/machine/arm/common/gicv2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ impl GICv2 {

/// Configures the interrupt controller. At the end of this function
/// the current calling CPU is ready to recieve interrupts.
pub fn configure(&self) {
// enable the gic distributor
self.global.enable();

pub fn configure_local(&self) {
// set the interrupt priority mask to accept all interrupts
self.set_interrupt_mask(GICC::ACCEPT_ALL);

// enable the gic cpu interface
self.local.enable();
}

/// Configures global state in the interrupt controller. This should only
/// really be called once during system intialization by the boostrap core.
pub fn configure_global(&self) {
// enable the gic distributor
self.global.enable();
}

/// Sets the interrupt priority mask for the current calling CPU.
fn set_interrupt_mask(&self, mask: u8) {
// set the interrupt priority mask that we will accept
Expand Down
3 changes: 1 addition & 2 deletions src/kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ fn kernel_main<B: BootInfo>(boot_info: &mut B) -> ! {
panic::init(kernel_image);
}

arch::init_interrupts();

logln!("[kernel::cpu] enumerating secondary CPUs");
let bsp_id = arch::processor::enumerate_cpus();
processor::init_cpu(image::get_tls(), bsp_id);
arch::init_interrupts();
arch::init_secondary();
initrd::init(boot_info.get_modules());
logln!("[kernel::cpu] booting secondary CPUs");
Expand Down

0 comments on commit f384373

Please sign in to comment.