Force usage of pcid_interface

This commit is contained in:
bjorn3
2024-01-20 19:42:06 +01:00
parent 3b4d0e858f
commit dc13752d74
18 changed files with 31 additions and 79 deletions
-1
View File
@@ -3,4 +3,3 @@ name = "AC97 Audio"
class = 0x04
subclass = 0x01
command = ["ac97d"]
use_channel = true
+7 -7
View File
@@ -4,10 +4,10 @@
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};
@@ -81,7 +81,11 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut name = pci_config.func.name();
name.push_str("_ahci");
let bar = pci_config.func.bars[5];
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 irq = pci_config.func.legacy_interrupt_line;
@@ -92,11 +96,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let address = unsafe {
common::physmap(
match bar {
PciBar::Memory32(addr) => addr as usize,
PciBar::Memory64(addr) => addr as usize,
PciBar::None | PciBar::Port(_) => unreachable!(),
},
bar,
bar_size as usize,
common::Prot { read: true, write: true },
common::MemoryType::Uncacheable,
-2
View File
@@ -4,7 +4,6 @@ class = 0x03
vendor = 0x1234
device = 0x1111
command = ["bgad"]
use_channel = true
[[drivers]]
name = "VirtualBox Graphics Array"
@@ -12,4 +11,3 @@ class = 0x03
vendor = 0x80EE
device = 0xBEEF
command = ["bgad"]
use_channel = true
-1
View File
@@ -3,4 +3,3 @@ name = "E1000 NIC"
class = 0x02
ids = { 0x8086 = [0x1004, 0x100e, 0x100f, 0x1503] }
command = ["e1000d"]
use_channel = true
-1
View File
@@ -3,4 +3,3 @@ name = "Intel HD Audio"
class = 0x04
subclass = 0x03
command = ["ihdad"]
use_channel = true
+1 -1
View File
@@ -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);
-5
View File
@@ -6,7 +6,6 @@ name = "AHCI storage"
class = 1
subclass = 6
command = ["ahcid"]
use_channel = true
# ided
[[drivers]]
@@ -14,7 +13,6 @@ name = "IDE storage"
class = 1
subclass = 1
command = ["ided"]
use_channel = true
# nvmed
[[drivers]]
@@ -22,7 +20,6 @@ name = "NVME storage"
class = 1
subclass = 8
command = ["nvmed"]
use_channel = true
[[drivers]]
name = "virtio-blk"
@@ -31,7 +28,6 @@ subclass = 0
vendor = 6900
device = 4097
command = ["virtio-blkd"]
use_channel = true
[[drivers]]
name = "virtio-gpu"
@@ -39,4 +35,3 @@ class = 3
vendor = 6900
device = 4176
command = ["virtio-gpud"]
use_channel = true
-1
View File
@@ -3,4 +3,3 @@ name = "Intel 10G NIC"
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"]
use_channel = true
-1
View File
@@ -19,5 +19,4 @@ pub struct DriverConfig {
pub device: Option<u16>,
pub device_id_range: Option<Range<u16>>,
pub command: Option<Vec<String>>,
pub use_channel: Option<bool>,
}
+16 -35
View File
@@ -189,17 +189,15 @@ impl DriverHandler {
}
}
}
fn handle_spawn(mut self, pcid_to_client_write: Option<usize>, pcid_from_client_read: Option<usize>, 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<State>, 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<State>, 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<State>, 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) => {
-13
View File
@@ -1,5 +1,3 @@
use std::fmt;
use serde::{Serialize, Deserialize};
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
@@ -41,14 +39,3 @@ impl From<u32> 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")
}
}
}
-1
View File
@@ -3,4 +3,3 @@ name = "RTL8139 NIC"
class = 0x02
ids = { 0x10ec = [0x8139] }
command = ["rtl8139d"]
use_channel = true
+2 -2
View File
@@ -183,7 +183,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option<File> {
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
-1
View File
@@ -3,4 +3,3 @@ name = "RTL8168 NIC"
class = 0x02
ids = { 0x10ec = [0x8168, 0x8169] }
command = ["rtl8168d"]
use_channel = true
+2 -2
View File
@@ -181,7 +181,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option<File> {
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
-1
View File
@@ -4,4 +4,3 @@ class = 0x08
vendor = 0x80EE
device = 0xCAFE
command = ["vboxd"]
use_channel = true
-1
View File
@@ -4,4 +4,3 @@ class = 0x02
vendor = 0x1AF4
device = 0x1000
command = ["virtio-netd"]
use_channel = true
+3 -3
View File
@@ -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);