#interrupt #kernel #apic

nightly no-std x2apic

A Rust interface to the x2apic interrupt architecture

10 releases

0.4.3 Sep 19, 2023
0.4.2 Feb 7, 2023
0.4.1 Aug 4, 2022
0.4.0 Oct 11, 2021
0.1.0 Jun 25, 2019

#147 in No standard library

Download history 1126/week @ 2024-07-21 1276/week @ 2024-07-28 330/week @ 2024-08-04 431/week @ 2024-08-11 310/week @ 2024-08-18 333/week @ 2024-08-25 522/week @ 2024-09-01 783/week @ 2024-09-08 494/week @ 2024-09-15 597/week @ 2024-09-22 292/week @ 2024-09-29 742/week @ 2024-10-06 1343/week @ 2024-10-13 1007/week @ 2024-10-20 867/week @ 2024-10-27 210/week @ 2024-11-03

3,558 downloads per month
Used in 2 crates

MIT/Apache

43KB
936 lines

x2apic-rs

A Rust interface to the x2apic interrupt architecture.

This crate is in its early stages and has only been tested in QEMU; code contributions and bug reports are welcome.

It will use x2APIC mode if supported by the CPU, otherwise it falls back to xAPIC mode.

Usage

The local APIC is initialized like so:

use x2apic::lapic::{LocalApic, LocalApicBuilder, xapic_base};

let apic_physical_address: u64 = unsafe { xapic_base() };
let apic_virtual_address: u64 = <convert from physical address>

let lapic = LocalApicBuilder::new()
    .timer_vector(timer_index)
    .error_vector(error_index)
    .spurious_vector(spurious_index)
    .set_xapic_base(apic_virtual_address)
    .build()
    .unwrap_or_else(|err| panic!("{}", err));

unsafe {
    lapic.enable();
}

This initializes and enables the local APIC timer with a default configuration. The timer can be configured with the builder or directly on the APIC.

The IOAPIC is initialized like so:

use x2apic::ioapic::{IoApic, IrqFlags, IrqMode, RedirectionTableEntry};

// !!! Map the IOAPIC's MMIO address `addr` here !!!

unsafe {
    let ioapic = IoApic::new(addr);

    ioapic.init(irq_offset);

    let mut entry = RedirectionTableEntry::default();
    entry.set_mode(IrqMode::Fixed);
    entry.set_flags(IrqFlags::LEVEL_TRIGGERED | IrqFlags::LOW_ACTIVE | IrqFlags::MASKED);
    entry.set_dest(dest); // CPU(s)
    ioapic.set_table_entry(irq_number, entry);

    ioapic.enable_irq(irq_number);
}

Please refer to the documentation for more details.

Dependencies

~1MB
~20K SLoC