[Denali] Use mutexes to synchronize the AHCI responses.
This is a temporary solution to allow denali to migrate to the yunq framework until we have a good async solution.
This commit is contained in:
parent
adfffdd3c3
commit
acfaf26391
|
@ -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,
|
||||||
DmaCallback callback, ResponseContext& response)
|
Mutex& callback_mutex, ResponseContext& response)
|
||||||
: response_(response),
|
: response_(response),
|
||||||
lba_(lba),
|
lba_(lba),
|
||||||
sector_cnt_(sector_cnt),
|
sector_cnt_(sector_cnt),
|
||||||
callback_(callback) {
|
callback_mutex_(callback_mutex) {
|
||||||
region_ = MappedMemoryRegion::ContiguousPhysical(sector_cnt * 512);
|
region_ = MappedMemoryRegion::ContiguousPhysical(sector_cnt * 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,4 @@ void DmaReadCommand::PopulatePrdt(PhysicalRegionDescriptor* prdt) {
|
||||||
prdt[0].region_address = region_.paddr();
|
prdt[0].region_address = region_.paddr();
|
||||||
prdt[0].byte_count = region_.size();
|
prdt[0].byte_count = region_.size();
|
||||||
}
|
}
|
||||||
void DmaReadCommand::Callback() {
|
void DmaReadCommand::Callback() { callback_mutex_.Release(); }
|
||||||
callback_(response_, lba_, sector_cnt_, region_.cap());
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#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 <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -16,8 +17,7 @@ class Command {
|
||||||
|
|
||||||
class DmaReadCommand : public Command {
|
class DmaReadCommand : public Command {
|
||||||
public:
|
public:
|
||||||
typedef void (*DmaCallback)(ResponseContext&, uint64_t, uint64_t, z_cap_t);
|
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, Mutex& callback_mutex_,
|
||||||
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaCallback callback,
|
|
||||||
ResponseContext& reply_port);
|
ResponseContext& reply_port);
|
||||||
|
|
||||||
virtual ~DmaReadCommand() override;
|
virtual ~DmaReadCommand() override;
|
||||||
|
@ -27,10 +27,12 @@ class DmaReadCommand : public Command {
|
||||||
|
|
||||||
void Callback() override;
|
void Callback() override;
|
||||||
|
|
||||||
|
z_cap_t GetMemoryRegion() { return region_.cap(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResponseContext& response_;
|
ResponseContext& response_;
|
||||||
uint64_t lba_;
|
uint64_t lba_;
|
||||||
uint64_t sector_cnt_;
|
uint64_t sector_cnt_;
|
||||||
DmaCallback callback_;
|
Mutex& callback_mutex_;
|
||||||
MappedMemoryRegion region_;
|
MappedMemoryRegion region_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,14 +5,6 @@
|
||||||
#include <mammoth/debug.h>
|
#include <mammoth/debug.h>
|
||||||
#include <zcall.h>
|
#include <zcall.h>
|
||||||
|
|
||||||
namespace {
|
|
||||||
DenaliServer* gServer = nullptr;
|
|
||||||
void HandleResponse(ResponseContext& response, uint64_t lba, uint64_t size,
|
|
||||||
z_cap_t mem) {
|
|
||||||
gServer->HandleResponse(response, lba, size, mem);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
|
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
|
||||||
AhciDriver& driver) {
|
AhciDriver& driver) {
|
||||||
z_cap_t cap;
|
z_cap_t cap;
|
||||||
|
@ -45,19 +37,20 @@ glcr::ErrorCode DenaliServer::HandleRequest(RequestContext& request,
|
||||||
glcr::ErrorCode DenaliServer::HandleRead(DenaliReadRequest* request,
|
glcr::ErrorCode DenaliServer::HandleRead(DenaliReadRequest* request,
|
||||||
ResponseContext& context) {
|
ResponseContext& context) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(request->device_id));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(request->device_id));
|
||||||
|
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
|
||||||
|
RET_ERR(mutex.Lock());
|
||||||
|
|
||||||
device->IssueCommand(new DmaReadCommand(request->lba, request->size,
|
DmaReadCommand command(request->lba, request->size, mutex, context);
|
||||||
::HandleResponse, context));
|
device->IssueCommand(&command);
|
||||||
|
|
||||||
return glcr::OK;
|
// Wait for read operation to complete.
|
||||||
}
|
RET_ERR(mutex.Lock());
|
||||||
|
RET_ERR(mutex.Release());
|
||||||
void DenaliServer::HandleResponse(ResponseContext& response, uint64_t lba,
|
|
||||||
uint64_t size, z_cap_t mem) {
|
|
||||||
DenaliReadResponse resp{
|
DenaliReadResponse resp{
|
||||||
.device_id = 0,
|
.device_id = request->device_id,
|
||||||
.lba = lba,
|
.lba = request->lba,
|
||||||
.size = size,
|
.size = request->size,
|
||||||
};
|
};
|
||||||
check(response.WriteStructWithCap<DenaliReadResponse>(resp, mem));
|
return context.WriteStructWithCap<DenaliReadResponse>(
|
||||||
|
resp, command.GetMemoryRegion());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,6 @@ class DenaliServer : public EndpointServer {
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create(
|
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create(
|
||||||
AhciDriver& driver);
|
AhciDriver& driver);
|
||||||
|
|
||||||
void HandleResponse(ResponseContext& response, uint64_t lba, uint64_t size,
|
|
||||||
z_cap_t cap);
|
|
||||||
|
|
||||||
virtual glcr::ErrorCode HandleRequest(RequestContext& request,
|
virtual glcr::ErrorCode HandleRequest(RequestContext& request,
|
||||||
ResponseContext& response) override;
|
ResponseContext& response) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue