Unverified Commit c11736f7 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #21 from ghatdev/master

pcid: fix error E0133
parents b7fe49cc dd5f83cd
...@@ -41,11 +41,13 @@ fn main() { ...@@ -41,11 +41,13 @@ fn main() {
if let Some(header) = func.header() { if let Some(header) = func.header() {
let pci_class = PciClass::from(header.class); let pci_class = PciClass::from(header.class);
let mut string = format!("PCI {:>02X}/{:>02X}/{:>02X} {:>04X}:{:>04X} {:>02X}.{:>02X}.{:>02X}.{:>02X} {:?}", let mut string = unsafe {
bus.num, dev.num, func.num, format!("PCI {:>02X}/{:>02X}/{:>02X} {:>04X}:{:>04X} {:>02X}.{:>02X}.{:>02X}.{:>02X} {:?}",
header.vendor_id, header.device_id, bus.num, dev.num, func.num,
header.class, header.subclass, header.interface, header.revision, header.vendor_id, header.device_id,
pci_class); header.class, header.subclass, header.interface, header.revision,
pci_class)
};
match pci_class { match pci_class {
PciClass::Storage => match header.subclass { PciClass::Storage => match header.subclass {
...@@ -78,14 +80,16 @@ fn main() { ...@@ -78,14 +80,16 @@ fn main() {
_ => () _ => ()
} }
for i in 0..header.bars.len() { unsafe {
match PciBar::from(header.bars[i]) { for i in 0..header.bars.len() {
PciBar::None => (), match PciBar::from(header.bars[i]) {
PciBar::Memory(address) => string.push_str(&format!(" {}={:>08X}", i, address)), PciBar::None => (),
PciBar::Port(address) => string.push_str(&format!(" {}={:>04X}", i, address)) PciBar::Memory(address) => string.push_str(&format!(" {}={:>08X}", i, address)),
PciBar::Port(address) => string.push_str(&format!(" {}={:>04X}", i, address))
}
} }
} }
string.push('\n'); string.push('\n');
print!("{}", string); print!("{}", string);
...@@ -124,27 +128,31 @@ fn main() { ...@@ -124,27 +128,31 @@ fn main() {
let mut command = Command::new(program); let mut command = Command::new(program);
for arg in args { for arg in args {
let bar_arg = |i| -> String { let bar_arg = |i| -> String {
match PciBar::from(header.bars[i]) { unsafe {
PciBar::None => String::new(), match PciBar::from(header.bars[i]) {
PciBar::Memory(address) => format!("{:>08X}", address), PciBar::None => String::new(),
PciBar::Port(address) => format!("{:>04X}", address) PciBar::Memory(address) => format!("{:>08X}", address),
PciBar::Port(address) => format!("{:>04X}", address)
}
} }
}; };
let arg = match arg.as_str() { let arg = unsafe {
"$BUS" => format!("{:>02X}", bus.num), match arg.as_str() {
"$DEV" => format!("{:>02X}", dev.num), "$BUS" => format!("{:>02X}", bus.num),
"$FUNC" => format!("{:>02X}", func.num), "$DEV" => format!("{:>02X}", dev.num),
"$NAME" => format!("pci-{:>02X}.{:>02X}.{:>02X}", bus.num, dev.num, func.num), "$FUNC" => format!("{:>02X}", func.num),
"$BAR0" => bar_arg(0), "$NAME" => format!("pci-{:>02X}.{:>02X}.{:>02X}", bus.num, dev.num, func.num),
"$BAR1" => bar_arg(1), "$BAR0" => bar_arg(0),
"$BAR2" => bar_arg(2), "$BAR1" => bar_arg(1),
"$BAR3" => bar_arg(3), "$BAR2" => bar_arg(2),
"$BAR4" => bar_arg(4), "$BAR3" => bar_arg(3),
"$BAR5" => bar_arg(5), "$BAR4" => bar_arg(4),
"$IRQ" => format!("{}", header.interrupt_line), "$BAR5" => bar_arg(5),
"$VENID" => format!("{:>04X}",header.vendor_id), "$IRQ" => format!("{}", header.interrupt_line),
"$DEVID" => format!("{:>04X}",header.device_id), "$VENID" => format!("{:>04X}",header.vendor_id),
_ => arg.clone() "$DEVID" => format!("{:>04X}",header.device_id),
_ => arg.clone()
}
}; };
command.arg(&arg); command.arg(&arg);
} }
......
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::{slice, mem}; use std::{slice, mem};
#[derive(Debug, Default)] #[derive(Default)]
#[repr(packed)] #[repr(packed)]
pub struct PciHeader { pub struct PciHeader {
pub vendor_id: u16, pub vendor_id: u16,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment