[Denali] Use semaphores for DMA callback signaling.
This commit is contained in:
parent
4c2492e985
commit
2b8ae027df
|
@ -85,7 +85,7 @@ void AhciDevice::HandleIrq() {
|
||||||
for (uint64_t i = 0; i < 32; i++) {
|
for (uint64_t i = 0; i < 32; i++) {
|
||||||
if (commands_finished & (1 << i)) {
|
if (commands_finished & (1 << i)) {
|
||||||
commands_issued_ &= ~(1 << i);
|
commands_issued_ &= ~(1 << i);
|
||||||
commands_[i]->Callback();
|
commands_[i]->SignalComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
Command::~Command() {}
|
Command::~Command() {}
|
||||||
|
|
||||||
DmaReadCommand::DmaReadCommand(uint64_t lba, uint64_t sector_cnt,
|
DmaReadCommand::DmaReadCommand(uint64_t lba, uint64_t sector_cnt,
|
||||||
uint64_t paddr, Mutex& callback_mutex)
|
uint64_t paddr)
|
||||||
: lba_(lba),
|
: lba_(lba),
|
||||||
sector_cnt_(sector_cnt),
|
sector_cnt_(sector_cnt),
|
||||||
paddr_(paddr),
|
paddr_(paddr),
|
||||||
callback_mutex_(callback_mutex) {}
|
callback_semaphore_() {}
|
||||||
|
|
||||||
DmaReadCommand::~DmaReadCommand() {}
|
DmaReadCommand::~DmaReadCommand() {}
|
||||||
|
|
||||||
|
@ -47,4 +47,6 @@ void DmaReadCommand::PopulatePrdt(PhysicalRegionDescriptor* prdt) {
|
||||||
prdt[0].region_address = paddr_;
|
prdt[0].region_address = paddr_;
|
||||||
prdt[0].byte_count = sector_cnt_ * 512;
|
prdt[0].byte_count = sector_cnt_ * 512;
|
||||||
}
|
}
|
||||||
void DmaReadCommand::Callback() { callback_mutex_.Release(); }
|
|
||||||
|
void DmaReadCommand::SignalComplete() { callback_semaphore_.Signal(); }
|
||||||
|
void DmaReadCommand::WaitComplete() { callback_semaphore_.Wait(); }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mammoth/memory_region.h>
|
#include <mammoth/memory_region.h>
|
||||||
#include <mammoth/mutex.h>
|
|
||||||
#include <mammoth/response_context.h>
|
#include <mammoth/response_context.h>
|
||||||
|
#include <mammoth/semaphore.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "ahci/ahci.h"
|
#include "ahci/ahci.h"
|
||||||
|
@ -12,24 +12,27 @@ class Command {
|
||||||
virtual ~Command();
|
virtual ~Command();
|
||||||
virtual void PopulateFis(uint8_t* command_fis) = 0;
|
virtual void PopulateFis(uint8_t* command_fis) = 0;
|
||||||
virtual void PopulatePrdt(PhysicalRegionDescriptor* prdt) = 0;
|
virtual void PopulatePrdt(PhysicalRegionDescriptor* prdt) = 0;
|
||||||
virtual void Callback() = 0;
|
virtual void WaitComplete() = 0;
|
||||||
|
virtual void SignalComplete() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DmaReadCommand : public Command {
|
class DmaReadCommand : public Command {
|
||||||
public:
|
public:
|
||||||
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, uint64_t dest_paddr,
|
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, uint64_t dest_paddr);
|
||||||
Mutex& callback_mutex);
|
|
||||||
|
|
||||||
virtual ~DmaReadCommand() override;
|
virtual ~DmaReadCommand() override;
|
||||||
|
|
||||||
void PopulateFis(uint8_t* command_fis) override;
|
void PopulateFis(uint8_t* command_fis) override;
|
||||||
void PopulatePrdt(PhysicalRegionDescriptor* prdt) override;
|
void PopulatePrdt(PhysicalRegionDescriptor* prdt) override;
|
||||||
|
|
||||||
void Callback() override;
|
void WaitComplete() override;
|
||||||
|
void SignalComplete() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t lba_;
|
uint64_t lba_;
|
||||||
uint64_t sector_cnt_;
|
uint64_t sector_cnt_;
|
||||||
uint64_t paddr_;
|
uint64_t paddr_;
|
||||||
Mutex& callback_mutex_;
|
// TODO: Make this owned by the device so that we don't have to create a new
|
||||||
|
// one with the kernel every time a command is issued.
|
||||||
|
Semaphore callback_semaphore_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,19 +15,15 @@ glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
|
||||||
glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
|
glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
|
||||||
ReadResponse& resp) {
|
ReadResponse& resp) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
||||||
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
|
|
||||||
RET_ERR(mutex.Lock());
|
|
||||||
|
|
||||||
uint64_t paddr;
|
uint64_t paddr;
|
||||||
OwnedMemoryRegion region =
|
OwnedMemoryRegion region =
|
||||||
OwnedMemoryRegion::ContiguousPhysical(req.size() * 512, &paddr);
|
OwnedMemoryRegion::ContiguousPhysical(req.size() * 512, &paddr);
|
||||||
|
|
||||||
DmaReadCommand command(req.lba(), req.size(), paddr, mutex);
|
DmaReadCommand command(req.lba(), req.size(), paddr);
|
||||||
device->IssueCommand(&command);
|
device->IssueCommand(&command);
|
||||||
|
|
||||||
// Wait for read operation to complete.
|
command.WaitComplete();
|
||||||
RET_ERR(mutex.Lock());
|
|
||||||
RET_ERR(mutex.Release());
|
|
||||||
|
|
||||||
resp.set_device_id(req.device_id());
|
resp.set_device_id(req.device_id());
|
||||||
resp.set_size(req.size());
|
resp.set_size(req.size());
|
||||||
|
@ -38,8 +34,6 @@ glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
|
||||||
glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
ReadResponse& resp) {
|
ReadResponse& resp) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
||||||
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
|
|
||||||
RET_ERR(mutex.Lock());
|
|
||||||
|
|
||||||
uint64_t region_paddr;
|
uint64_t region_paddr;
|
||||||
OwnedMemoryRegion region = OwnedMemoryRegion::ContiguousPhysical(
|
OwnedMemoryRegion region = OwnedMemoryRegion::ContiguousPhysical(
|
||||||
|
@ -54,11 +48,9 @@ glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
uint64_t lba = vec.at(curr_run_start);
|
uint64_t lba = vec.at(curr_run_start);
|
||||||
uint64_t size = (i - curr_run_start) + 1;
|
uint64_t size = (i - curr_run_start) + 1;
|
||||||
uint64_t paddr = region_paddr + curr_run_start * 512;
|
uint64_t paddr = region_paddr + curr_run_start * 512;
|
||||||
DmaReadCommand command(lba, size, paddr, mutex);
|
DmaReadCommand command(lba, size, paddr);
|
||||||
device->IssueCommand(&command);
|
device->IssueCommand(&command);
|
||||||
|
command.WaitComplete();
|
||||||
// Wait for read operation to complete.
|
|
||||||
RET_ERR(mutex.Lock());
|
|
||||||
|
|
||||||
curr_run_start = i + 1;
|
curr_run_start = i + 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue