From c2dfe1736352c164df44211e1446669aa6594710 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Wed, 21 Jun 2023 18:46:06 -0700 Subject: [PATCH] [zion] Use ErrorOr in PciConfiguration --- lib/glacier/status/error_or.h | 2 +- zion/boot/acpi.cpp | 6 ++---- zion/boot/acpi.h | 7 ++++++- zion/syscall/memory_object.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/glacier/status/error_or.h b/lib/glacier/status/error_or.h index 755def3..38c00c8 100644 --- a/lib/glacier/status/error_or.h +++ b/lib/glacier/status/error_or.h @@ -12,7 +12,7 @@ class ErrorOr { ErrorOr(ErrorOr&&) = delete; ErrorOr(ErrorCode code) : error_(code), ok_(false) {} - ErrorOr(T obj) : obj_(obj), ok_(true) {} + ErrorOr(const T& obj) : obj_(obj), ok_(true) {} ErrorOr(T&& obj) : obj_(obj), ok_(true) {} bool ok() { return ok_; } diff --git a/zion/boot/acpi.cpp b/zion/boot/acpi.cpp index eb6fc53..9c450db 100644 --- a/zion/boot/acpi.cpp +++ b/zion/boot/acpi.cpp @@ -255,12 +255,10 @@ void ProbeRsdp() { #endif } -z_err_t GetPciExtendedConfiguration(uint64_t* base, uint64_t* offset) { +glcr::ErrorOr GetPciExtendedConfiguration() { if (gPcieEcSize == 0) { return glcr::NOT_FOUND; } - *base = gPcieEcBase; - *offset = gPcieEcSize; - return glcr::OK; + return PcieConfiguration{gPcieEcBase, gPcieEcSize}; } diff --git a/zion/boot/acpi.h b/zion/boot/acpi.h index c151ed0..1216540 100644 --- a/zion/boot/acpi.h +++ b/zion/boot/acpi.h @@ -1,9 +1,14 @@ #pragma once +#include #include #include "include/ztypes.h" void ProbeRsdp(); -z_err_t GetPciExtendedConfiguration(uint64_t* base, uint64_t* offset); +struct PcieConfiguration { + uint64_t base; + uint64_t offset; +}; +glcr::ErrorOr GetPciExtendedConfiguration(); diff --git a/zion/syscall/memory_object.cpp b/zion/syscall/memory_object.cpp index d9bba0a..a17ef00 100644 --- a/zion/syscall/memory_object.cpp +++ b/zion/syscall/memory_object.cpp @@ -32,11 +32,11 @@ z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) { z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req) { auto& curr_proc = gScheduler->CurrentProcess(); - uint64_t pci_base, pci_size; - RET_ERR(GetPciExtendedConfiguration(&pci_base, &pci_size)); - auto vmmo_ref = glcr::MakeRefCounted(pci_base, pci_size); + ASSIGN_OR_RETURN(PcieConfiguration config, GetPciExtendedConfiguration()); + auto vmmo_ref = + glcr::MakeRefCounted(config.base, config.offset); *req->vmmo_cap = curr_proc.AddNewCapability( StaticCastRefPtr(vmmo_ref), ZC_WRITE); - *req->vmmo_size = pci_size; + *req->vmmo_size = config.offset; return glcr::OK; }