diff options
| author | 2020-04-17 16:33:08 -0400 | |
|---|---|---|
| committer | 2020-04-17 16:33:08 -0400 | |
| commit | b8f5c71f2d7f819821acf036175cce65ab1ae12c (patch) | |
| tree | 151d7ed4e47536dc0e149a7117387b6a502d7da6 /src/core/hle/kernel/kernel.cpp | |
| parent | Merge pull request #3682 from lioncash/uam (diff) | |
| parent | core: hle: Address various feedback & code cleanup. (diff) | |
| download | yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.gz yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.tar.xz yuzu-b8f5c71f2d7f819821acf036175cce65ab1ae12c.zip | |
Merge pull request #3666 from bunnei/new-vmm
Implement a new virtual memory manager
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 122 |
1 files changed, 121 insertions, 1 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 014d647cf..7655382fa 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -18,15 +18,20 @@ | |||
| 18 | #include "core/core.h" | 18 | #include "core/core.h" |
| 19 | #include "core/core_timing.h" | 19 | #include "core/core_timing.h" |
| 20 | #include "core/core_timing_util.h" | 20 | #include "core/core_timing_util.h" |
| 21 | #include "core/device_memory.h" | ||
| 21 | #include "core/hardware_properties.h" | 22 | #include "core/hardware_properties.h" |
| 22 | #include "core/hle/kernel/client_port.h" | 23 | #include "core/hle/kernel/client_port.h" |
| 23 | #include "core/hle/kernel/errors.h" | 24 | #include "core/hle/kernel/errors.h" |
| 24 | #include "core/hle/kernel/handle_table.h" | 25 | #include "core/hle/kernel/handle_table.h" |
| 25 | #include "core/hle/kernel/kernel.h" | 26 | #include "core/hle/kernel/kernel.h" |
| 27 | #include "core/hle/kernel/memory/memory_layout.h" | ||
| 28 | #include "core/hle/kernel/memory/memory_manager.h" | ||
| 29 | #include "core/hle/kernel/memory/slab_heap.h" | ||
| 26 | #include "core/hle/kernel/physical_core.h" | 30 | #include "core/hle/kernel/physical_core.h" |
| 27 | #include "core/hle/kernel/process.h" | 31 | #include "core/hle/kernel/process.h" |
| 28 | #include "core/hle/kernel/resource_limit.h" | 32 | #include "core/hle/kernel/resource_limit.h" |
| 29 | #include "core/hle/kernel/scheduler.h" | 33 | #include "core/hle/kernel/scheduler.h" |
| 34 | #include "core/hle/kernel/shared_memory.h" | ||
| 30 | #include "core/hle/kernel/synchronization.h" | 35 | #include "core/hle/kernel/synchronization.h" |
| 31 | #include "core/hle/kernel/thread.h" | 36 | #include "core/hle/kernel/thread.h" |
| 32 | #include "core/hle/kernel/time_manager.h" | 37 | #include "core/hle/kernel/time_manager.h" |
| @@ -110,6 +115,7 @@ struct KernelCore::Impl { | |||
| 110 | 115 | ||
| 111 | InitializePhysicalCores(); | 116 | InitializePhysicalCores(); |
| 112 | InitializeSystemResourceLimit(kernel); | 117 | InitializeSystemResourceLimit(kernel); |
| 118 | InitializeMemoryLayout(); | ||
| 113 | InitializeThreads(); | 119 | InitializeThreads(); |
| 114 | InitializePreemption(); | 120 | InitializePreemption(); |
| 115 | } | 121 | } |
| @@ -154,12 +160,17 @@ struct KernelCore::Impl { | |||
| 154 | system_resource_limit = ResourceLimit::Create(kernel); | 160 | system_resource_limit = ResourceLimit::Create(kernel); |
| 155 | 161 | ||
| 156 | // If setting the default system values fails, then something seriously wrong has occurred. | 162 | // If setting the default system values fails, then something seriously wrong has occurred. |
| 157 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::PhysicalMemory, 0x200000000) | 163 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::PhysicalMemory, 0x100000000) |
| 158 | .IsSuccess()); | 164 | .IsSuccess()); |
| 159 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Threads, 800).IsSuccess()); | 165 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Threads, 800).IsSuccess()); |
| 160 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Events, 700).IsSuccess()); | 166 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Events, 700).IsSuccess()); |
| 161 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::TransferMemory, 200).IsSuccess()); | 167 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::TransferMemory, 200).IsSuccess()); |
| 162 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Sessions, 900).IsSuccess()); | 168 | ASSERT(system_resource_limit->SetLimitValue(ResourceType::Sessions, 900).IsSuccess()); |
| 169 | |||
| 170 | if (!system_resource_limit->Reserve(ResourceType::PhysicalMemory, 0) || | ||
| 171 | !system_resource_limit->Reserve(ResourceType::PhysicalMemory, 0x60000)) { | ||
| 172 | UNREACHABLE(); | ||
| 173 | } | ||
| 163 | } | 174 | } |
| 164 | 175 | ||
| 165 | void InitializeThreads() { | 176 | void InitializeThreads() { |
| @@ -237,6 +248,57 @@ struct KernelCore::Impl { | |||
| 237 | return result; | 248 | return result; |
| 238 | } | 249 | } |
| 239 | 250 | ||
| 251 | void InitializeMemoryLayout() { | ||
| 252 | // Initialize memory layout | ||
| 253 | constexpr Memory::MemoryLayout layout{Memory::MemoryLayout::GetDefaultLayout()}; | ||
| 254 | constexpr std::size_t hid_size{0x40000}; | ||
| 255 | constexpr std::size_t font_size{0x1100000}; | ||
| 256 | constexpr std::size_t irs_size{0x8000}; | ||
| 257 | constexpr std::size_t time_size{0x1000}; | ||
| 258 | constexpr PAddr hid_addr{layout.System().StartAddress()}; | ||
| 259 | constexpr PAddr font_pa{layout.System().StartAddress() + hid_size}; | ||
| 260 | constexpr PAddr irs_addr{layout.System().StartAddress() + hid_size + font_size}; | ||
| 261 | constexpr PAddr time_addr{layout.System().StartAddress() + hid_size + font_size + irs_size}; | ||
| 262 | |||
| 263 | // Initialize memory manager | ||
| 264 | memory_manager = std::make_unique<Memory::MemoryManager>(); | ||
| 265 | memory_manager->InitializeManager(Memory::MemoryManager::Pool::Application, | ||
| 266 | layout.Application().StartAddress(), | ||
| 267 | layout.Application().EndAddress()); | ||
| 268 | memory_manager->InitializeManager(Memory::MemoryManager::Pool::Applet, | ||
| 269 | layout.Applet().StartAddress(), | ||
| 270 | layout.Applet().EndAddress()); | ||
| 271 | memory_manager->InitializeManager(Memory::MemoryManager::Pool::System, | ||
| 272 | layout.System().StartAddress(), | ||
| 273 | layout.System().EndAddress()); | ||
| 274 | |||
| 275 | hid_shared_mem = Kernel::SharedMemory::Create( | ||
| 276 | system.Kernel(), system.DeviceMemory(), nullptr, | ||
| 277 | {hid_addr, hid_size / Memory::PageSize}, Memory::MemoryPermission::None, | ||
| 278 | Memory::MemoryPermission::Read, hid_addr, hid_size, "HID:SharedMemory"); | ||
| 279 | font_shared_mem = Kernel::SharedMemory::Create( | ||
| 280 | system.Kernel(), system.DeviceMemory(), nullptr, | ||
| 281 | {font_pa, font_size / Memory::PageSize}, Memory::MemoryPermission::None, | ||
| 282 | Memory::MemoryPermission::Read, font_pa, font_size, "Font:SharedMemory"); | ||
| 283 | irs_shared_mem = Kernel::SharedMemory::Create( | ||
| 284 | system.Kernel(), system.DeviceMemory(), nullptr, | ||
| 285 | {irs_addr, irs_size / Memory::PageSize}, Memory::MemoryPermission::None, | ||
| 286 | Memory::MemoryPermission::Read, irs_addr, irs_size, "IRS:SharedMemory"); | ||
| 287 | time_shared_mem = Kernel::SharedMemory::Create( | ||
| 288 | system.Kernel(), system.DeviceMemory(), nullptr, | ||
| 289 | {time_addr, time_size / Memory::PageSize}, Memory::MemoryPermission::None, | ||
| 290 | Memory::MemoryPermission::Read, time_addr, time_size, "Time:SharedMemory"); | ||
| 291 | |||
| 292 | // Allocate slab heaps | ||
| 293 | user_slab_heap_pages = std::make_unique<Memory::SlabHeap<Memory::Page>>(); | ||
| 294 | |||
| 295 | // Initialize slab heaps | ||
| 296 | constexpr u64 user_slab_heap_size{0x3de000}; | ||
| 297 | user_slab_heap_pages->Initialize( | ||
| 298 | system.DeviceMemory().GetPointer(Core::DramMemoryMap::SlabHeapBase), | ||
| 299 | user_slab_heap_size); | ||
| 300 | } | ||
| 301 | |||
| 240 | std::atomic<u32> next_object_id{0}; | 302 | std::atomic<u32> next_object_id{0}; |
| 241 | std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin}; | 303 | std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin}; |
| 242 | std::atomic<u64> next_user_process_id{Process::ProcessIDMin}; | 304 | std::atomic<u64> next_user_process_id{Process::ProcessIDMin}; |
| @@ -271,6 +333,16 @@ struct KernelCore::Impl { | |||
| 271 | std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads; | 333 | std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads; |
| 272 | std::mutex register_thread_mutex; | 334 | std::mutex register_thread_mutex; |
| 273 | 335 | ||
| 336 | // Kernel memory management | ||
| 337 | std::unique_ptr<Memory::MemoryManager> memory_manager; | ||
| 338 | std::unique_ptr<Memory::SlabHeap<Memory::Page>> user_slab_heap_pages; | ||
| 339 | |||
| 340 | // Shared memory for services | ||
| 341 | std::shared_ptr<Kernel::SharedMemory> hid_shared_mem; | ||
| 342 | std::shared_ptr<Kernel::SharedMemory> font_shared_mem; | ||
| 343 | std::shared_ptr<Kernel::SharedMemory> irs_shared_mem; | ||
| 344 | std::shared_ptr<Kernel::SharedMemory> time_shared_mem; | ||
| 345 | |||
| 274 | // System context | 346 | // System context |
| 275 | Core::System& system; | 347 | Core::System& system; |
| 276 | }; | 348 | }; |
| @@ -437,4 +509,52 @@ Core::EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const { | |||
| 437 | return impl->GetCurrentEmuThreadID(); | 509 | return impl->GetCurrentEmuThreadID(); |
| 438 | } | 510 | } |
| 439 | 511 | ||
| 512 | Memory::MemoryManager& KernelCore::MemoryManager() { | ||
| 513 | return *impl->memory_manager; | ||
| 514 | } | ||
| 515 | |||
| 516 | const Memory::MemoryManager& KernelCore::MemoryManager() const { | ||
| 517 | return *impl->memory_manager; | ||
| 518 | } | ||
| 519 | |||
| 520 | Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() { | ||
| 521 | return *impl->user_slab_heap_pages; | ||
| 522 | } | ||
| 523 | |||
| 524 | const Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() const { | ||
| 525 | return *impl->user_slab_heap_pages; | ||
| 526 | } | ||
| 527 | |||
| 528 | Kernel::SharedMemory& KernelCore::GetHidSharedMem() { | ||
| 529 | return *impl->hid_shared_mem; | ||
| 530 | } | ||
| 531 | |||
| 532 | const Kernel::SharedMemory& KernelCore::GetHidSharedMem() const { | ||
| 533 | return *impl->hid_shared_mem; | ||
| 534 | } | ||
| 535 | |||
| 536 | Kernel::SharedMemory& KernelCore::GetFontSharedMem() { | ||
| 537 | return *impl->font_shared_mem; | ||
| 538 | } | ||
| 539 | |||
| 540 | const Kernel::SharedMemory& KernelCore::GetFontSharedMem() const { | ||
| 541 | return *impl->font_shared_mem; | ||
| 542 | } | ||
| 543 | |||
| 544 | Kernel::SharedMemory& KernelCore::GetIrsSharedMem() { | ||
| 545 | return *impl->irs_shared_mem; | ||
| 546 | } | ||
| 547 | |||
| 548 | const Kernel::SharedMemory& KernelCore::GetIrsSharedMem() const { | ||
| 549 | return *impl->irs_shared_mem; | ||
| 550 | } | ||
| 551 | |||
| 552 | Kernel::SharedMemory& KernelCore::GetTimeSharedMem() { | ||
| 553 | return *impl->time_shared_mem; | ||
| 554 | } | ||
| 555 | |||
| 556 | const Kernel::SharedMemory& KernelCore::GetTimeSharedMem() const { | ||
| 557 | return *impl->time_shared_mem; | ||
| 558 | } | ||
| 559 | |||
| 440 | } // namespace Kernel | 560 | } // namespace Kernel |