From 35a844ac75f97f9a29934b31c119eb82a5d8baf2 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Mon, 8 May 2023 21:28:28 +0200 Subject: [PATCH] Kernel: Implement {enable,disable}_msi interrupts in PCI Device Implement enabling and disabling MSI interrupts for a PCI device. Removes two more TODO()s from PCI::Device.cpp :^) --- Kernel/Bus/PCI/Definitions.h | 1 + Kernel/Bus/PCI/Device.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Kernel/Bus/PCI/Definitions.h b/Kernel/Bus/PCI/Definitions.h index ebdee86ed9b..e8e3268b698 100644 --- a/Kernel/Bus/PCI/Definitions.h +++ b/Kernel/Bus/PCI/Definitions.h @@ -80,6 +80,7 @@ static constexpr u16 none_value = 0xffff; static constexpr size_t memory_range_per_bus = mmio_device_space_size * to_underlying(Limits::MaxFunctionsPerDevice) * to_underlying(Limits::MaxDevicesPerBus); static constexpr u32 bar_address_mask = 0xfffffff0; static constexpr u8 msi_control_offset = 2; +static constexpr u16 msi_control_enable = 0x0001; static constexpr u16 msi_address_format_mask = 0x80; static constexpr u8 msi_mmc_format_mask = 0xe; static constexpr u16 msix_control_table_mask = 0x07ff; diff --git a/Kernel/Bus/PCI/Device.cpp b/Kernel/Bus/PCI/Device.cpp index 7fe2503eb86..8bfb17d2ae7 100644 --- a/Kernel/Bus/PCI/Device.cpp +++ b/Kernel/Bus/PCI/Device.cpp @@ -41,11 +41,17 @@ void Device::disable_pin_based_interrupts() const void Device::enable_message_signalled_interrupts() { - TODO(); + for (auto& capability : m_pci_identifier->capabilities()) { + if (capability.id().value() == PCI::Capabilities::ID::MSI) + capability.write16(msi_control_offset, capability.read16(msi_control_offset) | msi_control_enable); + } } void Device::disable_message_signalled_interrupts() { - TODO(); + for (auto& capability : m_pci_identifier->capabilities()) { + if (capability.id().value() == PCI::Capabilities::ID::MSI) + capability.write16(msi_control_offset, capability.read16(msi_control_offset) & ~(msi_control_enable)); + } } void Device::enable_extended_message_signalled_interrupts()