2023-06-12 23:24:05 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-06-19 22:57:08 -07:00
|
|
|
#include <ztypes.h>
|
2023-06-12 23:24:05 -07:00
|
|
|
|
2023-11-22 14:59:41 -08:00
|
|
|
namespace mmth {
|
2023-11-19 17:54:28 -08:00
|
|
|
/*
|
|
|
|
* Memory Region class that unmaps its memory and releases its
|
|
|
|
* capability when it goes out of scope.
|
|
|
|
*/
|
|
|
|
class OwnedMemoryRegion {
|
|
|
|
public:
|
|
|
|
OwnedMemoryRegion() = default;
|
|
|
|
|
|
|
|
OwnedMemoryRegion(const OwnedMemoryRegion&) = delete;
|
|
|
|
OwnedMemoryRegion& operator=(const OwnedMemoryRegion&) = delete;
|
|
|
|
|
|
|
|
OwnedMemoryRegion(OwnedMemoryRegion&&);
|
|
|
|
OwnedMemoryRegion& operator=(OwnedMemoryRegion&&);
|
|
|
|
|
|
|
|
~OwnedMemoryRegion();
|
|
|
|
|
|
|
|
static OwnedMemoryRegion FromCapability(z_cap_t vmmo_cap);
|
2023-11-19 20:42:38 -08:00
|
|
|
// TODO: Consider making this its own class.
|
|
|
|
static OwnedMemoryRegion ContiguousPhysical(uint64_t size, uint64_t* paddr);
|
2023-11-19 20:48:23 -08:00
|
|
|
static OwnedMemoryRegion DirectPhysical(uint64_t paddr, uint64_t size);
|
2023-11-19 17:54:28 -08:00
|
|
|
|
|
|
|
uint64_t vaddr() { return vaddr_; }
|
|
|
|
uint64_t size() { return size_; }
|
|
|
|
|
2023-11-19 20:35:55 -08:00
|
|
|
z_cap_t cap() { return vmmo_cap_; }
|
|
|
|
z_cap_t DuplicateCap();
|
2023-11-19 17:54:28 -08:00
|
|
|
|
|
|
|
bool empty() { return vmmo_cap_ != 0; }
|
|
|
|
explicit operator bool() { return vmmo_cap_ != 0; }
|
|
|
|
|
|
|
|
private:
|
2023-11-19 19:03:20 -08:00
|
|
|
OwnedMemoryRegion(uint64_t vmmo_cap, uint64_t vaddr, uint64_t size)
|
|
|
|
: vmmo_cap_(vmmo_cap), vaddr_(vaddr), size_(size) {}
|
2023-11-19 17:54:28 -08:00
|
|
|
uint64_t vmmo_cap_ = 0;
|
|
|
|
uint64_t vaddr_ = 0;
|
2023-11-19 20:48:23 -08:00
|
|
|
// TODO: We may want to differentiate between VMMO size and mapped size?
|
2023-11-19 17:54:28 -08:00
|
|
|
uint64_t size_ = 0;
|
|
|
|
};
|
2023-11-22 14:59:41 -08:00
|
|
|
|
|
|
|
} // namespace mmth
|