A Rust driver for the ARM Generic Interrupt Controller (GIC), designed for bare-metal and OS kernel environments.
- Multi-version Support: Compatible with GICv1, GICv2, GICv3
- Memory Safety: Written in safe Rust with zero-cost abstractions
- No Standard Library:
#![no_std]
compatible for embedded environments - Type Safety: Strong typing for interrupt IDs and register access
- Comprehensive Testing: Extensive test suites for different GIC versions
use arm_gic_driver::v3::*;
let mut gic = unsafe { Gic::new(0xF901_0000.into(), 0xF902_0000.into()) };
gic.init();
// Every CPU should initialize its own CPU interface
let mut cpu = gic.cpu_interface();
cpu.init_current_cpu().unwrap();
// It implements `Send` and `Sync` traits, so it can be used as static value in trap handler easily.
let trap = cpu.trap_operations();
// Enable an Timer interrupt
let irq_id = IntId::ppi(14);
gic.set_irq_enable(irq_id, true);
// Set interrupt priority
gic.set_priority(irq_id, 0x80);
// Acknowledge and handle interrupts group1
let ack = trap.ack1();
if !ack.is_special() {
trap.eoi1(ack);
if trap.eoi_mode() {
trap.dir(ack);
}
}
This driver supports multiple ARM GIC versions:
- GICv1: Legacy interrupt controller
- GICv2: Supports up to 8 CPU cores
- GICv3: Scalable to many cores, supports message-based interrupts
- Rust nightly toolchain (specified in
rust-toolchain.toml
) - QEMU (for running platform tests)
The project includes comprehensive test suites for different platforms and GIC versions:
# Test GICv2 on AArch64
./test.sh
# Test with EL2 support
./test-el2.sh
# Test GICv3
./test_v3.sh
VirtAddr
: Type-safe virtual address wrapperIntId
: Interrupt identifier with validationv2::Gic
,v3::Gic
: Version-specific GIC implementations
See the itest/
directory for comprehensive examples of using the driver in different scenarios.
Contributions are welcome! Please ensure that:
- All tests pass:
cargo test --workspace
- Code is properly formatted:
cargo fmt
- No clippy warnings:
cargo clippy
- Platform tests pass on relevant architectures
This project is licensed under the Mulan PSL v2 License. See the LICENSE file for details.