summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/init
diff options
context:
space:
mode:
authorGravatar bunnei2022-10-29 14:45:09 -0700
committerGravatar bunnei2022-11-03 21:17:07 -0700
commit32d7faafa8e6c12b9bbdb75505c7f0e58fa1bb4a (patch)
tree0d64d4f0f6fc5bbce1ff4e9fcb5ac4ceb60b1c80 /src/core/hle/kernel/init
parentcore: hle: kernel: k_dynamic_page_manager: Refresh. (diff)
downloadyuzu-32d7faafa8e6c12b9bbdb75505c7f0e58fa1bb4a.tar.gz
yuzu-32d7faafa8e6c12b9bbdb75505c7f0e58fa1bb4a.tar.xz
yuzu-32d7faafa8e6c12b9bbdb75505c7f0e58fa1bb4a.zip
core: hle: kernel: Integrate system KSystemResource.
Diffstat (limited to 'src/core/hle/kernel/init')
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp74
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.h2
2 files changed, 49 insertions, 27 deletions
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp
index 477e4e407..aa2dddcc6 100644
--- a/src/core/hle/kernel/init/init_slab_setup.cpp
+++ b/src/core/hle/kernel/init/init_slab_setup.cpp
@@ -10,7 +10,9 @@
10#include "core/hardware_properties.h" 10#include "core/hardware_properties.h"
11#include "core/hle/kernel/init/init_slab_setup.h" 11#include "core/hle/kernel/init/init_slab_setup.h"
12#include "core/hle/kernel/k_code_memory.h" 12#include "core/hle/kernel/k_code_memory.h"
13#include "core/hle/kernel/k_debug.h"
13#include "core/hle/kernel/k_event.h" 14#include "core/hle/kernel/k_event.h"
15#include "core/hle/kernel/k_event_info.h"
14#include "core/hle/kernel/k_memory_layout.h" 16#include "core/hle/kernel/k_memory_layout.h"
15#include "core/hle/kernel/k_memory_manager.h" 17#include "core/hle/kernel/k_memory_manager.h"
16#include "core/hle/kernel/k_page_buffer.h" 18#include "core/hle/kernel/k_page_buffer.h"
@@ -22,6 +24,7 @@
22#include "core/hle/kernel/k_shared_memory.h" 24#include "core/hle/kernel/k_shared_memory.h"
23#include "core/hle/kernel/k_shared_memory_info.h" 25#include "core/hle/kernel/k_shared_memory_info.h"
24#include "core/hle/kernel/k_system_control.h" 26#include "core/hle/kernel/k_system_control.h"
27#include "core/hle/kernel/k_system_resource.h"
25#include "core/hle/kernel/k_thread.h" 28#include "core/hle/kernel/k_thread.h"
26#include "core/hle/kernel/k_thread_local_page.h" 29#include "core/hle/kernel/k_thread_local_page.h"
27#include "core/hle/kernel/k_transfer_memory.h" 30#include "core/hle/kernel/k_transfer_memory.h"
@@ -44,7 +47,10 @@ namespace Kernel::Init {
44 HANDLER(KThreadLocalPage, \ 47 HANDLER(KThreadLocalPage, \
45 (SLAB_COUNT(KProcess) + (SLAB_COUNT(KProcess) + SLAB_COUNT(KThread)) / 8), \ 48 (SLAB_COUNT(KProcess) + (SLAB_COUNT(KProcess) + SLAB_COUNT(KThread)) / 8), \
46 ##__VA_ARGS__) \ 49 ##__VA_ARGS__) \
47 HANDLER(KResourceLimit, (SLAB_COUNT(KResourceLimit)), ##__VA_ARGS__) 50 HANDLER(KResourceLimit, (SLAB_COUNT(KResourceLimit)), ##__VA_ARGS__) \
51 HANDLER(KEventInfo, (SLAB_COUNT(KThread) + SLAB_COUNT(KDebug)), ##__VA_ARGS__) \
52 HANDLER(KDebug, (SLAB_COUNT(KDebug)), ##__VA_ARGS__) \
53 HANDLER(KSecureSystemResource, (SLAB_COUNT(KProcess)), ##__VA_ARGS__)
48 54
49namespace { 55namespace {
50 56
@@ -73,8 +79,20 @@ constexpr size_t SlabCountKResourceLimit = 5;
73constexpr size_t SlabCountKDebug = Core::Hardware::NUM_CPU_CORES; 79constexpr size_t SlabCountKDebug = Core::Hardware::NUM_CPU_CORES;
74constexpr size_t SlabCountKIoPool = 1; 80constexpr size_t SlabCountKIoPool = 1;
75constexpr size_t SlabCountKIoRegion = 6; 81constexpr size_t SlabCountKIoRegion = 6;
82constexpr size_t SlabcountKSessionRequestMappings = 40;
76 83
77constexpr size_t SlabCountExtraKThread = 160; 84constexpr size_t SlabCountExtraKThread = (1024 + 256 + 256) - SlabCountKThread;
85
86namespace test {
87
88static_assert(KernelPageBufferHeapSize ==
89 2 * PageSize + (SlabCountKProcess + SlabCountKThread +
90 (SlabCountKProcess + SlabCountKThread) / 8) *
91 PageSize);
92static_assert(KernelPageBufferAdditionalSize ==
93 (SlabCountExtraKThread + (SlabCountExtraKThread / 8)) * PageSize);
94
95} // namespace test
78 96
79/// Helper function to translate from the slab virtual address to the reserved location in physical 97/// Helper function to translate from the slab virtual address to the reserved location in physical
80/// memory. 98/// memory.
@@ -109,7 +127,7 @@ VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAd
109} 127}
110 128
111size_t CalculateSlabHeapGapSize() { 129size_t CalculateSlabHeapGapSize() {
112 constexpr size_t KernelSlabHeapGapSize = 2_MiB - 296_KiB; 130 constexpr size_t KernelSlabHeapGapSize = 2_MiB - 320_KiB;
113 static_assert(KernelSlabHeapGapSize <= KernelSlabHeapGapsSizeMax); 131 static_assert(KernelSlabHeapGapSize <= KernelSlabHeapGapsSizeMax);
114 return KernelSlabHeapGapSize; 132 return KernelSlabHeapGapSize;
115} 133}
@@ -134,6 +152,7 @@ KSlabResourceCounts KSlabResourceCounts::CreateDefault() {
134 .num_KDebug = SlabCountKDebug, 152 .num_KDebug = SlabCountKDebug,
135 .num_KIoPool = SlabCountKIoPool, 153 .num_KIoPool = SlabCountKIoPool,
136 .num_KIoRegion = SlabCountKIoRegion, 154 .num_KIoRegion = SlabCountKIoRegion,
155 .num_KSessionRequestMappings = SlabcountKSessionRequestMappings,
137 }; 156 };
138} 157}
139 158
@@ -164,29 +183,6 @@ size_t CalculateTotalSlabHeapSize(const KernelCore& kernel) {
164 return size; 183 return size;
165} 184}
166 185
167void InitializeKPageBufferSlabHeap(Core::System& system) {
168 auto& kernel = system.Kernel();
169
170 const auto& counts = kernel.SlabResourceCounts();
171 const size_t num_pages =
172 counts.num_KProcess + counts.num_KThread + (counts.num_KProcess + counts.num_KThread) / 8;
173 const size_t slab_size = num_pages * PageSize;
174
175 // Reserve memory from the system resource limit.
176 ASSERT(kernel.GetSystemResourceLimit()->Reserve(LimitableResource::PhysicalMemory, slab_size));
177
178 // Allocate memory for the slab.
179 constexpr auto AllocateOption = KMemoryManager::EncodeOption(
180 KMemoryManager::Pool::System, KMemoryManager::Direction::FromFront);
181 const PAddr slab_address =
182 kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, AllocateOption);
183 ASSERT(slab_address != 0);
184
185 // Initialize the slabheap.
186 KPageBuffer::InitializeSlabHeap(kernel, system.DeviceMemory().GetPointer<void>(slab_address),
187 slab_size);
188}
189
190void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) { 186void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
191 auto& kernel = system.Kernel(); 187 auto& kernel = system.Kernel();
192 188
@@ -258,3 +254,29 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
258} 254}
259 255
260} // namespace Kernel::Init 256} // namespace Kernel::Init
257
258namespace Kernel {
259
260void KPageBufferSlabHeap::Initialize(Core::System& system) {
261 auto& kernel = system.Kernel();
262 const auto& counts = kernel.SlabResourceCounts();
263 const size_t num_pages =
264 counts.num_KProcess + counts.num_KThread + (counts.num_KProcess + counts.num_KThread) / 8;
265 const size_t slab_size = num_pages * PageSize;
266
267 // Reserve memory from the system resource limit.
268 ASSERT(kernel.GetSystemResourceLimit()->Reserve(LimitableResource::PhysicalMemory, slab_size));
269
270 // Allocate memory for the slab.
271 constexpr auto AllocateOption = KMemoryManager::EncodeOption(
272 KMemoryManager::Pool::System, KMemoryManager::Direction::FromFront);
273 const PAddr slab_address =
274 kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, AllocateOption);
275 ASSERT(slab_address != 0);
276
277 // Initialize the slabheap.
278 KPageBuffer::InitializeSlabHeap(kernel, system.DeviceMemory().GetPointer<void>(slab_address),
279 slab_size);
280}
281
282} // namespace Kernel
diff --git a/src/core/hle/kernel/init/init_slab_setup.h b/src/core/hle/kernel/init/init_slab_setup.h
index 13be63c87..5e22821bc 100644
--- a/src/core/hle/kernel/init/init_slab_setup.h
+++ b/src/core/hle/kernel/init/init_slab_setup.h
@@ -33,11 +33,11 @@ struct KSlabResourceCounts {
33 size_t num_KDebug; 33 size_t num_KDebug;
34 size_t num_KIoPool; 34 size_t num_KIoPool;
35 size_t num_KIoRegion; 35 size_t num_KIoRegion;
36 size_t num_KSessionRequestMappings;
36}; 37};
37 38
38void InitializeSlabResourceCounts(KernelCore& kernel); 39void InitializeSlabResourceCounts(KernelCore& kernel);
39size_t CalculateTotalSlabHeapSize(const KernelCore& kernel); 40size_t CalculateTotalSlabHeapSize(const KernelCore& kernel);
40void InitializeKPageBufferSlabHeap(Core::System& system);
41void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout); 41void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout);
42 42
43} // namespace Kernel::Init 43} // namespace Kernel::Init