2020-12-05 13:08:24 +01:00
|
|
|
#pragma once
|
2014-06-25 00:38:34 +02:00
|
|
|
|
2017-01-29 17:50:18 +01:00
|
|
|
#include "sys_sync.h"
|
2018-09-26 00:14:10 +02:00
|
|
|
|
2018-09-25 22:34:45 +02:00
|
|
|
#include "Emu/Memory/vm_ptr.h"
|
2020-12-12 12:24:01 +01:00
|
|
|
#include "Emu/Cell/ErrorCodes.h"
|
2015-06-19 17:49:38 +02:00
|
|
|
|
2018-09-26 00:14:10 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-05-07 20:57:06 +02:00
|
|
|
struct lv2_memory_container;
|
2017-10-08 22:37:54 +02:00
|
|
|
|
2020-11-07 23:56:35 +01:00
|
|
|
namespace utils
|
|
|
|
|
{
|
|
|
|
|
class shm;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 17:50:18 +01:00
|
|
|
struct lv2_memory : lv2_obj
|
2014-06-25 00:38:34 +02:00
|
|
|
{
|
2017-01-25 18:50:30 +01:00
|
|
|
static const u32 id_base = 0x08000000;
|
|
|
|
|
|
2016-05-25 20:04:08 +02:00
|
|
|
const u32 size; // Memory size
|
|
|
|
|
const u32 align; // Alignment required
|
2015-07-10 16:45:16 +02:00
|
|
|
const u64 flags;
|
2019-09-17 22:46:07 +02:00
|
|
|
lv2_memory_container* const ct; // Associated memory container
|
2018-05-07 20:57:06 +02:00
|
|
|
const std::shared_ptr<utils::shm> shm;
|
2016-04-27 00:27:24 +02:00
|
|
|
|
2018-05-07 20:57:06 +02:00
|
|
|
atomic_t<u32> counter{0};
|
2014-06-25 00:38:34 +02:00
|
|
|
|
2019-09-17 22:46:07 +02:00
|
|
|
lv2_memory(u32 size, u32 align, u64 flags, lv2_memory_container* ct);
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
2017-10-08 22:37:54 +02:00
|
|
|
enum : u64
|
|
|
|
|
{
|
|
|
|
|
SYS_MEMORY_PAGE_FAULT_EVENT_KEY = 0xfffe000000000000ULL,
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-02 17:07:52 +01:00
|
|
|
enum : u64
|
|
|
|
|
{
|
|
|
|
|
SYS_MMAPPER_NO_SHM_KEY = 0xffff000000000000ull, // Unofficial name
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-23 17:49:01 +02:00
|
|
|
enum : u64
|
2017-10-08 22:37:54 +02:00
|
|
|
{
|
2018-10-23 17:49:01 +02:00
|
|
|
SYS_MEMORY_PAGE_FAULT_CAUSE_NON_MAPPED = 0x2ULL,
|
|
|
|
|
SYS_MEMORY_PAGE_FAULT_CAUSE_READ_ONLY = 0x1ULL,
|
|
|
|
|
SYS_MEMORY_PAGE_FAULT_TYPE_PPU_THREAD = 0x0ULL,
|
|
|
|
|
SYS_MEMORY_PAGE_FAULT_TYPE_SPU_THREAD = 0x1ULL,
|
|
|
|
|
SYS_MEMORY_PAGE_FAULT_TYPE_RAW_SPU = 0x2ULL,
|
2017-10-08 22:37:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct page_fault_notification_entry
|
|
|
|
|
{
|
|
|
|
|
u32 start_addr; // Starting address of region to monitor.
|
|
|
|
|
u32 event_queue_id; // Queue to be notified.
|
|
|
|
|
u32 port_id; // Port used to notify the queue.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Used to hold list of queues to be notified on page fault event.
|
|
|
|
|
struct page_fault_notification_entries
|
|
|
|
|
{
|
2018-05-07 20:57:06 +02:00
|
|
|
std::vector<page_fault_notification_entry> entries;
|
2019-02-17 16:53:38 +01:00
|
|
|
shared_mutex mutex;
|
2017-10-08 22:37:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct page_fault_event_entries
|
|
|
|
|
{
|
2020-05-21 18:47:47 +02:00
|
|
|
// First = thread, second = addr
|
|
|
|
|
std::unordered_map<class cpu_thread*, u32> events;
|
2018-11-26 16:55:22 +01:00
|
|
|
shared_mutex pf_mutex;
|
2017-10-08 22:37:54 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-02 17:07:52 +01:00
|
|
|
struct mmapper_unk_entry_struct0
|
|
|
|
|
{
|
|
|
|
|
be_t<u32> a; // 0x0
|
|
|
|
|
be_t<u32> b; // 0x4
|
|
|
|
|
be_t<u32> c; // 0x8
|
|
|
|
|
be_t<u32> d; // 0xc
|
|
|
|
|
be_t<u64> type; // 0x10
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-14 16:48:51 +02:00
|
|
|
// Aux
|
|
|
|
|
class ppu_thread;
|
|
|
|
|
|
2020-05-21 18:47:47 +02:00
|
|
|
error_code mmapper_thread_recover_page_fault(cpu_thread* cpu);
|
2019-02-17 16:53:38 +01:00
|
|
|
|
2014-06-25 00:38:34 +02:00
|
|
|
// SysCalls
|
2019-07-14 16:48:51 +02:00
|
|
|
error_code sys_mmapper_allocate_address(ppu_thread&, u64 size, u64 flags, u64 alignment, vm::ptr<u32> alloc_addr);
|
|
|
|
|
error_code sys_mmapper_allocate_fixed_address(ppu_thread&);
|
2020-09-26 19:06:06 +02:00
|
|
|
error_code sys_mmapper_allocate_shared_memory(ppu_thread&, u64 ipc_key, u64 size, u64 flags, vm::ptr<u32> mem_id);
|
|
|
|
|
error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread&, u64 ipc_key, u64 size, u32 cid, u64 flags, vm::ptr<u32> mem_id);
|
|
|
|
|
error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread&, u64 ipc_key, u64 size, u32 flags, vm::ptr<mmapper_unk_entry_struct0> src, s32 count, vm::ptr<u32> mem_id);
|
|
|
|
|
error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread&, u64 ipc_key, u64 size, u64 flags, u32 mc_id, vm::ptr<mmapper_unk_entry_struct0> entries, s32 entry_count, vm::ptr<u32> mem_id);
|
2019-07-14 16:48:51 +02:00
|
|
|
error_code sys_mmapper_change_address_access_right(ppu_thread&, u32 addr, u64 flags);
|
|
|
|
|
error_code sys_mmapper_free_address(ppu_thread&, u32 addr);
|
|
|
|
|
error_code sys_mmapper_free_shared_memory(ppu_thread&, u32 mem_id);
|
|
|
|
|
error_code sys_mmapper_map_shared_memory(ppu_thread&, u32 addr, u32 mem_id, u64 flags);
|
|
|
|
|
error_code sys_mmapper_search_and_map(ppu_thread&, u32 start_addr, u32 mem_id, u64 flags, vm::ptr<u32> alloc_addr);
|
|
|
|
|
error_code sys_mmapper_unmap_shared_memory(ppu_thread&, u32 addr, vm::ptr<u32> mem_id);
|
|
|
|
|
error_code sys_mmapper_enable_page_fault_notification(ppu_thread&, u32 start_addr, u32 event_queue_id);
|