Code: Select all
pub fn probe() {
printkln!("Init: PCI scan started");
if let Ok(table) = acpi::init() {
if let Some(regions) = table.pci_config_regions {
for sg in 0..MAX_SG {
for bus in 0..MAX_BUS {
for device in 0..MAX_DEVICE {
for function in 0..MAX_FUNCTION {
if let Some(addr) = regions.physical_address(
sg as u16,
bus as u8,
device as u8,
function as u8,
) {
// Do this check anyway
use crate::memory::{allocate_phys_range, free_range};
allocate_phys_range(addr.clone(), addr.clone() + 4096);
if (read_dword(addr as usize, VENDOR_ID) & 0xFFFF) == 0xFFFF {
free_range(addr.clone(), addr.clone() + 4096);
continue;
}
// Add the device...
} else {
continue;
}
}
}
}
}
let devs = PCI_DEVICES.read();
printkln!("init: PCI scan complete; {} devices found", devs.len());
} else {
printkln!("init: error: no PCI regions");
}
} else {
printkln!("init: error: ACPI unsupported");
}
}
Edit: Also, if I scan a segment group and ask for all devices on BDF 0:0:0, can I safely assume that no devices exist if I ask for <sg here>:0:0:0 but I don't get anything on that sgdev:func? Like, if I ask the system for segment group 32, and BDF 0:0:0, can I safely assume that there are no devices in SG 32 if I get nothing back?