summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/init
diff options
context:
space:
mode:
authorGravatar bunnei2021-05-04 21:35:42 -0700
committerGravatar bunnei2021-05-05 16:40:54 -0700
commitb805ee653f3d178ed2b4b2e0a403bb0ab61dad8b (patch)
treefd54235441ff4c2a0986e106bf57c501c2c9982b /src/core/hle/kernel/init
parentfixup! hle: kernel: Migrate KSharedMemory to KAutoObject. (diff)
downloadyuzu-b805ee653f3d178ed2b4b2e0a403bb0ab61dad8b.tar.gz
yuzu-b805ee653f3d178ed2b4b2e0a403bb0ab61dad8b.tar.xz
yuzu-b805ee653f3d178ed2b4b2e0a403bb0ab61dad8b.zip
hle: kernel: Move slab resource counts to Kernel.
Diffstat (limited to 'src/core/hle/kernel/init')
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp54
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.h9
2 files changed, 31 insertions, 32 deletions
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp
index 2dd792e71..69ae405e6 100644
--- a/src/core/hle/kernel/init/init_slab_setup.cpp
+++ b/src/core/hle/kernel/init/init_slab_setup.cpp
@@ -25,7 +25,7 @@
25 25
26namespace Kernel::Init { 26namespace Kernel::Init {
27 27
28#define SLAB_COUNT(CLASS) g_slab_resource_counts.num_##CLASS 28#define SLAB_COUNT(CLASS) kernel.SlabResourceCounts().num_##CLASS
29 29
30#define FOREACH_SLAB_TYPE(HANDLER, ...) \ 30#define FOREACH_SLAB_TYPE(HANDLER, ...) \
31 HANDLER(KProcess, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) \ 31 HANDLER(KProcess, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) \
@@ -67,26 +67,6 @@ constexpr size_t SlabCountKBeta = 6;
67 67
68constexpr size_t SlabCountExtraKThread = 160; 68constexpr size_t SlabCountExtraKThread = 160;
69 69
70// Global to hold our resource counts.
71KSlabResourceCounts g_slab_resource_counts = {
72 .num_KProcess = SlabCountKProcess,
73 .num_KThread = SlabCountKThread,
74 .num_KEvent = SlabCountKEvent,
75 .num_KInterruptEvent = SlabCountKInterruptEvent,
76 .num_KPort = SlabCountKPort,
77 .num_KSharedMemory = SlabCountKSharedMemory,
78 .num_KTransferMemory = SlabCountKTransferMemory,
79 .num_KCodeMemory = SlabCountKCodeMemory,
80 .num_KDeviceAddressSpace = SlabCountKDeviceAddressSpace,
81 .num_KSession = SlabCountKSession,
82 .num_KLightSession = SlabCountKLightSession,
83 .num_KObjectName = SlabCountKObjectName,
84 .num_KResourceLimit = SlabCountKResourceLimit,
85 .num_KDebug = SlabCountKDebug,
86 .num_KAlpha = SlabCountKAlpha,
87 .num_KBeta = SlabCountKBeta,
88};
89
90template <typename T> 70template <typename T>
91VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address, 71VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address,
92 size_t num_objects) { 72 size_t num_objects) {
@@ -105,19 +85,35 @@ VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAd
105 85
106} // namespace 86} // namespace
107 87
108const KSlabResourceCounts& GetSlabResourceCounts() { 88KSlabResourceCounts KSlabResourceCounts::CreateDefault() {
109 return g_slab_resource_counts; 89 return {
90 .num_KProcess = SlabCountKProcess,
91 .num_KThread = SlabCountKThread,
92 .num_KEvent = SlabCountKEvent,
93 .num_KInterruptEvent = SlabCountKInterruptEvent,
94 .num_KPort = SlabCountKPort,
95 .num_KSharedMemory = SlabCountKSharedMemory,
96 .num_KTransferMemory = SlabCountKTransferMemory,
97 .num_KCodeMemory = SlabCountKCodeMemory,
98 .num_KDeviceAddressSpace = SlabCountKDeviceAddressSpace,
99 .num_KSession = SlabCountKSession,
100 .num_KLightSession = SlabCountKLightSession,
101 .num_KObjectName = SlabCountKObjectName,
102 .num_KResourceLimit = SlabCountKResourceLimit,
103 .num_KDebug = SlabCountKDebug,
104 .num_KAlpha = SlabCountKAlpha,
105 .num_KBeta = SlabCountKBeta,
106 };
110} 107}
111 108
112void InitializeSlabResourceCounts() { 109void InitializeSlabResourceCounts(KernelCore& kernel) {
113 // Note: Nintendo initializes all fields here, but we initialize all constants at compile-time. 110 kernel.SlabResourceCounts() = KSlabResourceCounts::CreateDefault();
114
115 if (KSystemControl::Init::ShouldIncreaseThreadResourceLimit()) { 111 if (KSystemControl::Init::ShouldIncreaseThreadResourceLimit()) {
116 g_slab_resource_counts.num_KThread += SlabCountExtraKThread; 112 kernel.SlabResourceCounts().num_KThread += SlabCountExtraKThread;
117 } 113 }
118} 114}
119 115
120size_t CalculateTotalSlabHeapSize() { 116size_t CalculateTotalSlabHeapSize(const KernelCore& kernel) {
121 size_t size = 0; 117 size_t size = 0;
122 118
123#define ADD_SLAB_SIZE(NAME, COUNT, ...) \ 119#define ADD_SLAB_SIZE(NAME, COUNT, ...) \
@@ -138,6 +134,8 @@ size_t CalculateTotalSlabHeapSize() {
138} 134}
139 135
140void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) { 136void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
137 auto& kernel = system.Kernel();
138
141 // Get the start of the slab region, since that's where we'll be working. 139 // Get the start of the slab region, since that's where we'll be working.
142 VAddr address = memory_layout.GetSlabRegionAddress(); 140 VAddr address = memory_layout.GetSlabRegionAddress();
143 141
diff --git a/src/core/hle/kernel/init/init_slab_setup.h b/src/core/hle/kernel/init/init_slab_setup.h
index 6418b97ac..a8f7e0918 100644
--- a/src/core/hle/kernel/init/init_slab_setup.h
+++ b/src/core/hle/kernel/init/init_slab_setup.h
@@ -9,12 +9,15 @@ class System;
9} // namespace Core 9} // namespace Core
10 10
11namespace Kernel { 11namespace Kernel {
12class KernelCore;
12class KMemoryLayout; 13class KMemoryLayout;
13} // namespace Kernel 14} // namespace Kernel
14 15
15namespace Kernel::Init { 16namespace Kernel::Init {
16 17
17struct KSlabResourceCounts { 18struct KSlabResourceCounts {
19 static KSlabResourceCounts CreateDefault();
20
18 size_t num_KProcess; 21 size_t num_KProcess;
19 size_t num_KThread; 22 size_t num_KThread;
20 size_t num_KEvent; 23 size_t num_KEvent;
@@ -33,10 +36,8 @@ struct KSlabResourceCounts {
33 size_t num_KBeta; 36 size_t num_KBeta;
34}; 37};
35 38
36void InitializeSlabResourceCounts(); 39void InitializeSlabResourceCounts(KernelCore& kernel);
37const KSlabResourceCounts& GetSlabResourceCounts(); 40size_t CalculateTotalSlabHeapSize(const KernelCore& kernel);
38
39size_t CalculateTotalSlabHeapSize();
40void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout); 41void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout);
41 42
42} // namespace Kernel::Init 43} // namespace Kernel::Init