Launch commands for each device found if specified
This commit is contained in:
parent
0e8487cf83
commit
98399b030f
|
@ -2,5 +2,12 @@
|
||||||
name = "pcid"
|
name = "pcid"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rustc-serialize = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
||||||
|
toml = "*"
|
||||||
|
|
||||||
[dependencies.syscall]
|
[dependencies.syscall]
|
||||||
path = "../../syscall/"
|
path = "../../syscall/"
|
||||||
|
|
||||||
|
[replace]
|
||||||
|
"rustc-serialize:0.3.19" = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
||||||
|
|
14
drivers/pcid/src/config.rs
Normal file
14
drivers/pcid/src/config.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#[derive(Debug, Default, RustcDecodable)]
|
||||||
|
pub struct Config {
|
||||||
|
pub drivers: Vec<DriverConfig>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, RustcDecodable)]
|
||||||
|
pub struct DriverConfig {
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub class: Option<u8>,
|
||||||
|
pub subclass: Option<u8>,
|
||||||
|
pub vendor: Option<u16>,
|
||||||
|
pub device: Option<u16>,
|
||||||
|
pub command: Option<Vec<String>>
|
||||||
|
}
|
|
@ -1,15 +1,40 @@
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
||||||
|
extern crate rustc_serialize;
|
||||||
extern crate syscall;
|
extern crate syscall;
|
||||||
|
extern crate toml;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::process::Command;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use syscall::iopl;
|
use syscall::iopl;
|
||||||
|
|
||||||
|
use config::Config;
|
||||||
use pci::{Pci, PciBar, PciClass};
|
use pci::{Pci, PciBar, PciClass};
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod pci;
|
mod pci;
|
||||||
|
|
||||||
fn enumerate_pci() {
|
fn main() {
|
||||||
|
thread::spawn(|| {
|
||||||
|
let mut config = Config::default();
|
||||||
|
|
||||||
|
let mut args = env::args().skip(1);
|
||||||
|
if let Some(config_path) = args.next() {
|
||||||
|
if let Ok(mut config_file) = File::open(&config_path) {
|
||||||
|
let mut config_data = String::new();
|
||||||
|
if let Ok(_) = config_file.read_to_string(&mut config_data) {
|
||||||
|
config = toml::decode_str(&config_data).unwrap_or(Config::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:?}", config);
|
||||||
|
|
||||||
|
unsafe { iopl(3).unwrap() };
|
||||||
|
|
||||||
println!("PCI BS/DV/FN VEND:DEVI CL.SC.IN.RV");
|
println!("PCI BS/DV/FN VEND:DEVI CL.SC.IN.RV");
|
||||||
|
|
||||||
let pci = Pci::new();
|
let pci = Pci::new();
|
||||||
|
@ -64,16 +89,56 @@ fn enumerate_pci() {
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("\n");
|
print!("\n");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
for driver in config.drivers.iter() {
|
||||||
thread::spawn(||{
|
if let Some(class) = driver.class {
|
||||||
unsafe { iopl(3).unwrap() };
|
if class != header.class { continue; }
|
||||||
|
}
|
||||||
|
|
||||||
enumerate_pci();
|
if let Some(subclass) = driver.subclass {
|
||||||
|
if subclass != header.subclass { continue; }
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(vendor) = driver.vendor {
|
||||||
|
if vendor != header.vendor_id { continue; }
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(device) = driver.device {
|
||||||
|
if device != header.device_id { continue; }
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref args) = driver.command {
|
||||||
|
let mut args = args.iter();
|
||||||
|
if let Some(program) = args.next() {
|
||||||
|
let mut command = Command::new(program);
|
||||||
|
for arg in args {
|
||||||
|
let bar_arg = |i| -> String {
|
||||||
|
match PciBar::from(header.bars[i]) {
|
||||||
|
PciBar::None => String::new(),
|
||||||
|
PciBar::Memory(address) => format!("{:>08X}", address),
|
||||||
|
PciBar::Port(address) => format!("{:>04X}", address)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let arg = match arg.as_str() {
|
||||||
|
"$0" => bar_arg(0),
|
||||||
|
"$1" => bar_arg(1),
|
||||||
|
"$2" => bar_arg(2),
|
||||||
|
"$3" => bar_arg(3),
|
||||||
|
"$4" => bar_arg(4),
|
||||||
|
"$5" => bar_arg(5),
|
||||||
|
_ => arg.clone()
|
||||||
|
};
|
||||||
|
command.arg(&arg);
|
||||||
|
}
|
||||||
|
println!("{:?}", command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Driver: {:?}", driver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
initfs:bin/vesad
|
initfs:bin/vesad
|
||||||
initfs:bin/ps2d
|
initfs:bin/ps2d
|
||||||
#initfs:bin/pcid
|
initfs:bin/pcid initfs:etc/pcid.toml
|
||||||
initfs:bin/example
|
#initfs:bin/example
|
||||||
#initfs:bin/login display: initfs:bin/ion
|
initfs:bin/login display: initfs:bin/ion
|
||||||
|
|
5
initfs/etc/pcid.toml
Normal file
5
initfs/etc/pcid.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[[drivers]]
|
||||||
|
name = "AHCI storage"
|
||||||
|
class = 1
|
||||||
|
subclass = 6
|
||||||
|
command = ["ahcid", "$5"]
|
Loading…
Reference in a new issue