[Mammoth] Get rid of last uses of MappedMemoryRegion.
This commit is contained in:
parent
d41a565721
commit
344e84c313
|
@ -3,34 +3,6 @@
|
|||
#include <stdint.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
class MappedMemoryRegion {
|
||||
public:
|
||||
// FIXME: Introduce optional type to contain error or.
|
||||
static MappedMemoryRegion DirectPhysical(uint64_t phys_addr, uint64_t size);
|
||||
static MappedMemoryRegion Default(uint64_t size);
|
||||
|
||||
MappedMemoryRegion() {}
|
||||
// TODO: Disallow copy before doing any cleanup here.
|
||||
~MappedMemoryRegion() {}
|
||||
|
||||
uint64_t paddr() { return paddr_; }
|
||||
uint64_t vaddr() { return vaddr_; }
|
||||
uint64_t size() { return size_; }
|
||||
|
||||
uint64_t cap() { return vmmo_cap_; }
|
||||
|
||||
operator bool() { return vmmo_cap_ != 0; }
|
||||
|
||||
private:
|
||||
MappedMemoryRegion(uint64_t vmmo_cap, uint64_t paddr, uint64_t vaddr,
|
||||
uint64_t size)
|
||||
: vmmo_cap_(vmmo_cap), paddr_(paddr), vaddr_(vaddr), size_(size) {}
|
||||
uint64_t vmmo_cap_ = 0;
|
||||
uint64_t paddr_ = 0;
|
||||
uint64_t vaddr_ = 0;
|
||||
uint64_t size_ = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
* Memory Region class that unmaps its memory and releases its
|
||||
* capability when it goes out of scope.
|
||||
|
@ -50,6 +22,7 @@ class OwnedMemoryRegion {
|
|||
static OwnedMemoryRegion FromCapability(z_cap_t vmmo_cap);
|
||||
// TODO: Consider making this its own class.
|
||||
static OwnedMemoryRegion ContiguousPhysical(uint64_t size, uint64_t* paddr);
|
||||
static OwnedMemoryRegion DirectPhysical(uint64_t paddr, uint64_t size);
|
||||
|
||||
uint64_t vaddr() { return vaddr_; }
|
||||
uint64_t size() { return size_; }
|
||||
|
@ -65,5 +38,6 @@ class OwnedMemoryRegion {
|
|||
: vmmo_cap_(vmmo_cap), vaddr_(vaddr), size_(size) {}
|
||||
uint64_t vmmo_cap_ = 0;
|
||||
uint64_t vaddr_ = 0;
|
||||
// TODO: We may want to differentiate between VMMO size and mapped size?
|
||||
uint64_t size_ = 0;
|
||||
};
|
||||
|
|
|
@ -5,27 +5,6 @@
|
|||
#include "mammoth/debug.h"
|
||||
#include "mammoth/init.h"
|
||||
|
||||
MappedMemoryRegion MappedMemoryRegion::DirectPhysical(uint64_t paddr,
|
||||
uint64_t size) {
|
||||
uint64_t vmmo_cap;
|
||||
check(ZMemoryObjectCreatePhysical(paddr, size, &vmmo_cap));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
|
||||
return MappedMemoryRegion(vmmo_cap, paddr, vaddr, size);
|
||||
}
|
||||
|
||||
MappedMemoryRegion MappedMemoryRegion::Default(uint64_t size) {
|
||||
uint64_t vmmo_cap;
|
||||
check(ZMemoryObjectCreate(size, &vmmo_cap));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
|
||||
return MappedMemoryRegion(vmmo_cap, 0, vaddr, size);
|
||||
}
|
||||
|
||||
OwnedMemoryRegion::OwnedMemoryRegion(OwnedMemoryRegion&& other)
|
||||
: OwnedMemoryRegion(other.vmmo_cap_, other.vaddr_, other.size_) {
|
||||
other.vmmo_cap_ = 0;
|
||||
|
@ -74,6 +53,16 @@ OwnedMemoryRegion OwnedMemoryRegion::ContiguousPhysical(uint64_t size,
|
|||
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
||||
}
|
||||
|
||||
OwnedMemoryRegion OwnedMemoryRegion::DirectPhysical(uint64_t paddr,
|
||||
uint64_t size) {
|
||||
uint64_t vmmo_cap;
|
||||
check(ZMemoryObjectCreatePhysical(paddr, size, &vmmo_cap));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
||||
}
|
||||
|
||||
z_cap_t OwnedMemoryRegion::DuplicateCap() {
|
||||
z_cap_t cap;
|
||||
check(ZCapDuplicate(vmmo_cap_, kZionPerm_All, &cap));
|
||||
|
|
|
@ -192,7 +192,7 @@ glcr::ErrorCode AhciDriver::RegisterIrq() {
|
|||
|
||||
glcr::ErrorCode AhciDriver::LoadHbaRegisters() {
|
||||
ahci_region_ =
|
||||
MappedMemoryRegion::DirectPhysical(pci_device_header_->abar, 0x1100);
|
||||
OwnedMemoryRegion ::DirectPhysical(pci_device_header_->abar, 0x1100);
|
||||
ahci_hba_ = reinterpret_cast<AhciHba*>(ahci_region_.vaddr());
|
||||
num_ports_ = (ahci_hba_->capabilities & 0x1F) + 1;
|
||||
num_commands_ = ((ahci_hba_->capabilities & 0x1F00) >> 8) + 1;
|
||||
|
|
|
@ -24,7 +24,7 @@ class AhciDriver {
|
|||
private:
|
||||
OwnedMemoryRegion pci_region_;
|
||||
PciDeviceHeader* pci_device_header_ = nullptr;
|
||||
MappedMemoryRegion ahci_region_;
|
||||
OwnedMemoryRegion ahci_region_;
|
||||
AhciHba* ahci_hba_ = nullptr;
|
||||
|
||||
// TODO: Allocate these dynamically.
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "framebuffer/framebuffer.h"
|
||||
|
||||
#include <mammoth/memory_region.h>
|
||||
|
||||
Framebuffer::Framebuffer(const FramebufferInfo& info) : fb_info_(info) {
|
||||
uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch();
|
||||
MappedMemoryRegion region = MappedMemoryRegion::DirectPhysical(
|
||||
fb_info_.address_phys(), buff_size_bytes);
|
||||
fb_ = reinterpret_cast<uint32_t*>(region.vaddr());
|
||||
fb_memory_ = OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(),
|
||||
buff_size_bytes);
|
||||
fb_ = reinterpret_cast<uint32_t*>(fb_memory_.vaddr());
|
||||
}
|
||||
|
||||
void Framebuffer::DrawPixel(uint32_t row, uint32_t col, uint32_t pixel) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <mammoth/memory_region.h>
|
||||
#include <yellowstone/yellowstone.yunq.h>
|
||||
|
||||
class Framebuffer {
|
||||
|
@ -12,5 +13,7 @@ class Framebuffer {
|
|||
// FIXME: Implement Yunq copy or move so we
|
||||
// don't have to store a reference here.
|
||||
const FramebufferInfo& fb_info_;
|
||||
|
||||
OwnedMemoryRegion fb_memory_;
|
||||
uint32_t* fb_;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue