diff --git a/Cargo.lock b/Cargo.lock index a75774a6d9..5364d127f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "bitflags 1.3.2", "common", "log", + "pcid", "redox-daemon", "redox-log", "redox_event 0.1.0", @@ -46,6 +47,7 @@ dependencies = [ "common", "log", "partitionlib", + "pcid", "redox-daemon", "redox-log", "redox_syscall 0.4.1", @@ -166,6 +168,7 @@ name = "bgad" version = "0.1.0" dependencies = [ "orbclient", + "pcid", "redox-daemon", "redox_syscall 0.4.1", ] @@ -376,6 +379,7 @@ dependencies = [ "bitflags 1.3.2", "common", "netutils", + "pcid", "redox-daemon", "redox_event 0.1.0", "redox_syscall 0.4.1", @@ -661,6 +665,7 @@ dependencies = [ "bitflags 1.3.2", "common", "netutils", + "pcid", "redox-daemon", "redox_event 0.1.0", "redox_syscall 0.4.1", @@ -1662,6 +1667,7 @@ version = "0.1.0" dependencies = [ "common", "orbclient", + "pcid", "redox-daemon", "redox_event 0.1.0", "redox_syscall 0.4.1", diff --git a/ac97d/Cargo.toml b/ac97d/Cargo.toml index 784990155a..6a8c4a477f 100644 --- a/ac97d/Cargo.toml +++ b/ac97d/Cargo.toml @@ -12,3 +12,5 @@ redox-log = "0.1" redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } redox_syscall = "0.4" spin = "0.9" + +pcid = { path = "../pcid" } diff --git a/ac97d/config.toml b/ac97d/config.toml index 7bafbb4975..106ce703a3 100644 --- a/ac97d/config.toml +++ b/ac97d/config.toml @@ -1,5 +1,5 @@ [[drivers]] name = "AC97 Audio" -class = 4 -subclass = 1 -command = ["ac97d", "$NAME", "$BAR0", "$BAR1", "$IRQ"] +class = 0x04 +subclass = 0x01 +command = ["ac97d"] diff --git a/ac97d/src/main.rs b/ac97d/src/main.rs index 6c65e75ad5..a1e6760070 100644 --- a/ac97d/src/main.rs +++ b/ac97d/src/main.rs @@ -5,16 +5,17 @@ extern crate spin; extern crate syscall; extern crate event; -use std::{env, usize}; use std::fs::File; use std::io::{ErrorKind, Read, Write, Result}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; -use syscall::{Packet, SchemeBlockMut, EventFlags}; use std::cell::RefCell; use std::sync::Arc; +use std::usize; use event::EventQueue; +use pcid_interface::{PciBar, PcidServerHandle}; use redox_log::{OutputBuilder, RedoxLogger}; +use syscall::{EventFlags, Packet, SchemeBlockMut}; pub mod device; @@ -63,26 +64,33 @@ fn setup_logging() -> Option<&'static RedoxLogger> { } fn main() { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("ac97d: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("ac97d: failed to fetch config"); - let mut name = args.next().expect("ac97: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_ac97"); - let bar0_str = args.next().expect("ac97: no address provided"); - let bar0 = u16::from_str_radix(&bar0_str, 16).expect("ac97: failed to parse address"); + let bar0 = match pci_config.func.bars[0] { + PciBar::Port(port) => port, + _ => unreachable!(), + }; - let bar1_str = args.next().expect("ac97: no address provided"); - let bar1 = u16::from_str_radix(&bar1_str, 16).expect("ac97: failed to parse address"); + let bar1 = match pci_config.func.bars[1] { + PciBar::Port(port) => port, + _ => unreachable!(), + }; - let irq_str = args.next().expect("ac97: no irq provided"); - let irq = irq_str.parse::().expect("ac97: failed to parse irq"); + let irq = pci_config.func.legacy_interrupt_line; print!("{}", format!(" + ac97 {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1, irq)); // Daemonize redox_daemon::Daemon::new(move |daemon| { let _logger_ref = setup_logging(); - + unsafe { syscall::iopl(3) }.expect("ac97d: failed to set I/O privilege level to Ring 3"); let mut irq_file = File::open(format!("irq:{}", irq)).expect("ac97d: failed to open IRQ file"); diff --git a/ahcid/Cargo.toml b/ahcid/Cargo.toml index 2741d9d05f..cb5637dd69 100644 --- a/ahcid/Cargo.toml +++ b/ahcid/Cargo.toml @@ -14,3 +14,4 @@ redox_syscall = "0.4" block-io-wrapper = { path = "../block-io-wrapper" } common = { path = "../common" } +pcid = { path = "../pcid" } diff --git a/ahcid/src/main.rs b/ahcid/src/main.rs index 1e5d44b4bf..f41f397e73 100644 --- a/ahcid/src/main.rs +++ b/ahcid/src/main.rs @@ -4,11 +4,12 @@ extern crate syscall; extern crate byteorder; -use std::{env, usize}; use std::fs::File; use std::io::{ErrorKind, Read, Write}; use std::os::unix::io::{FromRawFd, RawFd}; +use std::usize; +use pcid_interface::{PciBar, PcidServerHandle}; use syscall::error::{Error, ENODEV}; use syscall::data::{Event, Packet}; use syscall::flag::EVENT_READ; @@ -71,28 +72,32 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("ahcid: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("ahcid: failed to fetch config"); - let mut name = args.next().expect("ahcid: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_ahci"); - let bar_str = args.next().expect("ahcid: no address provided"); - let bar = usize::from_str_radix(&bar_str, 16).expect("ahcid: failed to parse address"); + let bar = match pci_config.func.bars[5] { + PciBar::Memory32(addr) => addr as usize, + PciBar::Memory64(addr) => addr as usize, + PciBar::None | PciBar::Port(_) => unreachable!(), + }; + let bar_size = pci_config.func.bar_sizes[5]; - let bar_size_str = args.next().expect("ahcid: no address size provided"); - let bar_size = usize::from_str_radix(&bar_size_str, 16).expect("ahcid: failed to parse address size"); - - let irq_str = args.next().expect("ahcid: no irq provided"); - let irq = irq_str.parse::().expect("ahcid: failed to parse irq"); + let irq = pci_config.func.legacy_interrupt_line; let _logger_ref = setup_logging(&name); - info!(" + AHCI {} on: {:X} size: {} IRQ: {}", name, bar, bar_size, irq); + info!(" + AHCI {} on: {} size: {} IRQ: {}", name, bar, bar_size, irq); let address = unsafe { common::physmap( bar, - bar_size, + bar_size as usize, common::Prot { read: true, write: true }, common::MemoryType::Uncacheable, ).expect("ahcid: failed to map address") diff --git a/bgad/Cargo.toml b/bgad/Cargo.toml index 6ae79cdb86..596bf0f54d 100644 --- a/bgad/Cargo.toml +++ b/bgad/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" orbclient = "0.3.27" redox-daemon = "0.1" redox_syscall = "0.4" + +pcid = { path = "../pcid" } diff --git a/bgad/config.toml b/bgad/config.toml index 184aacc0d4..a07ff05bbc 100644 --- a/bgad/config.toml +++ b/bgad/config.toml @@ -1,13 +1,13 @@ [[drivers]] name = "QEMU Graphics Array" -class = 3 -vendor = 4660 -device = 4369 -command = ["bgad", "$NAME", "$BAR0"] +class = 0x03 +vendor = 0x1234 +device = 0x1111 +command = ["bgad"] [[drivers]] name = "VirtualBox Graphics Array" -class = 3 -vendor = 33006 -device = 48879 -command = ["bgad", "$NAME", "$BAR0"] +class = 0x03 +vendor = 0x80EE +device = 0xBEEF +command = ["bgad"] diff --git a/bgad/src/main.rs b/bgad/src/main.rs index cc7570efab..e9b7bb7600 100644 --- a/bgad/src/main.rs +++ b/bgad/src/main.rs @@ -1,12 +1,10 @@ -#![deny(warnings)] - extern crate orbclient; extern crate syscall; -use std::env; use std::fs::File; use std::io::{Read, Write}; +use pcid_interface::PcidServerHandle; use syscall::call::iopl; use syscall::data::Packet; use syscall::scheme::SchemeMut; @@ -18,15 +16,16 @@ mod bga; mod scheme; fn main() { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("bgad: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("bgad: failed to fetch config"); - let mut name = args.next().expect("bgad: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_bga"); - let bar_str = args.next().expect("bgad: no address provided"); - let bar = usize::from_str_radix(&bar_str, 16).expect("bgad: failed to parse address"); - - print!("{}", format!(" + BGA {} on: {:X}\n", name, bar)); + println!(" + BGA {}", name); redox_daemon::Daemon::new(move |daemon| { unsafe { iopl(3).unwrap() }; @@ -34,11 +33,11 @@ fn main() { let mut socket = File::create(":bga").expect("bgad: failed to create bga scheme"); let mut bga = Bga::new(); - print!("{}", format!(" - BGA {}x{}\n", bga.width(), bga.height())); + println!(" - BGA {}x{}", bga.width(), bga.height()); let mut scheme = BgaScheme { bga, - display: File::open("input:producer").ok() + display: File::open("input:producer").ok(), }; scheme.update_size(); @@ -49,12 +48,19 @@ fn main() { loop { let mut packet = Packet::default(); - if socket.read(&mut packet).expect("bgad: failed to read events from bga scheme") == 0 { + if socket + .read(&mut packet) + .expect("bgad: failed to read events from bga scheme") + == 0 + { break; } scheme.handle(&mut packet); - socket.write(&packet).expect("bgad: failed to write responses to bga scheme"); + socket + .write(&packet) + .expect("bgad: failed to write responses to bga scheme"); } std::process::exit(0); - }).expect("bgad: failed to daemonize"); + }) + .expect("bgad: failed to daemonize"); } diff --git a/e1000d/Cargo.toml b/e1000d/Cargo.toml index bc1bc8b47e..90b9367de0 100644 --- a/e1000d/Cargo.toml +++ b/e1000d/Cargo.toml @@ -11,3 +11,4 @@ redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } redox_syscall = "0.4" common = { path = "../common" } +pcid = { path = "../pcid" } diff --git a/e1000d/config.toml b/e1000d/config.toml index 19d0b57f84..44ce84dd09 100644 --- a/e1000d/config.toml +++ b/e1000d/config.toml @@ -1,5 +1,5 @@ [[drivers]] name = "E1000 NIC" -class = 2 +class = 0x02 ids = { 0x8086 = [0x1004, 0x100e, 0x100f, 0x1503] } -command = ["e1000d", "$NAME", "$BAR0", "$BARSIZE0", "$IRQ"] +command = ["e1000d"] diff --git a/e1000d/src/main.rs b/e1000d/src/main.rs index 2e2a617c8f..328c7d0d3c 100644 --- a/e1000d/src/main.rs +++ b/e1000d/src/main.rs @@ -3,13 +3,14 @@ extern crate netutils; extern crate syscall; use std::cell::RefCell; -use std::{env, process}; use std::fs::File; use std::io::{ErrorKind, Read, Result, Write}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::process; use std::sync::Arc; use event::EventQueue; +use pcid_interface::{PciBar, PcidServerHandle}; use syscall::{EventFlags, Packet, SchemeBlockMut}; pub mod device; @@ -58,19 +59,23 @@ fn handle_update( } fn main() { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("e1000d: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("e1000d: failed to fetch config"); - let mut name = args.next().expect("e1000d: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_e1000"); - let bar_str = args.next().expect("e1000d: no address provided"); - let bar = usize::from_str_radix(&bar_str, 16).expect("e1000d: failed to parse address"); + let bar = match pci_config.func.bars[0] { + PciBar::Memory32(addr) => addr as usize, + PciBar::Memory64(addr) => addr as usize, + PciBar::None | PciBar::Port(_) => unreachable!(), + }; + let bar_size = pci_config.func.bar_sizes[0] as usize; - let bar_size_str = args.next().expect("e1000d: no address size provided"); - let bar_size = usize::from_str_radix(&bar_size_str, 16).expect("e1000d: failed to parse address size"); - - let irq_str = args.next().expect("e1000d: no irq provided"); - let irq = irq_str.parse::().expect("e1000d: failed to parse irq"); + let irq = pci_config.func.legacy_interrupt_line; eprintln!(" + E1000 {} on: {:X} size: {} IRQ: {}", name, bar, bar_size, irq); diff --git a/ihdad/config.toml b/ihdad/config.toml index b4d8a132d7..8be0418577 100644 --- a/ihdad/config.toml +++ b/ihdad/config.toml @@ -1,6 +1,5 @@ [[drivers]] name = "Intel HD Audio" -class = 4 -subclass = 3 +class = 0x04 +subclass = 0x03 command = ["ihdad"] -use_channel = true diff --git a/ihdad/src/main.rs b/ihdad/src/main.rs index 789b0be20e..d91013cc47 100755 --- a/ihdad/src/main.rs +++ b/ihdad/src/main.rs @@ -171,7 +171,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { 0 => panic!("BAR 0 is mapped to address 0"), _ => ptr, }, - other => panic!("Expected memory bar, found {}", other), + other => panic!("Expected memory bar, found {:?}", other), }; log::info!(" + IHDA {} on: {:#X} size: {}", name, bar_ptr, bar_size); diff --git a/initfs.toml b/initfs.toml index d648d466ad..62479eaee7 100644 --- a/initfs.toml +++ b/initfs.toml @@ -5,7 +5,7 @@ name = "AHCI storage" class = 1 subclass = 6 -command = ["ahcid", "$NAME", "$BAR5", "$BARSIZE5", "$IRQ"] +command = ["ahcid"] # ided [[drivers]] @@ -13,7 +13,6 @@ name = "IDE storage" class = 1 subclass = 1 command = ["ided"] -use_channel = true # nvmed [[drivers]] @@ -21,7 +20,6 @@ name = "NVME storage" class = 1 subclass = 8 command = ["nvmed"] -use_channel = true [[drivers]] name = "virtio-blk" @@ -30,7 +28,6 @@ subclass = 0 vendor = 6900 device = 4097 command = ["virtio-blkd"] -use_channel = true [[drivers]] name = "virtio-gpu" @@ -38,4 +35,3 @@ class = 3 vendor = 6900 device = 4176 command = ["virtio-gpud"] -use_channel = true diff --git a/ixgbed/Cargo.toml b/ixgbed/Cargo.toml index 94d0af3ed1..1760a676bc 100644 --- a/ixgbed/Cargo.toml +++ b/ixgbed/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "ixgbed" version = "1.0.0" +edition = "2021" [dependencies] bitflags = "1.0" @@ -10,3 +11,4 @@ redox_syscall = "0.4" redox-daemon = "0.1" common = { path = "../common" } +pcid = { path = "../pcid" } diff --git a/ixgbed/config.toml b/ixgbed/config.toml index db2d47838a..a10fba5a8f 100644 --- a/ixgbed/config.toml +++ b/ixgbed/config.toml @@ -1,6 +1,5 @@ [[drivers]] name = "Intel 10G NIC" -class = 2 +class = 0x02 ids = { 0x8086 = [0x10F7, 0x1514, 0x1517, 0x151C, 0x10F9, 0x10FB, 0x152a, 0x1529, 0x1507, 0x154D, 0x1557, 0x10FC, 0x10F8, 0x154F, 0x1528, 0x154A, 0x1558, 0x1560, 0x1563, 0x15D1, 0x15AA, 0x15AB, 0x15AC, 0x15AD, 0x15AE, 0x15B0, 0x15C2, 0x15C3, 0x15C4, 0x15C6, 0x15C7, 0x15C8, 0x15CE, 0x15E4, 0x15E5, 0x10ED, 0x1515, 0x1565, 0x15A8, 0x15C5] } -command = ["ixgbed", "$NAME", "$BAR0", "$IRQ"] - +command = ["ixgbed"] diff --git a/ixgbed/src/device.rs b/ixgbed/src/device.rs index 2803ccca5f..9d0f59abd4 100644 --- a/ixgbed/src/device.rs +++ b/ixgbed/src/device.rs @@ -10,7 +10,7 @@ use syscall::scheme::SchemeBlockMut; use common::dma::Dma; use netutils::setcfg; -use ixgbe::*; +use crate::ixgbe::*; pub struct Intel8259x { base: usize, diff --git a/ixgbed/src/main.rs b/ixgbed/src/main.rs index b192450af0..b60cfb9982 100644 --- a/ixgbed/src/main.rs +++ b/ixgbed/src/main.rs @@ -10,9 +10,10 @@ use std::fs::File; use std::io::{ErrorKind, Read, Result, Write}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::sync::Arc; -use std::{env, thread}; +use std::thread; use event::EventQueue; +use pcid_interface::{PciBar, PcidServerHandle}; use std::time::Duration; use syscall::{EventFlags, Packet, SchemeBlockMut}; @@ -66,16 +67,22 @@ fn handle_update( } fn main() { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("ixgbed: failed to fetch config"); - let mut name = args.next().expect("ixgbed: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_ixgbe"); - let bar_str = args.next().expect("ixgbed: no address provided"); - let bar = usize::from_str_radix(&bar_str, 16).expect("ixgbed: failed to parse address"); + let bar = match pci_config.func.bars[0] { + PciBar::Memory32(addr) => addr as usize, + PciBar::Memory64(addr) => addr as usize, + PciBar::None | PciBar::Port(_) => unreachable!(), + }; - let irq_str = args.next().expect("ixgbed: no irq provided"); - let irq = irq_str.parse::().expect("ixgbed: failed to parse irq"); + let irq = pci_config.func.legacy_interrupt_line; println!(" + IXGBE {} on: {:X} IRQ: {}", name, bar, irq); diff --git a/pcid/src/config.rs b/pcid/src/config.rs index c74f05842a..83faddd586 100644 --- a/pcid/src/config.rs +++ b/pcid/src/config.rs @@ -19,5 +19,4 @@ pub struct DriverConfig { pub device: Option, pub device_id_range: Option>, pub command: Option>, - pub use_channel: Option, } diff --git a/pcid/src/main.rs b/pcid/src/main.rs index 5de73c48cc..e579a6d4ab 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -189,17 +189,15 @@ impl DriverHandler { } } } - fn handle_spawn(mut self, pcid_to_client_write: Option, pcid_from_client_read: Option, args: driver_interface::SubdriverArguments) { + fn handle_spawn(mut self, pcid_to_client_write: usize, pcid_from_client_read: usize, args: driver_interface::SubdriverArguments) { use driver_interface::*; - if let (Some(pcid_to_client_fd), Some(pcid_from_client_fd)) = (pcid_to_client_write, pcid_from_client_read) { - let mut pcid_to_client = unsafe { File::from_raw_fd(pcid_to_client_fd as RawFd) }; - let mut pcid_from_client = unsafe { File::from_raw_fd(pcid_from_client_fd as RawFd) }; + let mut pcid_to_client = unsafe { File::from_raw_fd(pcid_to_client_write as RawFd) }; + let mut pcid_from_client = unsafe { File::from_raw_fd(pcid_from_client_read as RawFd) }; while let Ok(msg) = recv(&mut pcid_from_client) { let response = self.respond(msg, &args); send(&mut pcid_to_client, &response).unwrap(); - } } } } @@ -256,8 +254,11 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he } for (i, bar) in header.bars().iter().enumerate() { - if !bar.is_none() { - string.push_str(&format!(" {}={}", i, bar)); + match bar { + PciBar::None => {}, + PciBar::Memory32(addr) => string.push_str(&format!(" {i}={addr:08X}")), + PciBar::Memory64(addr) => string.push_str(&format!(" {i}={addr:016X}")), + PciBar::Port(port) => string.push_str(&format!(" {i}=P{port:04X}")), } } @@ -411,34 +412,14 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he if let Some(program) = args.next() { let mut command = Command::new(program); for arg in args { - let arg = match arg.as_str() { - "$BUS" => format!("{:>02X}", addr.bus()), - "$DEV" => format!("{:>02X}", addr.device()), - "$FUNC" => format!("{:>02X}", addr.function()), - "$NAME" => func.name(), - "$BAR0" => format!("{}", bars[0]), - "$BAR1" => format!("{}", bars[1]), - "$BAR2" => format!("{}", bars[2]), - "$BAR3" => format!("{}", bars[3]), - "$BAR4" => format!("{}", bars[4]), - "$BAR5" => format!("{}", bars[5]), - "$BARSIZE0" => format!("{:>08X}", bar_sizes[0]), - "$BARSIZE1" => format!("{:>08X}", bar_sizes[1]), - "$BARSIZE2" => format!("{:>08X}", bar_sizes[2]), - "$BARSIZE3" => format!("{:>08X}", bar_sizes[3]), - "$BARSIZE4" => format!("{:>08X}", bar_sizes[4]), - "$BARSIZE5" => format!("{:>08X}", bar_sizes[5]), - "$IRQ" => format!("{}", irq), - "$VENID" => format!("{:>04X}", header.vendor_id()), - "$DEVID" => format!("{:>04X}", header.device_id()), - _ => arg.clone() - }; - command.arg(&arg); + if arg.starts_with("$") { + panic!("support for $VARIABLE has been removed. use pcid_interface instead"); + } + command.arg(arg); } info!("PCID SPAWN {:?}", command); - let (pcid_to_client_write, pcid_from_client_read, envs) = if driver.use_channel.unwrap_or(false) { // TODO: libc wrapper? let [fds1, fds2] = unsafe { let mut fds1 = [0 as libc::c_int; 2]; @@ -456,10 +437,10 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he let [pcid_to_client_read, pcid_to_client_write] = fds1; let [pcid_from_client_read, pcid_from_client_write] = fds2; - (Some(pcid_to_client_write), Some(pcid_from_client_read), vec! [("PCID_TO_CLIENT_FD", format!("{}", pcid_to_client_read)), ("PCID_FROM_CLIENT_FD", format!("{}", pcid_from_client_write))]) - } else { - (None, None, vec! []) - }; + let envs = vec![ + ("PCID_TO_CLIENT_FD", format!("{}", pcid_to_client_read)), + ("PCID_FROM_CLIENT_FD", format!("{}", pcid_from_client_write)), + ]; match command.envs(envs).spawn() { Ok(mut child) => { diff --git a/pcid/src/pci/bar.rs b/pcid/src/pci/bar.rs index 2698818f58..e51c0b31d2 100644 --- a/pcid/src/pci/bar.rs +++ b/pcid/src/pci/bar.rs @@ -1,5 +1,3 @@ -use std::fmt; - use serde::{Serialize, Deserialize}; #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] @@ -41,14 +39,3 @@ impl From for PciBar { } } } - -impl fmt::Display for PciBar { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &PciBar::Memory32(address) => write!(f, "{:>08X}", address), - &PciBar::Memory64(address) => write!(f, "{:>016X}", address), - &PciBar::Port(address) => write!(f, "{:>04X}", address), - &PciBar::None => write!(f, "None") - } - } -} diff --git a/rtl8139d/config.toml b/rtl8139d/config.toml index 92e19426e9..05c5322479 100644 --- a/rtl8139d/config.toml +++ b/rtl8139d/config.toml @@ -1,6 +1,5 @@ [[drivers]] name = "RTL8139 NIC" -class = 2 +class = 0x02 ids = { 0x10ec = [0x8139] } command = ["rtl8139d"] -use_channel = true diff --git a/rtl8139d/src/main.rs b/rtl8139d/src/main.rs index eac441a25f..fd26b06812 100644 --- a/rtl8139d/src/main.rs +++ b/rtl8139d/src/main.rs @@ -183,7 +183,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { 0 => panic!("BAR {} is mapped to address 0", bir), _ => ptr, }, - other => panic!("Expected memory bar, found {}", other), + other => panic!("Expected memory bar, found {:?}", other), }; let address = unsafe { @@ -325,7 +325,7 @@ fn find_bar(pci_config: &SubdriverArguments) -> Option<(usize, usize)> { pci_config.func.bar_sizes[barnum].try_into().unwrap() )), }, - other => log::warn!("BAR {} is {} instead of memory BAR", barnum, other), + other => log::warn!("BAR {} is {:?} instead of memory BAR", barnum, other), } } None diff --git a/rtl8168d/config.toml b/rtl8168d/config.toml index 6fdb0e7b30..ee98e345f3 100644 --- a/rtl8168d/config.toml +++ b/rtl8168d/config.toml @@ -1,6 +1,5 @@ [[drivers]] name = "RTL8168 NIC" -class = 2 +class = 0x02 ids = { 0x10ec = [0x8168, 0x8169] } command = ["rtl8168d"] -use_channel = true diff --git a/rtl8168d/src/main.rs b/rtl8168d/src/main.rs index 2eea0c80f1..53415a2d0f 100644 --- a/rtl8168d/src/main.rs +++ b/rtl8168d/src/main.rs @@ -181,7 +181,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { 0 => panic!("BAR {} is mapped to address 0", bir), _ => ptr, }, - other => panic!("Expected memory bar, found {}", other), + other => panic!("Expected memory bar, found {:?}", other), }; let address = unsafe { @@ -323,7 +323,7 @@ fn find_bar(pci_config: &SubdriverArguments) -> Option<(usize, usize)> { pci_config.func.bar_sizes[barnum].try_into().unwrap() )), }, - other => log::warn!("BAR {} is {} instead of memory BAR", barnum, other), + other => log::warn!("BAR {} is {:?} instead of memory BAR", barnum, other), } } None diff --git a/vboxd/Cargo.toml b/vboxd/Cargo.toml index b27804da77..23a4273c2a 100644 --- a/vboxd/Cargo.toml +++ b/vboxd/Cargo.toml @@ -10,3 +10,4 @@ redox_syscall = "0.4" redox-daemon = "0.1" common = { path = "../common" } +pcid = { path = "../pcid" } diff --git a/vboxd/config.toml b/vboxd/config.toml index c97272fb3d..1216625579 100644 --- a/vboxd/config.toml +++ b/vboxd/config.toml @@ -1,6 +1,6 @@ [[drivers]] name = "VirtualBox Guest Device" -class = 8 -vendor = 33006 -device = 51966 -command = ["vboxd", "$NAME", "$BAR0", "$BAR1", "$IRQ"] +class = 0x08 +vendor = 0x80EE +device = 0xCAFE +command = ["vboxd"] diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index 845464d5e4..555b5eb675 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -5,11 +5,12 @@ extern crate orbclient; extern crate syscall; use event::EventQueue; -use std::{env, mem}; +use std::mem; use std::os::unix::io::AsRawFd; use std::fs::File; use std::io::{Result, Read, Write}; +use pcid_interface::{PciBar, PcidServerHandle}; use syscall::call::iopl; use syscall::flag::EventFlags; use syscall::io::{Io, Mmio, Pio}; @@ -184,19 +185,27 @@ impl VboxGuestInfo { } fn main() { - let mut args = env::args().skip(1); + let mut pcid_handle = + PcidServerHandle::connect_default().expect("vboxd: failed to setup channel to pcid"); + let pci_config = pcid_handle + .fetch_config() + .expect("vboxd: failed to fetch config"); - let mut name = args.next().expect("vboxd: no name provided"); + let mut name = pci_config.func.name(); name.push_str("_vbox"); - let bar0_str = args.next().expect("vboxd: no address provided"); - let bar0 = usize::from_str_radix(&bar0_str, 16).expect("vboxd: failed to parse address"); + let bar0 = match pci_config.func.bars[0] { + PciBar::Port(port) => port, + _ => unreachable!(), + }; - let bar1_str = args.next().expect("vboxd: no address provided"); - let bar1 = usize::from_str_radix(&bar1_str, 16).expect("vboxd: failed to parse address"); + let bar1 = match pci_config.func.bars[1] { + PciBar::Memory32(addr) => addr as usize, + PciBar::Memory64(addr) => addr as usize, + PciBar::None | PciBar::Port(_) => unreachable!(), + }; - let irq_str = args.next().expect("vboxd: no irq provided"); - let irq = irq_str.parse::().expect("vboxd: failed to parse irq"); + let irq = pci_config.func.legacy_interrupt_line; print!("{}", format!(" + VirtualBox {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1, irq)); diff --git a/virtio-netd/config.toml b/virtio-netd/config.toml index 93949ce905..ebedb9e40c 100644 --- a/virtio-netd/config.toml +++ b/virtio-netd/config.toml @@ -1,7 +1,6 @@ [[drivers]] name = "virtio-net" -class = 2 -vendor = 6900 -device = 4096 +class = 0x02 +vendor = 0x1AF4 +device = 0x1000 command = ["virtio-netd"] -use_channel = true diff --git a/xhcid/config.toml b/xhcid/config.toml index b80bae57a4..80e781c52a 100644 --- a/xhcid/config.toml +++ b/xhcid/config.toml @@ -1,7 +1,7 @@ [[drivers]] name = "XHCI" -class = 12 -subclass = 3 -interface = 48 +class = 0x0C +subclass = 0x03 +interface = 0x30 command = ["xhcid"] use_channel = true diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 8f33ddce1a..6e15e8b0da 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -98,7 +98,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option 0 => panic!("BAR 0 is mapped to address 0"), _ => ptr, }, - other => panic!("Expected memory bar, found {}", other), + other => panic!("Expected memory bar, found {:?}", other), }; let all_pci_features = pcid_handle.fetch_all_features().expect("xhcid: failed to fetch pci features"); @@ -260,7 +260,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { 0 => panic!("BAR 0 is mapped to address 0"), _ => ptr, }, - other => panic!("Expected memory bar, found {}", other), + other => panic!("Expected memory bar, found {:?}", other), }; let address = unsafe { @@ -272,7 +272,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { print!( "{}", - format!(" + XHCI {} on: {} IRQ: {}\n", name, bar, irq) + format!(" + XHCI {} on: {:016X} IRQ: {}\n", name, bar_ptr, irq) ); let scheme_name = format!("usb.{}", name);