[Denali] Update HBA pointers to volatile. Store CommandList in arrayview.

This commit is contained in:
Drew Galbraith 2023-12-07 22:41:15 -08:00
parent c530921bda
commit 5a18d7d559
5 changed files with 20 additions and 15 deletions

View File

@ -10,7 +10,9 @@ class ArrayView {
ArrayView() : data_(nullptr), size_(0) {} ArrayView() : data_(nullptr), size_(0) {}
ArrayView(const ArrayView&) = default; ArrayView(const ArrayView&) = default;
ArrayView& operator=(const ArrayView&) = default;
ArrayView(ArrayView&&) = default; ArrayView(ArrayView&&) = default;
ArrayView& operator=(ArrayView&&) = default;
ArrayView(T* data, uint64_t size) : data_(data), size_(size) {} ArrayView(T* data, uint64_t size) : data_(data), size_(size) {}

View File

@ -155,10 +155,12 @@ glcr::ErrorCode AhciController::LoadCapabilities() {
dbgln("No caps!"); dbgln("No caps!");
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
uint8_t* base = reinterpret_cast<uint8_t*>(pci_device_header_); volatile uint8_t* base =
reinterpret_cast<volatile uint8_t*>(pci_device_header_);
uint16_t offset = pci_device_header_->cap_ptr; uint16_t offset = pci_device_header_->cap_ptr;
do { do {
uint16_t* cap = reinterpret_cast<uint16_t*>(base + offset); volatile uint16_t* cap =
reinterpret_cast<volatile uint16_t*>(base + offset);
switch (*cap & 0xFF) { switch (*cap & 0xFF) {
case 0x01: case 0x01:
dbgln("Power Management"); dbgln("Power Management");

View File

@ -23,7 +23,7 @@ class AhciController {
private: private:
mmth::OwnedMemoryRegion pci_region_; mmth::OwnedMemoryRegion pci_region_;
PciDeviceHeader* pci_device_header_ = nullptr; volatile PciDeviceHeader* pci_device_header_ = nullptr;
mmth::OwnedMemoryRegion ahci_region_; mmth::OwnedMemoryRegion ahci_region_;
volatile AhciHba* ahci_hba_ = nullptr; volatile AhciHba* ahci_hba_ = nullptr;

View File

@ -25,8 +25,8 @@ AhciDevice::AhciDevice(AhciPort* port) : port_struct_(port) {
port_struct_->fis_base = paddr + 0x400; port_struct_->fis_base = paddr + 0x400;
port_struct_->command |= kCommand_FIS_Receive_Enable; port_struct_->command |= kCommand_FIS_Receive_Enable;
command_tables_ = command_tables_ = glcr::ArrayView(
reinterpret_cast<CommandTable*>(command_structures_.vaddr() + 0x500); reinterpret_cast<CommandTable*>(command_structures_.vaddr() + 0x500), 32);
for (uint64_t i = 0; i < 32; i++) { for (uint64_t i = 0; i < 32; i++) {
// This leaves space for 2 prdt entries. // This leaves space for 2 prdt entries.
@ -50,7 +50,6 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) {
dbgln("All slots full"); dbgln("All slots full");
return glcr::INTERNAL; return glcr::INTERNAL;
} }
CommandTable* command_table = command_tables_ + slot;
command->PopulateFis(command_tables_[slot].command_fis); command->PopulateFis(command_tables_[slot].command_fis);
command->PopulatePrdt(command_tables_[slot].prdt); command->PopulatePrdt(command_tables_[slot].prdt);
@ -61,8 +60,8 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) {
commands_[slot] = command; commands_[slot] = command;
commands_issued_ |= 1 << slot; commands_issued_ |= (1 << slot);
port_struct_->command_issue |= 1 << slot; port_struct_->command_issue |= (1 << slot);
return glcr::OK; return glcr::OK;
} }
@ -96,7 +95,8 @@ void AhciDevice::HandleIrq() {
// TODO: Do something with this information. // TODO: Do something with this information.
if (int_status & 0x1) { if (int_status & 0x1) {
// Device to host. // 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) { if (fis.fis_type != FIS_TYPE_REG_D2H) {
dbgln("BAD FIS TYPE (exp,act): {x}, {x}", dbgln("BAD FIS TYPE (exp,act): {x}, {x}",
static_cast<uint64_t>(FIS_TYPE_REG_D2H), static_cast<uint64_t>(FIS_TYPE_REG_D2H),
@ -110,7 +110,7 @@ void AhciDevice::HandleIrq() {
} }
if (int_status & 0x2) { if (int_status & 0x2) {
// PIO. // PIO.
PioSetupFis& fis = received_fis_->pio_set_fis; volatile PioSetupFis& fis = received_fis_->pio_set_fis;
if (fis.fis_type != FIS_TYPE_PIO_SETUP) { if (fis.fis_type != FIS_TYPE_PIO_SETUP) {
dbgln("BAD FIS TYPE (exp,act): {x}, {x}", dbgln("BAD FIS TYPE (exp,act): {x}, {x}",
static_cast<uint64_t>(FIS_TYPE_PIO_SETUP), static_cast<uint64_t>(FIS_TYPE_PIO_SETUP),

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <glacier/container/array_view.h>
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/util/memory_region.h> #include <mammoth/util/memory_region.h>
#include <ztypes.h> #include <ztypes.h>
@ -25,13 +26,13 @@ class AhciDevice {
AhciDevice& operator=(const AhciDevice&) = delete; AhciDevice& operator=(const AhciDevice&) = delete;
private: private:
AhciPort* port_struct_ = nullptr; volatile AhciPort* port_struct_ = nullptr;
mmth::OwnedMemoryRegion command_structures_; mmth::OwnedMemoryRegion command_structures_;
CommandList* command_list_ = nullptr; volatile CommandList* command_list_ = nullptr;
ReceivedFis* received_fis_ = nullptr; volatile ReceivedFis* received_fis_ = nullptr;
CommandTable* command_tables_ = nullptr; glcr::ArrayView<CommandTable> command_tables_;
Command* commands_[32]; Command* commands_[32];
volatile uint32_t commands_issued_ = 0; uint32_t commands_issued_ = 0;
}; };