commit 9b195c65bde947d415ef0528444ade3ff48e58ae
parent 447795997b7242010674ba241fb3078dba898c03
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 5 May 2024 13:57:45 +0900
read MSI-X Table.
need to modify the print function
Diffstat:
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/sys/include/pci.h b/sys/include/pci.h
@@ -82,10 +82,14 @@ typedef struct MSIXCap {
uint32 pba_offset;
} MSIXCap;
-typedef struct MSIXTab {
-} MSIXTab;
-typedef struct MSIXPBA {
-} MSIXPBA;
+typedef struct MSIXTabEntry {
+ uint32 MsgAddr;
+ uint32 MsgUpperAddr;
+ uint32 MsgData;
+ uint32 VectorControl;
+} *MSIXTab;
+
+typedef uint64 MSIXPBA[];
extern PCIDev pci_dev[MaxPCIDev];
extern int num_pci_dev;
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -127,18 +127,35 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
xhc.runtime->IR[0].IMOD = 4000;
xhc.runtime->IR[0].IMAN |= 3; // IMAN.IP & IMAN.IE
xhc.op->USBCMD |= 1 << 2; // USBCMD.INTE
- // set MSI
+ // setup interrupt
cons_printf(&con0, "local apic id: %x\n", *(uint32 *) (0xfee00020) >> 24);
uintptr pci_config_base = (uintptr) pci_xhc;
PCICap *cap = (PCICap *) (pci_config_base + pci_xhc->capabilities_pointer);
for (;; cap = (PCICap *) (pci_config_base + cap->next_pointer)) {
switch (cap->capability_id) {
case 0x5:
- cons_printf(&con0, "MSI: %x\n", ((MSICap *)cap)->message_control);
+ cons_printf(&con0, "MSI\n");
break;
case 0x11:
- cons_printf(&con0, "MSI-X: %x\n", ((MSIXCap *)cap)->message_control);
+ MSIXCap *msix_cap = (MSIXCap *)cap;
+ cons_printf(&con0, "MSI-X\n");
+ // enable msi-x
+ msix_cap->message_control |= 1 << 15;
+ cons_printf(&con0, "message control: %x\n", msix_cap->message_control);
+ MSIXTab msixtab = (MSIXTab)(xhc.base + (msix_cap->table_offset&~0x3));
+ // TODO: select which BAR to use by the lower bits of table_offset.
+ cons_printf(&con0, "capability_id: %x\n", msix_cap->capability_id);
+ cons_printf(&con0, "next_pointer: %x\n", msix_cap->next_pointer);
+ cons_printf(&con0, "table_offset: %x\n", msix_cap->table_offset);
+ cons_printf(&con0, "pba_offset: %x\n", msix_cap->pba_offset);
+ for (int i = 0; i < (msix_cap->message_control&0xf) + 1; i++) {
+ cons_printf(&con0, "msixtab[%d]:\n\tmsgaddr:\t%x\n\tvectorcontrol:\t%x\n",
+ i, msixtab[i], msixtab[i].VectorControl);
+ }
+ cons_printf(&con0, "msgaddr:\t%x\nmsgupperaddr:\t%x\nmsgdata:\t%x\nvectorcontrol:\t%x\n",
+ msixtab[0].MsgAddr, msixtab[0].MsgUpperAddr,
+ msixtab[0].MsgData, msixtab[0].VectorControl);
break;
default:
cons_printf(&con0, "unsupported capability: 0x%x\n",