diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-27 16:10:38 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-27 16:10:38 +0200 |
| commit | dca8353027526b9e522ad8be169d9763e447b08b (patch) | |
| tree | 45614de8059a2a67a853c8407dbbd6073f902e40 /kapi | |
| parent | 1cad7524b291fd7a6f77e01bb90e763e6b557620 (diff) | |
| download | kernel-dca8353027526b9e522ad8be169d9763e447b08b.tar.xz kernel-dca8353027526b9e522ad8be169d9763e447b08b.zip | |
kapi: fix device resource lookup
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/devices/resource.hpp | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/kapi/kapi/devices/resource.hpp b/kapi/kapi/devices/resource.hpp index 5c01aba5..1b491225 100644 --- a/kapi/kapi/devices/resource.hpp +++ b/kapi/kapi/devices/resource.hpp @@ -102,8 +102,54 @@ namespace kapi::devices , m_value{.channel = channel} {} - //! The exact type of this resource. - resource_type type{resource_type::invalid}; + constexpr auto friend operator==(resource const & lhs, resource const & rhs) noexcept -> bool + { + if (lhs.type != rhs.type) + { + return false; + } + + switch (lhs.type) + { + case resource_type::invalid: + return true; + case resource_type::mmio: + return lhs.m_value.range == rhs.m_value.range; + case resource_type::port: + return lhs.m_value.port == rhs.m_value.port; + case resource_type::irq: + return lhs.m_value.irq == rhs.m_value.irq; + case resource_type::dma: + return lhs.m_value.channel == rhs.m_value.channel; + }; + + return false; + } + + constexpr auto friend operator==(resource const & lhs, invalid_resource const &) noexcept -> bool + { + return lhs.type == resource_type::invalid; + } + + constexpr auto friend operator==(resource const & lhs, mmio_range const & rhs) noexcept -> bool + { + return lhs.type == resource_type::mmio && lhs.m_value.range == rhs; + } + + constexpr auto friend operator==(resource const & lhs, io_port const & rhs) noexcept -> bool + { + return lhs.type == resource_type::port && lhs.m_value.port == rhs; + } + + constexpr auto friend operator==(resource const & lhs, interrupt_line const & rhs) noexcept -> bool + { + return lhs.type == resource_type::irq && lhs.m_value.irq == rhs; + } + + constexpr auto friend operator==(resource const & lhs, dma_channel const & rhs) noexcept -> bool + { + return lhs.type == resource_type::dma && lhs.m_value.channel == rhs; + } //! Get the resource value. template<resource_type Type> @@ -136,6 +182,9 @@ namespace kapi::devices return m_value; } + //! The exact type of this resource. + resource_type type{resource_type::invalid}; + private: union { |
