[zion] Add a method for duplicating and scoping down VMMOs.

Use the AHCI section of the PCI config as an example POC of this.

We can now pass a memory capability instead of just the physical
address.
This commit is contained in:
Drew Galbraith 2023-08-01 17:46:26 -07:00
parent 8f84f8c3ca
commit 48c6e5b3a4
12 changed files with 62 additions and 18 deletions

View file

@ -27,8 +27,11 @@ PciReader::PciReader() {
header_ = PciHeader(vaddr, 0, 0, 0);
}
uint64_t PciReader::GetAhciPhysical() {
return phys_mem_offset_ + achi_device_offset_;
z_cap_t PciReader::GetAhciVmmo() {
uint64_t new_cap;
check(ZMemoryObjectDuplicate(gBootPciVmmoCap, achi_device_offset_,
kPcieConfigurationSize, &new_cap));
return new_cap;
}
void PciReader::FunctionDump(uint64_t base, uint64_t bus, uint64_t dev,

View file

@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <ztypes.h>
struct PciDeviceHeader {
uint16_t vendor_id;
@ -17,16 +18,19 @@ struct PciDeviceHeader {
uint8_t bist;
} __attribute__((packed));
// TODO: Figure out if it safe to hardcode this.
// For the memory mapped access to PCI, it may be true that
// each configuration item is always the size of a single page.
const uint64_t kPcieConfigurationSize = 0x1000;
class PciReader {
public:
PciReader();
uint64_t GetAhciPhysical();
z_cap_t GetAhciVmmo();
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;

View file

@ -13,7 +13,7 @@ struct YellowstoneGetReq {
struct YellowstoneGetRegistrationResp {};
struct YellowstoneGetAhciResp {
uint64_t type;
uint64_t ahci_phys_offset;
uint64_t ahci_length;
};
// Has a denali cap attached.

View file

@ -4,12 +4,6 @@
#include "include/yellowstone.h"
namespace {
const uint64_t kPciSize = 0x1000;
} // namespace
YellowstoneStub::YellowstoneStub(z_cap_t yellowstone_cap)
: yellowstone_stub_(EndpointClient::AdoptEndpoint(yellowstone_cap)) {}
@ -18,10 +12,10 @@ glcr::ErrorOr<MappedMemoryRegion> YellowstoneStub::GetAhciConfig() {
.type = kYellowstoneGetAhci,
};
ASSIGN_OR_RETURN(
YellowstoneGetAhciResp resp,
(yellowstone_stub_
->CallEndpoint<YellowstoneGetReq, YellowstoneGetAhciResp>(req)));
return MappedMemoryRegion::DirectPhysical(resp.ahci_phys_offset, kPciSize);
auto resp_cap_pair,
(yellowstone_stub_->CallEndpointGetCap<YellowstoneGetReq,
YellowstoneGetAhciResp>(req)));
return MappedMemoryRegion::FromCapability(resp_cap_pair.second());
}
glcr::ErrorOr<ScopedDenaliClient> YellowstoneStub::GetDenali() {

View file

@ -8,6 +8,7 @@
#include <stdlib.h>
#include "hw/gpt.h"
#include "hw/pcie.h"
#include "include/yellowstone.h"
namespace {
@ -55,9 +56,11 @@ glcr::ErrorCode YellowstoneServer::HandleRequest(RequestContext& request,
dbgln("Yellowstone::GetAHCI");
YellowstoneGetAhciResp resp{
.type = kYellowstoneGetAhci,
.ahci_phys_offset = pci_reader_.GetAhciPhysical(),
.ahci_length = kPcieConfigurationSize,
};
RET_ERR(response.WriteStruct<YellowstoneGetAhciResp>(resp));
z_cap_t vmmo_cap = pci_reader_.GetAhciVmmo();
RET_ERR(
response.WriteStructWithCap<YellowstoneGetAhciResp>(resp, vmmo_cap));
break;
}
case kYellowstoneGetRegistration: {