diff --git a/sys/denali/CMakeLists.txt b/sys/denali/CMakeLists.txt index 3d5064d..e27b1bb 100644 --- a/sys/denali/CMakeLists.txt +++ b/sys/denali/CMakeLists.txt @@ -13,6 +13,7 @@ target_include_directories(denali target_link_libraries(denali cxx + glacier mammoth_lib ) diff --git a/sys/denali/ahci/ahci_device.cpp b/sys/denali/ahci/ahci_device.cpp index 1b52504..d95f955 100644 --- a/sys/denali/ahci/ahci_device.cpp +++ b/sys/denali/ahci/ahci_device.cpp @@ -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); diff --git a/sys/denali/ahci/ahci_device.h b/sys/denali/ahci/ahci_device.h index 957846c..07ffbc2 100644 --- a/sys/denali/ahci/ahci_device.h +++ b/sys/denali/ahci/ahci_device.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -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(); diff --git a/sys/denali/ahci/ahci_driver.cpp b/sys/denali/ahci/ahci_driver.cpp index c6ea418..4d0fa0e 100644 --- a/sys/denali/ahci/ahci_driver.cpp +++ b/sys/denali/ahci/ahci_driver.cpp @@ -1,6 +1,7 @@ #include "ahci/ahci_driver.h" #include +#include #include #include #include @@ -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 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(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(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; diff --git a/sys/denali/ahci/ahci_driver.h b/sys/denali/ahci/ahci_driver.h index 8c526b0..c27eb1b 100644 --- a/sys/denali/ahci/ahci_driver.h +++ b/sys/denali/ahci/ahci_driver.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -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 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(); }; diff --git a/sys/denali/denali_server.cpp b/sys/denali/denali_server.cpp index 3c01ac8..5208862 100644 --- a/sys/denali/denali_server.cpp +++ b/sys/denali/denali_server.cpp @@ -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)); diff --git a/sys/denali/denali_server.h b/sys/denali/denali_server.h index e1c1011..d762c95 100644 --- a/sys/denali/denali_server.h +++ b/sys/denali/denali_server.h @@ -1,5 +1,7 @@ #pragma once +#include + #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); };