ARM VGIC - Virtual Generic Interrupt Controller
A Virtual Generic Interrupt Controller (VGIC) implementation for ARM architecture, designed for the ArceOS hypervisor ecosystem.
Overview
This crate provides a comprehensive implementation of ARM's Virtual Generic Interrupt Controller (VGIC), enabling virtualized interrupt management for guest operating systems running under a hypervisor. The VGIC emulates the behavior of ARM's Generic Interrupt Controller (GIC) hardware, allowing multiple virtual machines to share the underlying interrupt controller while maintaining isolation.
Features
- GICv2 Support: Complete implementation of GIC version 2 virtualization
- GICv3 Support: Optional GIC version 3 support (enabled with
vgicv3feature) - Interrupt Types: Support for all ARM interrupt types:
- Software Generated Interrupts (SGI) - IDs 0-15
- Private Peripheral Interrupts (PPI) - IDs 16-31
- Shared Peripheral Interrupts (SPI) - IDs 32-511
- Virtual Timer: Virtualized timer implementation with system register emulation
- Memory-Mapped I/O: Complete MMIO interface emulation for guest access
- Multi-VCPU Support: Proper interrupt routing and distribution across virtual CPUs
Architecture
The crate is organized into several key components:
Core Components
- VGIC (
vgic.rs): Main VGIC controller implementation - VGICD (
vgicd.rs): Virtual GIC Distributor for interrupt routing - Interrupts (
interrupt.rs): Interrupt state management and operations - Registers (
registers.rs): GIC register definitions and access - List Registers (
list_register.rs): Hardware list register management
Usage
Basic Setup
use Vgic;
// Create a new VGIC instance
let vgic = new;
// The VGIC implements BaseDeviceOps for MMIO handling
// Register it with your hypervisor's device management system
Feature Flags
Enable GICv3 support:
[]
= { = "*", = ["vgicv3"] }
Integration with ArceOS
This crate is designed to integrate seamlessly with the ArceOS hypervisor ecosystem:
- Uses
axdevice_basefor device abstraction - Integrates with
axaddrspacefor memory management - Leverages
axvisor_apifor hypervisor operations
Memory Layout
The VGIC exposes the following memory-mapped regions to guest VMs:
- GIC Distributor (GICD):
0x0800_0000-0x0800_FFFF(64KB) - GIC CPU Interface (GICC):
0x0801_0000-0x0801_FFFF(64KB) - GICv3 Redistributor (GICR):
0x0802_0000+(128KB per CPU)
Register Support
Distributor Registers (GICD)
GICD_CTLR- Distributor Control RegisterGICD_TYPER- Interrupt Controller Type RegisterGICD_IIDR- Distributor Implementer Identification RegisterGICD_IGROUPR- Interrupt Group RegistersGICD_ISENABLER- Interrupt Set-Enable RegistersGICD_ICENABLER- Interrupt Clear-Enable RegistersGICD_ISPENDR- Interrupt Set-Pending RegistersGICD_ICPENDR- Interrupt Clear-Pending RegistersGICD_ISACTIVER- Interrupt Set-Active RegistersGICD_ICACTIVER- Interrupt Clear-Active RegistersGICD_IPRIORITYR- Interrupt Priority RegistersGICD_ITARGETSR- Interrupt Processor Targets RegistersGICD_ICFGR- Interrupt Configuration RegistersGICD_SGIR- Software Generated Interrupt Register
CPU Interface Registers (GICC)
GICC_CTLR- CPU Interface Control RegisterGICC_PMR- Interrupt Priority Mask RegisterGICC_BPR- Binary Point RegisterGICC_IAR- Interrupt Acknowledge RegisterGICC_EOIR- End Of Interrupt RegisterGICC_RPR- Running Priority RegisterGICC_HPPIR- Highest Priority Pending Interrupt Register
ArceOS Integration
axdevice_base: Device abstraction layeraxaddrspace: Address space managementaxvisor_api: Hypervisor API and operations
Platform Support
- Primary:
aarch64-unknown-none-softfloat - Architecture: ARM64/AArch64 only
- Hypervisor: ArceOS hypervisor
Examples
Interrupt Injection
// Interrupt injection is handled through the ArceOS VMM API
use InterruptVector;
// Hardware interrupt injection (handled by hypervisor)
let vector = new; // IRQ 42
// The VGIC will handle the virtualization automatically
Timer Management
use get_sysreg_device;
// Get virtual timer system register devices
let timer_devices = get_sysreg_device;
// Register with your system register handler
for device in timer_devices
Testing
# Run tests
# Run tests with all features
Contributing
This project is part of the ArceOS hypervisor ecosystem. Contributions should follow the ArceOS project guidelines and maintain compatibility with the broader ecosystem.
Related Projects
- axdevice_crates - Device abstraction layer
- axvisor_api - Hypervisor API definitions
- axaddrspace - Address space management