summaryrefslogtreecommitdiff
path: root/Kernel/Interrupts/GenericInterruptHandler.h
blob: 368d03c0f07e0882e57ffd25dbe841397fa1867b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/HashTable.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <Kernel/Arch/x86/CPU.h>

namespace Kernel {

enum class HandlerType : u8 {
    IRQHandler = 1,
    SharedIRQHandler = 2,
    UnhandledInterruptHandler = 3,
    SpuriousInterruptHandler = 4
};

class GenericInterruptHandler {
public:
    static GenericInterruptHandler& from(u8 interrupt_number);
    virtual ~GenericInterruptHandler()
    {
        VERIFY(!m_registered);
    }
    virtual void handle_interrupt(const RegisterState& regs) = 0;

    void will_be_destroyed();
    bool is_registered() const { return m_registered; }
    void register_interrupt_handler();
    void unregister_interrupt_handler();

    u8 interrupt_number() const { return m_interrupt_number; }

    size_t get_invoking_count() const { return m_invoking_count; }

    virtual size_t sharing_devices_count() const = 0;
    virtual bool is_shared_handler() const = 0;
    virtual bool is_sharing_with_others() const = 0;

    virtual HandlerType type() const = 0;
    virtual const char* purpose() const = 0;
    virtual const char* controller() const = 0;

    virtual bool eoi() = 0;
    ALWAYS_INLINE void increment_invoking_counter()
    {
        m_invoking_count++;
    }

protected:
    void change_interrupt_number(u8 number);
    GenericInterruptHandler(u8 interrupt_number, bool disable_remap = false);

    void disable_remap() { m_disable_remap = true; }

private:
    Atomic<u32, AK::MemoryOrder::memory_order_relaxed> m_invoking_count { 0 };
    u8 m_interrupt_number { 0 };
    bool m_disable_remap { false };
    bool m_registered { false };
};
}