From 96798efb7e5163c17af0e93a79ee0e41b92c34bb Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 23 Sep 2024 15:22:07 -0500 Subject: [PATCH] Dump device BARs in logs --- src/main.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 941bc2e..d5931ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()