Compare commits
3 Commits
a8db218204
...
c057da88ad
Author | SHA1 | Date |
---|---|---|
|
c057da88ad | |
|
72483a3437 | |
|
318356e54c |
|
@ -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() { return cap_; }
|
z_cap_t GetCap() const { return cap_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EndpointClient(uint64_t cap) : cap_(cap) {}
|
EndpointClient(uint64_t cap) : cap_(cap) {}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
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>
|
||||||
|
@ -16,8 +17,10 @@ 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_;
|
z_cap_t port_cap_ = 0;
|
||||||
|
|
||||||
PortClient(z_cap_t port_cap);
|
PortClient(z_cap_t port_cap);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -20,18 +18,11 @@ 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(
|
||||||
uint64_t ahci_phys) {
|
MappedMemoryRegion pci_region) {
|
||||||
PciDeviceHeader* header = LoadPciDeviceHeader(ahci_phys);
|
glcr::UniquePtr<AhciDriver> driver(new AhciDriver(pci_region));
|
||||||
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());
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
class AhciDriver {
|
class AhciDriver {
|
||||||
public:
|
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();
|
glcr::ErrorCode RegisterIrq();
|
||||||
|
|
||||||
void InterruptLoop();
|
void InterruptLoop();
|
||||||
|
@ -21,6 +22,7 @@ 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;
|
||||||
|
@ -38,6 +40,8 @@ class AhciDriver {
|
||||||
glcr::ErrorCode LoadHbaRegisters();
|
glcr::ErrorCode LoadHbaRegisters();
|
||||||
glcr::ErrorCode LoadDevices();
|
glcr::ErrorCode LoadDevices();
|
||||||
|
|
||||||
AhciDriver(PciDeviceHeader* device_header)
|
AhciDriver(MappedMemoryRegion pci_region)
|
||||||
: pci_device_header_(device_header) {}
|
: pci_region_(pci_region),
|
||||||
|
pci_device_header_(
|
||||||
|
reinterpret_cast<PciDeviceHeader*>(pci_region_.vaddr())) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#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"
|
||||||
|
@ -13,37 +14,16 @@ 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t ahci_addr = resp_or.value().ahci_phys_offset;
|
YellowstoneStub stub(gInitEndpointCap);
|
||||||
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_addr));
|
ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig());
|
||||||
|
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());
|
||||||
notify.WriteMessage("denali", client->GetCap());
|
check(stub.Register("denali", *client));
|
||||||
|
|
||||||
DenaliServer server(glcr::Move(endpoint), *driver);
|
DenaliServer server(glcr::Move(endpoint), *driver);
|
||||||
RET_ERR(server.RunServer());
|
RET_ERR(server.RunServer());
|
||||||
|
|
|
@ -4,7 +4,8 @@ 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
|
||||||
|
@ -27,6 +28,10 @@ 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}"
|
||||||
|
|
|
@ -55,6 +55,7 @@ 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 =
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#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_;
|
||||||
|
};
|
|
@ -1,3 +1,39 @@
|
||||||
// PLACEHOLDER
|
#include "include/yellowstone_stub.h"
|
||||||
#include <stdint.h>
|
|
||||||
uint64_t a = 0;
|
#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<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());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue