Name ACPI hardware IDs instead of magic _HID strings
Turn acpi-ids.zig's flat name table into a HardwareId enum modeled on ps2-library's Port: one entry() switch holds the registry (variant -> _HID string + human-readable name), with hid(), description(), and fromHid() methods. The free description(hid) lookup the kernel's device-tree dump uses survives, implemented over the enum, and a new test round-trips every variant through fromHid. Callers now name the device instead of quoting its id: - ps2-library's DeviceType.hid() and ps2-bus's descriptor lookups use HardwareId.ps2_keyboard / .ps2_mouse. - device-manager's driverFor parses the HID once with fromHid and switches on named values. - acpi.zig's isPciRootNode carried the same ids twice, as strings and as packed-EISA integers (0x030AD041/0x080AD041); both branches now decode to the string form and answer through one isPciRootHid helper using .pci_bus / .pci_express_root_bridge. - build.zig threads the acpi-ids module (previously kernel-only) into every user binary, like xkeyboard-config.
This commit is contained in:
+12
-6
@@ -17,6 +17,7 @@
|
||||
const std = @import("std");
|
||||
const boot_handoff = @import("boot-handoff");
|
||||
const abi = @import("abi");
|
||||
const acpi_ids = @import("acpi-ids");
|
||||
const parameters = @import("parameters");
|
||||
const device_model = @import("device-model.zig");
|
||||
const aml = @import("aml/aml.zig");
|
||||
@@ -914,7 +915,14 @@ fn readAdr(node: *aml.Node) ?u32 {
|
||||
return @truncate(readIntObj(n.value, &p) orelse return null);
|
||||
}
|
||||
|
||||
/// Whether a namespace device is a PCI(e) host bridge (`PNP0A03` / `PNP0A08`).
|
||||
/// Whether a `_HID` string names a PCI(e) host bridge.
|
||||
fn isPciRootHid(hid: []const u8) bool {
|
||||
const id = acpi_ids.HardwareId.fromHid(hid) orelse return false;
|
||||
return id == .pci_bus or id == .pci_express_root_bridge;
|
||||
}
|
||||
|
||||
/// Whether a namespace device is a PCI(e) host bridge. A packed EISA id is decoded
|
||||
/// to its string form first, so both encodings answer through the one registry.
|
||||
fn isPciRootNode(node: *aml.Node) bool {
|
||||
const hid = aml.Namespace.childOf(node, seg4("_HID")) orelse return false;
|
||||
if (hid.kind != .name or hid.value.len == 0) return false;
|
||||
@@ -922,12 +930,10 @@ fn isPciRootNode(node: *aml.Node) bool {
|
||||
0x00, 0x01, 0xFF, 0x0A, 0x0B, 0x0C, 0x0E => {
|
||||
var p: usize = 0;
|
||||
const n = readIntObj(hid.value, &p) orelse return false;
|
||||
return n == 0x030AD041 or n == 0x080AD041; // PNP0A03 / PNP0A08
|
||||
},
|
||||
0x0D => {
|
||||
const s = cstr(hid.value[1..]);
|
||||
return std.mem.eql(u8, s, "PNP0A03") or std.mem.eql(u8, s, "PNP0A08");
|
||||
var buffer: [8]u8 = undefined;
|
||||
return isPciRootHid(eisaIdToStr(@truncate(n), &buffer));
|
||||
},
|
||||
0x0D => return isPciRootHid(cstr(hid.value[1..])),
|
||||
else => return false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user