From a7677f1d9bb2cf1265006dbd8382057dffef0050 Mon Sep 17 00:00:00 2001 From: Liav A Date: Thu, 10 Feb 2022 20:35:30 +0200 Subject: Kernel/PCI: Expose PCI option ROM data from the sysfs interface For each exposed PCI device in sysfs, there's a new node called "rom" and by reading it, it exposes the raw data of a PCI option ROM blob to a user for examining the blob. --- Kernel/Bus/PCI/API.cpp | 13 +++++++++++++ Kernel/Bus/PCI/API.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'Kernel/Bus') diff --git a/Kernel/Bus/PCI/API.cpp b/Kernel/Bus/PCI/API.cpp index 5ea9b5245a..ff4602acd4 100644 --- a/Kernel/Bus/PCI/API.cpp +++ b/Kernel/Bus/PCI/API.cpp @@ -232,6 +232,19 @@ size_t get_BAR_space_size(DeviceIdentifier const& identifier, HeaderType0BaseReg return space_size; } +size_t get_expansion_rom_space_size(DeviceIdentifier const& identifier) +{ + SpinlockLocker locker(identifier.operation_lock()); + u8 field = to_underlying(PCI::RegisterOffset::EXPANSION_ROM_POINTER); + u32 bar_reserved = read32_offsetted(identifier, field); + write32_offsetted(identifier, field, 0xFFFFFFFF); + u32 space_size = read32_offsetted(identifier, field); + write32_offsetted(identifier, field, bar_reserved); + space_size &= 0xfffffff0; + space_size = (~space_size) + 1; + return space_size; +} + void raw_access(DeviceIdentifier const& identifier, u32 field, size_t access_size, u32 value) { SpinlockLocker locker(identifier.operation_lock()); diff --git a/Kernel/Bus/PCI/API.h b/Kernel/Bus/PCI/API.h index 1b7c641c2e..5f9a62ade3 100644 --- a/Kernel/Bus/PCI/API.h +++ b/Kernel/Bus/PCI/API.h @@ -35,6 +35,8 @@ u32 get_BAR5(DeviceIdentifier const&); u32 get_BAR(DeviceIdentifier const&, HeaderType0BaseRegister); size_t get_BAR_space_size(DeviceIdentifier const&, HeaderType0BaseRegister); BARSpaceType get_BAR_space_type(u32 pci_bar_value); +size_t get_expansion_rom_space_size(DeviceIdentifier const&); + void enable_bus_mastering(DeviceIdentifier const&); void disable_bus_mastering(DeviceIdentifier const&); void enable_io_space(DeviceIdentifier const&); -- cgit v1.2.3