From 3299a070f23b5a4c2102b502382eafd2d1f1c5a9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:21:37 +0200 Subject: [PATCH 1/4] pcid: Also return bar size from physmap_mem and use it in two more drivers --- audio/ihdad/src/main.rs | 2 +- net/e1000d/src/main.rs | 2 +- net/ixgbed/src/main.rs | 16 +++------------ net/rtl8139d/src/main.rs | 2 +- net/rtl8168d/src/main.rs | 2 +- pcid/src/pci/bar.rs | 7 ++++--- storage/ahcid/src/main.rs | 2 +- storage/nvmed/src/main.rs | 37 ++++++++++++++-------------------- vboxd/src/main.rs | 2 +- virtio-core/src/arch/x86_64.rs | 2 +- xhcid/src/main.rs | 2 +- 11 files changed, 30 insertions(+), 46 deletions(-) diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index e86cc832a4..a8e6aa4ef3 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -146,7 +146,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { log::info!(" + IHDA {}", pci_config.func.display()); - let address = unsafe { bar.physmap_mem("ihdad") } as usize; + let address = unsafe { bar.physmap_mem("ihdad") }.0 as usize; //TODO: MSI-X let mut irq_file = get_int_method(&mut pcid_handle); diff --git a/net/e1000d/src/main.rs b/net/e1000d/src/main.rs index b5480587bc..db893106e7 100644 --- a/net/e1000d/src/main.rs +++ b/net/e1000d/src/main.rs @@ -33,7 +33,7 @@ fn main() { redox_daemon::Daemon::new(move |daemon| { let mut irq_file = irq.irq_handle("e1000d"); - let address = unsafe { bar.physmap_mem("e1000d") } as usize; + let address = unsafe { bar.physmap_mem("e1000d") }.0 as usize; let device = unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") }; diff --git a/net/ixgbed/src/main.rs b/net/ixgbed/src/main.rs index 716253324a..2c54c73ee2 100644 --- a/net/ixgbed/src/main.rs +++ b/net/ixgbed/src/main.rs @@ -13,8 +13,6 @@ pub mod device; #[rustfmt::skip] mod ixgbe; -const IXGBE_MMIO_SIZE: usize = 512 * 1024; - fn main() { let mut pcid_handle = PcidServerHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); @@ -25,8 +23,6 @@ fn main() { let mut name = pci_config.func.name(); name.push_str("_ixgbe"); - let (bar, _) = pci_config.func.bars[0].expect_mem(); - let irq = pci_config .func .legacy_interrupt_line @@ -37,17 +33,11 @@ fn main() { redox_daemon::Daemon::new(move |daemon| { let mut irq_file = irq.irq_handle("ixgbed"); - let address = unsafe { - common::physmap( - bar, - IXGBE_MMIO_SIZE, - common::Prot::RW, - common::MemoryType::Uncacheable, - ) - .expect("ixgbed: failed to map address") as usize + let (address, size) = unsafe { + pci_config.func.bars[0].physmap_mem("ixgbed") }; - let device = device::Intel8259x::new(address, IXGBE_MMIO_SIZE) + let device = device::Intel8259x::new(address as usize, size) .expect("ixgbed: failed to allocate device"); let mut scheme = NetworkScheme::new(device, format!("network.{name}")); diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index a949d46e18..04cba8fc48 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -136,7 +136,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { msix_info.validate(pci_config.func.bars); let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("rtl8139d") } as usize; + let bar_address = unsafe { bar.physmap_mem("rtl8139d") }.0 as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index c797c2e059..f8177b98d8 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -131,7 +131,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { msix_info.validate(pci_config.func.bars); let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("rtl8168d") } as usize; + let bar_address = unsafe { bar.physmap_mem("rtl8168d") }.0 as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; diff --git a/pcid/src/pci/bar.rs b/pcid/src/pci/bar.rs index b279c44577..706479008b 100644 --- a/pcid/src/pci/bar.rs +++ b/pcid/src/pci/bar.rs @@ -53,9 +53,9 @@ impl PciBar { } } - pub unsafe fn physmap_mem(&self, driver: &str) -> *mut () { + pub unsafe fn physmap_mem(&self, driver: &str) -> (*mut (), usize) { let (bar, bar_size) = self.expect_mem(); - unsafe { + let addr = unsafe { common::physmap( bar, bar_size, @@ -64,6 +64,7 @@ impl PciBar { common::MemoryType::Uncacheable, ) } - .unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}")) + .unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}")); + (addr, bar_size) } } diff --git a/storage/ahcid/src/main.rs b/storage/ahcid/src/main.rs index 7aae947b78..a5bb6f79db 100644 --- a/storage/ahcid/src/main.rs +++ b/storage/ahcid/src/main.rs @@ -88,7 +88,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { info!(" + AHCI {}", pci_config.func.display()); - let address = unsafe { bar.physmap_mem("ahcid") }; + let (address, _) = unsafe { bar.physmap_mem("ahcid") }; { let scheme_name = format!("disk.{}", name); let socket = Socket::::nonblock(&scheme_name).expect("ahcid: failed to create disk scheme"); diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index 39167633d2..6910e0a65b 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -27,22 +27,12 @@ mod scheme; /// A wrapper for a BAR allocation. pub struct Bar { ptr: NonNull, - physical: usize, bar_size: usize, } impl Bar { - pub fn allocate(bar: usize, bar_size: usize) -> Result { + pub fn new(ptr: *mut (), bar_size: usize) -> Result { Ok(Self { - ptr: NonNull::new( - unsafe { common::physmap( - bar, - bar_size, - common::Prot { read: true, write: true }, - common::MemoryType::Uncacheable, - )? as *mut u8 }, - ) - .expect("Mapping a BAR resulted in a nullptr"), - physical: bar, + ptr: NonNull::new(ptr.cast::()).expect("Mapping a BAR resulted in a nullptr"), bar_size, }) } @@ -101,9 +91,9 @@ fn get_int_method( match &mut *bar_guard { &mut Some(ref bar) => Ok(bar.ptr), bar_to_set @ &mut None => { - let (bar, bar_size) = function.bars[bir].expect_mem(); + let (ptr, bar_size) = unsafe { function.bars[bir].physmap_mem("nvmed") }; - let bar = Bar::allocate(bar, bar_size)?; + let bar = Bar::new(ptr, bar_size)?; *bar_to_set = Some(bar); Ok(bar_to_set.as_ref().unwrap().ptr) } @@ -265,18 +255,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let _logger_ref = setup_logging(&scheme_name); - let bar = &pci_config.func.bars[0]; - let (bar_ptr, bar_size) = bar.expect_mem(); - log::debug!("NVME PCI CONFIG: {:?}", pci_config); let allocated_bars = AllocatedBars::default(); - let address = unsafe { bar.physmap_mem("nvmed") } as usize; + let bar = &pci_config.func.bars[0]; + let (address, bar_size) = unsafe { bar.physmap_mem("nvmed") }; + *allocated_bars.0[0].lock().unwrap() = Some(Bar { - physical: bar_ptr, bar_size, - ptr: NonNull::new(address as *mut u8).expect("Physmapping BAR gave nullptr"), + ptr: NonNull::new(address.cast::()).expect("Physmapping BAR gave nullptr"), }); let socket = Socket::::create(&scheme_name).expect("nvmed: failed to create disk scheme"); @@ -287,8 +275,13 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let (interrupt_method, interrupt_sources) = get_int_method(&mut pcid_handle, &pci_config.func, &allocated_bars) .expect("nvmed: failed to find a suitable interrupt method"); - let mut nvme = Nvme::new(address, interrupt_method, pcid_handle, reactor_sender) - .expect("nvmed: failed to allocate driver data"); + let mut nvme = Nvme::new( + address as usize, + interrupt_method, + pcid_handle, + reactor_sender, + ) + .expect("nvmed: failed to allocate driver data"); unsafe { nvme.init() } log::debug!("Finished base initialization"); let nvme = Arc::new(nvme); diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index b24ddb0dcf..be65b6a11d 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -217,7 +217,7 @@ fn main() { let mut irq_file = irq.irq_handle("vboxd"); let mut port = Pio::::new(bar0 as u16); - let address = unsafe { bar1.physmap_mem("vboxd") }; + let (address, _) = unsafe { bar1.physmap_mem("vboxd") }; { let vmmdev = unsafe { &mut *(address as *mut VboxVmmDev) }; diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index e1b25fbbb5..95072fd0ac 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -19,7 +19,7 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { msix_info.validate(pci_config.func.bars); let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("virtio-core") } as usize; + let bar_address = unsafe { bar.physmap_mem("virtio-core") }.0 as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; let mut info = MappedMsixRegs { diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index ef5b122beb..3c3aa0dbce 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -195,7 +195,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { log::debug!("XHCI PCI CONFIG: {:?}", pci_config); let bar = &pci_config.func.bars[0]; - let address = unsafe { bar.physmap_mem("xhcid") } as usize; + let address = unsafe { bar.physmap_mem("xhcid") }.0 as usize; let (irq_file, interrupt_method) = (None, InterruptMethod::Polling); //TODO: get_int_method(&mut pcid_handle, address); From fdb9ea816b99077b320657afadbb6d3fc192c10f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:05:42 +0200 Subject: [PATCH 2/4] pcid: Rename PcidServerHandle to PciFunctionHandle --- audio/ac97d/src/main.rs | 4 ++-- audio/ihdad/src/main.rs | 8 ++++---- graphics/bgad/src/main.rs | 4 ++-- graphics/virtio-gpud/src/main.rs | 4 ++-- net/e1000d/src/main.rs | 4 ++-- net/ixgbed/src/main.rs | 4 ++-- net/rtl8139d/src/main.rs | 8 ++++---- net/rtl8168d/src/main.rs | 8 ++++---- net/virtio-netd/src/main.rs | 4 ++-- pcid/src/driver_interface/mod.rs | 4 ++-- storage/ahcid/src/main.rs | 4 ++-- storage/ided/src/main.rs | 4 ++-- storage/nvmed/src/main.rs | 8 ++++---- storage/nvmed/src/nvme/mod.rs | 6 +++--- storage/virtio-blkd/src/main.rs | 2 +- vboxd/src/main.rs | 4 ++-- virtio-core/src/arch/x86_64.rs | 4 ++-- virtio-core/src/probe.rs | 4 ++-- xhcid/src/main.rs | 8 ++++---- xhcid/src/xhci/mod.rs | 6 +++--- 20 files changed, 51 insertions(+), 51 deletions(-) diff --git a/audio/ac97d/src/main.rs b/audio/ac97d/src/main.rs index bbc6143b46..846a8af1a0 100644 --- a/audio/ac97d/src/main.rs +++ b/audio/ac97d/src/main.rs @@ -14,7 +14,7 @@ use std::usize; use event::{user_data, EventQueue}; use libredox::flag; -use pcid_interface::{PciBar, PcidServerHandle}; +use pcid_interface::{PciBar, PciFunctionHandle}; use redox_log::{OutputBuilder, RedoxLogger}; use syscall::{EventFlags, Packet, SchemeBlockMut}; @@ -66,7 +66,7 @@ fn setup_logging() -> Option<&'static RedoxLogger> { fn main() { let mut pcid_handle = - PcidServerHandle::connect_default().expect("ac97d: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("ac97d: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("ac97d: failed to fetch config"); diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index a8e6aa4ef3..a7ba09d801 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -16,7 +16,7 @@ use std::cell::RefCell; use std::sync::Arc; use event::{user_data, EventQueue}; -use pcid_interface::{MsiSetFeatureInfo, PcidServerHandle, PciFeature, PciFeatureInfo, SetFeatureInfo}; +use pcid_interface::{MsiSetFeatureInfo, PciFunctionHandle, PciFeature, PciFeatureInfo, SetFeatureInfo}; #[cfg(target_arch = "x86_64")] use pcid_interface::irq_helpers::allocate_single_interrupt_vector_for_msi; use pcid_interface::irq_helpers::read_bsp_apic_id; @@ -76,7 +76,7 @@ fn setup_logging() -> Option<&'static RedoxLogger> { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); let all_pci_features = pcid_handle.fetch_all_features().expect("ihdad: failed to fetch pci features"); @@ -121,7 +121,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); if let Some(irq) = pci_config.func.legacy_interrupt_line { @@ -135,7 +135,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { fn daemon(daemon: redox_daemon::Daemon) -> ! { let _logger_ref = setup_logging(); - let mut pcid_handle = PcidServerHandle::connect_default().expect("ihdad: failed to setup channel to pcid"); + 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"); diff --git a/graphics/bgad/src/main.rs b/graphics/bgad/src/main.rs index a80423f392..b03f81a2f0 100644 --- a/graphics/bgad/src/main.rs +++ b/graphics/bgad/src/main.rs @@ -4,7 +4,7 @@ extern crate syscall; use std::fs::File; use std::io::{Read, Write}; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use syscall::call::iopl; use syscall::data::Packet; use syscall::scheme::SchemeMut; @@ -17,7 +17,7 @@ mod scheme; fn main() { let mut pcid_handle = - PcidServerHandle::connect_default().expect("bgad: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("bgad: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("bgad: failed to fetch config"); diff --git a/graphics/virtio-gpud/src/main.rs b/graphics/virtio-gpud/src/main.rs index 8a80510fbc..3fbeb0681d 100644 --- a/graphics/virtio-gpud/src/main.rs +++ b/graphics/virtio-gpud/src/main.rs @@ -27,7 +27,7 @@ use std::fs::File; use std::io::{Read, Write}; use std::sync::Arc; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use syscall::{Packet, SchemeMut}; use virtio_core::transport::{self, Queue}; @@ -409,7 +409,7 @@ fn reinit(control_queue: Arc, cursor_queue: Arc) -> Result<(), tra } fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { - let mut pcid_handle = PcidServerHandle::connect_default()?; + let mut pcid_handle = PciFunctionHandle::connect_default()?; // Double check that we have the right device. // diff --git a/net/e1000d/src/main.rs b/net/e1000d/src/main.rs index db893106e7..005770f09d 100644 --- a/net/e1000d/src/main.rs +++ b/net/e1000d/src/main.rs @@ -6,14 +6,14 @@ use std::rc::Rc; use driver_network::NetworkScheme; use event::{user_data, EventQueue}; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use syscall::EventFlags; pub mod device; fn main() { let mut pcid_handle = - PcidServerHandle::connect_default().expect("e1000d: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("e1000d: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("e1000d: failed to fetch config"); diff --git a/net/ixgbed/src/main.rs b/net/ixgbed/src/main.rs index 2c54c73ee2..a9fe183a79 100644 --- a/net/ixgbed/src/main.rs +++ b/net/ixgbed/src/main.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use driver_network::NetworkScheme; use event::{user_data, EventQueue}; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use syscall::EventFlags; pub mod device; @@ -15,7 +15,7 @@ mod ixgbe; fn main() { let mut pcid_handle = - PcidServerHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("ixgbed: failed to fetch config"); diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index 04cba8fc48..2eb17379b8 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -15,7 +15,7 @@ use pcid_interface::irq_helpers::allocate_single_interrupt_vector_for_msi; use pcid_interface::irq_helpers::read_bsp_apic_id; use pcid_interface::msi::{MsixInfo, MsixTableEntry}; use pcid_interface::{ - MsiSetFeatureInfo, PciFeature, PciFeatureInfo, PcidServerHandle, SetFeatureInfo, + MsiSetFeatureInfo, PciFeature, PciFeatureInfo, PciFunctionHandle, SetFeatureInfo, SubdriverArguments, }; use redox_log::{OutputBuilder, RedoxLogger}; @@ -95,7 +95,7 @@ impl MappedMsixRegs { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8139d: failed to fetch pci features"); @@ -177,7 +177,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); if let Some(irq) = pci_config.func.legacy_interrupt_line { @@ -209,7 +209,7 @@ fn find_bar(pci_config: &SubdriverArguments) -> Option<(usize, usize)> { fn daemon(daemon: redox_daemon::Daemon) -> ! { let _logger_ref = setup_logging(); - let mut pcid_handle = PcidServerHandle::connect_default().expect("rtl8139d: failed to setup channel to pcid"); + 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"); diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index f8177b98d8..45a16d3ca5 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use driver_network::NetworkScheme; use event::{user_data, EventQueue}; -use pcid_interface::{MsiSetFeatureInfo, PcidServerHandle, PciFeature, PciFeatureInfo, SetFeatureInfo, SubdriverArguments}; +use pcid_interface::{MsiSetFeatureInfo, PciFunctionHandle, PciFeature, PciFeatureInfo, SetFeatureInfo, SubdriverArguments}; #[cfg(target_arch = "x86_64")] use pcid_interface::irq_helpers::allocate_single_interrupt_vector_for_msi; use pcid_interface::irq_helpers::read_bsp_apic_id; @@ -90,7 +90,7 @@ impl MappedMsixRegs { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8168d: failed to fetch pci features"); @@ -172,7 +172,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { +fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); if let Some(irq) = pci_config.func.legacy_interrupt_line { @@ -204,7 +204,7 @@ fn find_bar(pci_config: &SubdriverArguments) -> Option<(usize, usize)> { fn daemon(daemon: redox_daemon::Daemon) -> ! { let _logger_ref = setup_logging(); - let mut pcid_handle = PcidServerHandle::connect_default().expect("rtl8168d: failed to setup channel to pcid"); + 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"); diff --git a/net/virtio-netd/src/main.rs b/net/virtio-netd/src/main.rs index d2a2411f55..d413e62da8 100644 --- a/net/virtio-netd/src/main.rs +++ b/net/virtio-netd/src/main.rs @@ -5,7 +5,7 @@ use std::io::{Read, Write}; use std::mem; use driver_network::NetworkScheme; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use scheme::VirtioNet; @@ -28,7 +28,7 @@ static_assertions::const_assert_eq!(core::mem::size_of::(), 12); const MAX_BUFFER_LEN: usize = 65535; fn deamon(daemon: redox_daemon::Daemon) -> Result<(), Box> { - let mut pcid_handle = PcidServerHandle::connect_default()?; + let mut pcid_handle = PciFunctionHandle::connect_default()?; // Double check that we have the right device. // diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 70bb982c33..6f92124b53 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -227,7 +227,7 @@ pub enum PcidClientResponse { // very similar to crossbeam-channel or libstd's mpsc (except the cycle, enqueue and dequeue fields // are stored in the same buffer as the actual data). /// A handle from a `pcid` client (e.g. `ahcid`) to `pcid`. -pub struct PcidServerHandle { +pub struct PciFunctionHandle { pcid_to_client: File, pcid_from_client: File, } @@ -253,7 +253,7 @@ pub(crate) fn recv(r: &mut R) -> Result { Ok(bincode::deserialize_from(&data[..])?) } -impl PcidServerHandle { +impl PciFunctionHandle { pub fn connect_default() -> Result { let pcid_to_client_fd = env::var("PCID_TO_CLIENT_FD")?.parse::().map_err(PcidClientHandleError::EnvValidityError)?; let pcid_from_client_fd = env::var("PCID_FROM_CLIENT_FD")?.parse::().map_err(PcidClientHandleError::EnvValidityError)?; diff --git a/storage/ahcid/src/main.rs b/storage/ahcid/src/main.rs index a5bb6f79db..a912de71a5 100644 --- a/storage/ahcid/src/main.rs +++ b/storage/ahcid/src/main.rs @@ -9,7 +9,7 @@ use std::os::fd::AsRawFd; use std::usize; use event::{EventFlags, RawEventQueue}; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; use redox_scheme::{RequestKind, Response, SignalBehavior, Socket, V2}; use syscall::error::{Error, ENODEV}; @@ -72,7 +72,7 @@ fn main() { fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = - PcidServerHandle::connect_default().expect("ahcid: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("ahcid: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("ahcid: failed to fetch config"); diff --git a/storage/ided/src/main.rs b/storage/ided/src/main.rs index 0a10a625a0..b8dd79a70d 100644 --- a/storage/ided/src/main.rs +++ b/storage/ided/src/main.rs @@ -2,7 +2,7 @@ use driver_block::Disk; use event::{EventFlags, RawEventQueue}; use libredox::flag; use log::{error, info}; -use pcid_interface::{PciBar, PcidServerHandle}; +use pcid_interface::{PciBar, PciFunctionHandle}; use redox_log::{OutputBuilder, RedoxLogger}; use redox_scheme::{RequestKind, Response, SignalBehavior, Socket, V2}; use std::{ @@ -75,7 +75,7 @@ fn main() { fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = - PcidServerHandle::connect_default().expect("ided: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("ided: failed to setup channel to pcid"); let pci_config = pcid_handle.fetch_config().expect("ided: failed to fetch config"); diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index 6910e0a65b..f00ef3bbb9 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -10,7 +10,7 @@ use std::sync::{Arc, Mutex}; use std::{slice, usize}; use libredox::flag; -use pcid_interface::{PciFeature, PciFeatureInfo, PciFunction, PcidServerHandle}; +use pcid_interface::{PciFeature, PciFeatureInfo, PciFunction, PciFunctionHandle}; use redox_scheme::{CallRequest, RequestKind, SignalBehavior, Socket, V2}; use syscall::{ Event, Mmio, Packet, Result, SchemeBlockMut, @@ -58,7 +58,7 @@ pub struct AllocatedBars(pub [Mutex>; 6]); /// structures), and the handles to the interrupts. #[cfg(target_arch = "x86_64")] fn get_int_method( - pcid_handle: &mut PcidServerHandle, + pcid_handle: &mut PciFunctionHandle, function: &PciFunction, allocated_bars: &AllocatedBars, ) -> Result<(InterruptMethod, InterruptSources)> { @@ -184,7 +184,7 @@ fn get_int_method( //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] fn get_int_method( - pcid_handle: &mut PcidServerHandle, + pcid_handle: &mut PciFunctionHandle, function: &PciFunction, allocated_bars: &AllocatedBars, ) -> Result<(InterruptMethod, InterruptSources)> { @@ -246,7 +246,7 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = - PcidServerHandle::connect_default().expect("nvmed: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("nvmed: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("nvmed: failed to fetch config"); diff --git a/storage/nvmed/src/nvme/mod.rs b/storage/nvmed/src/nvme/mod.rs index 993736b890..14e502777a 100644 --- a/storage/nvmed/src/nvme/mod.rs +++ b/storage/nvmed/src/nvme/mod.rs @@ -23,7 +23,7 @@ use self::cq_reactor::NotifReq; pub use self::queues::{NvmeCmd, NvmeCmdQueue, NvmeComp, NvmeCompQueue}; use pcid_interface::msi::{MsiInfo, MsixInfo, MsixTableEntry}; -use pcid_interface::PcidServerHandle; +use pcid_interface::PciFunctionHandle; #[cfg(target_arch = "aarch64")] #[inline(always)] @@ -173,7 +173,7 @@ pub type AtomicCmdId = AtomicU16; pub struct Nvme { interrupt_method: Mutex, - pcid_interface: Mutex, + pcid_interface: Mutex, regs: RwLock<&'static mut NvmeRegs>, pub(crate) submission_queues: RwLock, CqId)>>, @@ -209,7 +209,7 @@ impl Nvme { pub fn new( address: usize, interrupt_method: InterruptMethod, - pcid_interface: PcidServerHandle, + pcid_interface: PciFunctionHandle, reactor_sender: Sender, ) -> Result { Ok(Nvme { diff --git a/storage/virtio-blkd/src/main.rs b/storage/virtio-blkd/src/main.rs index abdbacaba7..289a4d91a1 100644 --- a/storage/virtio-blkd/src/main.rs +++ b/storage/virtio-blkd/src/main.rs @@ -109,7 +109,7 @@ pub struct BlockVirtRequest { const_assert_eq!(core::mem::size_of::(), 16); fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { - let mut pcid_handle = PcidServerHandle::connect_default()?; + let mut pcid_handle = PciFunctionHandle::connect_default()?; // Double check that we have the right device. // diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index be65b6a11d..16b1dae847 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -6,7 +6,7 @@ use std::os::unix::io::AsRawFd; use std::fs::File; use std::io::{Result, Read, Write}; -use pcid_interface::{PciBar, PcidServerHandle}; +use pcid_interface::{PciBar, PciFunctionHandle}; use syscall::flag::EventFlags; use syscall::io::{Io, Mmio, Pio}; @@ -181,7 +181,7 @@ impl VboxGuestInfo { fn main() { let mut pcid_handle = - PcidServerHandle::connect_default().expect("vboxd: failed to setup channel to pcid"); + PciFunctionHandle::connect_default().expect("vboxd: failed to setup channel to pcid"); let pci_config = pcid_handle .fetch_config() .expect("vboxd: failed to fetch config"); diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index 95072fd0ac..5413b2f169 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -8,7 +8,7 @@ use crate::{probe::MappedMsixRegs, MSIX_PRIMARY_VECTOR}; use pcid_interface::*; -pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { +pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { let pci_config = pcid_handle.fetch_config()?; // Extended message signaled interrupts. @@ -50,7 +50,7 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { pub fn probe_legacy_port_transport( pci_config: &SubdriverArguments, - pcid_handle: &mut PcidServerHandle, + pcid_handle: &mut PciFunctionHandle, ) -> Result { let port = pci_config.func.bars[0].expect_port(); diff --git a/virtio-core/src/probe.rs b/virtio-core/src/probe.rs index 3cd6d8d8fb..7da40a958d 100644 --- a/virtio-core/src/probe.rs +++ b/virtio-core/src/probe.rs @@ -41,7 +41,7 @@ static_assertions::const_assert_eq!(std::mem::size_of::(), 16); pub const MSIX_PRIMARY_VECTOR: u16 = 0; #[cfg(not(target_arch = "x86_64"))] -fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { +fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { panic!("Msi-X only supported on x86_64"); } @@ -59,7 +59,7 @@ fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { /// /// ## Panics /// This function panics if the device is not a virtio device. -pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result { +pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result { let pci_config = pcid_handle.fetch_config()?; assert_eq!( diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 3c3aa0dbce..9a1bb570f4 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex}; use std::env; use libredox::flag; -use pcid_interface::{MsiSetFeatureInfo, PcidServerHandle, PciFeature, PciFeatureInfo, SetFeatureInfo}; +use pcid_interface::{MsiSetFeatureInfo, PciFunctionHandle, PciFeature, PciFeatureInfo, SetFeatureInfo}; #[cfg(target_arch = "x86_64")] use pcid_interface::irq_helpers::allocate_single_interrupt_vector_for_msi; use pcid_interface::irq_helpers::read_bsp_apic_id; @@ -85,7 +85,7 @@ fn setup_logging(name: &str) -> Option<&'static RedoxLogger> { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle, bar0_address: usize) -> (Option, InterruptMethod) { +fn get_int_method(pcid_handle: &mut PciFunctionHandle, bar0_address: usize) -> (Option, InterruptMethod) { let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); let all_pci_features = pcid_handle.fetch_all_features().expect("xhcid: failed to fetch pci features"); @@ -167,7 +167,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, bar0_address: usize) -> (O //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option, InterruptMethod) { +fn get_int_method(pcid_handle: &mut PciFunctionHandle, address: usize) -> (Option, InterruptMethod) { let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); if let Some(irq) = pci_config.func.legacy_interrupt_line { @@ -184,7 +184,7 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let mut pcid_handle = PcidServerHandle::connect_default().expect("xhcid: failed to setup channel to pcid"); + 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 mut name = pci_config.func.name(); diff --git a/xhcid/src/xhci/mod.rs b/xhcid/src/xhci/mod.rs index 32eb7f7dd4..f42482f1ea 100644 --- a/xhcid/src/xhci/mod.rs +++ b/xhcid/src/xhci/mod.rs @@ -22,7 +22,7 @@ use serde::Deserialize; use crate::usb; use pcid_interface::msi::{MsixInfo, MsixTableEntry}; -use pcid_interface::{PcidServerHandle, PciFeature}; +use pcid_interface::{PciFunctionHandle, PciFeature}; mod capability; mod context; @@ -198,7 +198,7 @@ pub struct Xhci { scheme_name: String, interrupt_method: InterruptMethod, - pcid_handle: Mutex, + pcid_handle: Mutex, irq_reactor: Mutex>>, @@ -258,7 +258,7 @@ impl EndpointState { } impl Xhci { - pub fn new(scheme_name: String, address: usize, interrupt_method: InterruptMethod, pcid_handle: PcidServerHandle) -> Result { + pub fn new(scheme_name: String, address: usize, interrupt_method: InterruptMethod, pcid_handle: PciFunctionHandle) -> Result { let cap = unsafe { &mut *(address as *mut CapabilityRegs) }; debug!("CAP REGS BASE {:X}", address); From a3b957c2e5b7c9138732e2c4c14eba9bf62d8b3e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:16:09 +0200 Subject: [PATCH 3/4] pcid: Fetch config in PciFunctionHandle::connect_default() --- audio/ac97d/src/main.rs | 6 ++---- audio/ihdad/src/main.rs | 6 +++--- graphics/bgad/src/main.rs | 6 ++---- graphics/virtio-gpud/src/main.rs | 2 +- net/e1000d/src/main.rs | 6 ++---- net/ixgbed/src/main.rs | 6 ++---- net/rtl8139d/src/main.rs | 6 +++--- net/rtl8168d/src/main.rs | 6 +++--- net/virtio-netd/src/main.rs | 2 +- pcid/src/driver_interface/mod.rs | 23 +++++++++++++++-------- storage/ahcid/src/main.rs | 6 ++---- storage/ided/src/main.rs | 4 ++-- storage/nvmed/src/main.rs | 4 +--- storage/virtio-blkd/src/main.rs | 2 +- vboxd/src/main.rs | 6 ++---- virtio-core/src/arch/x86_64.rs | 2 +- virtio-core/src/probe.rs | 2 +- xhcid/src/main.rs | 8 ++++---- 18 files changed, 48 insertions(+), 55 deletions(-) diff --git a/audio/ac97d/src/main.rs b/audio/ac97d/src/main.rs index 846a8af1a0..9066acc52a 100644 --- a/audio/ac97d/src/main.rs +++ b/audio/ac97d/src/main.rs @@ -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"); diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index a7ba09d801..820b5d2cc1 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -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"); diff --git a/graphics/bgad/src/main.rs b/graphics/bgad/src/main.rs index b03f81a2f0..c4832e8560 100644 --- a/graphics/bgad/src/main.rs +++ b/graphics/bgad/src/main.rs @@ -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"); diff --git a/graphics/virtio-gpud/src/main.rs b/graphics/virtio-gpud/src/main.rs index 3fbeb0681d..938ec8c817 100644 --- a/graphics/virtio-gpud/src/main.rs +++ b/graphics/virtio-gpud/src/main.rs @@ -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 :^)"); diff --git a/net/e1000d/src/main.rs b/net/e1000d/src/main.rs index 005770f09d..7e7bb90ade 100644 --- a/net/e1000d/src/main.rs +++ b/net/e1000d/src/main.rs @@ -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"); diff --git a/net/ixgbed/src/main.rs b/net/ixgbed/src/main.rs index a9fe183a79..0b8640dafc 100644 --- a/net/ixgbed/src/main.rs +++ b/net/ixgbed/src/main.rs @@ -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"); diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index 2eb17379b8..d0893aec93 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -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"); diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index 45a16d3ca5..b2ec6f69b5 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -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"); diff --git a/net/virtio-netd/src/main.rs b/net/virtio-netd/src/main.rs index d413e62da8..76e07b160f 100644 --- a/net/virtio-netd/src/main.rs +++ b/net/virtio-netd/src/main.rs @@ -33,7 +33,7 @@ fn deamon(daemon: redox_daemon::Daemon) -> Result<(), Box // 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 :^)"); diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 6f92124b53..5f57c343ad 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -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: &mut W, message: &T) -> Result<()> { @@ -258,9 +259,19 @@ impl PciFunctionHandle { let pcid_to_client_fd = env::var("PCID_TO_CLIENT_FD")?.parse::().map_err(PcidClientHandleError::EnvValidityError)?; let pcid_from_client_fd = env::var("PCID_FROM_CLIENT_FD")?.parse::().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 { recv(&mut self.pcid_to_client) } - pub fn fetch_config(&mut self) -> Result { - 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> { diff --git a/storage/ahcid/src/main.rs b/storage/ahcid/src/main.rs index a912de71a5..1947c02094 100644 --- a/storage/ahcid/src/main.rs +++ b/storage/ahcid/src/main.rs @@ -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"); diff --git a/storage/ided/src/main.rs b/storage/ided/src/main.rs index b8dd79a70d..c4723fad54 100644 --- a/storage/ided/src/main.rs +++ b/storage/ided/src/main.rs @@ -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"); diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index f00ef3bbb9..b6abc0e856 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -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()); diff --git a/storage/virtio-blkd/src/main.rs b/storage/virtio-blkd/src/main.rs index 289a4d91a1..8d819db570 100644 --- a/storage/virtio-blkd/src/main.rs +++ b/storage/virtio-blkd/src/main.rs @@ -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 :^)"); diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index 16b1dae847..9a1ab423db 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -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"); diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index 5413b2f169..c804ab9dfa 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -9,7 +9,7 @@ use crate::{probe::MappedMsixRegs, MSIX_PRIMARY_VECTOR}; use pcid_interface::*; pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { - 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)? { diff --git a/virtio-core/src/probe.rs b/virtio-core/src/probe.rs index 7da40a958d..984acd88d2 100644 --- a/virtio-core/src/probe.rs +++ b/virtio-core/src/probe.rs @@ -60,7 +60,7 @@ fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { /// ## Panics /// This function panics if the device is not a virtio device. pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result { - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); assert_eq!( pci_config.func.full_device_id.vendor_id, 6900, diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 9a1bb570f4..fc441b03bc 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -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, 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, 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"); From 23ac69649163c41d4573060a66d7bb4050ef4447 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:47:48 +0200 Subject: [PATCH 4/4] pcid: Add PciFunctionHandle::map_bar method This will enable the pcid driver interface to safely map the MSI-X table in the future without having to worry about a BAR being mapped twice. --- audio/ihdad/src/main.rs | 4 +- net/e1000d/src/main.rs | 9 +++-- net/ixgbed/src/main.rs | 8 ++-- net/rtl8139d/src/main.rs | 5 ++- net/rtl8168d/src/main.rs | 5 ++- pcid/src/driver_interface/mod.rs | 31 +++++++++++++++ pcid/src/pci/bar.rs | 15 -------- storage/ahcid/src/main.rs | 6 +-- storage/nvmed/src/main.rs | 66 +++----------------------------- vboxd/src/main.rs | 6 +-- virtio-core/src/arch/x86_64.rs | 5 ++- xhcid/src/main.rs | 9 +++-- 12 files changed, 66 insertions(+), 103 deletions(-) diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index 820b5d2cc1..78f2ebbe32 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -142,11 +142,9 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut name = pci_config.func.name(); name.push_str("_ihda"); - let bar = &pci_config.func.bars[0]; - log::info!(" + IHDA {}", pci_config.func.display()); - let address = unsafe { bar.physmap_mem("ihdad") }.0 as usize; + let address = unsafe { pcid_handle.map_bar(0).expect("ihdad") }.ptr.as_ptr() as usize; //TODO: MSI-X let mut irq_file = get_int_method(&mut pcid_handle); diff --git a/net/e1000d/src/main.rs b/net/e1000d/src/main.rs index 7e7bb90ade..1ed1608237 100644 --- a/net/e1000d/src/main.rs +++ b/net/e1000d/src/main.rs @@ -12,15 +12,13 @@ use syscall::EventFlags; pub mod device; fn main() { - let pcid_handle = + let mut pcid_handle = PciFunctionHandle::connect_default().expect("e1000d: failed to setup channel to pcid"); let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_e1000"); - let bar = &pci_config.func.bars[0]; - let irq = pci_config .func .legacy_interrupt_line @@ -31,7 +29,10 @@ fn main() { redox_daemon::Daemon::new(move |daemon| { let mut irq_file = irq.irq_handle("e1000d"); - let address = unsafe { bar.physmap_mem("e1000d") }.0 as usize; + let address = unsafe { pcid_handle.map_bar(0) } + .expect("e1000d") + .ptr + .as_ptr() as usize; let device = unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") }; diff --git a/net/ixgbed/src/main.rs b/net/ixgbed/src/main.rs index 0b8640dafc..8382823230 100644 --- a/net/ixgbed/src/main.rs +++ b/net/ixgbed/src/main.rs @@ -14,7 +14,7 @@ pub mod device; mod ixgbe; fn main() { - let pcid_handle = + let mut pcid_handle = PciFunctionHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); let pci_config = pcid_handle.config(); @@ -31,9 +31,9 @@ fn main() { redox_daemon::Daemon::new(move |daemon| { let mut irq_file = irq.irq_handle("ixgbed"); - let (address, size) = unsafe { - pci_config.func.bars[0].physmap_mem("ixgbed") - }; + let mapped_bar = unsafe { pcid_handle.map_bar(0) }.expect("ixgbed"); + let address = mapped_bar.ptr.as_ptr(); + let size = mapped_bar.bar_size; let device = device::Intel8259x::new(address as usize, size) .expect("ixgbed: failed to allocate device"); diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index d0893aec93..4c3d8d0073 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -135,8 +135,9 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { }; msix_info.validate(pci_config.func.bars); - let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("rtl8139d") }.0 as usize; + let bar_address = unsafe { pcid_handle.map_bar(msix_info.table_bar).expect("rtl8139d") } + .ptr + .as_ptr() as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index b2ec6f69b5..7ba886d4c5 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -130,8 +130,9 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { }; msix_info.validate(pci_config.func.bars); - let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("rtl8168d") }.0 as usize; + let bar_address = unsafe { pcid_handle.map_bar(msix_info.table_bar).expect("rtl8168d") } + .ptr + .as_ptr() as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 5f57c343ad..f65d2885cc 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -1,6 +1,7 @@ use std::fmt; use std::fs::File; use std::io::prelude::*; +use std::ptr::NonNull; use std::{env, io}; use std::os::unix::io::{FromRawFd, RawFd}; @@ -222,6 +223,11 @@ pub enum PcidClientResponse { WriteConfig, } +pub struct MappedBar { + pub ptr: NonNull, + pub bar_size: usize, +} + // TODO: Ideally, pcid might have its own scheme, like lots of other Redox drivers, where this kind of IPC is done. Otherwise, instead of writing serde messages over // a channel, the communication could potentially be done via mmap, using a channel // very similar to crossbeam-channel or libstd's mpsc (except the cycle, enqueue and dequeue fields @@ -231,6 +237,7 @@ pub struct PciFunctionHandle { pcid_to_client: File, pcid_from_client: File, config: SubdriverArguments, + mapped_bars: [Option; 6], } pub(crate) fn send(w: &mut W, message: &T) -> Result<()> { @@ -272,6 +279,7 @@ impl PciFunctionHandle { pcid_to_client, pcid_from_client, config, + mapped_bars: [const { None }; 6], }) } fn send(&mut self, req: &PcidClientRequest) -> Result<()> { @@ -336,4 +344,27 @@ impl PciFunctionHandle { other => Err(PcidClientHandleError::InvalidResponse(other)), } } + pub unsafe fn map_bar(&mut self, bir: u8) -> Result<&MappedBar> { + let mapped_bar = &mut self.mapped_bars[bir as usize]; + if let Some(mapped_bar) = mapped_bar { + Ok(mapped_bar) + } else { + let (bar, bar_size) = self.config.func.bars[bir as usize].expect_mem(); + let ptr = unsafe { + common::physmap( + bar, + bar_size, + common::Prot::RW, + // FIXME once the kernel supports this use write-through for prefetchable BAR + common::MemoryType::Uncacheable, + ) + } + .map_err(|err| io::Error::other(format!("failed to map BAR at {bar:016X}: {err}")))?; + + Ok(mapped_bar.insert(MappedBar { + ptr: NonNull::new(ptr.cast::()).expect("Mapping a BAR resulted in a nullptr"), + bar_size, + })) + } + } } diff --git a/pcid/src/pci/bar.rs b/pcid/src/pci/bar.rs index 706479008b..b2c1d35bbd 100644 --- a/pcid/src/pci/bar.rs +++ b/pcid/src/pci/bar.rs @@ -52,19 +52,4 @@ impl PciBar { PciBar::None => panic!("expected BAR to exist"), } } - - pub unsafe fn physmap_mem(&self, driver: &str) -> (*mut (), usize) { - let (bar, bar_size) = self.expect_mem(); - let addr = unsafe { - common::physmap( - bar, - bar_size, - common::Prot::RW, - // FIXME once the kernel supports this use write-through for prefetchable BAR - common::MemoryType::Uncacheable, - ) - } - .unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}")); - (addr, bar_size) - } } diff --git a/storage/ahcid/src/main.rs b/storage/ahcid/src/main.rs index 1947c02094..a3a8107729 100644 --- a/storage/ahcid/src/main.rs +++ b/storage/ahcid/src/main.rs @@ -71,22 +71,20 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let pcid_handle = + let mut pcid_handle = PciFunctionHandle::connect_default().expect("ahcid: failed to setup channel to pcid"); let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ahci"); - let bar = &pci_config.func.bars[5]; - let irq = pci_config.func.legacy_interrupt_line.expect("ahcid: no legacy interrupts supported"); let _logger_ref = setup_logging(&name); info!(" + AHCI {}", pci_config.func.display()); - let (address, _) = unsafe { bar.physmap_mem("ahcid") }; + let address = unsafe { pcid_handle.map_bar(5).expect("ahcid") }.ptr.as_ptr() as usize; { let scheme_name = format!("disk.{}", name); let socket = Socket::::nonblock(&scheme_name).expect("ahcid: failed to create disk scheme"); diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index b6abc0e856..f3bc114106 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -24,35 +24,6 @@ use self::scheme::DiskScheme; mod nvme; mod scheme; -/// A wrapper for a BAR allocation. -pub struct Bar { - ptr: NonNull, - bar_size: usize, -} -impl Bar { - pub fn new(ptr: *mut (), bar_size: usize) -> Result { - Ok(Self { - ptr: NonNull::new(ptr.cast::()).expect("Mapping a BAR resulted in a nullptr"), - bar_size, - }) - } -} - -impl Drop for Bar { - fn drop(&mut self) { - let _ = unsafe { - libredox::call::munmap( - self.ptr.as_ptr().cast(), - self.bar_size.next_multiple_of(PAGE_SIZE), - ) - }; - } -} - -/// The PCI BARs that may be allocated. -#[derive(Default)] -pub struct AllocatedBars(pub [Mutex>; 6]); - /// Get the most optimal yet functional interrupt mechanism: either (in the order of preference): /// MSI-X, MSI, and INTx# pin. Returns both runtime interrupt structures (MSI/MSI-X capability /// structures), and the handles to the interrupts. @@ -60,7 +31,6 @@ pub struct AllocatedBars(pub [Mutex>; 6]); fn get_int_method( pcid_handle: &mut PciFunctionHandle, function: &PciFunction, - allocated_bars: &AllocatedBars, ) -> Result<(InterruptMethod, InterruptSources)> { log::trace!("Begin get_int_method"); use pcid_interface::irq_helpers; @@ -81,26 +51,11 @@ fn get_int_method( _ => unreachable!(), }; msix_info.validate(function.bars); - fn bar_base( - allocated_bars: &AllocatedBars, - function: &PciFunction, - bir: u8, - ) -> Result> { - let bir = usize::from(bir); - let mut bar_guard = allocated_bars.0[bir].lock().unwrap(); - match &mut *bar_guard { - &mut Some(ref bar) => Ok(bar.ptr), - bar_to_set @ &mut None => { - let (ptr, bar_size) = unsafe { function.bars[bir].physmap_mem("nvmed") }; - - let bar = Bar::new(ptr, bar_size)?; - *bar_to_set = Some(bar); - Ok(bar_to_set.as_ref().unwrap().ptr) - } - } + fn bar_base(pcid_handle: &mut PciFunctionHandle, bir: u8) -> Result> { + Ok(unsafe { pcid_handle.map_bar(bir) }.expect("nvmed").ptr) } let table_bar_base: *mut u8 = - bar_base(allocated_bars, function, msix_info.table_bar)?.as_ptr(); + bar_base(pcid_handle, msix_info.table_bar)?.as_ptr(); let table_base = unsafe { table_bar_base.offset(msix_info.table_offset as isize) }; @@ -186,7 +141,6 @@ fn get_int_method( fn get_int_method( pcid_handle: &mut PciFunctionHandle, function: &PciFunction, - allocated_bars: &AllocatedBars, ) -> Result<(InterruptMethod, InterruptSources)> { if let Some(irq) = function.legacy_interrupt_line { // INTx# pin based interrupts. @@ -255,15 +209,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { log::debug!("NVME PCI CONFIG: {:?}", pci_config); - let allocated_bars = AllocatedBars::default(); - - let bar = &pci_config.func.bars[0]; - let (address, bar_size) = unsafe { bar.physmap_mem("nvmed") }; - - *allocated_bars.0[0].lock().unwrap() = Some(Bar { - bar_size, - ptr: NonNull::new(address.cast::()).expect("Physmapping BAR gave nullptr"), - }); + let address = unsafe { pcid_handle.map_bar(0).expect("nvmed").ptr }; let socket = Socket::::create(&scheme_name).expect("nvmed: failed to create disk scheme"); @@ -271,10 +217,10 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let (reactor_sender, reactor_receiver) = crossbeam_channel::unbounded(); let (interrupt_method, interrupt_sources) = - get_int_method(&mut pcid_handle, &pci_config.func, &allocated_bars) + get_int_method(&mut pcid_handle, &pci_config.func) .expect("nvmed: failed to find a suitable interrupt method"); let mut nvme = Nvme::new( - address as usize, + address.as_ptr() as usize, interrupt_method, pcid_handle, reactor_sender, diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index 9a1ab423db..fac9717351 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -180,7 +180,7 @@ impl VboxGuestInfo { } fn main() { - let pcid_handle = + let mut pcid_handle = PciFunctionHandle::connect_default().expect("vboxd: failed to setup channel to pcid"); let pci_config = pcid_handle.config(); @@ -189,8 +189,6 @@ fn main() { let bar0 = pci_config.func.bars[0].expect_port(); - let bar1 = &pci_config.func.bars[1]; - let irq = pci_config.func.legacy_interrupt_line.expect("vboxd: no legacy interrupts supported"); println!(" + VirtualBox {}", pci_config.func.display()); @@ -215,7 +213,7 @@ fn main() { let mut irq_file = irq.irq_handle("vboxd"); let mut port = Pio::::new(bar0 as u16); - let (address, _) = unsafe { bar1.physmap_mem("vboxd") }; + let address = unsafe { pcid_handle.map_bar(1) }.expect("vboxd").ptr.as_ptr(); { let vmmdev = unsafe { &mut *(address as *mut VboxVmmDev) }; diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index c804ab9dfa..edb85ab942 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -18,8 +18,9 @@ pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { }; msix_info.validate(pci_config.func.bars); - let bar = &pci_config.func.bars[msix_info.table_bar as usize]; - let bar_address = unsafe { bar.physmap_mem("virtio-core") }.0 as usize; + let bar_address = unsafe { pcid_handle.map_bar(msix_info.table_bar)? } + .ptr + .as_ptr() as usize; let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry; let mut info = MappedMsixRegs { diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index fc441b03bc..6248e4264f 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -184,7 +184,8 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let pcid_handle = PciFunctionHandle::connect_default().expect("xhcid: failed to setup channel to pcid"); + let mut 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(); @@ -193,9 +194,11 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let _logger_ref = setup_logging(&name); log::debug!("XHCI PCI CONFIG: {:?}", pci_config); - let bar = &pci_config.func.bars[0]; - let address = unsafe { bar.physmap_mem("xhcid") }.0 as usize; + let address = unsafe { pcid_handle.map_bar(0) } + .expect("xhcid") + .ptr + .as_ptr() as usize; let (irq_file, interrupt_method) = (None, InterruptMethod::Polling); //TODO: get_int_method(&mut pcid_handle, address);