[denali] Use glcr::ErrorOr as a POC.
This commit is contained in:
parent
0b86a94f14
commit
3a3ab8717b
7 changed files with 29 additions and 25 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue