Kernel: Replace InterruptController CriticalScopes with SpinLock

This commit is contained in:
Bananymous 2024-02-28 23:04:32 +02:00
parent 21f05eb118
commit 18253b6966
4 changed files with 16 additions and 10 deletions

View File

@ -2,6 +2,7 @@
#include <BAN/Vector.h>
#include <kernel/InterruptController.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/Memory/Types.h>
namespace Kernel
@ -52,6 +53,7 @@ namespace Kernel
};
private:
SpinLock m_lock;
BAN::Vector<Processor> m_processors;
Kernel::paddr_t m_local_apic_paddr = 0;
Kernel::vaddr_t m_local_apic_vaddr = 0;

View File

@ -1,6 +1,7 @@
#pragma once
#include <kernel/InterruptController.h>
#include <kernel/Lock/SpinLock.h>
namespace Kernel
{
@ -20,8 +21,12 @@ namespace Kernel
private:
static PIC* create();
friend class InterruptController;
private:
SpinLock m_lock;
uint16_t m_reserved_irqs { 0 };
friend class InterruptController;
};
}

View File

@ -223,7 +223,7 @@ namespace Kernel
void APIC::enable_irq(uint8_t irq)
{
CriticalScope _;
SpinLockGuard _(m_lock);
uint32_t gsi = m_irq_overrides[irq];
@ -268,7 +268,7 @@ namespace Kernel
BAN::ErrorOr<void> APIC::reserve_irq(uint8_t irq)
{
CriticalScope _;
SpinLockGuard _(m_lock);
uint32_t gsi = m_irq_overrides[irq];
@ -301,7 +301,7 @@ namespace Kernel
BAN::Optional<uint8_t> APIC::get_free_irq()
{
CriticalScope _;
SpinLockGuard _(m_lock);
for (int irq = 0; irq <= 0xFF; irq++)
{
uint32_t gsi = m_irq_overrides[irq];

View File

@ -1,4 +1,3 @@
#include <kernel/CriticalScope.h>
#include <kernel/IDT.h>
#include <kernel/IO.h>
#include <kernel/PIC.h>
@ -71,7 +70,7 @@ namespace Kernel
void PIC::eoi(uint8_t irq)
{
ASSERT(!interrupts_enabled());
SpinLockGuard _(m_lock);
if (irq >= 8)
IO::outb(PIC2_CMD, PIC_EOI);
IO::outb(PIC1_CMD, PIC_EOI);
@ -79,7 +78,7 @@ namespace Kernel
void PIC::enable_irq(uint8_t irq)
{
CriticalScope _;
SpinLockGuard _(m_lock);
ASSERT(irq < 16);
ASSERT(m_reserved_irqs & (1 << irq));
@ -99,7 +98,7 @@ namespace Kernel
dwarnln("PIC only supports 16 irqs");
return BAN::Error::from_errno(EFAULT);
}
CriticalScope _;
SpinLockGuard _(m_lock);
if (m_reserved_irqs & (1 << irq))
{
dwarnln("irq {} is already reserved", irq);
@ -111,7 +110,7 @@ namespace Kernel
BAN::Optional<uint8_t> PIC::get_free_irq()
{
CriticalScope _;
SpinLockGuard _(m_lock);
for (int irq = 0; irq < 16; irq++)
{
if (m_reserved_irqs & (1 << irq))
@ -119,12 +118,12 @@ namespace Kernel
m_reserved_irqs |= 1 << irq;
return irq;
}
return {};
}
bool PIC::is_in_service(uint8_t irq)
{
SpinLockGuard _(m_lock);
uint16_t port = PIC1_CMD;
if (irq >= 8)
{