From 1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 18:25:55 +0200 Subject: fix pi-lens warnings: unwraps, shell SC2046, dup code (fmtbuf/scripts/hexdump/cat/ahci/pci) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - memory.rs: self-test Layout::from_size_align no longer panics — the test fails cleanly on an invalid layout - fat.rs: v() no longer unwraps the active-volume slot — invariant violation logs + halts instead of panicking mid-disk-io - strbuf: shared FmtBuf replaces the duplicated PanicBuf/FmtBuf (main.rs + sched.rs) - test-disk.sh: SC2046 — conditional --fresh arg no longer relies on word splitting - scripts: boot.sh/boot-image.sh share lib-boot-args.sh (dup args loop) - shell: cat/hexdump stdin pairs unified with Option<&str> marker; hexdump format_row folded into format_partial - ahci: read/write_sectors unified behind dma_sectors - pci: config_read/write share config_addr --- rsnix/src/pci.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'rsnix/src/pci.rs') diff --git a/rsnix/src/pci.rs b/rsnix/src/pci.rs index 21d7536..b9c2265 100644 --- a/rsnix/src/pci.rs +++ b/rsnix/src/pci.rs @@ -46,25 +46,25 @@ fn inl(port: u16) -> u32 { val } -/// Read a dword from a device's config space (`reg` must be dword-aligned). -pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { - let addr = 0x8000_0000 +/// Encode the PCI config-space port address for (bus, dev, fn, reg); +/// `reg` must be dword-aligned. +fn config_addr(bus: u8, device: u8, func: u8, reg: u8) -> u32 { + 0x8000_0000 | ((bus as u32) << 16) | ((device as u32) << 11) | ((func as u32) << 8) - | ((reg as u32) & 0xFC); - outl(CONFIG_ADDRESS, addr); + | ((reg as u32) & 0xFC) +} + +/// Read a dword from a device's config space (`reg` must be dword-aligned). +pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { + outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); inl(CONFIG_DATA) } /// Write a dword to a device's config space (`reg` must be dword-aligned). pub fn config_write(bus: u8, device: u8, func: u8, reg: u8, val: u32) { - let addr = 0x8000_0000 - | ((bus as u32) << 16) - | ((device as u32) << 11) - | ((func as u32) << 8) - | ((reg as u32) & 0xFC); - outl(CONFIG_ADDRESS, addr); + outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); outl(CONFIG_DATA, val) } @@ -83,7 +83,11 @@ pub fn bar64(bus: u8, device: u8, func: u8, bar_index: u8) -> Option { 0 }; let base = ((hi as u64) << 32) | (lo as u64 & 0xFFFF_FFF0); - if base == 0 { None } else { Some(base) } + if base == 0 { + None + } else { + Some(base) + } } /// Enumerate every device/function present on all buses. -- cgit v1.2.3