mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
This makes it not as easy to forgot to handle OOMs in the kernel. This commit replaces most usages of this function with `try_append(...).release_value_but_fixme_should_propagate_errors()`. But in some cases, using the `TRY` macro or `unchecked_append()` is already possible. In places where allocations should not fail or an OOM would be fatal anyways, `MUST(try_append(...))` should be used explicitly.
91 lines
2.7 KiB
C++
91 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2023, Sönke Holz <[email protected]>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/NeverDestroyed.h>
|
|
#include <Kernel/Arch/Interrupts.h>
|
|
#include <Kernel/Arch/riscv64/IRQController.h>
|
|
#include <Kernel/Arch/riscv64/InterruptManagement.h>
|
|
#include <Kernel/Arch/riscv64/Interrupts/PLIC.h>
|
|
#include <Kernel/Firmware/DeviceTree/DeviceTree.h>
|
|
#include <Kernel/Interrupts/SharedIRQHandler.h>
|
|
|
|
namespace Kernel {
|
|
|
|
static NeverDestroyed<Vector<DeviceTree::DeviceRecipe<NonnullLockRefPtr<IRQController>>>> s_recipes;
|
|
static InterruptManagement* s_interrupt_management;
|
|
|
|
bool InterruptManagement::initialized()
|
|
{
|
|
return s_interrupt_management != nullptr;
|
|
}
|
|
|
|
InterruptManagement& InterruptManagement::the()
|
|
{
|
|
VERIFY(InterruptManagement::initialized());
|
|
return *s_interrupt_management;
|
|
}
|
|
|
|
void InterruptManagement::initialize()
|
|
{
|
|
VERIFY(!InterruptManagement::initialized());
|
|
s_interrupt_management = new InterruptManagement;
|
|
|
|
the().find_controllers();
|
|
}
|
|
|
|
void InterruptManagement::add_recipe(DeviceTree::DeviceRecipe<NonnullLockRefPtr<IRQController>> recipe)
|
|
{
|
|
MUST(s_recipes->try_append(move(recipe)));
|
|
}
|
|
|
|
void InterruptManagement::find_controllers()
|
|
{
|
|
for (auto& recipe : *s_recipes) {
|
|
auto device_or_error = recipe.create_device();
|
|
if (device_or_error.is_error()) {
|
|
dmesgln("InterruptManagement: Failed to create interrupt controller for device \"{}\" with driver {}: {}", recipe.node_name, recipe.driver_name, device_or_error.release_error());
|
|
continue;
|
|
}
|
|
|
|
MUST(m_interrupt_controllers.try_append(device_or_error.release_value()));
|
|
}
|
|
|
|
if (m_interrupt_controllers.is_empty())
|
|
dmesgln("InterruptManagement: No supported interrupt controller found in devicetree");
|
|
}
|
|
|
|
u8 InterruptManagement::acquire_mapped_interrupt_number(u8 original_irq)
|
|
{
|
|
return original_irq;
|
|
}
|
|
|
|
Vector<NonnullLockRefPtr<IRQController>> const& InterruptManagement::controllers()
|
|
{
|
|
return m_interrupt_controllers;
|
|
}
|
|
|
|
NonnullLockRefPtr<IRQController> InterruptManagement::get_responsible_irq_controller(size_t)
|
|
{
|
|
// TODO: Support more interrupt controllers
|
|
VERIFY(m_interrupt_controllers.size() == 1);
|
|
return m_interrupt_controllers[0];
|
|
}
|
|
|
|
void InterruptManagement::enumerate_interrupt_handlers(Function<void(GenericInterruptHandler&)> callback)
|
|
{
|
|
for (size_t i = 0; i < GENERIC_INTERRUPT_HANDLERS_COUNT; i++) {
|
|
auto& handler = get_interrupt_handler(i);
|
|
if (handler.type() == HandlerType::SharedIRQHandler) {
|
|
static_cast<SharedIRQHandler&>(handler).enumerate_handlers(callback);
|
|
continue;
|
|
}
|
|
if (handler.type() != HandlerType::UnhandledInterruptHandler)
|
|
callback(handler);
|
|
}
|
|
}
|
|
|
|
}
|