ACPI Support
Overview
The FreeWorld OS ACPI (Advanced Configuration and Power Interface) support provides complete table parsing, enumeration, and device tree building. This enables comprehensive hardware enumeration and configuration information from ACPI tables.
Key Features: RSDP detection, RSDT/XSDT parsing, table enumeration, device tree building, full ACPI table support
Components
1. ACPI Core Support (UEFI-Aware)
Location: kernel/acpi/acpi_uefi.asm (Primary)
Legacy: kernel/acpi/acpi.asm (Deprecated - memory search)
Complete ACPI table parsing and management using UEFI-provided RSDP:
- RSDP from UEFI: Retrieved from UEFI System Table Configuration Table (no memory searching needed)
- RSDP Validation: Checksum verification (ACPI 1.0 and 2.0+)
- RSDT Parsing: ACPI 1.0 Root System Description Table (32-bit pointers)
- XSDT Parsing: ACPI 2.0+ Extended System Description Table (64-bit pointers)
- Version Detection: Automatic ACPI 1.0 vs 2.0+ detection
- Table Enumeration: All ACPI tables scanned and stored
- Table Validation: Checksum verification for all tables
- Table Finding: Find tables by signature
- Address Extraction: Extracts I/O APIC, Local APIC, HPET base addresses
2. ACPI Table Support
Full support for standard ACPI tables:
- FADT (Fixed ACPI Description Table) - System configuration, power management
- MADT (Multiple APIC Description Table) - APIC information, interrupt routing
- DSDT (Differentiated System Description Table) - ACPI namespace, device definitions
- SSDT (Secondary System Description Table) - Additional device definitions
- SRAT (Static Resource Affinity Table) - NUMA topology, memory/CPU affinity
- SLIT (System Locality Information Table) - NUMA node distances
- MCFG (PCI Express Configuration) - PCIe configuration space base addresses
- HPET (High Precision Event Timer) - Timer information
- DMAR (DMA Remapping) - IOMMU information
3. Device Tree
Location: kernel/acpi/device_tree.asm
Hardware enumeration from ACPI tables:
- MADT Enumeration: Local APIC, I/O APIC devices
- MCFG Enumeration: PCI Express devices
- SRAT Enumeration: NUMA nodes
- FADT Enumeration: System devices (HPET, PM1a)
- DSDT Enumeration: ACPI namespace devices (structure ready)
- Device Nodes: Structured device information
- Device Finding: Find devices by name
ACPI Initialization Flow (UEFI-Aware)
UEFI Bootloader
↓
Get ACPI RSDP from UEFI System Table Configuration Table
↓ (BEFORE ExitBootServices - CRITICAL!)
Stash RSDP in boot_params_t
↓
ExitBootServices()
↓
Kernel Entry (kernel_entry_uefi.asm)
↓
Extract RSDP from boot_params_t
↓
ACPI Initialization (acpi_init_uefi)
↓
1. Validate RSDP
- Checksum verification
- Version detection (1.0 vs 2.0+)
↓
2. Parse RSDT/XSDT
- ACPI 1.0: RSDT (32-bit pointers)
- ACPI 2.0+: XSDT (64-bit pointers)
↓
3. Enumerate All Tables
- Scan RSDT/XSDT entries
- Validate each table (checksum)
- Store in table list
↓
4. Parse Important Tables
- FADT (system configuration)
- MADT (APIC information - extracts I/O APIC, Local APIC)
- SRAT (NUMA topology)
- MCFG (PCIe configuration)
- HPET (timer information - extracts HPET base)
↓
5. Extract Hardware Addresses
- I/O APIC base from MADT
- Local APIC base from MADT
- HPET base from HPET table
↓
6. Build Device Tree
- Enumerate devices from tables
- Create device nodes
- Link device tree
↓
ACPI Ready
API Functions
ACPI Core Functions
; Initialize ACPI
acpi_init:
; Input: RAX = RSDP address (or 0 to search)
; Returns: RAX = 0 on success, non-zero on error
; Find ACPI table by signature
acpi_find_table:
; Input: RSI = signature (4 bytes, null-padded to 8)
; Returns: RAX = table address or 0
; Get specific table addresses
acpi_get_fadt: ; Returns: RAX = FADT address
acpi_get_madt: ; Returns: RAX = MADT address
acpi_get_dsdt: ; Returns: RAX = DSDT address
acpi_get_srat: ; Returns: RAX = SRAT address
acpi_get_mcfg: ; Returns: RAX = MCFG address
acpi_get_hpet: ; Returns: RAX = HPET address
; Get ACPI information
acpi_get_version: ; Returns: AL = version (1 or 2)
acpi_is_initialized: ; Returns: AL = 1 if initialized
acpi_get_table_count: ; Returns: EAX = table count
acpi_get_table_list: ; Returns: RAX = pointer to table list
Device Tree Functions
; Build device tree from ACPI tables
acpi_build_device_tree:
; Returns: RAX = 0 on success, non-zero on error
; Get device tree information
acpi_get_device_tree_root: ; Returns: RAX = root node pointer
acpi_get_device_node_count: ; Returns: EAX = device node count
acpi_get_device_nodes: ; Returns: RAX = pointer to device nodes
; Find device by name
acpi_find_device:
; Input: RSI = device name (null-terminated)
; Returns: RAX = device node pointer or 0
ACPI Tables
FADT (Fixed ACPI Description Table)
Contains fixed hardware addresses and configuration:
- PM1a/PM1b Event and Control Blocks
- PM2 Control Block
- PM Timer Block
- GPE0/GPE1 Blocks
- DSDT address
- HPET address (ACPI 2.0+)
MADT (Multiple APIC Description Table)
Contains APIC and interrupt information:
- Local APIC entries (processor information)
- I/O APIC entries (I/O APIC addresses)
- Interrupt Source Override entries
- NMI Source entries
- Local APIC NMI entries
DSDT (Differentiated System Description Table)
Contains ACPI namespace in AML (ACPI Machine Language):
- Device definitions
- Method definitions
- Resource definitions
- Power management definitions
- Note: Full parsing requires AML interpreter (structure ready)
SRAT (Static Resource Affinity Table)
Contains NUMA topology information:
- Processor Local APIC/SAPIC Affinity entries
- Memory Affinity entries
- Processor Local x2APIC Affinity entries
- GICC Affinity entries (ARM)
- GIC ITS Affinity entries (ARM)
MCFG (PCI Express Configuration)
Contains PCI Express configuration space information:
- Base address for each PCIe segment
- Bus range for each segment
- Segment group number
HPET (High Precision Event Timer)
Contains HPET timer information:
- HPET base address
- HPET capabilities
- Timer count
Device Tree Structure
Device Node Structure
struc DEVICE_NODE
.name: resb 64 ; Device name/path
.type: resb 1 ; Device type
.address: resq 1 ; Device address
.irq: resb 1 ; IRQ number
.vendor_id: resw 1 ; Vendor ID
.device_id: resw 1 ; Device ID
.class_code: resd 1 ; Class code
.parent: resq 1 ; Parent node pointer
.children: resq 1 ; Children list pointer
.next: resq 1 ; Next sibling
endstruc
Device Types
DEVICE_TYPE_UNKNOWN- Unknown deviceDEVICE_TYPE_PCI- PCI deviceDEVICE_TYPE_PCIe- PCI Express deviceDEVICE_TYPE_ISA- ISA deviceDEVICE_TYPE_ACPI- ACPI deviceDEVICE_TYPE_IOAPIC- I/O APICDEVICE_TYPE_LAPIC- Local APICDEVICE_TYPE_HPET- HPET timerDEVICE_TYPE_TIMER- Timer device
Usage Examples
Initialize ACPI
; Get RSDP from early hardware detection
extern get_early_hardware_info
call get_early_hardware_info
mov rsi, rax
mov rax, [rsi + 112] ; acpi_rsdp offset
; Initialize ACPI
extern acpi_init
call acpi_init
test rax, rax
jnz .acpi_error
; Build device tree
extern acpi_build_device_tree
call acpi_build_device_tree
Access ACPI Tables
; Get MADT address
extern acpi_get_madt
call acpi_get_madt
; RAX = MADT address
; Find table by signature
extern acpi_find_table
mov rsi, acpi_sig_srat ; "SRAT"
call acpi_find_table
; RAX = SRAT address or 0
Access Device Tree
; Get device tree root
extern acpi_get_device_tree_root
call acpi_get_device_tree_root
; RAX = root node pointer
; Find device by name
extern acpi_find_device
mov rsi, device_name ; "/LAPIC"
call acpi_find_device
; RAX = device node pointer or 0
Integration Points
With Early Hardware Detection
- RSDP passed from early hardware detection
- ACPI version detected
- RSDP address available
With Kernel Initialization
- ACPI initialized after hardware detection
- Device tree built during kernel init
- Tables available for driver matching
With Driver System
- Device nodes used for driver matching
- Device addresses from ACPI tables
- IRQ information from MADT
With Memory Management
- NUMA topology from SRAT
- Memory affinity information
- Node distance information (SLIT)
With Boot Parameters
- ACPI can be disabled via
acpi=offornoacpi - Boot parameter checked before ACPI init
File Structure
kernel/acpi/
├── acpi.asm # Core ACPI support (~600 lines)
├── device_tree.asm # Device tree enumeration (~500 lines)
└── Makefile # Build system
Future Enhancements
- AML Interpreter: Full DSDT/SSDT parsing, ACPI namespace traversal, method execution
- Power Management: ACPI power states, sleep/wake support, CPU power management
- Thermal Management: Thermal zones, cooling devices, temperature monitoring
- Device Configuration: Device-specific configuration, resource allocation, interrupt routing
Related Documentation
- UEFI Boot - RSDP passing from UEFI
- Early Hardware Detection - RSDP detection
- Boot Parameters - ACPI disable support
- Kernel - Kernel initialization phases
- Device Drivers - Driver matching using ACPI
- Memory Management - NUMA topology usage