diff --git a/ac97d/src/main.rs b/ac97d/src/main.rs index 04a5f3f7be..f061fcda7d 100644 --- a/ac97d/src/main.rs +++ b/ac97d/src/main.rs @@ -76,7 +76,7 @@ fn main() { let bar0 = pci_config.func.bars[0].expect_port(); let bar1 = pci_config.func.bars[1].expect_port(); - let irq = pci_config.func.legacy_interrupt_line; + let irq = pci_config.func.legacy_interrupt_line.expect("ac97d: no legacy interrupts supported"); print!("{}", format!(" + ac97 {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1, irq)); diff --git a/ahcid/src/main.rs b/ahcid/src/main.rs index 3d661c321f..03ebaefd69 100644 --- a/ahcid/src/main.rs +++ b/ahcid/src/main.rs @@ -83,7 +83,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let (bar, bar_size) = pci_config.func.bars[5].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; + let irq = pci_config.func.legacy_interrupt_line.expect("ahcid: no legacy interrupts supported"); let _logger_ref = setup_logging(&name); diff --git a/e1000d/src/main.rs b/e1000d/src/main.rs index dffeb43f4d..3520e5be71 100644 --- a/e1000d/src/main.rs +++ b/e1000d/src/main.rs @@ -70,7 +70,7 @@ fn main() { let (bar, bar_size) = pci_config.func.bars[0].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; + let irq = pci_config.func.legacy_interrupt_line.expect("e1000d: no legacy interrupts supported"); eprintln!(" + E1000 {} on: {:X} size: {} IRQ: {}", name, bar, bar_size, irq); diff --git a/ihdad/src/main.rs b/ihdad/src/main.rs index 860446ad5c..f447df8566 100755 --- a/ihdad/src/main.rs +++ b/ihdad/src/main.rs @@ -74,11 +74,9 @@ fn setup_logging() -> Option<&'static RedoxLogger> { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - let all_pci_features = pcid_handle.fetch_all_features().expect("ihdad: failed to fetch pci features"); log::debug!("PCI FEATURES: {:?}", all_pci_features); @@ -123,30 +121,27 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { pcid_handle.enable_feature(PciFeature::Msi).expect("ihdad: failed to enable MSI"); log::debug!("Enabled MSI"); - Some(interrupt_handle) - } else if pci_config.func.legacy_interrupt_pin.is_some() { + interrupt_handle + } else if let Some(irq) = pci_config.func.legacy_interrupt_line { log::debug!("Legacy IRQ {}", irq); // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("ihdad: no interrupts supported at all") } } //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - if pci_config.func.legacy_interrupt_pin.is_some() { + if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("ihdad: no interrupts supported at all") } } @@ -170,7 +165,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { }; //TODO: MSI-X - let mut irq_file = get_int_method(&mut pcid_handle).expect("ihdad: no interrupt file"); + let mut irq_file = get_int_method(&mut pcid_handle); { let vend_prod: u32 = ((pci_config.func.full_device_id.vendor_id as u32) << 16) diff --git a/ixgbed/src/main.rs b/ixgbed/src/main.rs index 4666b98142..f53c0259b8 100644 --- a/ixgbed/src/main.rs +++ b/ixgbed/src/main.rs @@ -78,7 +78,7 @@ fn main() { let (bar, _) = pci_config.func.bars[0].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; + let irq = pci_config.func.legacy_interrupt_line.expect("ixgbed: no legacy interrupts supported"); println!(" + IXGBE {} on: {:X} IRQ: {}", name, bar, irq); diff --git a/nvmed/src/main.rs b/nvmed/src/main.rs index 09ced15aff..eda7d701c9 100644 --- a/nvmed/src/main.rs +++ b/nvmed/src/main.rs @@ -205,14 +205,13 @@ fn get_int_method( pcid_handle.enable_feature(PciFeature::Msi).unwrap(); Ok((interrupt_method, interrupt_sources)) - } else if function.legacy_interrupt_pin.is_some() { + } else if let Some(irq) = function.legacy_interrupt_line { // INTx# pin based interrupts. - let irq_handle = File::open(format!("irq:{}", function.legacy_interrupt_line)) + let irq_handle = File::open(format!("irq:{}", irq)) .expect("nvmed: failed to open INTx# interrupt line"); Ok((InterruptMethod::Intx, InterruptSources::Intx(irq_handle))) } else { - // No interrupts at all - todo!("handling of no interrupts") + panic!("nvmed: no interrupts supported at all") } } @@ -223,14 +222,13 @@ fn get_int_method( function: &PciFunction, allocated_bars: &AllocatedBars, ) -> Result<(InterruptMethod, InterruptSources)> { - if function.legacy_interrupt_pin.is_some() { + if let Some(irq) = function.legacy_interrupt_line { // INTx# pin based interrupts. - let irq_handle = File::open(format!("irq:{}", function.legacy_interrupt_line)) + let irq_handle = File::open(format!("irq:{}", irq)) .expect("nvmed: failed to open INTx# interrupt line"); Ok((InterruptMethod::Intx, InterruptSources::Intx(irq_handle))) } else { - // No interrupts at all - todo!("handling of no interrupts") + panic!("nvmed: no interrupts supported at all") } } diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 36c002a15f..faae3229f8 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -57,10 +57,8 @@ pub struct PciFunction { /// Legacy IRQ line: It's the responsibility of pcid to make sure that it be mapped in either /// the I/O APIC or the 8259 PIC, so that the subdriver can map the interrupt vector directly. /// The vector to map is always this field, plus 32. - pub legacy_interrupt_line: u8, - - /// Legacy interrupt pin (INTx#), none if INTx# interrupts aren't supported at all. - pub legacy_interrupt_pin: Option, + /// If INTx# interrupts aren't supported at all this is `None`. + pub legacy_interrupt_line: Option, /// All identifying information of the PCI function. pub full_device_id: FullDeviceId, diff --git a/pcid/src/main.rs b/pcid/src/main.rs index 2858433a43..09ef81d23b 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -280,6 +280,16 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he state.pcie.write(addr, 0x3C, data); }; + let legacy_interrupt_enabled = match interrupt_pin { + 0 => false, + 1 | 2 | 3 | 4 => true, + + other => { + warn!("pcid: invalid interrupt pin: {}", other); + false + } + }; + let capabilities = if endpoint_header.status(&state.pcie).has_capability_list() { let func = PciFunc { pci: &state.pcie, @@ -291,26 +301,10 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he }; debug!("PCI DEVICE CAPABILITIES for {}: {:?}", args.iter().map(|string| string.as_ref()).nth(0).unwrap_or("[unknown]"), capabilities); - use driver_interface::LegacyInterruptPin; - - let legacy_interrupt_pin = match interrupt_pin { - 0 => None, - 1 => Some(LegacyInterruptPin::IntA), - 2 => Some(LegacyInterruptPin::IntB), - 3 => Some(LegacyInterruptPin::IntC), - 4 => Some(LegacyInterruptPin::IntD), - - other => { - warn!("pcid: invalid interrupt pin: {}", other); - None - } - }; - let func = driver_interface::PciFunction { bars, addr, - legacy_interrupt_line: irq, - legacy_interrupt_pin, + legacy_interrupt_line: if legacy_interrupt_enabled { Some(irq) } else { None }, full_device_id: header.full_device_id().clone(), }; diff --git a/rtl8139d/src/main.rs b/rtl8139d/src/main.rs index dc3616a08a..95051c4eb4 100644 --- a/rtl8139d/src/main.rs +++ b/rtl8139d/src/main.rs @@ -108,11 +108,9 @@ impl MsixInfo { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8139d: failed to fetch pci features"); log::info!("PCI FEATURES: {:?}", all_pci_features); @@ -157,7 +155,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { pcid_handle.enable_feature(PciFeature::Msi).expect("rtl8139d: failed to enable MSI"); log::info!("Enabled MSI"); - Some(interrupt_handle) + interrupt_handle } else if msix_enabled { let capability = match pcid_handle.feature_info(PciFeature::MsiX).expect("rtl8139d: failed to retrieve the MSI-X capability structure from pcid") { PciFeatureInfo::Msi(_) => panic!(), @@ -220,34 +218,31 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { table_entry_pointer.msg_data.write(msg_data); table_entry_pointer.vec_ctl.writef(MsixTableEntry::VEC_CTL_MASK_BIT, false); - Some(interrupt_handle) + interrupt_handle }; pcid_handle.enable_feature(PciFeature::MsiX).expect("rtl8139d: failed to enable MSI-X"); log::info!("Enabled MSI-X"); method - } else if pci_config.func.legacy_interrupt_pin.is_some() { + } else if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("rtl8139d: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("rtl8139d: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("rtl8139d: no interrupts supported at all") } } //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - if pci_config.func.legacy_interrupt_pin.is_some() { + if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("rtl8139d: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("rtl8139d: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("rtl8139d: no interrupts supported at all") } } @@ -340,7 +335,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { })); //TODO: MSI-X - let mut irq_file = get_int_method(&mut pcid_handle).expect("rtl8139d: no interrupt file"); + let mut irq_file = get_int_method(&mut pcid_handle); { let device = Arc::new(RefCell::new(unsafe { diff --git a/rtl8168d/src/main.rs b/rtl8168d/src/main.rs index 2592100b2c..c657a716dc 100644 --- a/rtl8168d/src/main.rs +++ b/rtl8168d/src/main.rs @@ -106,11 +106,9 @@ impl MsixInfo { } #[cfg(target_arch = "x86_64")] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8168d: failed to fetch pci features"); log::info!("PCI FEATURES: {:?}", all_pci_features); @@ -155,7 +153,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { pcid_handle.enable_feature(PciFeature::Msi).expect("rtl8168d: failed to enable MSI"); log::info!("Enabled MSI"); - Some(interrupt_handle) + interrupt_handle } else if msix_enabled { let capability = match pcid_handle.feature_info(PciFeature::MsiX).expect("rtl8168d: failed to retrieve the MSI-X capability structure from pcid") { PciFeatureInfo::Msi(_) => panic!(), @@ -218,34 +216,31 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { table_entry_pointer.msg_data.write(msg_data); table_entry_pointer.vec_ctl.writef(MsixTableEntry::VEC_CTL_MASK_BIT, false); - Some(interrupt_handle) + interrupt_handle }; pcid_handle.enable_feature(PciFeature::MsiX).expect("rtl8168d: failed to enable MSI-X"); log::info!("Enabled MSI-X"); method - } else if pci_config.func.legacy_interrupt_pin.is_some() { + } else if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("rtl8168d: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("rtl8168d: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("rtl8168d: no interrupts supported at all") } } //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] -fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option { +fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - if pci_config.func.legacy_interrupt_pin.is_some() { + if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - Some(File::open(format!("irq:{}", irq)).expect("rtl8168d: failed to open legacy IRQ file")) + File::open(format!("irq:{}", irq)).expect("rtl8168d: failed to open legacy IRQ file") } else { - // no interrupts at all - None + panic!("rtl8168d: no interrupts supported at all") } } @@ -338,7 +333,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { })); //TODO: MSI-X - let mut irq_file = get_int_method(&mut pcid_handle).expect("rtl8168d: no interrupt file"); + let mut irq_file = get_int_method(&mut pcid_handle); { let device = Arc::new(RefCell::new(unsafe { diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index 77f43eb10d..be17b4f934 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -198,7 +198,7 @@ fn main() { let (bar1, _) = pci_config.func.bars[1].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; + let irq = pci_config.func.legacy_interrupt_line.expect("vboxd: no legacy interrupts supported"); print!("{}", format!(" + VirtualBox {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1, irq)); diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 9c8dbf542e..7fad420600 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -86,7 +86,6 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); let (bar_ptr, bar_size) = pci_config.func.bars[0].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; let all_pci_features = pcid_handle.fetch_all_features().expect("xhcid: failed to fetch pci features"); log::debug!("XHCI PCI FEATURES: {:?}", all_pci_features); @@ -194,7 +193,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option log::debug!("Enabled MSI-X"); method - } else if pci_config.func.legacy_interrupt_pin.is_some() { + } else if let Some(irq) = pci_config.func.legacy_interrupt_line { log::debug!("Legacy IRQ {}", irq); // legacy INTx# interrupt pins. @@ -209,9 +208,8 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option #[cfg(not(target_arch = "x86_64"))] fn get_int_method(pcid_handle: &mut PcidServerHandle, address: usize) -> (Option, InterruptMethod) { let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); - let irq = pci_config.func.legacy_interrupt_line; - if pci_config.func.legacy_interrupt_pin.is_some() { + if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. (Some(File::open(format!("irq:{}", irq)).expect("xhcid: failed to open legacy IRQ file")), InterruptMethod::Intx) } else { @@ -235,7 +233,6 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { log::debug!("XHCI PCI CONFIG: {:?}", pci_config); let (bar_ptr, bar_size) = pci_config.func.bars[0].expect_mem(); - let irq = pci_config.func.legacy_interrupt_line; let address = unsafe { common::physmap(bar_ptr, bar_size, common::Prot::RW, common::MemoryType::Uncacheable) @@ -246,7 +243,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { print!( "{}", - format!(" + XHCI {} on: {:016X} IRQ: {}\n", name, bar_ptr, irq) + format!(" + XHCI {} on: {:016X}\n", name, bar_ptr) ); let scheme_name = format!("usb.{}", name);