From dca8353027526b9e522ad8be169d9763e447b08b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 27 Jul 2026 16:10:38 +0200 Subject: kapi: fix device resource lookup --- kapi/kapi/devices/resource.hpp | 53 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'kapi') 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 @@ -136,6 +182,9 @@ namespace kapi::devices return m_value; } + //! The exact type of this resource. + resource_type type{resource_type::invalid}; + private: union { -- cgit v1.2.3