[denali] Use glcr::ErrorOr as a POC.

This commit is contained in:
Drew Galbraith 2023-06-21 18:38:11 -07:00
parent 0b86a94f14
commit 3a3ab8717b
7 changed files with 29 additions and 25 deletions

View File

@ -13,6 +13,7 @@ target_include_directories(denali
target_link_libraries(denali
cxx
glacier
mammoth_lib
)

View File

@ -35,7 +35,7 @@ AhciDevice::AhciDevice(AhciPort* port) : port_struct_(port) {
port_struct_->interrupt_enable = 0xFFFFFFFF;
}
z_err_t AhciDevice::IssueCommand(Command* command) {
glcr::ErrorCode AhciDevice::IssueCommand(Command* command) {
command->PopulateFis(command_table_->command_fis);
command->PopulatePrdt(command_table_->prdt);

View File

@ -1,5 +1,6 @@
#pragma once
#include <glacier/status/error.h>
#include <mammoth/memory_region.h>
#include <ztypes.h>
@ -16,7 +17,7 @@ class AhciDevice {
bool IsInit() { return port_struct_ != nullptr && command_structures_; }
z_err_t IssueCommand(Command* command);
glcr::ErrorCode IssueCommand(Command* command);
void HandleIrq();

View File

@ -1,6 +1,7 @@
#include "ahci/ahci_driver.h"
#include <glacier/status/error.h>
#include <glacier/status/error_or.h>
#include <mammoth/debug.h>
#include <stdint.h>
#include <zcall.h>
@ -22,7 +23,7 @@ void interrupt_thread(void* void_driver) {
} // namespace
z_err_t AhciDriver::Init() {
glcr::ErrorCode AhciDriver::Init() {
RET_ERR(LoadPciDeviceHeader());
// RET_ERR(LoadCapabilities());
RET_ERR(RegisterIrq());
@ -34,7 +35,7 @@ z_err_t AhciDriver::Init() {
return glcr::OK;
}
z_err_t AhciDriver::GetDevice(uint64_t id, AhciDevice** device) {
glcr::ErrorOr<AhciDevice*> AhciDriver::GetDevice(uint64_t id) {
if (id >= 32) {
return glcr::INVALID_ARGUMENT;
}
@ -43,8 +44,7 @@ z_err_t AhciDriver::GetDevice(uint64_t id, AhciDevice** device) {
return glcr::NOT_FOUND;
}
*device = devices_[id];
return glcr::OK;
return devices_[id];
}
void AhciDriver::DumpCapabilities() {
@ -154,13 +154,13 @@ void AhciDriver::InterruptLoop() {
}
}
z_err_t AhciDriver::LoadPciDeviceHeader() {
glcr::ErrorCode AhciDriver::LoadPciDeviceHeader() {
pci_region_ = MappedMemoryRegion::DirectPhysical(kSataPciPhys, kPciSize);
pci_device_header_ = reinterpret_cast<PciDeviceHeader*>(pci_region_.vaddr());
return glcr::OK;
}
z_err_t AhciDriver::LoadCapabilities() {
glcr::ErrorCode AhciDriver::LoadCapabilities() {
if (!(pci_device_header_->status_reg & 0x10)) {
dbgln("No caps!");
return glcr::FAILED_PRECONDITION;
@ -189,9 +189,9 @@ z_err_t AhciDriver::LoadCapabilities() {
return glcr::OK;
}
z_err_t AhciDriver::RegisterIrq() {
glcr::ErrorCode AhciDriver::RegisterIrq() {
if (pci_device_header_->interrupt_pin == 0) {
crash("Can't register IRQ without a pin num", Z_INVALID);
crash("Can't register IRQ without a pin num", glcr::INVALID_ARGUMENT);
}
uint64_t irq_num = Z_IRQ_PCI_BASE + pci_device_header_->interrupt_pin - 1;
RET_ERR(ZIrqRegister(irq_num, &irq_port_cap_));
@ -199,7 +199,7 @@ z_err_t AhciDriver::RegisterIrq() {
return glcr::OK;
}
z_err_t AhciDriver::LoadHbaRegisters() {
glcr::ErrorCode AhciDriver::LoadHbaRegisters() {
ahci_region_ =
MappedMemoryRegion::DirectPhysical(pci_device_header_->abar, 0x1100);
ahci_hba_ = reinterpret_cast<AhciHba*>(ahci_region_.vaddr());
@ -209,7 +209,7 @@ z_err_t AhciDriver::LoadHbaRegisters() {
return glcr::OK;
}
z_err_t AhciDriver::LoadDevices() {
glcr::ErrorCode AhciDriver::LoadDevices() {
for (uint8_t i = 0; i < 32; i++) {
if (!(ahci_hba_->port_implemented & (1 << i))) {
continue;

View File

@ -1,5 +1,6 @@
#pragma once
#include <glacier/status/error_or.h>
#include <mammoth/thread.h>
#include <ztypes.h>
@ -8,11 +9,11 @@
class AhciDriver {
public:
z_err_t Init();
glcr::ErrorCode Init();
void InterruptLoop();
z_err_t GetDevice(uint64_t id, AhciDevice** device);
glcr::ErrorOr<AhciDevice*> GetDevice(uint64_t id);
void DumpCapabilities();
void DumpPorts();
@ -32,9 +33,9 @@ class AhciDriver {
uint64_t num_ports_;
uint64_t num_commands_;
z_err_t LoadPciDeviceHeader();
z_err_t LoadCapabilities();
z_err_t RegisterIrq();
z_err_t LoadHbaRegisters();
z_err_t LoadDevices();
glcr::ErrorCode LoadPciDeviceHeader();
glcr::ErrorCode LoadCapabilities();
glcr::ErrorCode RegisterIrq();
glcr::ErrorCode LoadHbaRegisters();
glcr::ErrorCode LoadDevices();
};

View File

@ -16,7 +16,7 @@ DenaliServer::DenaliServer(uint64_t channel_cap, AhciDriver& driver)
gServer = this;
}
z_err_t DenaliServer::RunServer() {
glcr::ErrorCode DenaliServer::RunServer() {
while (true) {
uint64_t buff_size = kBuffSize;
uint64_t cap_size = 0;
@ -44,9 +44,8 @@ z_err_t DenaliServer::RunServer() {
}
}
z_err_t DenaliServer::HandleRead(const DenaliRead& read) {
AhciDevice* device;
RET_ERR(driver_.GetDevice(read.device_id, &device));
glcr::ErrorCode DenaliServer::HandleRead(const DenaliRead& read) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(read.device_id));
device->IssueCommand(
new DmaReadCommand(read.lba, read.size, ::HandleResponse));

View File

@ -1,5 +1,7 @@
#pragma once
#include <glacier/status/error.h>
#include "ahci/ahci_driver.h"
#include "denali/denali.h"
@ -7,7 +9,7 @@ class DenaliServer {
public:
DenaliServer(uint64_t channel_cap, AhciDriver& driver);
z_err_t RunServer();
glcr::ErrorCode RunServer();
void HandleResponse(uint64_t lba, uint64_t size, uint64_t cap);
@ -18,5 +20,5 @@ class DenaliServer {
AhciDriver& driver_;
z_err_t HandleRead(const DenaliRead& read);
glcr::ErrorCode HandleRead(const DenaliRead& read);
};