Make legacy_interrupt_line an Option

Drivers don't need to know the exact legacy_interrupt_pin in use.
Just if legacy interrupts are enabled and if so which
legacy_interrupt_line is used.
This commit is contained in:
bjorn3
2024-01-22 19:07:57 +01:00
parent e972047567
commit bd6716efe4
12 changed files with 59 additions and 87 deletions
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
+10 -15
View File
@@ -74,11 +74,9 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
}
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option<File> {
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<File> {
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<File> {
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)
+1 -1
View File
@@ -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);
+6 -8
View File
@@ -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")
}
}
+2 -4
View File
@@ -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<LegacyInterruptPin>,
/// If INTx# interrupts aren't supported at all this is `None`.
pub legacy_interrupt_line: Option<u8>,
/// All identifying information of the PCI function.
pub full_device_id: FullDeviceId,
+11 -17
View File
@@ -280,6 +280,16 @@ fn handle_parsed_header(state: Arc<State>, 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<State>, 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(),
};
+11 -16
View File
@@ -108,11 +108,9 @@ impl MsixInfo {
}
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option<File> {
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<File> {
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<File> {
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<File> {
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 {
+11 -16
View File
@@ -106,11 +106,9 @@ impl MsixInfo {
}
#[cfg(target_arch = "x86_64")]
fn get_int_method(pcid_handle: &mut PcidServerHandle) -> Option<File> {
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<File> {
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<File> {
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<File> {
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 {
+1 -1
View File
@@ -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));
+3 -6
View File
@@ -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<File>, 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);