2020-02-22 19:36:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-22 19:36:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-21 20:21:29 +02:00
|
|
|
#include <AK/IntrusiveList.h>
|
2020-02-22 19:36:40 +02:00
|
|
|
#include <AK/Types.h>
|
2021-10-14 23:01:29 +01:00
|
|
|
#include <Kernel/Arch/RegisterState.h>
|
2020-02-22 19:36:40 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2020-03-05 19:13:55 +02:00
|
|
|
enum class HandlerType : u8 {
|
2020-02-22 19:36:40 +02:00
|
|
|
IRQHandler = 1,
|
|
|
|
SharedIRQHandler = 2,
|
|
|
|
UnhandledInterruptHandler = 3,
|
2020-02-28 18:23:32 +02:00
|
|
|
SpuriousInterruptHandler = 4
|
2020-02-22 19:36:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class GenericInterruptHandler {
|
|
|
|
public:
|
|
|
|
static GenericInterruptHandler& from(u8 interrupt_number);
|
2021-02-26 17:17:57 -07:00
|
|
|
virtual ~GenericInterruptHandler()
|
|
|
|
{
|
|
|
|
VERIFY(!m_registered);
|
|
|
|
}
|
2021-06-05 09: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 20:58:27 +03:00
|
|
|
virtual bool handle_interrupt(RegisterState const& regs) = 0;
|
2020-02-22 19:36:40 +02:00
|
|
|
|
2021-02-26 17:17:57 -07:00
|
|
|
void will_be_destroyed();
|
|
|
|
bool is_registered() const { return m_registered; }
|
|
|
|
void register_interrupt_handler();
|
|
|
|
void unregister_interrupt_handler();
|
|
|
|
|
2020-02-22 19:36:40 +02:00
|
|
|
u8 interrupt_number() const { return m_interrupt_number; }
|
|
|
|
|
2023-02-05 19:02:54 +00:00
|
|
|
ReadonlySpan<u32> per_cpu_call_counts() const;
|
2020-02-22 19:36:40 +02:00
|
|
|
|
2020-02-23 14:14:01 +02:00
|
|
|
virtual size_t sharing_devices_count() const = 0;
|
2020-02-22 19:36:40 +02:00
|
|
|
virtual bool is_shared_handler() const = 0;
|
|
|
|
|
2020-03-05 19:13:55 +02:00
|
|
|
virtual HandlerType type() const = 0;
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView purpose() const = 0;
|
|
|
|
virtual StringView controller() const = 0;
|
2020-02-22 19:36:40 +02:00
|
|
|
|
|
|
|
virtual bool eoi() = 0;
|
2022-11-18 21:39:49 +01:00
|
|
|
void increment_call_count();
|
2023-07-07 22:48:11 -04:00
|
|
|
void set_reserved() { m_reserved = true; }
|
|
|
|
bool reserved() const { return m_reserved; }
|
2020-02-22 19:36:40 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void change_interrupt_number(u8 number);
|
2020-08-28 00:28:07 +03:00
|
|
|
GenericInterruptHandler(u8 interrupt_number, bool disable_remap = false);
|
2020-02-22 19:36:40 +02:00
|
|
|
|
2020-10-25 09:13:47 -06:00
|
|
|
void disable_remap() { m_disable_remap = true; }
|
|
|
|
|
2020-02-22 19:36:40 +02:00
|
|
|
private:
|
2022-11-18 22:07:57 +01:00
|
|
|
Array<u32, MAX_CPU_COUNT> m_per_cpu_call_counts {};
|
|
|
|
|
2020-02-22 19:36:40 +02:00
|
|
|
u8 m_interrupt_number { 0 };
|
2020-07-06 07:27:22 -06:00
|
|
|
bool m_disable_remap { false };
|
2021-02-26 17:17:57 -07:00
|
|
|
bool m_registered { false };
|
2023-04-28 14:06:26 +02:00
|
|
|
bool m_reserved { false };
|
2021-07-21 20:21:29 +02:00
|
|
|
|
|
|
|
IntrusiveListNode<GenericInterruptHandler> m_list_node;
|
|
|
|
|
|
|
|
public:
|
2021-09-09 16:30:59 +04:30
|
|
|
using List = IntrusiveList<&GenericInterruptHandler::m_list_node>;
|
2020-02-22 19:36:40 +02:00
|
|
|
};
|
|
|
|
}
|