[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

@ -67,3 +67,13 @@ uint64_t MemoryObject::PageNumberToPhysAddr(uint64_t page_num) {
}
return *iter;
}
glcr::ErrorOr<glcr::RefPtr<MemoryObject>> FixedMemoryObject::Duplicate(
uint64_t offset, uint64_t length) {
if (offset + length > size()) {
return glcr::INVALID_ARGUMENT;
}
return glcr::StaticCastRefPtr<MemoryObject>(
glcr::MakeRefCounted<FixedMemoryObject>(physical_addr_ + offset, length));
}

View file

@ -1,6 +1,8 @@
#pragma once
#include <glacier/container/linked_list.h>
#include <glacier/memory/ref_ptr.h>
#include <glacier/status/error_or.h>
#include "object/kernel_object.h"
@ -28,6 +30,11 @@ class MemoryObject : public KernelObject {
void CopyBytesToObject(uint64_t source, uint64_t length);
virtual glcr::ErrorOr<glcr::RefPtr<MemoryObject>> Duplicate(uint64_t offset,
uint64_t length) {
return glcr::UNIMPLEMENTED;
}
protected:
// Hacky to avoid linked_list creation.
MemoryObject(uint64_t size, bool) : size_(size) {}
@ -47,6 +54,9 @@ class FixedMemoryObject : public MemoryObject {
FixedMemoryObject(uint64_t physical_addr, uint64_t size)
: MemoryObject(size, true), physical_addr_(physical_addr) {}
virtual glcr::ErrorOr<glcr::RefPtr<MemoryObject>> Duplicate(
uint64_t offset, uint64_t length) override;
private:
uint64_t physical_addr_;