1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:47:34 +00:00

Interrupts: Use Optional container in IOAPIC

We return the Optional container in find_redirection_entry_by_vector()
method instead of a raw integer. This makes the code more readable and
correct.
This commit is contained in:
Liav A 2020-03-21 09:45:39 +02:00 committed by Andreas Kling
parent 0b7fc525e1
commit 8d9b6c57b5
2 changed files with 14 additions and 13 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/Optional.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <Kernel/ACPI/MultiProcessorParser.h> #include <Kernel/ACPI/MultiProcessorParser.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
@ -251,14 +252,14 @@ u8 IOAPIC::read_redirection_entry_vector(u8 index) const
return (read_register((index << 1) + IOAPIC_REDIRECTION_ENTRY_OFFSET) & 0xFF); return (read_register((index << 1) + IOAPIC_REDIRECTION_ENTRY_OFFSET) & 0xFF);
} }
int IOAPIC::find_redirection_entry_by_vector(u8 vector) const Optional<int> IOAPIC::find_redirection_entry_by_vector(u8 vector) const
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
for (size_t index = 0; index < m_redirection_entries_count; index++) { for (size_t index = 0; index < m_redirection_entries_count; index++) {
if (read_redirection_entry_vector(index) == (InterruptManagement::acquire_mapped_interrupt_number(vector) + IRQ_VECTOR_BASE)) if (read_redirection_entry_vector(index) == (InterruptManagement::acquire_mapped_interrupt_number(vector) + IRQ_VECTOR_BASE))
return index; return index;
} }
return -1; return {};
} }
void IOAPIC::disable(const GenericInterruptHandler& handler) void IOAPIC::disable(const GenericInterruptHandler& handler)
@ -267,13 +268,13 @@ void IOAPIC::disable(const GenericInterruptHandler& handler)
ASSERT(!is_hard_disabled()); ASSERT(!is_hard_disabled());
u8 interrupt_vector = handler.interrupt_number(); u8 interrupt_vector = handler.interrupt_number();
ASSERT(interrupt_vector >= gsi_base() && interrupt_vector < interrupt_vectors_count()); ASSERT(interrupt_vector >= gsi_base() && interrupt_vector < interrupt_vectors_count());
int index = find_redirection_entry_by_vector(interrupt_vector); auto found_index = find_redirection_entry_by_vector(interrupt_vector);
if (index == (-1)) { if (!found_index.has_value()) {
map_interrupt_redirection(interrupt_vector); map_interrupt_redirection(interrupt_vector);
index = find_redirection_entry_by_vector(interrupt_vector); found_index = find_redirection_entry_by_vector(interrupt_vector);
} }
ASSERT(index != (-1)); ASSERT(found_index.has_value());
mask_redirection_entry(index); mask_redirection_entry(found_index.value());
} }
void IOAPIC::enable(const GenericInterruptHandler& handler) void IOAPIC::enable(const GenericInterruptHandler& handler)
@ -282,13 +283,13 @@ void IOAPIC::enable(const GenericInterruptHandler& handler)
ASSERT(!is_hard_disabled()); ASSERT(!is_hard_disabled());
u8 interrupt_vector = handler.interrupt_number(); u8 interrupt_vector = handler.interrupt_number();
ASSERT(interrupt_vector >= gsi_base() && interrupt_vector < interrupt_vectors_count()); ASSERT(interrupt_vector >= gsi_base() && interrupt_vector < interrupt_vectors_count());
int index = find_redirection_entry_by_vector(interrupt_vector); auto found_index = find_redirection_entry_by_vector(interrupt_vector);
if (index == (-1)) { if (!found_index.has_value()) {
map_interrupt_redirection(interrupt_vector); map_interrupt_redirection(interrupt_vector);
index = find_redirection_entry_by_vector(interrupt_vector); found_index = find_redirection_entry_by_vector(interrupt_vector);
} }
ASSERT(index != (-1)); ASSERT(found_index.has_value());
unmask_redirection_entry(index); unmask_redirection_entry(found_index.value());
} }
void IOAPIC::eoi(const GenericInterruptHandler& handler) const void IOAPIC::eoi(const GenericInterruptHandler& handler) const

View file

@ -68,7 +68,7 @@ private:
bool is_redirection_entry_masked(u8 index) const; bool is_redirection_entry_masked(u8 index) const;
u8 read_redirection_entry_vector(u8 index) const; u8 read_redirection_entry_vector(u8 index) const;
int find_redirection_entry_by_vector(u8 vector) const; Optional<int> find_redirection_entry_by_vector(u8 vector) const;
void configure_redirections() const; void configure_redirections() const;
void write_register(u32 index, u32 value) const; void write_register(u32 index, u32 value) const;