From 5a18d7d559b9dfbe93c09de9a29d38db89ae2383 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Thu, 7 Dec 2023 22:41:15 -0800 Subject: [PATCH] [Denali] Update HBA pointers to volatile. Store CommandList in arrayview. --- lib/glacier/container/array_view.h | 2 ++ sys/denali/ahci/ahci_controller.cpp | 6 ++++-- sys/denali/ahci/ahci_controller.h | 2 +- sys/denali/ahci/ahci_device.cpp | 14 +++++++------- sys/denali/ahci/ahci_device.h | 11 ++++++----- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/glacier/container/array_view.h b/lib/glacier/container/array_view.h index da16e9d..684d6ac 100644 --- a/lib/glacier/container/array_view.h +++ b/lib/glacier/container/array_view.h @@ -10,7 +10,9 @@ class ArrayView { ArrayView() : data_(nullptr), size_(0) {} ArrayView(const ArrayView&) = default; + ArrayView& operator=(const ArrayView&) = default; ArrayView(ArrayView&&) = default; + ArrayView& operator=(ArrayView&&) = default; ArrayView(T* data, uint64_t size) : data_(data), size_(size) {} diff --git a/sys/denali/ahci/ahci_controller.cpp b/sys/denali/ahci/ahci_controller.cpp index 0c164e6..d4f2968 100644 --- a/sys/denali/ahci/ahci_controller.cpp +++ b/sys/denali/ahci/ahci_controller.cpp @@ -155,10 +155,12 @@ glcr::ErrorCode AhciController::LoadCapabilities() { dbgln("No caps!"); return glcr::FAILED_PRECONDITION; } - uint8_t* base = reinterpret_cast(pci_device_header_); + volatile uint8_t* base = + reinterpret_cast(pci_device_header_); uint16_t offset = pci_device_header_->cap_ptr; do { - uint16_t* cap = reinterpret_cast(base + offset); + volatile uint16_t* cap = + reinterpret_cast(base + offset); switch (*cap & 0xFF) { case 0x01: dbgln("Power Management"); diff --git a/sys/denali/ahci/ahci_controller.h b/sys/denali/ahci/ahci_controller.h index ffb4774..69cb2cc 100644 --- a/sys/denali/ahci/ahci_controller.h +++ b/sys/denali/ahci/ahci_controller.h @@ -23,7 +23,7 @@ class AhciController { private: mmth::OwnedMemoryRegion pci_region_; - PciDeviceHeader* pci_device_header_ = nullptr; + volatile PciDeviceHeader* pci_device_header_ = nullptr; mmth::OwnedMemoryRegion ahci_region_; volatile AhciHba* ahci_hba_ = nullptr; diff --git a/sys/denali/ahci/ahci_device.cpp b/sys/denali/ahci/ahci_device.cpp index b1627c2..c12aa2b 100644 --- a/sys/denali/ahci/ahci_device.cpp +++ b/sys/denali/ahci/ahci_device.cpp @@ -25,8 +25,8 @@ AhciDevice::AhciDevice(AhciPort* port) : port_struct_(port) { port_struct_->fis_base = paddr + 0x400; port_struct_->command |= kCommand_FIS_Receive_Enable; - command_tables_ = - reinterpret_cast(command_structures_.vaddr() + 0x500); + command_tables_ = glcr::ArrayView( + reinterpret_cast(command_structures_.vaddr() + 0x500), 32); for (uint64_t i = 0; i < 32; i++) { // This leaves space for 2 prdt entries. @@ -50,7 +50,6 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) { dbgln("All slots full"); return glcr::INTERNAL; } - CommandTable* command_table = command_tables_ + slot; command->PopulateFis(command_tables_[slot].command_fis); command->PopulatePrdt(command_tables_[slot].prdt); @@ -61,8 +60,8 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) { commands_[slot] = command; - commands_issued_ |= 1 << slot; - port_struct_->command_issue |= 1 << slot; + commands_issued_ |= (1 << slot); + port_struct_->command_issue |= (1 << slot); return glcr::OK; } @@ -96,7 +95,8 @@ void AhciDevice::HandleIrq() { // TODO: Do something with this information. if (int_status & 0x1) { // Device to host. - DeviceToHostRegisterFis& fis = received_fis_->device_to_host_register_fis; + volatile DeviceToHostRegisterFis& fis = + received_fis_->device_to_host_register_fis; if (fis.fis_type != FIS_TYPE_REG_D2H) { dbgln("BAD FIS TYPE (exp,act): {x}, {x}", static_cast(FIS_TYPE_REG_D2H), @@ -110,7 +110,7 @@ void AhciDevice::HandleIrq() { } if (int_status & 0x2) { // PIO. - PioSetupFis& fis = received_fis_->pio_set_fis; + volatile PioSetupFis& fis = received_fis_->pio_set_fis; if (fis.fis_type != FIS_TYPE_PIO_SETUP) { dbgln("BAD FIS TYPE (exp,act): {x}, {x}", static_cast(FIS_TYPE_PIO_SETUP), diff --git a/sys/denali/ahci/ahci_device.h b/sys/denali/ahci/ahci_device.h index bc4fc94..49c36fe 100644 --- a/sys/denali/ahci/ahci_device.h +++ b/sys/denali/ahci/ahci_device.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -25,13 +26,13 @@ class AhciDevice { AhciDevice& operator=(const AhciDevice&) = delete; private: - AhciPort* port_struct_ = nullptr; + volatile AhciPort* port_struct_ = nullptr; mmth::OwnedMemoryRegion command_structures_; - CommandList* command_list_ = nullptr; - ReceivedFis* received_fis_ = nullptr; - CommandTable* command_tables_ = nullptr; + volatile CommandList* command_list_ = nullptr; + volatile ReceivedFis* received_fis_ = nullptr; + glcr::ArrayView command_tables_; Command* commands_[32]; - volatile uint32_t commands_issued_ = 0; + uint32_t commands_issued_ = 0; };