2020-02-22 14:36:40 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-22 14:36:40 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-07-21 15:21:29 -03:00
|
|
|
#include <AK/IntrusiveList.h>
|
2020-02-22 14:36:40 -03:00
|
|
|
#include <AK/Types.h>
|
2021-10-14 19:01:29 -03:00
|
|
|
#include <Kernel/Arch/RegisterState.h>
|
2020-02-22 14:36:40 -03:00
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
2020-03-05 14:13:55 -03:00
|
|
|
enum class HandlerType : u8 {
|
2020-02-22 14:36:40 -03:00
|
|
|
IRQHandler = 1,
|
|
|
|
|
SharedIRQHandler = 2,
|
|
|
|
|
UnhandledInterruptHandler = 3,
|
2020-02-28 13:23:32 -03:00
|
|
|
SpuriousInterruptHandler = 4
|
2020-02-22 14:36:40 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GenericInterruptHandler {
|
|
|
|
|
public:
|
|
|
|
|
static GenericInterruptHandler& from(u8 interrupt_number);
|
2021-02-26 21:17:57 -03:00
|
|
|
virtual ~GenericInterruptHandler()
|
|
|
|
|
{
|
|
|
|
|
VERIFY(!m_registered);
|
|
|
|
|
}
|
2021-06-05 03:00:18 -03:00
|
|
|
// Note: this method returns boolean value, to indicate if the handler handled
|
|
|
|
|
// the interrupt or not. This is useful for shared handlers mostly.
|
2022-04-01 14:58:27 -03:00
|
|
|
virtual bool handle_interrupt(RegisterState const& regs) = 0;
|
2020-02-22 14:36:40 -03:00
|
|
|
|
2021-02-26 21:17:57 -03:00
|
|
|
void will_be_destroyed();
|
|
|
|
|
bool is_registered() const { return m_registered; }
|
|
|
|
|
void register_interrupt_handler();
|
|
|
|
|
void unregister_interrupt_handler();
|
|
|
|
|
|
2020-02-22 14:36:40 -03:00
|
|
|
u8 interrupt_number() const { return m_interrupt_number; }
|
|
|
|
|
|
2021-01-03 20:58:50 -03:00
|
|
|
size_t get_invoking_count() const { return m_invoking_count; }
|
2020-02-22 14:36:40 -03:00
|
|
|
|
2020-02-23 09:14:01 -03:00
|
|
|
virtual size_t sharing_devices_count() const = 0;
|
2020-02-22 14:36:40 -03:00
|
|
|
virtual bool is_shared_handler() const = 0;
|
|
|
|
|
virtual bool is_sharing_with_others() const = 0;
|
|
|
|
|
|
2020-03-05 14:13:55 -03:00
|
|
|
virtual HandlerType type() const = 0;
|
2021-07-10 20:46:09 -03:00
|
|
|
virtual StringView purpose() const = 0;
|
|
|
|
|
virtual StringView controller() const = 0;
|
2020-02-22 14:36:40 -03:00
|
|
|
|
|
|
|
|
virtual bool eoi() = 0;
|
2020-12-02 13:41:52 -03:00
|
|
|
ALWAYS_INLINE void increment_invoking_counter()
|
|
|
|
|
{
|
2021-01-03 20:58:50 -03:00
|
|
|
m_invoking_count++;
|
2020-12-02 13:41:52 -03:00
|
|
|
}
|
2020-02-22 14:36:40 -03:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void change_interrupt_number(u8 number);
|
2020-08-27 18:28:07 -03:00
|
|
|
GenericInterruptHandler(u8 interrupt_number, bool disable_remap = false);
|
2020-02-22 14:36:40 -03:00
|
|
|
|
2020-10-25 12:13:47 -03:00
|
|
|
void disable_remap() { m_disable_remap = true; }
|
|
|
|
|
|
2020-02-22 14:36:40 -03:00
|
|
|
private:
|
2021-01-03 20:58:50 -03:00
|
|
|
Atomic<u32, AK::MemoryOrder::memory_order_relaxed> m_invoking_count { 0 };
|
2020-02-22 14:36:40 -03:00
|
|
|
u8 m_interrupt_number { 0 };
|
2020-07-06 10:27:22 -03:00
|
|
|
bool m_disable_remap { false };
|
2021-02-26 21:17:57 -03:00
|
|
|
bool m_registered { false };
|
2021-07-21 15:21:29 -03:00
|
|
|
|
|
|
|
|
IntrusiveListNode<GenericInterruptHandler> m_list_node;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-09-09 09:00:59 -03:00
|
|
|
using List = IntrusiveList<&GenericInterruptHandler::m_list_node>;
|
2020-02-22 14:36:40 -03:00
|
|
|
};
|
|
|
|
|
}
|