Remove fetch_header from pcid_interface
Most things are already stored in SubdriverArguments and the couple of things that aren't may change over time and thus should be read again each time they are accessed, while fetch_header would receive a fixed copy from pcid.
This commit is contained in:
+3
-4
@@ -86,17 +86,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
|
||||
info!("IDE PCI CONFIG: {:?}", pci_config);
|
||||
|
||||
let pci_header = pcid_handle.fetch_header().expect("ided: failed to fetch PCI header");
|
||||
let busmaster_base = match pci_header.get_bar(4) {
|
||||
let busmaster_base = match pci_config.func.bars[4] {
|
||||
PciBar::Port(port) => port,
|
||||
other => panic!("TODO: IDE busmaster BAR {:#x?}", other),
|
||||
};
|
||||
let (primary, primary_irq) = if pci_header.interface() & 1 != 0 {
|
||||
let (primary, primary_irq) = if pci_config.func.full_device_id.interface & 1 != 0 {
|
||||
panic!("TODO: IDE primary channel is PCI native");
|
||||
} else {
|
||||
(Channel::primary_compat(busmaster_base).unwrap(), 14)
|
||||
};
|
||||
let (secondary, secondary_irq) = if pci_header.interface() & 1 != 0 {
|
||||
let (secondary, secondary_irq) = if pci_config.func.full_device_id.interface & 1 != 0 {
|
||||
panic!("TODO: IDE secondary channel is PCI native");
|
||||
} else {
|
||||
(Channel::secondary_compat(busmaster_base + 8).unwrap(), 15)
|
||||
|
||||
@@ -9,7 +9,7 @@ use thiserror::Error;
|
||||
|
||||
pub use crate::pci::cap::Capability;
|
||||
pub use crate::pci::msi;
|
||||
pub use crate::pci::{FullDeviceId, PciAddress, PciBar, PciHeader};
|
||||
pub use crate::pci::{FullDeviceId, PciAddress, PciBar};
|
||||
|
||||
pub mod irq_helpers;
|
||||
|
||||
@@ -163,7 +163,6 @@ pub enum SetFeatureInfo {
|
||||
#[non_exhaustive]
|
||||
pub enum PcidClientRequest {
|
||||
RequestConfig,
|
||||
RequestHeader,
|
||||
RequestFeatures,
|
||||
RequestCapabilities,
|
||||
EnableFeature(PciFeature),
|
||||
@@ -186,7 +185,6 @@ pub enum PcidServerResponseError {
|
||||
pub enum PcidClientResponse {
|
||||
Capabilities(Vec<Capability>),
|
||||
Config(SubdriverArguments),
|
||||
Header(PciHeader),
|
||||
AllFeatures(Vec<(PciFeature, FeatureStatus)>),
|
||||
FeatureEnabled(PciFeature),
|
||||
FeatureStatus(PciFeature, FeatureStatus),
|
||||
@@ -264,13 +262,6 @@ impl PcidServerHandle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_header(&mut self) -> Result<PciHeader> {
|
||||
self.send(&PcidClientRequest::RequestHeader)?;
|
||||
match self.recv()? {
|
||||
PcidClientResponse::Header(a) => Ok(a),
|
||||
other => Err(PcidClientHandleError::InvalidResponse(other)),
|
||||
}
|
||||
}
|
||||
pub fn fetch_all_features(&mut self) -> Result<Vec<(PciFeature, FeatureStatus)>> {
|
||||
self.send(&PcidClientRequest::RequestFeatures)?;
|
||||
match self.recv()? {
|
||||
|
||||
@@ -33,9 +33,7 @@ struct Args {
|
||||
}
|
||||
|
||||
pub struct DriverHandler {
|
||||
config: config::DriverConfig,
|
||||
addr: PciAddress,
|
||||
header: PciHeader,
|
||||
capabilities: Vec<(u8, PciCapability)>,
|
||||
|
||||
state: Arc<State>,
|
||||
@@ -59,9 +57,6 @@ impl DriverHandler {
|
||||
PcidClientRequest::RequestConfig => {
|
||||
PcidClientResponse::Config(args.clone())
|
||||
}
|
||||
PcidClientRequest::RequestHeader => {
|
||||
PcidClientResponse::Header(self.header.clone())
|
||||
}
|
||||
PcidClientRequest::RequestFeatures => {
|
||||
PcidClientResponse::AllFeatures(self.capabilities.iter().filter_map(|(_, capability)| match capability {
|
||||
PciCapability::Msi(msi) => Some((PciFeature::Msi, FeatureStatus::enabled(msi.enabled()))),
|
||||
@@ -409,8 +404,6 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, he
|
||||
Ok(mut child) => {
|
||||
let driver_handler = DriverHandler {
|
||||
addr,
|
||||
config: driver.clone(),
|
||||
header,
|
||||
state: Arc::clone(&state),
|
||||
capabilities,
|
||||
};
|
||||
|
||||
@@ -96,10 +96,10 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result<File, Error> {
|
||||
}
|
||||
|
||||
pub fn probe_legacy_port_transport(
|
||||
pci_header: &PciHeader,
|
||||
pci_config: &SubdriverArguments,
|
||||
pcid_handle: &mut PcidServerHandle,
|
||||
) -> Result<Device, Error> {
|
||||
if let PciBar::Port(port) = pci_header.get_bar(0) {
|
||||
if let PciBar::Port(port) = pci_config.func.bars[0] {
|
||||
unsafe { syscall::iopl(3).expect("virtio: failed to set I/O privilege level") };
|
||||
log::warn!("virtio: using legacy transport");
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result<File, Error> {
|
||||
/// This function panics if the device is not a virtio device.
|
||||
pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result<Device, Error> {
|
||||
let pci_config = pcid_handle.fetch_config()?;
|
||||
let pci_header = pcid_handle.fetch_header()?;
|
||||
|
||||
assert_eq!(
|
||||
pci_config.func.full_device_id.vendor_id, 6900,
|
||||
@@ -91,7 +90,7 @@ pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result<Device, Error>
|
||||
_ => continue,
|
||||
}
|
||||
|
||||
let bar = pci_header.get_bar(capability.bar as usize);
|
||||
let bar = pci_config.func.bars[capability.bar as usize];
|
||||
let addr = match bar {
|
||||
PciBar::Memory32(addr) => addr as usize,
|
||||
PciBar::Memory64(addr) => addr as usize,
|
||||
@@ -189,7 +188,7 @@ pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result<Device, Error>
|
||||
|
||||
Ok(device)
|
||||
} else {
|
||||
crate::arch::probe_legacy_port_transport(&pci_header, pcid_handle)
|
||||
crate::arch::probe_legacy_port_transport(&pci_config, pcid_handle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user