2016-09-11 23:56:48 +02:00
|
|
|
#![feature(asm)]
|
|
|
|
|
|
|
|
extern crate syscall;
|
|
|
|
|
|
|
|
use syscall::iopl;
|
|
|
|
|
|
|
|
use pci::{Pci, PciBar, PciClass};
|
|
|
|
|
|
|
|
mod pci;
|
|
|
|
|
|
|
|
fn enumerate_pci() {
|
|
|
|
println!("PCI BS/DV/FN VEND:DEVI CL.SC.IN.RV");
|
|
|
|
|
|
|
|
let pci = Pci::new();
|
|
|
|
for bus in pci.buses() {
|
|
|
|
for dev in bus.devs() {
|
|
|
|
for func in dev.funcs() {
|
|
|
|
if let Some(header) = func.header() {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!("PCI {:>02X}/{:>02X}/{:>02X} {:>04X}:{:>04X} {:>02X}.{:>02X}.{:>02X}.{:>02X}",
|
2016-09-11 23:56:48 +02:00
|
|
|
bus.num, dev.num, func.num,
|
|
|
|
header.vendor_id, header.device_id,
|
2016-09-12 00:24:43 +02:00
|
|
|
header.class, header.subclass, header.interface, header.revision);
|
2016-09-11 23:56:48 +02:00
|
|
|
|
2016-09-12 00:24:43 +02:00
|
|
|
let pci_class = PciClass::from(header.class);
|
|
|
|
print!(" {:?}", pci_class);
|
|
|
|
match pci_class {
|
2016-09-11 23:56:48 +02:00
|
|
|
PciClass::Storage => match header.subclass {
|
|
|
|
0x01 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" IDE");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
0x06 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" SATA");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
},
|
|
|
|
PciClass::SerialBus => match header.subclass {
|
|
|
|
0x03 => match header.interface {
|
|
|
|
0x00 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" UHCI");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
0x10 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" OHCI");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
0x20 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" EHCI");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
0x30 => {
|
2016-09-12 00:24:43 +02:00
|
|
|
print!(" XHCI");
|
2016-09-11 23:56:48 +02:00
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
}
|
2016-09-12 00:24:43 +02:00
|
|
|
|
|
|
|
for i in 0..header.bars.len() {
|
|
|
|
match PciBar::from(header.bars[i]) {
|
|
|
|
PciBar::None => (),
|
|
|
|
PciBar::Memory(address) => print!(" {}={:>08X}", i, address),
|
|
|
|
PciBar::Port(address) => print!(" {}={:>04X}", i, address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print!("\n");
|
2016-09-11 23:56:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe { iopl(3).unwrap() };
|
|
|
|
|
|
|
|
enumerate_pci();
|
|
|
|
}
|