core/memory: Create a special MapMemoryRegion for physical memory.
This allows us to create a fastmem arena within the memory.cpp helpers.
This commit is contained in:
		| @@ -14,6 +14,9 @@ namespace Kernel { | |||||||
| // - Second to ensure all host backing memory used is aligned to 256 bytes due | // - Second to ensure all host backing memory used is aligned to 256 bytes due | ||||||
| // to strict alignment restrictions on GPU memory. | // to strict alignment restrictions on GPU memory. | ||||||
|  |  | ||||||
| using PhysicalMemory = std::vector<u8, Common::AlignmentAllocator<u8, 256>>; | using PhysicalMemoryVector = std::vector<u8, Common::AlignmentAllocator<u8, 256>>; | ||||||
|  | class PhysicalMemory final : public PhysicalMemoryVector { | ||||||
|  |     using PhysicalMemoryVector::PhysicalMemoryVector; | ||||||
|  | }; | ||||||
|  |  | ||||||
| } // namespace Kernel | } // namespace Kernel | ||||||
|   | |||||||
| @@ -780,8 +780,7 @@ void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) { | |||||||
|         memory.UnmapRegion(page_table, vma.base, vma.size); |         memory.UnmapRegion(page_table, vma.base, vma.size); | ||||||
|         break; |         break; | ||||||
|     case VMAType::AllocatedMemoryBlock: |     case VMAType::AllocatedMemoryBlock: | ||||||
|         memory.MapMemoryRegion(page_table, vma.base, vma.size, |         memory.MapMemoryRegion(page_table, vma.base, vma.size, *vma.backing_block, vma.offset); | ||||||
|                                vma.backing_block->data() + vma.offset); |  | ||||||
|         break; |         break; | ||||||
|     case VMAType::BackingMemory: |     case VMAType::BackingMemory: | ||||||
|         memory.MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory); |         memory.MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory); | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ | |||||||
| #include "common/swap.h" | #include "common/swap.h" | ||||||
| #include "core/arm/arm_interface.h" | #include "core/arm/arm_interface.h" | ||||||
| #include "core/core.h" | #include "core/core.h" | ||||||
|  | #include "core/hle/kernel/physical_memory.h" | ||||||
| #include "core/hle/kernel/process.h" | #include "core/hle/kernel/process.h" | ||||||
| #include "core/hle/kernel/vm_manager.h" | #include "core/hle/kernel/vm_manager.h" | ||||||
| #include "core/memory.h" | #include "core/memory.h" | ||||||
| @@ -38,6 +39,11 @@ struct Memory::Impl { | |||||||
|         system.ArmInterface(3).PageTableChanged(*current_page_table, address_space_width); |         system.ArmInterface(3).PageTableChanged(*current_page_table, address_space_width); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, | ||||||
|  |                          Kernel::PhysicalMemory& memory, VAddr offset) { | ||||||
|  |         MapMemoryRegion(page_table, base, size, memory.data() + offset); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { |     void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { | ||||||
|         ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size); |         ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size); | ||||||
|         ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base); |         ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base); | ||||||
| @@ -601,6 +607,11 @@ void Memory::SetCurrentPageTable(Kernel::Process& process) { | |||||||
|     impl->SetCurrentPageTable(process); |     impl->SetCurrentPageTable(process); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, | ||||||
|  |                              Kernel::PhysicalMemory& memory, VAddr offset) { | ||||||
|  |     impl->MapMemoryRegion(page_table, base, size, memory, offset); | ||||||
|  | } | ||||||
|  |  | ||||||
| void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { | void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { | ||||||
|     impl->MapMemoryRegion(page_table, base, size, target); |     impl->MapMemoryRegion(page_table, base, size, target); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,8 +19,9 @@ class System; | |||||||
| } | } | ||||||
|  |  | ||||||
| namespace Kernel { | namespace Kernel { | ||||||
|  | class PhysicalMemory; | ||||||
| class Process; | class Process; | ||||||
| } | } // namespace Kernel | ||||||
|  |  | ||||||
| namespace Memory { | namespace Memory { | ||||||
|  |  | ||||||
| @@ -65,6 +66,19 @@ public: | |||||||
|      */ |      */ | ||||||
|     void SetCurrentPageTable(Kernel::Process& process); |     void SetCurrentPageTable(Kernel::Process& process); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Maps an physical buffer onto a region of the emulated process address space. | ||||||
|  |      * | ||||||
|  |      * @param page_table The page table of the emulated process. | ||||||
|  |      * @param base       The address to start mapping at. Must be page-aligned. | ||||||
|  |      * @param size       The amount of bytes to map. Must be page-aligned. | ||||||
|  |      * @param memory     Physical buffer with the memory backing the mapping. Must be of length | ||||||
|  |      *                   at least `size + offset`. | ||||||
|  |      * @param offset     The offset within the physical memory. Must be page-aligned. | ||||||
|  |      */ | ||||||
|  |     void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, | ||||||
|  |                          Kernel::PhysicalMemory& memory, VAddr offset); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Maps an allocated buffer onto a region of the emulated process address space. |      * Maps an allocated buffer onto a region of the emulated process address space. | ||||||
|      * |      * | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user