Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86_64 virtio:get irqnum support for x86_64 virtio dev #97

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

lklake
Copy link

@lklake lklake commented Jul 6, 2023

This PR

  • obtain the routing info from PCIe device pin to IOAPIC irq pin using ACPI table.
  • route IOAPIC irq to interrupt vector by programming IOAPIC.

Since the virtio framework in the main branch does not currently support interrupts, this PR provides the get_pci_irq_vector function for fetching x86_64 device interrupt numbers.

@equation314 equation314 self-requested a review July 8, 2023 09:18
modules/axhal/src/arch/x86_64/trap.rs Outdated Show resolved Hide resolved
modules/axhal/src/lib.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/apic.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/apic.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/mod.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
modules/axhal/src/platform/pc_x86/acpi.rs Outdated Show resolved Hide resolved
pub unsafe fn new() -> Self {
Acpi {
rsdp: AcpiTables::search_for_rsdp_bios(LocalAcpiHandler).unwrap(),
aml_context: AmlContext::new(Box::new(LocalAmlHandler), DebugVerbosity::None),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we eliminate the dependency of the crate aml to avoid alloc in axhal?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we can't for now. Because both acpi and aml crate rely on alloc. Crate acpi is used to parse ACPI table and Crate aml is used to invoke ACPI method. Both are need to finish the job of getting irq routing from PCI device pin to APIC pin.

Although the developers of acpi and aml crate offer another crate rsdp for environment without heap alloctors, it only finds and parses RSDP and cannot parse the data and methods in ACPI table.

Crate aml is hard to eliminate since we need to invoke ACPI method _PRT to get irq routing from PCI device pin to APIC pin.


However, if we accept a legacy way, we may get irq number of PCI device without ACPI completely.

It seems that PCI device irq pin connects to two APIC pins in many motherboards (e.g. in current arceos qemu environment, virtio-net PCI device pinA is connected to APIC pin both 11 and 22) , one (e.g. 11) is for compatibility with PIC, and can be readed from PCI configuration space under IRQ Line field.

Since arceos disables PIC and uses APIC only, I think it is better to use the pin specialized for APIC (which needs to get from ACPI) and neglect the pin for PIC.

By the way, using the PIC one(e.g. 11) has another (small) programming problem.
Current virtio_drivers crate on github, which is responsible for parsing virtio PCI configuration space, doesn't have a method to read IRQ Line field. We may need to add this method if we choose the legacy solution.

Any suggestions are welcome and appreciated.😁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop the legacy IRQ support and use MSI instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can. It seems to be a much better solution. I will try it later.

Can we drop the legacy IRQ support and use MSI instead?

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.

None yet

2 participants