2014-04-09 01:15:46 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-09 01:15:46 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2013-09-06 00:33:46 +02:00
|
|
|
|
2018-11-06 21:00:47 +01:00
|
|
|
#include <optional>
|
|
|
|
#include <boost/icl/interval_set.hpp>
|
2014-04-09 02:15:08 +02:00
|
|
|
#include "common/common_types.h"
|
2015-08-06 02:26:52 +02:00
|
|
|
|
2015-07-10 03:52:15 +02:00
|
|
|
namespace Kernel {
|
2015-08-06 02:26:52 +02:00
|
|
|
|
2018-10-26 03:07:15 +02:00
|
|
|
struct AddressMapping;
|
2015-07-10 03:52:15 +02:00
|
|
|
class VMManager;
|
2015-08-06 02:26:52 +02:00
|
|
|
|
|
|
|
struct MemoryRegionInfo {
|
|
|
|
u32 base; // Not an address, but offset from start of FCRAM
|
|
|
|
u32 size;
|
2015-11-27 04:00:16 +01:00
|
|
|
u32 used;
|
2015-08-06 02:26:52 +02:00
|
|
|
|
2018-11-06 21:00:47 +01:00
|
|
|
// The domain of the interval_set are offsets from start of FCRAM
|
|
|
|
using IntervalSet = boost::icl::interval_set<u32>;
|
|
|
|
using Interval = IntervalSet::interval_type;
|
|
|
|
|
|
|
|
IntervalSet free_blocks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the allocator state
|
|
|
|
* @param base The base offset the beginning of FCRAM.
|
|
|
|
* @param size The region size this allocator manages
|
|
|
|
*/
|
|
|
|
void Reset(u32 base, u32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates memory from the heap.
|
|
|
|
* @param size The size of memory to allocate.
|
|
|
|
* @returns The set of blocks that make up the allocation request. Empty set if there is no
|
|
|
|
* enough space.
|
|
|
|
*/
|
|
|
|
IntervalSet HeapAllocate(u32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates memory from the linear heap with specific address and size.
|
|
|
|
* @param offset the address offset to the beginning of FCRAM.
|
|
|
|
* @param size size of the memory to allocate.
|
|
|
|
* @returns true if the allocation is successful. false if the requested region is not free.
|
|
|
|
*/
|
|
|
|
bool LinearAllocate(u32 offset, u32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates memory from the linear heap with only size specified.
|
|
|
|
* @param size size of the memory to allocate.
|
|
|
|
* @returns the address offset to the beginning of FCRAM; null if there is no enough space
|
|
|
|
*/
|
|
|
|
std::optional<u32> LinearAllocate(u32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Frees one segment of memory. The memory must have been allocated as heap or linear heap.
|
|
|
|
* @param offset the region address offset to the beginning of FCRAM.
|
|
|
|
* @param size the size of the region to free.
|
|
|
|
*/
|
|
|
|
void Free(u32 offset, u32 size);
|
2019-08-11 01:20:09 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar, const unsigned int file_version)
|
|
|
|
{
|
|
|
|
ar & base;
|
|
|
|
ar & size;
|
|
|
|
ar & used;
|
|
|
|
// TODO: boost icl / free_blocks
|
|
|
|
}
|
2015-08-06 02:26:52 +02:00
|
|
|
};
|
|
|
|
|
2017-05-06 08:11:06 +02:00
|
|
|
} // namespace Kernel
|