77 lines
2.7 KiB
Zig
77 lines
2.7 KiB
Zig
//! The firmware-agnostic discovery facade.
|
|
//!
|
|
//! The kernel calls `platform.discover()` and gets back a generic `DeviceTree`
|
|
//! without ever naming ACPI or device-tree — the same way it imports `arch`
|
|
//! without naming x86_64. Which backend runs is decided *at runtime* from what
|
|
//! the bootloader handed us (an ACPI RSDP today, a device-tree blob later),
|
|
//! because a single image — a future ARM kernel especially — may boot under
|
|
//! either firmware. That's a deliberate divergence from `arch`, which is a
|
|
//! compile-time choice.
|
|
|
|
const std = @import("std");
|
|
const danos = @import("danos");
|
|
const device = @import("device.zig");
|
|
const acpi = @import("acpi.zig");
|
|
const power = @import("power.zig");
|
|
const devicetree = @import("devicetree.zig");
|
|
|
|
pub const DeviceTree = device.DeviceTree;
|
|
pub const Device = device.Device;
|
|
pub const DeviceClass = device.DeviceClass;
|
|
pub const Hal = device.Hal;
|
|
pub const PowerInfo = acpi.PowerInfo;
|
|
pub const AmlStats = acpi.AmlStats;
|
|
pub const PlatformInfo = acpi.PlatformInfo;
|
|
pub const RegAccess = acpi.RegAccess;
|
|
pub const IsoEntry = acpi.IsoEntry;
|
|
|
|
/// The register map + sleep types discovery extracted, for logging/diagnostics.
|
|
pub fn powerInfo() PowerInfo {
|
|
return acpi.power_info;
|
|
}
|
|
|
|
/// The scalar firmware facts the arch layer needs to avoid legacy assumptions
|
|
/// (8259 presence, LAPIC base, PM timer, SPCR UART, IRQ overrides).
|
|
pub fn platformInfo() PlatformInfo {
|
|
return acpi.platform_info;
|
|
}
|
|
|
|
/// AML parse integrity/diagnostics (namespace node count, bytes consumed).
|
|
pub fn amlStats() AmlStats {
|
|
return acpi.aml_stats;
|
|
}
|
|
|
|
/// Enumerate hardware into a fresh device tree. `hal` supplies the hardware
|
|
/// primitives the backend needs (MMIO mapping for PCIe config space, port I/O for
|
|
/// ACPI registers); pass the arch implementation. Errors leave nothing to clean up
|
|
/// beyond the tree's own allocations.
|
|
pub fn discover(
|
|
boot_info: *const danos.BootInfo,
|
|
allocator: std.mem.Allocator,
|
|
hal: Hal,
|
|
) !DeviceTree {
|
|
var dt = try DeviceTree.init(allocator);
|
|
|
|
if (boot_info.acpi_rsdp != 0) {
|
|
try acpi.discover(boot_info.acpi_rsdp, &dt, hal);
|
|
} else {
|
|
// No ACPI RSDP. A device-tree boot would parse its blob here; today that
|
|
// path is a stub, so this reports the machine described itself no way we
|
|
// understand yet.
|
|
try devicetree.discover(&dt);
|
|
}
|
|
|
|
return dt;
|
|
}
|
|
|
|
/// Restart the machine. Never returns on success; returns only if no reset method
|
|
/// worked (extremely unlikely). Backend-agnostic entry the kernel calls.
|
|
pub fn reboot(hal: Hal) void {
|
|
power.reboot(hal);
|
|
}
|
|
|
|
/// Power the machine off (ACPI S5). Never returns on success.
|
|
pub fn shutdown(hal: Hal) void {
|
|
power.shutdown(hal);
|
|
}
|