Add a yellowstone stub and partially migrate denali

This commit is contained in:
Drew Galbraith 2023-07-05 14:51:24 -07:00
parent 318356e54c
commit 72483a3437
6 changed files with 57 additions and 29 deletions

View file

@ -8,8 +8,6 @@
namespace {
const uint64_t kPciSize = 0x1000;
const uint64_t kGhc_InteruptEnable = 0x2;
void interrupt_thread(void* void_driver) {
@ -20,18 +18,11 @@ void interrupt_thread(void* void_driver) {
crash("Driver returned from interrupt loop", glcr::INTERNAL);
}
PciDeviceHeader* LoadPciDeviceHeader(uint64_t ahci_phys) {
MappedMemoryRegion pci_region =
MappedMemoryRegion::DirectPhysical(ahci_phys, kPciSize);
return reinterpret_cast<PciDeviceHeader*>(pci_region.vaddr());
}
} // namespace
glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> AhciDriver::Init(
uint64_t ahci_phys) {
PciDeviceHeader* header = LoadPciDeviceHeader(ahci_phys);
glcr::UniquePtr<AhciDriver> driver(new AhciDriver(header));
MappedMemoryRegion pci_region) {
glcr::UniquePtr<AhciDriver> driver(new AhciDriver(pci_region));
// RET_ERR(driver->LoadCapabilities());
RET_ERR(driver->LoadHbaRegisters());
RET_ERR(driver->LoadDevices());

View file

@ -10,7 +10,8 @@
class AhciDriver {
public:
static glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> Init(uint64_t ahci_phys);
static glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> Init(
MappedMemoryRegion ahci_phys);
glcr::ErrorCode RegisterIrq();
void InterruptLoop();
@ -21,6 +22,7 @@ class AhciDriver {
void DumpPorts();
private:
MappedMemoryRegion pci_region_;
PciDeviceHeader* pci_device_header_ = nullptr;
MappedMemoryRegion ahci_region_;
AhciHba* ahci_hba_ = nullptr;
@ -38,6 +40,8 @@ class AhciDriver {
glcr::ErrorCode LoadHbaRegisters();
glcr::ErrorCode LoadDevices();
AhciDriver(PciDeviceHeader* device_header)
: pci_device_header_(device_header) {}
AhciDriver(MappedMemoryRegion pci_region)
: pci_region_(pci_region),
pci_device_header_(
reinterpret_cast<PciDeviceHeader*>(pci_region_.vaddr())) {}
};

View file

@ -5,6 +5,7 @@
#include <mammoth/port_client.h>
#include <stdint.h>
#include <yellowstone.h>
#include <yellowstone_stub.h>
#include "ahci/ahci_driver.h"
#include "denali_server.h"
@ -13,18 +14,10 @@ uint64_t main(uint64_t init_port_cap) {
check(ParseInitPort(init_port_cap));
glcr::UniquePtr<EndpointClient> yellowstone =
EndpointClient::AdoptEndpoint(gInitEndpointCap);
YellowstoneGetReq ahci_req{
.type = kYellowstoneGetAhci,
};
auto resp_or =
yellowstone->CallEndpoint<YellowstoneGetReq, YellowstoneGetAhciResp>(
ahci_req);
if (!resp_or.ok()) {
check(resp_or.error());
}
uint64_t ahci_addr = resp_or.value().ahci_phys_offset;
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_addr));
YellowstoneStub stub(gInitEndpointCap);
ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig());
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_region));
YellowstoneGetReq req{
.type = kYellowstoneGetRegistration,