From 20eb92ae023ac9a4967cbecc392e603fb89176d1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:36:37 +0100 Subject: [PATCH] Assert PCI config space accesses are aligned --- pcid/src/pcie/fallback.rs | 8 ++------ pcid/src/pcie/mod.rs | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pcid/src/pcie/fallback.rs b/pcid/src/pcie/fallback.rs index 63f70eeb7a..90023961f7 100644 --- a/pcid/src/pcie/fallback.rs +++ b/pcid/src/pcie/fallback.rs @@ -42,18 +42,14 @@ impl Pci { } fn address(address: PciAddress, offset: u8) -> u32 { - // TODO: Find the part of pcid that uses an unaligned offset! - // - // assert_eq!(offset & 0xFC, offset, "pci offset is not aligned"); - // - let offset = offset & 0xFC; - assert_eq!( address.segment(), 0, "usage of multiple segments requires PCIe extended configuration" ); + assert_eq!(offset & 0xFC, offset, "pci offset is not aligned"); + 0x80000000 | (u32::from(address.bus()) << 16) | (u32::from(address.device()) << 11) diff --git a/pcid/src/pcie/mod.rs b/pcid/src/pcie/mod.rs index 24dbee0d12..0925b21d03 100644 --- a/pcid/src/pcie/mod.rs +++ b/pcid/src/pcie/mod.rs @@ -205,6 +205,8 @@ impl Pcie { "multiple segments not yet implemented" ); + assert_eq!(offset & 0xFC, offset, "pci offset is not aligned"); + let bus_addr = match self.bus_maps.get(address.bus() as usize) { Some(Some(bus_addr)) => bus_addr, Some(None) | None => return f(None),