Endpoint syscalls implemented
This commit is contained in:
parent
69501bfe01
commit
c064af5fa7
27 changed files with 391 additions and 42 deletions
|
|
@ -7,8 +7,11 @@
|
|||
Command::~Command() {}
|
||||
|
||||
DmaReadCommand::DmaReadCommand(uint64_t lba, uint64_t sector_cnt,
|
||||
DmaCallback callback)
|
||||
: lba_(lba), sector_cnt_(sector_cnt), callback_(callback) {
|
||||
DmaCallback callback, z_cap_t reply_port)
|
||||
: reply_port_(reply_port),
|
||||
lba_(lba),
|
||||
sector_cnt_(sector_cnt),
|
||||
callback_(callback) {
|
||||
region_ = MappedMemoryRegion::ContiguousPhysical(sector_cnt * 512);
|
||||
}
|
||||
|
||||
|
|
@ -46,4 +49,6 @@ void DmaReadCommand::PopulatePrdt(PhysicalRegionDescriptor* prdt) {
|
|||
prdt[0].region_address = region_.paddr();
|
||||
prdt[0].byte_count = region_.size();
|
||||
}
|
||||
void DmaReadCommand::Callback() { callback_(lba_, sector_cnt_, region_.cap()); }
|
||||
void DmaReadCommand::Callback() {
|
||||
callback_(reply_port_, lba_, sector_cnt_, region_.cap());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ class Command {
|
|||
|
||||
class DmaReadCommand : public Command {
|
||||
public:
|
||||
typedef void (*DmaCallback)(uint64_t, uint64_t, uint64_t);
|
||||
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaCallback callback);
|
||||
typedef void (*DmaCallback)(z_cap_t, uint64_t, uint64_t, z_cap_t);
|
||||
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaCallback callback,
|
||||
z_cap_t reply_port);
|
||||
|
||||
virtual ~DmaReadCommand() override;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ class DmaReadCommand : public Command {
|
|||
void Callback() override;
|
||||
|
||||
private:
|
||||
z_cap_t reply_port_;
|
||||
uint64_t lba_;
|
||||
uint64_t sector_cnt_;
|
||||
DmaCallback callback_;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <mammoth/channel.h>
|
||||
|
||||
#include <mammoth/debug.h>
|
||||
#include <mammoth/endpoint_server.h>
|
||||
#include <mammoth/init.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
@ -11,7 +12,8 @@ uint64_t main(uint64_t init_port_cap) {
|
|||
AhciDriver driver;
|
||||
RET_ERR(driver.Init());
|
||||
|
||||
DenaliServer server(gInitChannelCap, driver);
|
||||
EndpointServer endpoint = EndpointServer::Adopt(gInitEndpointCap);
|
||||
DenaliServer server(endpoint, driver);
|
||||
RET_ERR(server.RunServer());
|
||||
// FIXME: Add thread join.
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@
|
|||
|
||||
namespace {
|
||||
DenaliServer* gServer = nullptr;
|
||||
void HandleResponse(uint64_t lba, uint64_t size, uint64_t cap) {
|
||||
gServer->HandleResponse(lba, size, cap);
|
||||
void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
|
||||
z_cap_t mem) {
|
||||
gServer->HandleResponse(reply_port, lba, size, mem);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DenaliServer::DenaliServer(uint64_t channel_cap, AhciDriver& driver)
|
||||
: channel_cap_(channel_cap), driver_(driver) {
|
||||
DenaliServer::DenaliServer(EndpointServer server, AhciDriver& driver)
|
||||
: server_(server), driver_(driver) {
|
||||
gServer = this;
|
||||
}
|
||||
|
||||
glcr::ErrorCode DenaliServer::RunServer() {
|
||||
while (true) {
|
||||
uint64_t buff_size = kBuffSize;
|
||||
uint64_t cap_size = 0;
|
||||
RET_ERR(ZChannelRecv(channel_cap_, &buff_size, read_buffer_, &cap_size,
|
||||
nullptr));
|
||||
z_cap_t reply_port;
|
||||
RET_ERR(server_.Recieve(&buff_size, read_buffer_, &reply_port));
|
||||
if (buff_size < sizeof(uint64_t)) {
|
||||
dbgln("Skipping invalid message");
|
||||
continue;
|
||||
|
|
@ -34,7 +34,7 @@ glcr::ErrorCode DenaliServer::RunServer() {
|
|||
case DENALI_READ: {
|
||||
DenaliRead* read_req = reinterpret_cast<DenaliRead*>(read_buffer_);
|
||||
uint64_t memcap = 0;
|
||||
RET_ERR(HandleRead(*read_req));
|
||||
RET_ERR(HandleRead(*read_req, reply_port));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -44,21 +44,22 @@ glcr::ErrorCode DenaliServer::RunServer() {
|
|||
}
|
||||
}
|
||||
|
||||
glcr::ErrorCode DenaliServer::HandleRead(const DenaliRead& read) {
|
||||
glcr::ErrorCode DenaliServer::HandleRead(const DenaliRead& read,
|
||||
z_cap_t reply_port) {
|
||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(read.device_id));
|
||||
|
||||
device->IssueCommand(
|
||||
new DmaReadCommand(read.lba, read.size, ::HandleResponse));
|
||||
new DmaReadCommand(read.lba, read.size, ::HandleResponse, reply_port));
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
void DenaliServer::HandleResponse(uint64_t lba, uint64_t size, uint64_t cap) {
|
||||
void DenaliServer::HandleResponse(z_cap_t reply_port, uint64_t lba,
|
||||
uint64_t size, z_cap_t mem) {
|
||||
DenaliReadResponse resp{
|
||||
.device_id = 0,
|
||||
.lba = lba,
|
||||
.size = size,
|
||||
};
|
||||
check(ZChannelSend(channel_cap_, sizeof(resp),
|
||||
reinterpret_cast<uint8_t*>(&resp), 1, &cap));
|
||||
check(ZReplyPortSend(reply_port, sizeof(resp), &resp, 1, &mem));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
#include <mammoth/endpoint_server.h>
|
||||
|
||||
#include "ahci/ahci_driver.h"
|
||||
#include "denali/denali.h"
|
||||
|
||||
class DenaliServer {
|
||||
public:
|
||||
DenaliServer(uint64_t channel_cap, AhciDriver& driver);
|
||||
DenaliServer(EndpointServer server, AhciDriver& driver);
|
||||
|
||||
glcr::ErrorCode RunServer();
|
||||
|
||||
void HandleResponse(uint64_t lba, uint64_t size, uint64_t cap);
|
||||
void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
|
||||
z_cap_t cap);
|
||||
|
||||
private:
|
||||
static const uint64_t kBuffSize = 1024;
|
||||
uint64_t channel_cap_;
|
||||
EndpointServer server_;
|
||||
uint8_t read_buffer_[kBuffSize];
|
||||
|
||||
AhciDriver& driver_;
|
||||
|
||||
glcr::ErrorCode HandleRead(const DenaliRead& read);
|
||||
glcr::ErrorCode HandleRead(const DenaliRead& read, z_cap_t reply_port);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue