From 99d991aa26d6933e7cee94372e5d1016613b4d5f Mon Sep 17 00:00:00 2001 From: Himbeer Date: Fri, 2 Aug 2024 18:14:40 +0200 Subject: hwinfo: Make byAddress() ignore non-MMIO devices --- src/hwinfo.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/hwinfo.zig b/src/hwinfo.zig index 8e937c2..649f7c6 100644 --- a/src/hwinfo.zig +++ b/src/hwinfo.zig @@ -42,6 +42,16 @@ pub const DevKind = enum(u32) { else => false, }; } + + pub fn isMemoryMapped(self: DevKind) bool { + return switch (self) { + .cpus => false, + .plic => true, + .pcie => true, + .pci => true, + _ => false, + }; + } }; pub const Dev = extern struct { @@ -132,6 +142,7 @@ pub fn byAddress(reg_addr: usize, only_user_manageable: bool) !?Dev { var it = try iterator(); while (it.next()) |device| { const authorized = !only_user_manageable or device.kind.isUserManageable(); - if (device.reg.addr == reg_addr and authorized) return device; + const eligible = device.kind.isMemoryMapped() and authorized; + if (device.reg.addr == reg_addr and eligible) return device; } else return null; } -- cgit v1.2.3