Skip to content

Commit f92a9a3

Browse files
authored
feat(msix): dump MSI-X capability (#624)
* feat(msix): dump MSI-X capability Signed-off-by: Yuuki Takano <ytakanoster@gmail.com> * add `get_msix()` method Signed-off-by: Yuuki Takano <ytakanoster@gmail.com> --------- Signed-off-by: Yuuki Takano <ytakanoster@gmail.com>
1 parent f927461 commit f92a9a3

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

awkernel_drivers/src/pcie.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ impl PCIeInfo {
862862
self.msi.as_mut()
863863
}
864864

865+
pub fn get_msix(&mut self) -> Option<&capability::msix::Msix> {
866+
self.msix.as_ref()
867+
}
868+
865869
pub fn get_msix_mut(&mut self) -> Option<&mut capability::msix::Msix> {
866870
self.msix.as_mut()
867871
}

awkernel_drivers/src/pcie/capability/msix.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloc::{borrow::Cow, boxed::Box};
1+
use alloc::{borrow::Cow, boxed::Box, format, string::String};
22
use awkernel_lib::interrupt::IRQ;
33

44
use crate::pcie::{BaseAddress, ConfigSpace, PCIeDeviceErr, PCIeInfo};
@@ -23,8 +23,8 @@ pub struct Msix {
2323
table_offset: u32, // Table offset
2424
table_bar: BaseAddress,
2525

26-
_pba_offset: u32, // Pending Bit
27-
_pba_bar: BaseAddress,
26+
pba_offset: u32, // Pending Bit
27+
pba_bar: BaseAddress,
2828
}
2929

3030
impl Msix {
@@ -53,11 +53,40 @@ impl Msix {
5353
table_size,
5454
table_offset,
5555
table_bar,
56-
_pba_offset: pba_offset,
57-
_pba_bar: pba_bar,
56+
pba_offset,
57+
pba_bar,
5858
})
5959
}
6060

61+
pub fn dump(&self, info: &PCIeInfo) -> String {
62+
let header = info.config_space.read_u32(self.cap_ptr);
63+
let table_offset = info.config_space.read_u32(self.cap_ptr + 4);
64+
let pending_bit_array_offset = info.config_space.read_u32(self.cap_ptr + 8);
65+
let mut msg = format!("MSI-X Capability:\r\n header: {header:#08x}\r\n table offset: {table_offset:#08x}\r\n pending bit array offset: {pending_bit_array_offset:#08x}\r\n");
66+
67+
msg = format!("{msg}MSI-X Table:\r\n");
68+
for i in 0..=self.table_size {
69+
let offset = 16 * i as usize + self.table_offset as usize;
70+
let addr = self.table_bar.read32(offset).unwrap_or(0);
71+
let addr_upper = self.table_bar.read32(offset + 4).unwrap_or(0);
72+
let data = self.table_bar.read32(offset + 8).unwrap_or(0);
73+
let vector_control = self.table_bar.read32(offset + 12).unwrap_or(0);
74+
msg = format!("{msg} [{i}] addr: {addr:#08x}, addr_upper: {addr_upper:#08x}, data: {data:#08x}, vector_control: {vector_control:#08x}\r\n");
75+
}
76+
77+
msg = format!("{msg}MSI-X Pending Bit Array:\r\n");
78+
for i in 0..=(self.table_size / 64) {
79+
let offset = 8 * i as usize + self.pba_offset as usize;
80+
81+
let upper32 = self.pba_bar.read32(offset).unwrap_or(0);
82+
let lower32 = self.pba_bar.read32(offset + 4).unwrap_or(0);
83+
let pba = ((upper32 as u64) << 32) | (lower32 as u64);
84+
msg = format!("{msg} [{i}] {pba:#016x}\r\n");
85+
}
86+
87+
msg
88+
}
89+
6190
pub fn disable(&mut self) {
6291
let reg = self
6392
.config_space

0 commit comments

Comments
 (0)