Better way of scanning PCE?
Posted: Fri Aug 14, 2020 7:12 pm
So, I've just managed to get PCE working. (Hooray!) I'mable to enumerate all possible PCI devices on the system. The problem is, of course... that its, well... really, reaaaaally slow. Right now I scan for all 16,777,216 possible devices like this:
As you can imagine, this is absolutely insane. Is there a better way of doing this that doesn't require me to scan segment groups that don't exist?
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 sg
dev: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?
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 sg