1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

Kernel: Add APIs to PCI Device to use MSI(x)

Add reserve_irqs, allocate_irq, enable_interrupt and disable_interrupt
API to a PCI device.

reserve_irqs() can be used by a device driver that would like to
reserve irqs for MSI(x) interrupts. The API returns the type of IRQ
that was reserved by the PCI device. If the PCI device does not support
MSI(x), then it is a noop.

allocate_irq() API can be used to allocate an IRQ at an index. For
MSIx the driver needs to map the vector table into the memory and add
the corresponding IRQ at the given index. This API will return the
actual IRQ that was used so that the driver can use it create interrupt
handler for that IRQ.

{enable, disable}_interrupt API is used to enable or disable a
particular IRQ at the given index. It is a noop for pin-based
interrupts. This could be used by IRQHandler to enable or disable an
interrupt.
This commit is contained in:
Pankaj Raghav 2023-05-05 14:38:46 +02:00 committed by Jelle Raaijmakers
parent f0b6eb6932
commit 82cf0bfb75
2 changed files with 137 additions and 0 deletions

View file

@ -14,6 +14,25 @@
namespace Kernel::PCI {
enum class InterruptType {
PIN,
MSI,
MSIX
};
struct InterruptRange {
u8 m_start_irq { 0 };
u8 m_irq_count { 0 };
InterruptType m_type { InterruptType::PIN };
};
struct [[gnu::packed]] MSIxTableEntry {
u32 address_low;
u32 address_high;
u32 data;
u32 vector_control;
};
class Device {
public:
DeviceIdentifier const& device_identifier() const { return *m_pci_identifier; };
@ -33,12 +52,21 @@ public:
void enable_extended_message_signalled_interrupts();
void disable_extended_message_signalled_interrupts();
ErrorOr<InterruptType> reserve_irqs(u8 number_of_irqs, bool msi);
ErrorOr<u8> allocate_irq(u8 index);
PCI::InterruptType get_interrupt_type();
void enable_interrupt(u8 irq);
void disable_interrupt(u8 irq);
protected:
explicit Device(DeviceIdentifier const& pci_identifier);
private:
PhysicalAddress msix_table_entry_address(u8 irq);
private:
NonnullRefPtr<DeviceIdentifier> const m_pci_identifier;
InterruptRange m_interrupt_range;
};
template<typename... Parameters>