Kernel: Make AHCI controller thread safe

This commit is contained in:
Bananymous 2026-01-02 17:45:44 +02:00
parent 50ba743faf
commit 6cdf5a5a7f
2 changed files with 9 additions and 1 deletions

View File

@ -1,8 +1,9 @@
#pragma once
#include <kernel/ThreadBlocker.h>
#include <kernel/Memory/DMARegion.h>
#include <kernel/Storage/ATA/AHCI/Definitions.h>
#include <kernel/Storage/ATA/ATADevice.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel
{
@ -34,6 +35,8 @@ namespace Kernel
BAN::ErrorOr<void> block_until_command_completed(uint32_t command_slot);
private:
Mutex m_mutex;
BAN::RefPtr<AHCIController> m_controller;
volatile HBAPortMemorySpace* const m_port;

View File

@ -1,3 +1,4 @@
#include <kernel/Lock/LockGuard.h>
#include <kernel/Scheduler.h>
#include <kernel/Storage/ATA/AHCI/Controller.h>
#include <kernel/Storage/ATA/AHCI/Device.h>
@ -182,6 +183,8 @@ namespace Kernel
BAN::ErrorOr<void> AHCIDevice::read_sectors_impl(uint64_t lba, uint64_t sector_count, BAN::ByteSpan buffer)
{
LockGuard _(m_mutex);
ASSERT(buffer.size() >= sector_count * sector_size());
const size_t sectors_per_page = PAGE_SIZE / sector_size();
for (uint64_t sector_off = 0; sector_off < sector_count; sector_off += sectors_per_page)
@ -197,6 +200,8 @@ namespace Kernel
BAN::ErrorOr<void> AHCIDevice::write_sectors_impl(uint64_t lba, uint64_t sector_count, BAN::ConstByteSpan buffer)
{
LockGuard _(m_mutex);
ASSERT(buffer.size() >= sector_count * sector_size());
const size_t sectors_per_page = PAGE_SIZE / sector_size();
for (uint64_t sector_off = 0; sector_off < sector_count; sector_off += sectors_per_page)