summaryrefslogtreecommitdiff
path: root/Kernel/Time/HPETComparator.h
blob: a09408ce0dd515ac112ab900629ffeca50e59314 (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
/*
 * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Function.h>
#include <AK/Types.h>
#include <Kernel/Time/HPET.h>
#include <Kernel/Time/HardwareTimer.h>

namespace Kernel {
class HPETComparator final : public HardwareTimer<IRQHandler> {
    friend class HPET;

public:
    static NonnullRefPtr<HPETComparator> create(u8 number, u8 irq, bool periodic_capable, bool is_64bit_capable);

    virtual HardwareTimerType timer_type() const override { return HardwareTimerType::HighPrecisionEventTimer; }
    virtual StringView model() const override { return "HPET"sv; }

    u8 comparator_number() const { return m_comparator_number; }
    bool is_enabled() const { return m_enabled; }
    bool is_64bit_capable() const { return m_is_64bit_capable; }

    virtual size_t ticks_per_second() const override;

    virtual bool is_periodic() const override { return m_periodic; }
    virtual bool is_periodic_capable() const override { return m_periodic_capable; }
    virtual void set_periodic() override;
    virtual void set_non_periodic() override;
    virtual void disable() override;
    virtual bool can_query_raw() const override { return true; }
    virtual u64 current_raw() const override;
    virtual u64 raw_to_ns(u64) const override;

    virtual void reset_to_default_ticks_per_second() override;
    virtual bool try_to_set_frequency(size_t frequency) override;
    virtual bool is_capable_of_frequency(size_t frequency) const override;
    virtual size_t calculate_nearest_possible_frequency(size_t frequency) const override;

private:
    void set_new_countdown();
    virtual bool handle_irq(const RegisterState&) override;
    HPETComparator(u8 number, u8 irq, bool periodic_capable, bool is_64bit_capable);
    bool m_periodic : 1;
    bool m_periodic_capable : 1;
    bool m_enabled : 1;
    bool m_is_64bit_capable : 1;
    u8 m_comparator_number { 0 };
};
}