From 9b809312c20f74f4fb52d184de602cabed1ac718 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:56:29 +0100 Subject: [PATCH] Ignore MSI-X PBA in all drivers It isn't used in any driver and even on Linux no driver seems to use it at all. The only times it seems to be useful are if you were to mask an interrupt and want to check if the interrupt fired without unmasking or if you want to make the device itself trigger an interrupt. --- nvmed/src/main.rs | 10 ---------- nvmed/src/nvme/mod.rs | 1 - rtl8139d/src/main.rs | 16 ---------------- rtl8168d/src/main.rs | 16 ---------------- virtio-core/src/arch/x86_64.rs | 1 - xhcid/src/main.rs | 3 --- xhcid/src/xhci/mod.rs | 13 ------------- 7 files changed, 60 deletions(-) diff --git a/nvmed/src/main.rs b/nvmed/src/main.rs index 92f5c14729..e38060bc1b 100644 --- a/nvmed/src/main.rs +++ b/nvmed/src/main.rs @@ -109,22 +109,13 @@ fn get_int_method( } let table_bar_base: *mut u8 = bar_base(allocated_bars, function, capability_struct.table_bir())?.as_ptr(); - let pba_bar_base: *mut u8 = - bar_base(allocated_bars, function, capability_struct.pba_bir())?.as_ptr(); let table_base = unsafe { table_bar_base.offset(capability_struct.table_offset() as isize) }; - let pba_base = unsafe { pba_bar_base.offset(capability_struct.pba_offset() as isize) }; let vector_count = capability_struct.table_size(); let table_entries: &'static mut [MsixTableEntry] = unsafe { slice::from_raw_parts_mut(table_base as *mut MsixTableEntry, vector_count as usize) }; - let pba_entries: &'static mut [Mmio] = unsafe { - slice::from_raw_parts_mut( - table_base as *mut Mmio, - (vector_count as usize + 63) / 64, - ) - }; // Mask all interrupts in case some earlier driver/os already unmasked them (according to // the PCI Local Bus spec 3.0, they are masked after system reset). @@ -162,7 +153,6 @@ fn get_int_method( let interrupt_method = InterruptMethod::MsiX(MsixCfg { cap: capability_struct, table: table_entries, - pba: pba_entries, }); let interrupt_sources = InterruptSources::MsiX(std::iter::once((msix_vector_number, irq_handle)).collect()); diff --git a/nvmed/src/nvme/mod.rs b/nvmed/src/nvme/mod.rs index 1b368c521d..6378fa2fce 100644 --- a/nvmed/src/nvme/mod.rs +++ b/nvmed/src/nvme/mod.rs @@ -122,7 +122,6 @@ impl InterruptMethod { pub struct MsixCfg { pub cap: MsixCapability, pub table: &'static mut [MsixTableEntry], - pub pba: &'static mut [Mmio], } #[repr(packed)] diff --git a/rtl8139d/src/main.rs b/rtl8139d/src/main.rs index b019c2c2ce..a8400063be 100644 --- a/rtl8139d/src/main.rs +++ b/rtl8139d/src/main.rs @@ -81,7 +81,6 @@ where pub struct MsixInfo { pub virt_table_base: NonNull, - pub virt_pba_base: NonNull, pub capability: MsixCapability, } @@ -93,18 +92,6 @@ impl MsixInfo { assert!(k < self.capability.table_size() as usize); unsafe { self.table_entry_pointer_unchecked(k) } } - pub unsafe fn pba_pointer_unchecked(&mut self, k: usize) -> &mut u64 { - &mut *self.virt_pba_base.as_ptr().offset(k as isize) - } - pub fn pba_pointer(&mut self, k: usize) -> &mut u64 { - assert!(k < self.capability.table_size() as usize); - unsafe { self.pba_pointer_unchecked(k) } - } - pub fn pba(&mut self, k: usize) -> bool { - let byte = k / 64; - let bit = k % 64; - *self.pba_pointer(byte) & (1 << bit) != 0 - } } #[cfg(target_arch = "x86_64")] @@ -163,16 +150,13 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { }; capability.validate(pci_config.func.bars); - assert_eq!(capability.table_bir(), capability.pba_bir()); let bar = &pci_config.func.bars[capability.table_bir() as usize]; let bar_address = unsafe { bar.physmap_mem("rtl8139d") } as usize; let virt_table_base = (bar_address + capability.table_offset() as usize) as *mut MsixTableEntry; - let virt_pba_base = (bar_address + capability.pba_offset() as usize) as *mut u64; let mut info = MsixInfo { virt_table_base: NonNull::new(virt_table_base).unwrap(), - virt_pba_base: NonNull::new(virt_pba_base).unwrap(), capability, }; diff --git a/rtl8168d/src/main.rs b/rtl8168d/src/main.rs index b099a389e1..334554d12e 100644 --- a/rtl8168d/src/main.rs +++ b/rtl8168d/src/main.rs @@ -79,7 +79,6 @@ where pub struct MsixInfo { pub virt_table_base: NonNull, - pub virt_pba_base: NonNull, pub capability: MsixCapability, } @@ -91,18 +90,6 @@ impl MsixInfo { assert!(k < self.capability.table_size() as usize); unsafe { self.table_entry_pointer_unchecked(k) } } - pub unsafe fn pba_pointer_unchecked(&mut self, k: usize) -> &mut u64 { - &mut *self.virt_pba_base.as_ptr().offset(k as isize) - } - pub fn pba_pointer(&mut self, k: usize) -> &mut u64 { - assert!(k < self.capability.table_size() as usize); - unsafe { self.pba_pointer_unchecked(k) } - } - pub fn pba(&mut self, k: usize) -> bool { - let byte = k / 64; - let bit = k % 64; - *self.pba_pointer(byte) & (1 << bit) != 0 - } } #[cfg(target_arch = "x86_64")] @@ -161,16 +148,13 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File { }; capability.validate(pci_config.func.bars); - assert_eq!(capability.table_bir(), capability.pba_bir()); let bar = &pci_config.func.bars[capability.table_bir() as usize]; let bar_address = unsafe { bar.physmap_mem("rtl8168d") } as usize; let virt_table_base = (bar_address + capability.table_offset() as usize) as *mut MsixTableEntry; - let virt_pba_base = (bar_address + capability.pba_offset() as usize) as *mut u64; let mut info = MsixInfo { virt_table_base: NonNull::new(virt_table_base).unwrap(), - virt_pba_base: NonNull::new(virt_pba_base).unwrap(), capability, }; diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index 3ef5d171a3..3965e08c39 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -20,7 +20,6 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { }; capability.validate(pci_config.func.bars); - assert_eq!(capability.table_bir(), capability.pba_bir()); let bar = &pci_config.func.bars[capability.table_bir() as usize]; let bar_address = unsafe { bar.physmap_mem("virtio-core") } as usize; let virt_table_base = (bar_address + capability.table_offset() as usize) as *mut MsixTableEntry; diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 59290f4256..2315c2a1dc 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -138,13 +138,10 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle, bar0_address: usize) -> (O capability.validate(pci_config.func.bars); assert_eq!(capability.table_bir(), 0); - assert_eq!(capability.pba_bir(), 0); let virt_table_base = (bar0_address + capability.table_offset() as usize) as *mut MsixTableEntry; - let virt_pba_base = (bar0_address + capability.pba_offset() as usize) as *mut u64; let mut info = xhci::MsixInfo { virt_table_base: NonNull::new(virt_table_base).unwrap(), - virt_pba_base: NonNull::new(virt_pba_base).unwrap(), capability, }; diff --git a/xhcid/src/xhci/mod.rs b/xhcid/src/xhci/mod.rs index aaf8b453c1..32d9d1eb82 100644 --- a/xhcid/src/xhci/mod.rs +++ b/xhcid/src/xhci/mod.rs @@ -70,7 +70,6 @@ pub enum InterruptMethod { pub struct MsixInfo { pub virt_table_base: NonNull, - pub virt_pba_base: NonNull, pub capability: MsixCapability, } impl MsixInfo { @@ -81,18 +80,6 @@ impl MsixInfo { assert!(k < self.capability.table_size() as usize); unsafe { self.table_entry_pointer_unchecked(k) } } - pub unsafe fn pba_pointer_unchecked(&mut self, k: usize) -> &mut u64 { - &mut *self.virt_pba_base.as_ptr().offset(k as isize) - } - pub fn pba_pointer(&mut self, k: usize) -> &mut u64 { - assert!(k < self.capability.table_size() as usize); - unsafe { self.pba_pointer_unchecked(k) } - } - pub fn pba(&mut self, k: usize) -> bool { - let byte = k / 64; - let bit = k % 64; - *self.pba_pointer(byte) & (1 << bit) != 0 - } } impl Xhci {