diff --git a/sys/denali/ahci/ahci_driver.cpp b/sys/denali/ahci/ahci_driver.cpp index 28bd709..658b9ee 100644 --- a/sys/denali/ahci/ahci_driver.cpp +++ b/sys/denali/ahci/ahci_driver.cpp @@ -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(pci_region.vaddr()); -} - } // namespace glcr::ErrorOr> AhciDriver::Init( - uint64_t ahci_phys) { - PciDeviceHeader* header = LoadPciDeviceHeader(ahci_phys); - glcr::UniquePtr driver(new AhciDriver(header)); + MappedMemoryRegion pci_region) { + glcr::UniquePtr driver(new AhciDriver(pci_region)); // RET_ERR(driver->LoadCapabilities()); RET_ERR(driver->LoadHbaRegisters()); RET_ERR(driver->LoadDevices()); diff --git a/sys/denali/ahci/ahci_driver.h b/sys/denali/ahci/ahci_driver.h index 936f6dd..410ee5d 100644 --- a/sys/denali/ahci/ahci_driver.h +++ b/sys/denali/ahci/ahci_driver.h @@ -10,7 +10,8 @@ class AhciDriver { public: - static glcr::ErrorOr> Init(uint64_t ahci_phys); + static glcr::ErrorOr> 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(pci_region_.vaddr())) {} }; diff --git a/sys/denali/denali.cpp b/sys/denali/denali.cpp index f3e75f7..106020d 100644 --- a/sys/denali/denali.cpp +++ b/sys/denali/denali.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #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 yellowstone = EndpointClient::AdoptEndpoint(gInitEndpointCap); - YellowstoneGetReq ahci_req{ - .type = kYellowstoneGetAhci, - }; - auto resp_or = - yellowstone->CallEndpoint( - 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, diff --git a/sys/yellowstone/CMakeLists.txt b/sys/yellowstone/CMakeLists.txt index fe1082f..ac35d6c 100644 --- a/sys/yellowstone/CMakeLists.txt +++ b/sys/yellowstone/CMakeLists.txt @@ -4,7 +4,8 @@ add_executable(yellowstone yellowstone.cpp yellowstone_server.cpp ) - target_include_directories(yellowstone + +target_include_directories(yellowstone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(yellowstone @@ -27,6 +28,10 @@ target_include_directories(yellowstone_stub PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_link_libraries(yellowstone_stub + mammoth + ) + set_target_properties(yellowstone_stub PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" diff --git a/sys/yellowstone/include/yellowstone_stub.h b/sys/yellowstone/include/yellowstone_stub.h new file mode 100644 index 0000000..b665c22 --- /dev/null +++ b/sys/yellowstone/include/yellowstone_stub.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + +class YellowstoneStub { + public: + explicit YellowstoneStub(z_cap_t yellowstone_cap); + + glcr::ErrorOr GetAhciConfig(); + + private: + glcr::UniquePtr yellowstone_stub_; +}; diff --git a/sys/yellowstone/stub/yellowstone_stub.cpp b/sys/yellowstone/stub/yellowstone_stub.cpp index 85a0b90..d05ecb7 100644 --- a/sys/yellowstone/stub/yellowstone_stub.cpp +++ b/sys/yellowstone/stub/yellowstone_stub.cpp @@ -1,3 +1,23 @@ -// PLACEHOLDER -#include -uint64_t a = 0; +#include "include/yellowstone_stub.h" + +#include "include/yellowstone.h" + +namespace { + +const uint64_t kPciSize = 0x1000; + +} // namespace + +YellowstoneStub::YellowstoneStub(z_cap_t yellowstone_cap) + : yellowstone_stub_(EndpointClient::AdoptEndpoint(yellowstone_cap)) {} + +glcr::ErrorOr YellowstoneStub::GetAhciConfig() { + YellowstoneGetReq req{ + .type = kYellowstoneGetAhci, + }; + ASSIGN_OR_RETURN( + YellowstoneGetAhciResp resp, + (yellowstone_stub_ + ->CallEndpoint(req))); + return MappedMemoryRegion::DirectPhysical(resp.ahci_phys_offset, kPciSize); +}