From 1a27220bca77e2c92a78ed24424de3efb0dcbf52 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Sat, 25 Dec 2021 09:38:58 +0530 Subject: [PATCH] Kernel: Encapsulate APIC initialization inside InterruptManagement Currently the APIC class is constructed irrespective of whether it is used or not. So, move APIC initialization from init to the InterruptManagement class and construct the APIC class only when it is needed. --- Kernel/Interrupts/InterruptManagement.cpp | 1 + Kernel/Time/TimeManagement.cpp | 16 +++++++++------- Kernel/init.cpp | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index dee4223ef0..3e4530b7bd 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -182,6 +182,7 @@ UNMAP_AFTER_INIT void InterruptManagement::switch_to_ioapic_mode() m_pci_interrupt_overrides = mp_parser->get_pci_interrupt_redirections(); } + APIC::initialize(); APIC::the().init_bsp(); } diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 59c13ca68f..125464afcd 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -142,13 +142,15 @@ UNMAP_AFTER_INIT void TimeManagement::initialize(u32 cpu) VERIFY(!s_the.is_initialized()); s_the.ensure_instance(); - // Initialize the APIC timers after the other timers as the - // initialization needs to briefly enable interrupts, which then - // would trigger a deadlock trying to get the s_the instance while - // creating it. - if (auto* apic_timer = APIC::the().initialize_timers(*s_the->m_system_timer)) { - dmesgln("Time: Using APIC timer as system timer"); - s_the->set_system_timer(*apic_timer); + if (APIC::initialized()) { + // Initialize the APIC timers after the other timers as the + // initialization needs to briefly enable interrupts, which then + // would trigger a deadlock trying to get the s_the instance while + // creating it. + if (auto* apic_timer = APIC::the().initialize_timers(*s_the->m_system_timer)) { + dmesgln("Time: Using APIC timer as system timer"); + s_the->set_system_timer(*apic_timer); + } } s_the->m_time_page_region = MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value(); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index bddef41521..e3d6f99691 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -203,7 +203,6 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++) (*ctor)(); - APIC::initialize(); InterruptManagement::initialize(); ACPI::initialize();