Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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