Dump device BARs in logs

This commit is contained in:
pjht 2024-09-23 15:22:07 -05:00
parent 09ace0dfed
commit 96798efb7e
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -8,7 +8,7 @@ use device_types::{Class, InvalidClass};
use pci_rpc::Server;
use serde::{Deserialize, Serialize};
use spin::Mutex;
use x86_64::instructions::port::{Port, PortWriteOnly};
use x86_64::{instructions::port::{Port, PortWriteOnly}, registers::control};
pub mod device_types;
@ -374,6 +374,29 @@ fn main() {
device.common.header_type,
)
).unwrap();
if let &ConfigTypeSpecific::Type0(cfg_type0) = &device.type_specific {
let accessor = ConfigAccessor::new(device.bus, device.device, device.function);
for (i, &bar) in cfg_type0.bars.iter().enumerate() {
if bar == 0x0 {
continue;
}
let bar_idx = (i + 0x4) as u8;
accessor.write(bar_idx, 0xFFFF_FFFF);
let bar_tmp = accessor.read(bar_idx);
let info_bits = if bar & 0x1 == 1 {
bar_tmp & !0x3
} else {
bar_tmp & !0xF
};
let size = !(info_bits) + 1;
accessor.write(bar_idx, bar);
if bar & 0x1 == 1 {
syslog_client.send_text_message("pci", format!("BAR {}: IO {:#x}, size {:#x}", i, bar & (!0x3), size));
} else {
syslog_client.send_text_message("pci", format!("BAR {}: MEM {:#x}, size {:#x}", i, bar & (!0xF), size));
}
}
}
let driver = config
.mappings
.iter()