Skip to content

Commit

Permalink
refactor(pci): migrate to x86_64 crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 20, 2024
1 parent fe17e08 commit d3c803c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/arch/x86_64/kernel/pci.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
use pci_types::{ConfigRegionAccess, PciAddress, PciHeader};
use x86::io::*;
use x86_64::instructions::port::Port;

use crate::drivers::pci::{PciDevice, PCI_DEVICES};

const PCI_MAX_BUS_NUMBER: u8 = 32;
const PCI_MAX_DEVICE_NUMBER: u8 = 32;

const PCI_CONFIG_ADDRESS_PORT: u16 = 0xcf8;
const PCI_CONFIG_ADDRESS_ENABLE: u32 = 1 << 31;

const PCI_CONFIG_DATA_PORT: u16 = 0xcfc;
#[inline]
const fn config_address() -> Port<u32> {
Port::new(0xcf8)
}

#[inline]
const fn config_data() -> Port<u32> {
Port::new(0xcfc)
}

#[derive(Debug, Copy, Clone)]
pub(crate) struct PciConfigRegion;
Expand All @@ -29,8 +36,8 @@ impl ConfigRegionAccess for PciConfigRegion {
| u32::from(pci_addr.function()) << 8
| u32::from(register);
unsafe {
outl(PCI_CONFIG_ADDRESS_PORT, address);
u32::from_le(inl(PCI_CONFIG_DATA_PORT))
config_address().write(address);
config_data().read()
}
}

Expand All @@ -41,9 +48,10 @@ impl ConfigRegionAccess for PciConfigRegion {
| u32::from(pci_addr.device()) << 11
| u32::from(pci_addr.function()) << 8
| u32::from(register);

unsafe {
outl(PCI_CONFIG_ADDRESS_PORT, address);
outl(PCI_CONFIG_DATA_PORT, value.to_le());
config_address().write(address);
config_data().write(value);
}
}
}
Expand Down

0 comments on commit d3c803c

Please sign in to comment.