[denali] Get Ahci device address from yellowstone.

This commit is contained in:
Drew Galbraith 2023-06-26 17:01:59 -07:00
parent 02e6b49d90
commit 16dd675828
11 changed files with 125 additions and 52 deletions

View file

@ -6,28 +6,37 @@
namespace {
struct PciDeviceHeader {
uint16_t vendor_id;
uint16_t device_id;
uint16_t command_reg;
uint16_t status_reg;
uint8_t revision;
uint8_t prog_interface;
uint8_t subclass;
uint8_t class_code;
uint8_t cache_line_size;
uint8_t latency_timer;
uint8_t header_type;
uint8_t bist;
} __attribute__((packed));
PciDeviceHeader* PciHeader(uint64_t base, uint64_t bus, uint64_t dev,
uint64_t fun) {
return reinterpret_cast<PciDeviceHeader*>(base + (bus << 20) + (dev << 15) +
(fun << 12));
}
void FunctionDump(uint64_t base, uint64_t bus, uint64_t dev, uint64_t fun) {
} // namespace
PciReader::PciReader() {
dbgln("Creating PCI obj");
uint64_t vmmo_cap, vmmo_size;
check(ZTempPcieConfigObjectCreate(&vmmo_cap, &vmmo_size));
dbgln("Creating addr space");
uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
dbgln("Addr %lx", vaddr);
dbgln("Dumping PCI");
PciDump(vaddr);
dbgln("Done");
header_ = PciHeader(vaddr, 0, 0, 0);
}
uint64_t PciReader::GetAhciPhysical() {
return phys_mem_offset_ + achi_device_offset_;
}
void PciReader::FunctionDump(uint64_t base, uint64_t bus, uint64_t dev,
uint64_t fun) {
PciDeviceHeader* hdr = PciHeader(base, bus, dev, fun);
if (hdr->vendor_id == 0xFFFF) {
return;
@ -43,10 +52,11 @@ void FunctionDump(uint64_t base, uint64_t bus, uint64_t dev, uint64_t fun) {
}
if (hdr->class_code == 0x1) {
dbgln("SATA Device at: %lx", reinterpret_cast<uint64_t>(hdr) - base);
achi_device_offset_ = reinterpret_cast<uint64_t>(hdr) - base;
}
}
void DeviceDump(uint64_t base, uint64_t bus, uint64_t dev) {
void PciReader::DeviceDump(uint64_t base, uint64_t bus, uint64_t dev) {
PciDeviceHeader* hdr = PciHeader(base, bus, dev, 0);
if (hdr->vendor_id == 0xFFFF) {
return;
@ -62,13 +72,13 @@ void DeviceDump(uint64_t base, uint64_t bus, uint64_t dev) {
}
}
void BusDump(uint64_t base, uint64_t bus) {
void PciReader::BusDump(uint64_t base, uint64_t bus) {
for (uint64_t dev = 0; dev < 0x20; dev++) {
DeviceDump(base, bus, dev);
}
}
void PciDump(uint64_t base) {
void PciReader::PciDump(uint64_t base) {
PciDeviceHeader* hdr = PciHeader(base, 0, 0, 0);
if ((hdr->header_type & 0x80) == 0) {
// Single bus system.
@ -82,20 +92,3 @@ void PciDump(uint64_t base) {
}
}
}
} // namespace
void DumpPciEDevices() {
dbgln("Creating PCI obj");
uint64_t vmmo_cap, vmmo_size;
check(ZTempPcieConfigObjectCreate(&vmmo_cap, &vmmo_size));
dbgln("Creating addr space");
uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
dbgln("Addr %lx", vaddr);
dbgln("Dumping PCI");
PciDump(vaddr);
dbgln("Done");
}

View file

@ -1,3 +1,37 @@
#pragma once
void DumpPciEDevices();
#include <stdint.h>
struct PciDeviceHeader {
uint16_t vendor_id;
uint16_t device_id;
uint16_t command_reg;
uint16_t status_reg;
uint8_t revision;
uint8_t prog_interface;
uint8_t subclass;
uint8_t class_code;
uint8_t cache_line_size;
uint8_t latency_timer;
uint8_t header_type;
uint8_t bist;
} __attribute__((packed));
class PciReader {
public:
PciReader();
uint64_t GetAhciPhysical();
private:
PciDeviceHeader* header_;
// FIXME: Don't hardcode this (It is available from ACPI).
uint64_t phys_mem_offset_ = 0xB000'0000;
uint64_t achi_device_offset_ = 0;
void PciDump(uint64_t vaddr);
void BusDump(uint64_t base, uint64_t bus);
void DeviceDump(uint64_t base, uint64_t bus, uint64_t dev);
void FunctionDump(uint64_t base, uint64_t bus, uint64_t dev, uint64_t fun);
};

View file

@ -2,11 +2,15 @@
#include <stdint.h>
const uint64_t kYellowstoneGetAhci = 0x01;
const uint64_t kYellowstoneGetRegistration = 0x02;
const uint64_t kYellowstoneGetRegistration = 0x01;
const uint64_t kYellowstoneGetAhci = 0x02;
struct YellowstoneGetReq {
uint64_t type;
};
struct YellowstoneGetRegistrationResp {};
struct YellowstoneGetAhciResp {
uint64_t type;
uint64_t ahci_phys_offset;
};

View file

@ -15,7 +15,6 @@ uint64_t main(uint64_t port_cap) {
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread server_thread = server->RunServer();
Thread registration_thread = server->RunRegistration();
DumpPciEDevices();
uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));

View file

@ -57,9 +57,15 @@ void YellowstoneServer::ServerThread() {
YellowstoneGetReq* req =
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
switch (req->type) {
case kYellowstoneGetAhci:
case kYellowstoneGetAhci: {
dbgln("Yellowstone::GetAHCI");
YellowstoneGetAhciResp resp{
.type = kYellowstoneGetAhci,
.ahci_phys_offset = pci_reader_.GetAhciPhysical(),
};
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 0, nullptr));
break;
}
case kYellowstoneGetRegistration: {
dbgln("Yellowstone::GetRegistration");
auto client_or = register_port_.CreateClient();

View file

@ -6,6 +6,8 @@
#include <mammoth/port_server.h>
#include <mammoth/thread.h>
#include "hw/pcie.h"
class YellowstoneServer {
public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
@ -30,5 +32,7 @@ class YellowstoneServer {
z_cap_t denali_cap_ = 0;
z_cap_t victoria_falls_cap_ = 0;
PciReader pci_reader_;
YellowstoneServer(glcr::UniquePtr<EndpointServer> server, PortServer port);
};