Compare commits

..

No commits in common. "c057da88ad7650f2625d9d4696744d4ac3228bcc" and "a8db21820492cfa74ed143bba2d2c6866f555b7b" have entirely different histories.

9 changed files with 45 additions and 85 deletions

View File

@ -20,7 +20,7 @@ class EndpointClient {
template <typename Req, typename Resp> template <typename Req, typename Resp>
glcr::ErrorOr<Resp> CallEndpoint(const Req& req); glcr::ErrorOr<Resp> CallEndpoint(const Req& req);
z_cap_t GetCap() const { return cap_; } z_cap_t GetCap() { return cap_; }
private: private:
EndpointClient(uint64_t cap) : cap_(cap) {} EndpointClient(uint64_t cap) : cap_(cap) {}

View File

@ -7,7 +7,6 @@
class PortClient { class PortClient {
public: public:
PortClient() {}
static PortClient AdoptPort(z_cap_t port_cap); static PortClient AdoptPort(z_cap_t port_cap);
template <typename T> template <typename T>
@ -17,10 +16,8 @@ class PortClient {
z_cap_t cap() { return port_cap_; } z_cap_t cap() { return port_cap_; }
bool empty() { return port_cap_ == 0; }
private: private:
z_cap_t port_cap_ = 0; z_cap_t port_cap_;
PortClient(z_cap_t port_cap); PortClient(z_cap_t port_cap);
}; };

View File

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

View File

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

View File

@ -5,7 +5,6 @@
#include <mammoth/port_client.h> #include <mammoth/port_client.h>
#include <stdint.h> #include <stdint.h>
#include <yellowstone.h> #include <yellowstone.h>
#include <yellowstone_stub.h>
#include "ahci/ahci_driver.h" #include "ahci/ahci_driver.h"
#include "denali_server.h" #include "denali_server.h"
@ -14,16 +13,37 @@ uint64_t main(uint64_t init_port_cap) {
check(ParseInitPort(init_port_cap)); check(ParseInitPort(init_port_cap));
glcr::UniquePtr<EndpointClient> yellowstone = glcr::UniquePtr<EndpointClient> yellowstone =
EndpointClient::AdoptEndpoint(gInitEndpointCap); 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());
}
YellowstoneStub stub(gInitEndpointCap); uint64_t ahci_addr = resp_or.value().ahci_phys_offset;
ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig()); ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_addr));
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_region));
YellowstoneGetReq req{
.type = kYellowstoneGetRegistration,
};
auto resp_cap_or =
yellowstone->CallEndpointGetCap<YellowstoneGetReq,
YellowstoneGetRegistrationResp>(req);
if (!resp_cap_or.ok()) {
dbgln("Bad call");
check(resp_cap_or.error());
}
auto resp_cap = resp_cap_or.value();
PortClient notify = PortClient::AdoptPort(resp_cap.second());
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint,
EndpointServer::Create()); EndpointServer::Create());
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
endpoint->CreateClient()); endpoint->CreateClient());
check(stub.Register("denali", *client)); notify.WriteMessage("denali", client->GetCap());
DenaliServer server(glcr::Move(endpoint), *driver); DenaliServer server(glcr::Move(endpoint), *driver);
RET_ERR(server.RunServer()); RET_ERR(server.RunServer());

View File

@ -4,8 +4,7 @@ add_executable(yellowstone
yellowstone.cpp yellowstone.cpp
yellowstone_server.cpp yellowstone_server.cpp
) )
target_include_directories(yellowstone
target_include_directories(yellowstone
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(yellowstone target_link_libraries(yellowstone
@ -28,10 +27,6 @@ target_include_directories(yellowstone_stub
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(yellowstone_stub
mammoth
)
set_target_properties(yellowstone_stub PROPERTIES set_target_properties(yellowstone_stub PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"

View File

@ -55,7 +55,6 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
denali_->ReadSectors(0, 0, 2)); denali_->ReadSectors(0, 0, 2));
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE); uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
if (*mbr_sig != 0xAA55) { if (*mbr_sig != 0xAA55) {
dbgln("Invalid MBR Sig: %x", *mbr_sig);
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
MbrPartition* first_partition = MbrPartition* first_partition =

View File

@ -1,20 +0,0 @@
#pragma once
#include <mammoth/endpoint_client.h>
#include <mammoth/memory_region.h>
#include <mammoth/port_client.h>
#include <ztypes.h>
class YellowstoneStub {
public:
explicit YellowstoneStub(z_cap_t yellowstone_cap);
glcr::ErrorOr<MappedMemoryRegion> GetAhciConfig();
[[nodiscard]] glcr::ErrorCode Register(glcr::String name,
const EndpointClient& client);
private:
glcr::UniquePtr<EndpointClient> yellowstone_stub_;
PortClient register_port_;
};

View File

@ -1,39 +1,3 @@
#include "include/yellowstone_stub.h" // PLACEHOLDER
#include <stdint.h>
#include "include/yellowstone.h" uint64_t a = 0;
namespace {
const uint64_t kPciSize = 0x1000;
} // namespace
YellowstoneStub::YellowstoneStub(z_cap_t yellowstone_cap)
: yellowstone_stub_(EndpointClient::AdoptEndpoint(yellowstone_cap)) {}
glcr::ErrorOr<MappedMemoryRegion> YellowstoneStub::GetAhciConfig() {
YellowstoneGetReq req{
.type = kYellowstoneGetAhci,
};
ASSIGN_OR_RETURN(
YellowstoneGetAhciResp resp,
(yellowstone_stub_
->CallEndpoint<YellowstoneGetReq, YellowstoneGetAhciResp>(req)));
return MappedMemoryRegion::DirectPhysical(resp.ahci_phys_offset, kPciSize);
}
glcr::ErrorCode YellowstoneStub::Register(glcr::String name,
const EndpointClient& client) {
if (register_port_.empty()) {
YellowstoneGetReq req{
.type = kYellowstoneGetRegistration,
};
ASSIGN_OR_RETURN(
auto resp_cap,
(yellowstone_stub_->CallEndpointGetCap<
YellowstoneGetReq, YellowstoneGetRegistrationResp>(req)));
register_port_ = PortClient::AdoptPort(resp_cap.second());
}
return register_port_.WriteString(name, client.GetCap());
}