Kernel: Make AHCI controller thread safe
This commit is contained in:
parent
50ba743faf
commit
6cdf5a5a7f
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/Memory/DMARegion.h>
|
||||||
#include <kernel/Storage/ATA/AHCI/Definitions.h>
|
#include <kernel/Storage/ATA/AHCI/Definitions.h>
|
||||||
#include <kernel/Storage/ATA/ATADevice.h>
|
#include <kernel/Storage/ATA/ATADevice.h>
|
||||||
|
#include <kernel/ThreadBlocker.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
@ -34,6 +35,8 @@ namespace Kernel
|
||||||
BAN::ErrorOr<void> block_until_command_completed(uint32_t command_slot);
|
BAN::ErrorOr<void> block_until_command_completed(uint32_t command_slot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mutex m_mutex;
|
||||||
|
|
||||||
BAN::RefPtr<AHCIController> m_controller;
|
BAN::RefPtr<AHCIController> m_controller;
|
||||||
volatile HBAPortMemorySpace* const m_port;
|
volatile HBAPortMemorySpace* const m_port;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <kernel/Lock/LockGuard.h>
|
||||||
#include <kernel/Scheduler.h>
|
#include <kernel/Scheduler.h>
|
||||||
#include <kernel/Storage/ATA/AHCI/Controller.h>
|
#include <kernel/Storage/ATA/AHCI/Controller.h>
|
||||||
#include <kernel/Storage/ATA/AHCI/Device.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)
|
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());
|
ASSERT(buffer.size() >= sector_count * sector_size());
|
||||||
const size_t sectors_per_page = PAGE_SIZE / 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)
|
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)
|
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());
|
ASSERT(buffer.size() >= sector_count * sector_size());
|
||||||
const size_t sectors_per_page = PAGE_SIZE / 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)
|
for (uint64_t sector_off = 0; sector_off < sector_count; sector_off += sectors_per_page)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue