mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Move x86-specific timer code handling to Arch/x86/Time directory
The APICTimer, HPET and RTC (the RTC timer is in the context of the PC RTC here) are timers that exist only in x86 platforms, therefore, we move the handling code and the initialization code to the Arch/x86/Time directory. Other related code patterns in the TimeManagement singleton and in the Random.cpp file are guarded with #ifdef to ensure they are only compiled for x86 builds.
This commit is contained in:
parent
48f3d762af
commit
fe2bd8e3dd
16 changed files with 51 additions and 33 deletions
|
@ -4,10 +4,10 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Kernel/Arch/x86/Time/APICTimer.h>
|
||||||
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
||||||
#include <Kernel/Panic.h>
|
#include <Kernel/Panic.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Time/APICTimer.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
||||||
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
||||||
#include <Kernel/Time/HardwareTimer.h>
|
#include <Kernel/Time/HardwareTimer.h>
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/HPET.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/HPETComparator.h>
|
||||||
#include <Kernel/Debug.h>
|
#include <Kernel/Debug.h>
|
||||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||||
#include <Kernel/Memory/MemoryManager.h>
|
#include <Kernel/Memory/MemoryManager.h>
|
||||||
#include <Kernel/Memory/TypedMapping.h>
|
#include <Kernel/Memory/TypedMapping.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Time/HPET.h>
|
|
||||||
#include <Kernel/Time/HPETComparator.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
|
@ -5,10 +5,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
#include <Kernel/Arch/InterruptDisabler.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/HPETComparator.h>
|
||||||
#include <Kernel/Assertions.h>
|
#include <Kernel/Assertions.h>
|
||||||
#include <Kernel/Debug.h>
|
#include <Kernel/Debug.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Time/HPETComparator.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <Kernel/Time/HPET.h>
|
#include <Kernel/Arch/x86/Time/HPET.h>
|
||||||
#include <Kernel/Time/HardwareTimer.h>
|
#include <Kernel/Time/HardwareTimer.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
#include <Kernel/Arch/InterruptDisabler.h>
|
||||||
#include <Kernel/Arch/x86/IO.h>
|
#include <Kernel/Arch/x86/IO.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/PIT.h>
|
||||||
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
#include <Kernel/Interrupts/GenericInterruptHandler.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
#include <Kernel/Time/PIT.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
#define IRQ_TIMER 0
|
#define IRQ_TIMER 0
|
|
@ -7,8 +7,8 @@
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
#include <Kernel/Arch/InterruptDisabler.h>
|
||||||
#include <Kernel/Arch/x86/IO.h>
|
#include <Kernel/Arch/x86/IO.h>
|
||||||
#include <Kernel/Arch/x86/NonMaskableInterruptDisabler.h>
|
#include <Kernel/Arch/x86/NonMaskableInterruptDisabler.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/RTC.h>
|
||||||
#include <Kernel/Arch/x86/common/CMOS.h>
|
#include <Kernel/Arch/x86/common/CMOS.h>
|
||||||
#include <Kernel/Time/RTC.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Kernel/Arch/Delay.h>
|
#include <Kernel/Arch/Delay.h>
|
||||||
#include <Kernel/Arch/x86/MSR.h>
|
#include <Kernel/Arch/x86/MSR.h>
|
||||||
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/APICTimer.h>
|
||||||
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
||||||
#include <Kernel/Debug.h>
|
#include <Kernel/Debug.h>
|
||||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||||
|
@ -23,7 +24,6 @@
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
#include <Kernel/Time/APICTimer.h>
|
|
||||||
|
|
||||||
#define IRQ_APIC_TIMER (0xfc - IRQ_VECTOR_BASE)
|
#define IRQ_APIC_TIMER (0xfc - IRQ_VECTOR_BASE)
|
||||||
#define IRQ_APIC_IPI (0xfd - IRQ_VECTOR_BASE)
|
#define IRQ_APIC_IPI (0xfd - IRQ_VECTOR_BASE)
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Kernel/Arch/x86/IO.h>
|
#include <Kernel/Arch/x86/IO.h>
|
||||||
|
#include <Kernel/Arch/x86/Time/PIT.h>
|
||||||
#include <Kernel/Arch/x86/common/PCSpeaker.h>
|
#include <Kernel/Arch/x86/common/PCSpeaker.h>
|
||||||
#include <Kernel/Time/PIT.h>
|
|
||||||
|
|
||||||
void PCSpeaker::tone_on(int frequency)
|
void PCSpeaker::tone_on(int frequency)
|
||||||
{
|
{
|
||||||
|
|
|
@ -298,11 +298,6 @@ set(KERNEL_SOURCES
|
||||||
Thread.cpp
|
Thread.cpp
|
||||||
ThreadBlockers.cpp
|
ThreadBlockers.cpp
|
||||||
ThreadTracer.cpp
|
ThreadTracer.cpp
|
||||||
Time/APICTimer.cpp
|
|
||||||
Time/HPET.cpp
|
|
||||||
Time/HPETComparator.cpp
|
|
||||||
Time/PIT.cpp
|
|
||||||
Time/RTC.cpp
|
|
||||||
Time/TimeManagement.cpp
|
Time/TimeManagement.cpp
|
||||||
TimerQueue.cpp
|
TimerQueue.cpp
|
||||||
UBSanitizer.cpp
|
UBSanitizer.cpp
|
||||||
|
@ -345,6 +340,12 @@ if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||||
Arch/x86/PCI/IDELegacyModeController.cpp
|
Arch/x86/PCI/IDELegacyModeController.cpp
|
||||||
Arch/x86/PCI/Initializer.cpp
|
Arch/x86/PCI/Initializer.cpp
|
||||||
|
|
||||||
|
Arch/x86/Time/APICTimer.cpp
|
||||||
|
Arch/x86/Time/HPET.cpp
|
||||||
|
Arch/x86/Time/HPETComparator.cpp
|
||||||
|
Arch/x86/Time/PIT.cpp
|
||||||
|
Arch/x86/Time/RTC.cpp
|
||||||
|
|
||||||
Arch/x86/VGA/IOArbiter.cpp
|
Arch/x86/VGA/IOArbiter.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
|
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
#include <Kernel/Arch/Processor.h>
|
#include <Kernel/Arch/Processor.h>
|
||||||
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
|
# include <Kernel/Arch/x86/Time/HPET.h>
|
||||||
|
# include <Kernel/Arch/x86/Time/RTC.h>
|
||||||
|
#endif
|
||||||
#include <Kernel/Devices/RandomDevice.h>
|
#include <Kernel/Devices/RandomDevice.h>
|
||||||
#include <Kernel/Random.h>
|
#include <Kernel/Random.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Time/HPET.h>
|
|
||||||
#include <Kernel/Time/RTC.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
@ -48,7 +50,9 @@ UNMAP_AFTER_INIT KernelRng::KernelRng()
|
||||||
|
|
||||||
add_random_event(value, i % 32);
|
add_random_event(value, i % 32);
|
||||||
}
|
}
|
||||||
} else if (TimeManagement::the().can_query_precise_time()) {
|
}
|
||||||
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
|
else if (TimeManagement::the().can_query_precise_time()) {
|
||||||
// Add HPET as entropy source if we don't have anything better.
|
// Add HPET as entropy source if we don't have anything better.
|
||||||
dmesgln("KernelRng: Using HPET as entropy source");
|
dmesgln("KernelRng: Using HPET as entropy source");
|
||||||
|
|
||||||
|
@ -66,6 +70,7 @@ UNMAP_AFTER_INIT KernelRng::KernelRng()
|
||||||
current_time += 0x40b2u;
|
current_time += 0x40b2u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelRng::wait_for_entropy()
|
void KernelRng::wait_for_entropy()
|
||||||
|
|
|
@ -7,20 +7,22 @@
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
# include <Kernel/Arch/InterruptDisabler.h>
|
||||||
#include <Kernel/Arch/x86/common/RTC.h>
|
# include <Kernel/Arch/x86/Time/APICTimer.h>
|
||||||
|
# include <Kernel/Arch/x86/Time/HPET.h>
|
||||||
|
# include <Kernel/Arch/x86/Time/HPETComparator.h>
|
||||||
|
# include <Kernel/Arch/x86/Time/PIT.h>
|
||||||
|
# include <Kernel/Arch/x86/Time/RTC.h>
|
||||||
|
# include <Kernel/Arch/x86/common/Interrupts/APIC.h>
|
||||||
|
# include <Kernel/Arch/x86/common/RTC.h>
|
||||||
|
#endif
|
||||||
#include <Kernel/CommandLine.h>
|
#include <Kernel/CommandLine.h>
|
||||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||||
#include <Kernel/PerformanceManager.h>
|
#include <Kernel/PerformanceManager.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
#include <Kernel/Sections.h>
|
#include <Kernel/Sections.h>
|
||||||
#include <Kernel/Time/APICTimer.h>
|
|
||||||
#include <Kernel/Time/HPET.h>
|
|
||||||
#include <Kernel/Time/HPETComparator.h>
|
|
||||||
#include <Kernel/Time/HardwareTimer.h>
|
#include <Kernel/Time/HardwareTimer.h>
|
||||||
#include <Kernel/Time/PIT.h>
|
|
||||||
#include <Kernel/Time/RTC.h>
|
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
#include <Kernel/TimerQueue.h>
|
#include <Kernel/TimerQueue.h>
|
||||||
|
|
||||||
|
@ -137,8 +139,9 @@ u64 TimeManagement::uptime_ms() const
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void TimeManagement::initialize(u32 cpu)
|
UNMAP_AFTER_INIT void TimeManagement::initialize([[maybe_unused]] u32 cpu)
|
||||||
{
|
{
|
||||||
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
if (cpu == 0) {
|
if (cpu == 0) {
|
||||||
VERIFY(!s_the.is_initialized());
|
VERIFY(!s_the.is_initialized());
|
||||||
s_the.ensure_instance();
|
s_the.ensure_instance();
|
||||||
|
@ -160,6 +163,7 @@ UNMAP_AFTER_INIT void TimeManagement::initialize(u32 cpu)
|
||||||
apic_timer->enable_local_timer();
|
apic_timer->enable_local_timer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManagement::set_system_timer(HardwareTimerBase& timer)
|
void TimeManagement::set_system_timer(HardwareTimerBase& timer)
|
||||||
|
@ -184,6 +188,7 @@ time_t TimeManagement::boot_time()
|
||||||
UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
||||||
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
|
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
|
||||||
{
|
{
|
||||||
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
bool probe_non_legacy_hardware_timers = !(kernel_command_line().is_legacy_time_enabled());
|
bool probe_non_legacy_hardware_timers = !(kernel_command_line().is_legacy_time_enabled());
|
||||||
if (ACPI::is_enabled()) {
|
if (ACPI::is_enabled()) {
|
||||||
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
||||||
|
@ -198,12 +203,13 @@ UNMAP_AFTER_INIT TimeManagement::TimeManagement()
|
||||||
m_epoch_time.tv_sec += boot_time();
|
m_epoch_time.tv_sec += boot_time();
|
||||||
}
|
}
|
||||||
if (probe_non_legacy_hardware_timers) {
|
if (probe_non_legacy_hardware_timers) {
|
||||||
if (!probe_and_set_non_legacy_hardware_timers())
|
if (!probe_and_set_x86_non_legacy_hardware_timers())
|
||||||
if (!probe_and_set_legacy_hardware_timers())
|
if (!probe_and_set_x86_legacy_hardware_timers())
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
} else if (!probe_and_set_legacy_hardware_timers()) {
|
} else if (!probe_and_set_x86_legacy_hardware_timers()) {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Time TimeManagement::now()
|
Time TimeManagement::now()
|
||||||
|
@ -249,7 +255,8 @@ bool TimeManagement::is_hpet_periodic_mode_allowed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_non_legacy_hardware_timers()
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
|
UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_x86_non_legacy_hardware_timers()
|
||||||
{
|
{
|
||||||
if (!ACPI::is_enabled())
|
if (!ACPI::is_enabled())
|
||||||
return false;
|
return false;
|
||||||
|
@ -323,7 +330,7 @@ UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_non_legacy_hardware_timers()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_legacy_hardware_timers()
|
UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_x86_legacy_hardware_timers()
|
||||||
{
|
{
|
||||||
if (ACPI::is_enabled()) {
|
if (ACPI::is_enabled()) {
|
||||||
if (ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
if (ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
||||||
|
@ -343,6 +350,7 @@ UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_legacy_hardware_timers()
|
||||||
m_time_ticks_per_second = m_time_keeper_timer->ticks_per_second();
|
m_time_ticks_per_second = m_time_keeper_timer->ticks_per_second();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void TimeManagement::update_time(RegisterState const&)
|
void TimeManagement::update_time(RegisterState const&)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
#include <AK/Platform.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <Kernel/API/TimePage.h>
|
#include <Kernel/API/TimePage.h>
|
||||||
|
@ -79,8 +80,10 @@ private:
|
||||||
TimePage& time_page();
|
TimePage& time_page();
|
||||||
void update_time_page();
|
void update_time_page();
|
||||||
|
|
||||||
bool probe_and_set_legacy_hardware_timers();
|
#if ARCH(I386) || ARCH(X86_64)
|
||||||
bool probe_and_set_non_legacy_hardware_timers();
|
bool probe_and_set_x86_legacy_hardware_timers();
|
||||||
|
bool probe_and_set_x86_non_legacy_hardware_timers();
|
||||||
|
#endif
|
||||||
Vector<HardwareTimerBase*> scan_and_initialize_periodic_timers();
|
Vector<HardwareTimerBase*> scan_and_initialize_periodic_timers();
|
||||||
Vector<HardwareTimerBase*> scan_for_non_periodic_timers();
|
Vector<HardwareTimerBase*> scan_for_non_periodic_timers();
|
||||||
NonnullLockRefPtrVector<HardwareTimerBase> m_hardware_timers;
|
NonnullLockRefPtrVector<HardwareTimerBase> m_hardware_timers;
|
||||||
|
|
Loading…
Add table
Reference in a new issue