Kernel/riscv64: Make RISC-V Timer inherit from GenericInterruptHandler

IRQHandler is not the correct class to inherit from, as the timer
is not connected to an IRQController.
Each hart has one of these Timers directly connected to it.
This commit is contained in:
Sönke Holz 2024-01-18 17:02:27 +01:00 committed by Andrew Kaster
parent 8c017c3078
commit 8582f0720f
Notes: sideshowbarker 2024-07-17 14:33:07 +09:00
2 changed files with 21 additions and 19 deletions

View file

@ -19,14 +19,16 @@ Timer::Timer()
m_frequency = 10'000'000; // in Hz
set_interrupt_interval_usec(m_frequency / OPTIMAL_TICKS_PER_SECOND_RATE);
enable_interrupt_mode();
}
Timer::~Timer() = default;
set_compare(microseconds_since_boot() + m_interrupt_interval);
RISCV64::CSR::set_bits(RISCV64::CSR::Address::SIE, 1 << interrupt_number());
}
NonnullLockRefPtr<Timer> Timer::initialize()
{
return adopt_lock_ref(*new Timer);
auto timer = adopt_lock_ref(*new Timer);
timer->register_interrupt_handler();
return timer;
}
u64 Timer::microseconds_since_boot()
@ -34,9 +36,9 @@ u64 Timer::microseconds_since_boot()
return RISCV64::CSR::read(RISCV64::CSR::Address::TIME);
}
bool Timer::handle_irq(RegisterState const& regs)
bool Timer::handle_interrupt(RegisterState const& regs)
{
auto result = HardwareTimer::handle_irq(regs);
auto result = HardwareTimer::handle_interrupt(regs);
set_compare(microseconds_since_boot() + m_interrupt_interval);
@ -69,12 +71,6 @@ u64 Timer::update_time(u64& seconds_since_boot, u32& ticks_this_second, bool que
return (delta_ticks * 1000000000ull) / ticks_per_second;
}
void Timer::enable_interrupt_mode()
{
set_compare(microseconds_since_boot() + m_interrupt_interval);
enable_irq();
}
void Timer::set_interrupt_interval_usec(u32 interrupt_interval)
{
m_interrupt_interval = interrupt_interval;
@ -87,3 +83,12 @@ void Timer::set_compare(u64 compare)
}
}
namespace Kernel {
bool HardwareTimer<GenericInterruptHandler>::eoi()
{
return true;
}
}

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/Types.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Library/NonnullLockRefPtr.h>
#include <Kernel/Time/HardwareTimer.h>
@ -15,10 +15,8 @@ namespace Kernel::RISCV64 {
struct TimerRegisters;
class Timer final : public HardwareTimer<IRQHandler> {
class Timer final : public HardwareTimer<GenericInterruptHandler> {
public:
virtual ~Timer();
static NonnullLockRefPtr<Timer> initialize();
virtual HardwareTimerType timer_type() const override { return HardwareTimerType::RISCVTimer; }
@ -42,15 +40,14 @@ public:
u64 microseconds_since_boot();
void set_interrupt_interval_usec(u32);
void enable_interrupt_mode();
private:
Timer();
void set_compare(u64 compare);
//^ IRQHandler
virtual bool handle_irq(RegisterState const&) override;
//^ GenericInterruptHandler
virtual bool handle_interrupt(RegisterState const&) override;
u32 m_interrupt_interval { 0 };