pcid: Fetch config in PciFunctionHandle::connect_default()
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 :^)");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 :^)");
|
||||
|
||||
@@ -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>> {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
@@ -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)? {
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user