2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2019-10-13 10:04:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-21 08:16:57 +01:00
|
|
|
#include "KMemory.h"
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
namespace skyline::kernel::type {
|
|
|
|
/**
|
|
|
|
* @brief KTransferMemory is used to hold a particular amount of transferable memory
|
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
class KTransferMemory : public KMemory {
|
|
|
|
private:
|
|
|
|
ChunkDescriptor hostChunk{};
|
2019-10-13 10:04:47 +02:00
|
|
|
public:
|
2020-01-21 08:16:57 +01:00
|
|
|
bool host; //!< If the memory is mapped on the host or the guest
|
|
|
|
u64 address; //!< The current address of the allocated memory for the kernel
|
|
|
|
size_t size; //!< The current size of the allocated memory
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The state of the device
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param host If to map the memory on host or guest
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param address The address to map to (If NULL an arbitrary address is picked)
|
|
|
|
* @param size The size of the allocation
|
|
|
|
* @param permission The permissions of the memory
|
|
|
|
* @param type The type of the memory
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param memState The MemoryState of the chunk of memory
|
2019-10-13 10:04:47 +02:00
|
|
|
*/
|
2020-03-25 18:59:37 +01:00
|
|
|
KTransferMemory(const DeviceState &state, bool host, u64 address, size_t size, const memory::Permission permission, memory::MemoryState memState = memory::states::TransferMemory);
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Transfers this piece of memory to another process
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param host If to transfer memory to host or guest
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param address The address to map to (If NULL an arbitrary address is picked)
|
|
|
|
* @param size The amount of shared memory to map
|
|
|
|
* @return The address of the allocation
|
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
u64 Transfer(bool host, u64 address, u64 size = 0);
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief Remap a chunk of memory as to change the size occupied by it
|
|
|
|
* @param size The new size of the memory
|
|
|
|
* @return The address the memory was remapped to
|
2019-10-13 10:04:47 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
virtual void Resize(size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the permissions of a block of mapped memory
|
|
|
|
* @param address The starting address to change the permissions at
|
|
|
|
* @param size The size of the partition to change the permissions of
|
|
|
|
* @param permission The new permissions to be set for the memory
|
|
|
|
*/
|
|
|
|
virtual void UpdatePermission(const u64 address, const u64 size, memory::Permission permission);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the permissions of a chunk of mapped memory
|
|
|
|
* @param permission The new permissions to be set for the memory
|
|
|
|
*/
|
|
|
|
inline virtual void UpdatePermission(memory::Permission permission) {
|
|
|
|
UpdatePermission(address, size, permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Checks if the specified address is within the memory object
|
|
|
|
* @param address The address to check
|
|
|
|
* @return If the address is inside the memory object
|
|
|
|
*/
|
|
|
|
inline virtual bool IsInside(u64 address) {
|
|
|
|
return (this->address <= address) && ((this->address + this->size) > address);
|
|
|
|
}
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
* @brief The destructor of private memory, it deallocates the memory
|
2019-10-13 10:04:47 +02:00
|
|
|
*/
|
|
|
|
~KTransferMemory();
|
|
|
|
};
|
|
|
|
}
|