blob: f0a18ecb5174357127dbef6848178147c6598ffe (
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
|
#ifndef TEACHOS_ARCH_X86_64_DEVICES_LEGACY_PIT_HPP
#define TEACHOS_ARCH_X86_64_DEVICES_LEGACY_PIT_HPP
#include <arch/bus/isa.hpp>
#include <kapi/devices.hpp>
#include <kapi/interrupts.hpp>
#include <kstd/result.hpp>
#include <cstdint>
#include <span>
#include <string_view>
namespace arch::devices
{
//! The ISA device for the legacy Programmable Interrupt Timer.
//!
//! This type identifies the PIT device node to the driver, so the driver can be matched successfully.
struct pit_device final : kapi::devices::device, arch::bus::isa_identification
{
pit_device();
//! Get the synthetic ISA identifier for this device.
//!
//! @return the string "pit"
[[nodiscard]] auto isa_name() const -> std::string_view override;
protected:
auto query_interface(kapi::devices::interface interface) -> void * override;
};
//! The driver for the legacy, ISA-connected Programmable Interrupt Timer.
struct pit_driver final : kapi::devices::driver, arch::bus::isa_driver_identification, kapi::interrupts::handler
{
explicit pit_driver(std::uint32_t frequency_in_hz);
[[nodiscard]] auto probe(kapi::devices::device & device) -> kstd::result<void> override;
auto unbind(kapi::devices::device & device) -> void override;
[[nodiscard]] auto supported_names() const -> std::span<std::string_view const> override;
auto handle_interrupt(std::uint32_t irq_number) -> kapi::interrupts::status override;
protected:
auto query_interface(kapi::devices::interface interface) -> void * override;
private:
struct driver_data
{
std::uint32_t irq_number{};
std::uint32_t frequency_in_hz{};
std::uint64_t ticks{};
};
std::uint32_t m_frequency_in_hz{};
};
} // namespace arch::devices
#endif
|