pcid: Fetch config in PciFunctionHandle::connect_default()

This commit is contained in:
bjorn3
2024-06-15 15:16:09 +02:00
parent fdb9ea816b
commit a3b957c2e5
18 changed files with 48 additions and 55 deletions
+2 -4
View File
@@ -65,11 +65,9 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
}
fn main() {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("ac97d: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("ac97d: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_ac97");
+3 -3
View File
@@ -77,7 +77,7 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config");
let pci_config = pcid_handle.config();
let all_pci_features = pcid_handle.fetch_all_features().expect("ihdad: failed to fetch pci features");
log::debug!("PCI FEATURES: {:?}", all_pci_features);
@@ -122,7 +122,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
//TODO: MSI on non-x86_64?
#[cfg(not(target_arch = "x86_64"))]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config");
let pci_config = pcid_handle.config();
if let Some(irq) = pci_config.func.legacy_interrupt_line {
// legacy INTx# interrupt pins.
@@ -137,7 +137,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle = PciFunctionHandle::connect_default().expect("ihdad: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_ihda");
+2 -4
View File
@@ -16,11 +16,9 @@ mod bga;
mod scheme;
fn main() {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("bgad: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("bgad: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_bga");
+1 -1
View File
@@ -414,7 +414,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> {
// Double check that we have the right device.
//
// 0x1050 - virtio-gpu
let pci_config = pcid_handle.fetch_config()?;
let pci_config = pcid_handle.config();
assert_eq!(pci_config.func.full_device_id.device_id, 0x1050);
log::info!("virtio-gpu: initiating startup sequence :^)");
+2 -4
View File
@@ -12,11 +12,9 @@ use syscall::EventFlags;
pub mod device;
fn main() {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("e1000d: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("e1000d: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_e1000");
+2 -4
View File
@@ -14,11 +14,9 @@ pub mod device;
mod ixgbe;
fn main() {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("ixgbed: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("ixgbed: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_ixgbe");
+3 -3
View File
@@ -96,7 +96,7 @@ impl MappedMsixRegs {
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config");
let pci_config = pcid_handle.config();
let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8139d: failed to fetch pci features");
log::info!("PCI FEATURES: {:?}", all_pci_features);
@@ -178,7 +178,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
//TODO: MSI on non-x86_64?
#[cfg(not(target_arch = "x86_64"))]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config");
let pci_config = pcid_handle.config();
if let Some(irq) = pci_config.func.legacy_interrupt_line {
// legacy INTx# interrupt pins.
@@ -211,7 +211,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle = PciFunctionHandle::connect_default().expect("rtl8139d: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_rtl8139");
+3 -3
View File
@@ -91,7 +91,7 @@ impl MappedMsixRegs {
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config");
let pci_config = pcid_handle.config();
let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8168d: failed to fetch pci features");
log::info!("PCI FEATURES: {:?}", all_pci_features);
@@ -173,7 +173,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
//TODO: MSI on non-x86_64?
#[cfg(not(target_arch = "x86_64"))]
fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File {
let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config");
let pci_config = pcid_handle.config();
if let Some(irq) = pci_config.func.legacy_interrupt_line {
// legacy INTx# interrupt pins.
@@ -206,7 +206,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle = PciFunctionHandle::connect_default().expect("rtl8168d: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_rtl8168");
+1 -1
View File
@@ -33,7 +33,7 @@ fn deamon(daemon: redox_daemon::Daemon) -> Result<(), Box<dyn std::error::Error>
// Double check that we have the right device.
//
// 0x1000 - virtio-net
let pci_config = pcid_handle.fetch_config()?;
let pci_config = pcid_handle.config();
assert_eq!(pci_config.func.full_device_id.device_id, 0x1000);
log::info!("virtio-net: initiating startup sequence :^)");
+15 -8
View File
@@ -230,6 +230,7 @@ pub enum PcidClientResponse {
pub struct PciFunctionHandle {
pcid_to_client: File,
pcid_from_client: File,
config: SubdriverArguments,
}
pub(crate) fn send<W: Write, T: Serialize>(w: &mut W, message: &T) -> Result<()> {
@@ -258,9 +259,19 @@ impl PciFunctionHandle {
let pcid_to_client_fd = env::var("PCID_TO_CLIENT_FD")?.parse::<RawFd>().map_err(PcidClientHandleError::EnvValidityError)?;
let pcid_from_client_fd = env::var("PCID_FROM_CLIENT_FD")?.parse::<RawFd>().map_err(PcidClientHandleError::EnvValidityError)?;
let mut pcid_to_client = unsafe { File::from_raw_fd(pcid_to_client_fd) };
let mut pcid_from_client = unsafe { File::from_raw_fd(pcid_from_client_fd) };
send(&mut pcid_from_client, &PcidClientRequest::RequestConfig)?;
let config = match recv(&mut pcid_to_client)? {
PcidClientResponse::Config(a) => a,
other => return Err(PcidClientHandleError::InvalidResponse(other)),
};
Ok(Self {
pcid_to_client: unsafe { File::from_raw_fd(pcid_to_client_fd) },
pcid_from_client: unsafe { File::from_raw_fd(pcid_from_client_fd) },
pcid_to_client,
pcid_from_client,
config,
})
}
fn send(&mut self, req: &PcidClientRequest) -> Result<()> {
@@ -269,12 +280,8 @@ impl PciFunctionHandle {
fn recv(&mut self) -> Result<PcidClientResponse> {
recv(&mut self.pcid_to_client)
}
pub fn fetch_config(&mut self) -> Result<SubdriverArguments> {
self.send(&PcidClientRequest::RequestConfig)?;
match self.recv()? {
PcidClientResponse::Config(a) => Ok(a),
other => Err(PcidClientHandleError::InvalidResponse(other)),
}
pub fn config(&self) -> SubdriverArguments {
self.config.clone()
}
pub fn get_vendor_capabilities(&mut self) -> Result<Vec<VendorSpecificCapability>> {
+2 -4
View File
@@ -71,11 +71,9 @@ fn main() {
}
fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("ahcid: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("ahcid: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_ahci");
+2 -2
View File
@@ -74,10 +74,10 @@ fn main() {
}
fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("ided: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("ided: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_ide");
+1 -3
View File
@@ -247,9 +247,7 @@ fn main() {
fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle =
PciFunctionHandle::connect_default().expect("nvmed: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("nvmed: failed to fetch config");
let pci_config = pcid_handle.config();
let scheme_name = format!("disk.{}-nvme", pci_config.func.name());
+1 -1
View File
@@ -114,7 +114,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> {
// Double check that we have the right device.
//
// 0x1001 - virtio-blk
let pci_config = pcid_handle.fetch_config()?;
let pci_config = pcid_handle.config();
assert_eq!(pci_config.func.full_device_id.device_id, 0x1001);
log::info!("virtio-blk: initiating startup sequence :^)");
+2 -4
View File
@@ -180,11 +180,9 @@ impl VboxGuestInfo {
}
fn main() {
let mut pcid_handle =
let pcid_handle =
PciFunctionHandle::connect_default().expect("vboxd: failed to setup channel to pcid");
let pci_config = pcid_handle
.fetch_config()
.expect("vboxd: failed to fetch config");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_vbox");
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{probe::MappedMsixRegs, MSIX_PRIMARY_VECTOR};
use pcid_interface::*;
pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result<File, Error> {
let pci_config = pcid_handle.fetch_config()?;
let pci_config = pcid_handle.config();
// Extended message signaled interrupts.
let msix_info = match pcid_handle.feature_info(PciFeature::MsiX)? {
+1 -1
View File
@@ -60,7 +60,7 @@ fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result<File, Error> {
/// ## Panics
/// This function panics if the device is not a virtio device.
pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result<Device, Error> {
let pci_config = pcid_handle.fetch_config()?;
let pci_config = pcid_handle.config();
assert_eq!(
pci_config.func.full_device_id.vendor_id, 6900,
+4 -4
View File
@@ -86,7 +86,7 @@ fn setup_logging(name: &str) -> Option<&'static RedoxLogger> {
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PciFunctionHandle, bar0_address: usize) -> (Option<File>, InterruptMethod) {
let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config");
let pci_config = pcid_handle.config();
let all_pci_features = pcid_handle.fetch_all_features().expect("xhcid: failed to fetch pci features");
log::debug!("XHCI PCI FEATURES: {:?}", all_pci_features);
@@ -168,7 +168,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle, bar0_address: usize) -> (
//TODO: MSI on non-x86_64?
#[cfg(not(target_arch = "x86_64"))]
fn get_int_method(pcid_handle: &mut PciFunctionHandle, address: usize) -> (Option<File>, InterruptMethod) {
let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config");
let pci_config = pcid_handle.config();
if let Some(irq) = pci_config.func.legacy_interrupt_line {
// legacy INTx# interrupt pins.
@@ -184,8 +184,8 @@ fn main() {
}
fn daemon(daemon: redox_daemon::Daemon) -> ! {
let mut pcid_handle = PciFunctionHandle::connect_default().expect("xhcid: failed to setup channel to pcid");
let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config");
let pcid_handle = PciFunctionHandle::connect_default().expect("xhcid: failed to setup channel to pcid");
let pci_config = pcid_handle.config();
let mut name = pci_config.func.name();
name.push_str("_xhci");