Skip to content

Commit

Permalink
pci: Use correct address calculation for PCI ECAM
Browse files Browse the repository at this point in the history
Specifying the address in PCI ECAM space is different than in PCI I/O
config space.

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Mar 14, 2023
1 parent 79babb9 commit ab9e0a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit ab9e0a4

Please sign in to comment.