Skip to content

Fix: fix PCI MSI-X support#6

Merged
differrari merged 2 commits intodifferrari:mainfrom
Totto16:msix_support
Jun 12, 2025
Merged

Fix: fix PCI MSI-X support#6
differrari merged 2 commits intodifferrari:mainfrom
Totto16:msix_support

Conversation

@Totto16
Copy link
Copy Markdown
Contributor

@Totto16 Totto16 commented Jun 12, 2025

Hi me again, I noticed, that my local qemu doesn't support the device options msi=on,msix=off for the qemu-xhci device.

So I removed them, but then my keyboard didn't work. So there was this issue in your existing code:

You didn't check the return code of pci_setup_msi, if that returns false, no interrupts are enabled and the keyboard doesn't work.

So I added a function, that tries to initialize MSI and if that fails it tries to use MSI-X. While doing that I found some more bugs introduced by this behavior. If you don't call pci_setup_bar before calling pci_setup_msix the table pointer for the MSIX interrupts is null, which didn't throw an error before, but it is an error, as this should point to valid memory. So I fixed the order, and also added the assertion for the table to never be null.

I also improved a few things in the pci code, that I found. So I replaced hard coded values with named constants (e.g. #define PCI_CAPABILITY_MSI 0x05 )

I also added the capability of multiple interrupts to the MSI-X function, as msix support that.

I also added a small detection of the qemu device features, you can get them with qemu-system-aarch64 -device qemu-xhci,help so that if your qemu (as it may differ from distro to distro or if you compiled it yourself) options are supported.

It is a little more than just fixing the bug and making msix work but i debugged it for quite some time, as the issue was not that easy to find, so I added some more checks and improvements and I just didn't wanted to remove them just now.

So if you don't want to accept this exact code just let me know 😄

At least now the keyboard works with my qemu on my machine 😄

Totto16 added 2 commits June 12, 2025 14:34
- check return value of pci_setup_msi, if it fails try to use msix
- intilizate pci_setup_bar before using msix, as msix uses the bars memory address
- add support for multiple interrupts in the pci_setup_msix function, as msix supports that
@Totto16 Totto16 changed the title Msix support Fix: fix MSI-X support Jun 12, 2025
@Totto16 Totto16 changed the title Fix: fix MSI-X support Fix: fix PCI MSI-X support Jun 12, 2025
@differrari
Copy link
Copy Markdown
Owner

This is great, I noticed this but haven't gotten around to fixing it. Have you tried it on linux? Seems to keep detecting port change interrupts with MSIX

@Totto16
Copy link
Copy Markdown
Contributor Author

Totto16 commented Jun 12, 2025

This is great, I noticed this but haven't gotten around to fixing it. Have you tried it on linux? Seems to keep detecting port change interrupts with MSIX

I tried it on linux and it worked.

I newer saw a port change (at least I think i never saw one), this was my log in case it helps:

./run
Running emulator
UART output enabled
Exception vectors setup at 0x4109C000
Exception vectors set
Initializing kernel...
Device has 0x20000000 memory starting at 0x40000000. 0x1CA00000 for user starting at 0x43600000
Preparing for draw
[GIC] GIC enabled

Interrupts initialized
[PCI] Found device at bus 0, slot 2, func 0
GPU initialized. Issuing commands
Returned display size 1280x800
GPU ready
Selected and initialized GPU 0x436000200x500
GPU initialized
[PCI] Found device at bus 0, slot 4, func 0
[MMU warning]: Section already mapped 0x10014000
[xHCI] Interrupts setup with MSI-X
[xHCI] endpoint 3 info. Direction 1 type 3
[xHCI] Storing configuration for endpoint 3 -> 3 (0x43605D00)
[xHCI] Returned from configuration for endpoint 3 -> 3 (0x43605D00)
Initializing disk...
[PCI] Found device at bus 0, slot 3, func 0
[MMU warning]: Section already mapped 0x10018000
Finished MMU init
EXFAT Volume uses 512 cluster size
Cluster at 0x87E (0x1000 * 0x3E00 of size 0x8 each)
FAT: 0x100000 (0xFC00)
[0] = 0xFFFFFFF8
[1] = 0xFFFFFFFF
[2] = 0xFFFFFFFF
[3] = 0x4
[4] = 0xFFFFFFFF
[5] = 0xFFFFFFFF
MMU Mapped
Kernel initialization finished
Starting processes

@differrari
Copy link
Copy Markdown
Owner

I'll look into it if the issue persists

@differrari differrari merged commit fdc7d6f into differrari:main Jun 12, 2025
1 check passed
@Totto16 Totto16 deleted the msix_support branch June 12, 2025 17:13
differrari pushed a commit that referenced this pull request Aug 9, 2025
Fix: fix PCI MSI-X support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants