1- use alloc:: { borrow:: Cow , boxed:: Box } ;
1+ use alloc:: { borrow:: Cow , boxed:: Box , format , string :: String } ;
22use awkernel_lib:: interrupt:: IRQ ;
33
44use 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
3030impl 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