Add pcid logging.

This commit is contained in:
4lDO2
2020-04-22 18:27:43 +02:00
parent aea6e1b84c
commit fe95c942ac
5 changed files with 70 additions and 16 deletions
Generated
+2
View File
@@ -835,7 +835,9 @@ dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"redox-log 0.1.0 (git+https://gitlab.redox-os.org/redox-os/redox-log.git?tag=v0.1.0)",
"redox_syscall 0.1.56 (git+https://gitlab.redox-os.org/redox-os/syscall.git)",
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)",
+2
View File
@@ -16,7 +16,9 @@ bincode = "1.2"
bitflags = "1"
byteorder = "1.2"
libc = "0.2"
log = "0.4"
plain = "0.2"
redox-log = { git = "https://gitlab.redox-os.org/redox-os/redox-log.git", tag = "v0.1.0" }
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+56 -11
View File
@@ -9,6 +9,9 @@ use std::{env, io, i64, thread};
use syscall::iopl;
use log::{error, info, warn, trace};
use redox_log::{OutputBuilder, RedoxLogger};
use crate::config::Config;
use crate::pci::{CfgAccess, Pci, PciIter, PciBar, PciBus, PciClass, PciDev, PciFunc, PciHeader, PciHeaderError, PciHeaderType};
use crate::pci::cap::Capability as PciCapability;
@@ -245,7 +248,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, bus_num: u8,
string.push('\n');
print!("{}", string);
info!("{}", string);
for driver in config.drivers.iter() {
if let Some(class) = driver.class {
@@ -364,7 +367,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, bus_num: u8,
};
crate::pci::cap::CapabilitiesIter { inner: crate::pci::cap::CapabilityOffsetsIter::new(header.cap_pointer(), &func) }.collect::<Vec<_>>()
};
println!("PCI DEVICE CAPABILITIES for {}: {:?}", args.iter().map(|string| string.as_ref()).nth(0).unwrap_or("[unknown]"), capabilities);
info!("PCI DEVICE CAPABILITIES for {}: {:?}", args.iter().map(|string| string.as_ref()).nth(0).unwrap_or("[unknown]"), capabilities);
use driver_interface::LegacyInterruptPin;
@@ -376,7 +379,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, bus_num: u8,
4 => Some(LegacyInterruptPin::IntD),
other => {
println!("pcid: invalid interrupt pin: {}", other);
warn!("pcid: invalid interrupt pin: {}", other);
None
}
};
@@ -426,7 +429,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, bus_num: u8,
command.arg(&arg);
}
println!("PCID SPAWN {:?}", command);
info!("PCID SPAWN {:?}", command);
let (pcid_to_client_write, pcid_from_client_read, envs) = if driver.channel_name.is_some() {
let mut fds1 = [0usize; 2];
@@ -459,16 +462,56 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, bus_num: u8,
});
match child.wait() {
Ok(_status) => (),
Err(err) => println!("pcid: failed to wait for {:?}: {}", command, err),
Err(err) => error!("pcid: failed to wait for {:?}: {}", command, err),
}
}
Err(err) => println!("pcid: failed to execute {:?}: {}", command, err)
Err(err) => error!("pcid: failed to execute {:?}: {}", command, err)
}
}
}
}
}
fn setup_logging() -> Option<&'static RedoxLogger> {
let mut logger = RedoxLogger::new()
.with_output(
OutputBuilder::stderr()
.with_ansi_escape_codes()
.with_filter(log::LevelFilter::Info)
.flush_on_newline(true)
.build()
);
match OutputBuilder::in_redox_logging_scheme("bus", "pci", "pcid.log") {
Ok(b) => logger = logger.with_output(
b.with_filter(log::LevelFilter::Trace)
.flush_on_newline(true)
.build()
),
Err(error) => eprintln!("pcid: failed to open pcid.log"),
}
match OutputBuilder::in_redox_logging_scheme("bus", "pci", "pcid.ansi.log") {
Ok(b) => logger = logger.with_output(
b.with_filter(log::LevelFilter::Trace)
.with_ansi_escape_codes()
.flush_on_newline(true)
.build()
),
Err(error) => eprintln!("pcid: failed to open pcid.ansi.log"),
}
match logger.enable() {
Ok(logger_ref) => {
eprintln!("pcid: enabled logger");
Some(logger_ref)
}
Err(error) => {
eprintln!("pcid: failed to set default logger: {}", error);
None
}
}
}
fn main() {
let mut config = Config::default();
@@ -499,6 +542,8 @@ fn main() {
}
}
let _logger_ref = setup_logging();
let pci = Arc::new(Pci::new());
let state = Arc::new(State {
@@ -506,7 +551,7 @@ fn main() {
pcie: match Pcie::new(Arc::clone(&pci)) {
Ok(pcie) => Some(pcie),
Err(error) => {
println!("Couldn't retrieve PCIe info, perhaps the kernel is not compiled with acpi? Using the PCI 3.0 configuration space instead. Error: {:?}", error);
info!("Couldn't retrieve PCIe info, perhaps the kernel is not compiled with acpi? Using the PCI 3.0 configuration space instead. Error: {:?}", error);
None
}
},
@@ -515,7 +560,7 @@ fn main() {
let pci = state.preferred_cfg_access();
print!("PCI BS/DV/FN VEND:DEVI CL.SC.IN.RV\n");
info!("PCI BS/DV/FN VEND:DEVI CL.SC.IN.RV");
'bus: for bus in PciIter::new(pci) {
'dev: for dev in bus.devs() {
@@ -528,16 +573,16 @@ fn main() {
Err(PciHeaderError::NoDevice) => {
if func_num == 0 {
if dev.num == 0 {
// println!("PCI {:>02X}: no bus", bus.num);
trace!("PCI {:>02X}: no bus", bus.num);
continue 'bus;
} else {
// println!("PCI {:>02X}/{:>02X}: no dev", bus.num, dev.num);
trace!("PCI {:>02X}/{:>02X}: no dev", bus.num, dev.num);
continue 'dev;
}
}
},
Err(PciHeaderError::UnknownHeaderType(id)) => {
println!("pcid: unknown header type: {}", id);
warn!("pcid: unknown header type: {}", id);
}
}
}
+3 -1
View File
@@ -8,6 +8,8 @@ pub use self::dev::{PciDev, PciDevIter};
pub use self::func::PciFunc;
pub use self::header::{PciHeader, PciHeaderError, PciHeaderType};
use log::info;
mod bar;
mod bus;
pub mod cap;
@@ -45,7 +47,7 @@ impl Pci {
fn set_iopl() {
// make sure that pcid is not granted io port permission unless pcie memory-mapped
// configuration space is not available.
println!("PCI: couldn't find or access PCIe extended configuration, and thus falling back to PCI 3.0 io ports");
info!("PCI: couldn't find or access PCIe extended configuration, and thus falling back to PCI 3.0 io ports");
unsafe { syscall::iopl(3).expect("pcid: failed to set iopl to 3"); }
}
fn address(bus: u8, dev: u8, func: u8, offset: u8) -> u32 {
+7 -4
View File
@@ -44,6 +44,7 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
OutputBuilder::stderr()
.with_filter(log::LevelFilter::Info) // limit global output to important info
.with_ansi_escape_codes()
.flush_on_newline(true)
.build()
);
@@ -51,7 +52,8 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
Ok(b) => logger = logger.with_output(
// TODO: Add a configuration file for this
b.with_filter(log::LevelFilter::Trace)
.build()
.flush_on_newline(true)
.build()
),
Err(error) => eprintln!("Failed to create xhci.log: {}", error),
}
@@ -59,8 +61,9 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
match OutputBuilder::in_redox_logging_scheme("usb", "host", "xhci.ansi.log") {
Ok(b) => logger = logger.with_output(
b.with_filter(log::LevelFilter::Trace)
.with_ansi_escape_codes()
.build()
.with_ansi_escape_codes()
.flush_on_newline(true)
.build()
),
Err(error) => eprintln!("Failed to create xhci.ansi.log: {}", error),
}
@@ -88,7 +91,7 @@ fn main() {
return;
}
setup_logging();
let _logger_ref = setup_logging();
let mut pcid_handle = PcidServerHandle::connect_default().expect("xhcid: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config");