From ab9e0a429b3acf11fd71a0cd9987c75ff4013e05 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 14 Mar 2023 15:19:00 +0000 Subject: [PATCH] pci: Use correct address calculation for PCI ECAM Specifying the address in PCI ECAM space is different than in PCI I/O config space. Signed-off-by: Rob Bradford --- src/pci.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pci.rs b/src/pci.rs index fdfa8729..8e02bde4 100644 --- a/src/pci.rs +++ b/src/pci.rs @@ -102,6 +102,8 @@ impl PciConfig { } } + // This is the logic for calculating I/O port address + #[cfg(target_arch = "x86_64")] fn calculate_pci_address(bus: u8, device: u8, func: u8, offset: u8) -> u32 { assert_eq!(offset % 4, 0); assert!(bus < MAX_BUSES); @@ -117,6 +119,23 @@ impl PciConfig { addr } + // This is the logic for calculating PCI ECAM + #[cfg(not(target_arch = "x86_64"))] + fn calculate_pci_address(bus: u8, device: u8, func: u8, offset: u8) -> u32 { + assert_eq!(offset % 4, 0); + assert!(bus < MAX_BUSES); + assert!(device < MAX_DEVICES); + assert!(func < MAX_FUNCTIONS); + + let mut addr = 0; + addr |= u32::from(bus) << 20; // bus bits 20-27 + addr |= u32::from(device) << 15; // slot/device bits 15-19 + addr |= u32::from(func) << 12; // function bits 12-14 + addr |= offset as u32 & 0x3ff; // register + + addr + } + fn read(&mut self, bus: u8, device: u8, func: u8, offset: u8) -> u32 { let addr = Self::calculate_pci_address(bus, device, func, offset); self.read_at(addr)