diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-01 18:25:55 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-01 18:25:55 +0200 |
| commit | 1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5 (patch) | |
| tree | f28246586e387293d0c8beaf6b445210aaab8c48 /rsnix/src/pci.rs | |
| parent | klog/tty/pager: no more truncated lines — full lines flow, terminal wraps (diff) | |
| download | rs-dos-1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5.tar.gz rs-dos-1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5.zip | |
fix pi-lens warnings: unwraps, shell SC2046, dup code (fmtbuf/scripts/hexdump/cat/ahci/pci)
- 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
Diffstat (limited to '')
| -rw-r--r-- | rsnix/src/pci.rs | 28 |
1 files changed, 16 insertions, 12 deletions
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 { | |||
| 46 | val | 46 | val |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /// Read a dword from a device's config space (`reg` must be dword-aligned). | 49 | /// Encode the PCI config-space port address for (bus, dev, fn, reg); |
| 50 | pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { | 50 | /// `reg` must be dword-aligned. |
| 51 | let addr = 0x8000_0000 | 51 | fn config_addr(bus: u8, device: u8, func: u8, reg: u8) -> u32 { |
| 52 | 0x8000_0000 | ||
| 52 | | ((bus as u32) << 16) | 53 | | ((bus as u32) << 16) |
| 53 | | ((device as u32) << 11) | 54 | | ((device as u32) << 11) |
| 54 | | ((func as u32) << 8) | 55 | | ((func as u32) << 8) |
| 55 | | ((reg as u32) & 0xFC); | 56 | | ((reg as u32) & 0xFC) |
| 56 | outl(CONFIG_ADDRESS, addr); | 57 | } |
| 58 | |||
| 59 | /// Read a dword from a device's config space (`reg` must be dword-aligned). | ||
| 60 | pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { | ||
| 61 | outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); | ||
| 57 | inl(CONFIG_DATA) | 62 | inl(CONFIG_DATA) |
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | /// Write a dword to a device's config space (`reg` must be dword-aligned). | 65 | /// Write a dword to a device's config space (`reg` must be dword-aligned). |
| 61 | pub fn config_write(bus: u8, device: u8, func: u8, reg: u8, val: u32) { | 66 | pub fn config_write(bus: u8, device: u8, func: u8, reg: u8, val: u32) { |
| 62 | let addr = 0x8000_0000 | 67 | outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); |
| 63 | | ((bus as u32) << 16) | ||
| 64 | | ((device as u32) << 11) | ||
| 65 | | ((func as u32) << 8) | ||
| 66 | | ((reg as u32) & 0xFC); | ||
| 67 | outl(CONFIG_ADDRESS, addr); | ||
| 68 | outl(CONFIG_DATA, val) | 68 | outl(CONFIG_DATA, val) |
| 69 | } | 69 | } |
| 70 | 70 | ||
| @@ -83,7 +83,11 @@ pub fn bar64(bus: u8, device: u8, func: u8, bar_index: u8) -> Option<u64> { | |||
| 83 | 0 | 83 | 0 |
| 84 | }; | 84 | }; |
| 85 | let base = ((hi as u64) << 32) | (lo as u64 & 0xFFFF_FFF0); | 85 | let base = ((hi as u64) << 32) | (lo as u64 & 0xFFFF_FFF0); |
| 86 | if base == 0 { None } else { Some(base) } | 86 | if base == 0 { |
| 87 | None | ||
| 88 | } else { | ||
| 89 | Some(base) | ||
| 90 | } | ||
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | /// Enumerate every device/function present on all buses. | 93 | /// Enumerate every device/function present on all buses. |
