From c17beefe3d1e4850b3518a45892c0c5c6e11c95a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 18 Feb 2021 16:38:30 -0800 Subject: hle: kernel: Add architecture and board specific memory regions. --- .../nintendo/nx/k_memory_region_device_types.inc | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/core/hle/kernel/board/nintendo/nx/k_memory_region_device_types.inc (limited to 'src/core/hle/kernel/board') diff --git a/src/core/hle/kernel/board/nintendo/nx/k_memory_region_device_types.inc b/src/core/hle/kernel/board/nintendo/nx/k_memory_region_device_types.inc new file mode 100644 index 000000000..58d6c0b16 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/k_memory_region_device_types.inc @@ -0,0 +1,52 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +// All architectures must define NumBoardDeviceRegions. +constexpr inline const auto NumBoardDeviceRegions = 6; +// UNUSED: .Derive(NumBoardDeviceRegions, 0); +constexpr inline const auto KMemoryRegionType_MemoryController = + KMemoryRegionType_BoardDeviceBase.Derive(NumBoardDeviceRegions, 1) + .SetAttribute(KMemoryRegionAttr_NoUserMap); +constexpr inline const auto KMemoryRegionType_MemoryController1 = + KMemoryRegionType_BoardDeviceBase.Derive(NumBoardDeviceRegions, 2) + .SetAttribute(KMemoryRegionAttr_NoUserMap); +constexpr inline const auto KMemoryRegionType_MemoryController0 = + KMemoryRegionType_BoardDeviceBase.Derive(NumBoardDeviceRegions, 3) + .SetAttribute(KMemoryRegionAttr_NoUserMap); +constexpr inline const auto KMemoryRegionType_PowerManagementController = + KMemoryRegionType_BoardDeviceBase.Derive(NumBoardDeviceRegions, 4).DeriveTransition(); +constexpr inline const auto KMemoryRegionType_LegacyLpsDevices = + KMemoryRegionType_BoardDeviceBase.Derive(NumBoardDeviceRegions, 5); +static_assert(KMemoryRegionType_MemoryController.GetValue() == + (0x55 | KMemoryRegionAttr_NoUserMap)); +static_assert(KMemoryRegionType_MemoryController1.GetValue() == + (0x65 | KMemoryRegionAttr_NoUserMap)); +static_assert(KMemoryRegionType_MemoryController0.GetValue() == + (0x95 | KMemoryRegionAttr_NoUserMap)); +static_assert(KMemoryRegionType_PowerManagementController.GetValue() == (0x1A5)); + +static_assert(KMemoryRegionType_LegacyLpsDevices.GetValue() == 0xC5); + +constexpr inline const auto NumLegacyLpsDevices = 7; +constexpr inline const auto KMemoryRegionType_LegacyLpsExceptionVectors = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 0); +constexpr inline const auto KMemoryRegionType_LegacyLpsIram = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 1); +constexpr inline const auto KMemoryRegionType_LegacyLpsFlowController = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 2); +constexpr inline const auto KMemoryRegionType_LegacyLpsPrimaryICtlr = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 3); +constexpr inline const auto KMemoryRegionType_LegacyLpsSemaphore = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 4); +constexpr inline const auto KMemoryRegionType_LegacyLpsAtomics = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 5); +constexpr inline const auto KMemoryRegionType_LegacyLpsClkRst = + KMemoryRegionType_LegacyLpsDevices.Derive(NumLegacyLpsDevices, 6); +static_assert(KMemoryRegionType_LegacyLpsExceptionVectors.GetValue() == 0x3C5); +static_assert(KMemoryRegionType_LegacyLpsIram.GetValue() == 0x5C5); +static_assert(KMemoryRegionType_LegacyLpsFlowController.GetValue() == 0x6C5); +static_assert(KMemoryRegionType_LegacyLpsPrimaryICtlr.GetValue() == 0x9C5); +static_assert(KMemoryRegionType_LegacyLpsSemaphore.GetValue() == 0xAC5); +static_assert(KMemoryRegionType_LegacyLpsAtomics.GetValue() == 0xCC5); +static_assert(KMemoryRegionType_LegacyLpsClkRst.GetValue() == 0x11C5); -- cgit v1.2.3 From 57625177289624051e107578ccfce749a083f51a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 18 Feb 2021 18:38:23 -0800 Subject: hle: kernel: KSystemControl: Update to reflect board-specific behavior. --- src/core/CMakeLists.txt | 3 +- .../kernel/board/nintendo/nx/k_system_control.cpp | 46 ++++++++++++++++++++++ .../kernel/board/nintendo/nx/k_system_control.h | 22 +++++++++++ src/core/hle/kernel/k_system_control.cpp | 42 -------------------- src/core/hle/kernel/k_system_control.h | 18 +++++---- 5 files changed, 81 insertions(+), 50 deletions(-) create mode 100644 src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp create mode 100644 src/core/hle/kernel/board/nintendo/nx/k_system_control.h delete mode 100644 src/core/hle/kernel/k_system_control.cpp (limited to 'src/core/hle/kernel/board') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 299f1ed13..6cf7ff81f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -141,6 +141,8 @@ add_library(core STATIC hardware_interrupt_manager.h hle/ipc.h hle/ipc_helpers.h + hle/kernel/board/nintendo/nx/k_system_control.cpp + hle/kernel/board/nintendo/nx/k_system_control.h hle/kernel/client_port.cpp hle/kernel/client_port.h hle/kernel/client_session.cpp @@ -198,7 +200,6 @@ add_library(core STATIC hle/kernel/k_spin_lock.h hle/kernel/k_synchronization_object.cpp hle/kernel/k_synchronization_object.h - hle/kernel/k_system_control.cpp hle/kernel/k_system_control.h hle/kernel/k_thread.cpp hle/kernel/k_thread.h diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp new file mode 100644 index 000000000..0f41c4110 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -0,0 +1,46 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "core/hle/kernel/k_system_control.h" + +namespace Kernel::Board::Nintendo::Nx { + +bool KSystemControl::Init::ShouldIncreaseThreadResourceLimit() { + return true; +} + +namespace { +template +u64 GenerateUniformRange(u64 min, u64 max, F f) { + // Handle the case where the difference is too large to represent. + if (max == std::numeric_limits::max() && min == std::numeric_limits::min()) { + return f(); + } + + // Iterate until we get a value in range. + const u64 range_size = ((max + 1) - min); + const u64 effective_max = (std::numeric_limits::max() / range_size) * range_size; + while (true) { + if (const u64 rnd = f(); rnd < effective_max) { + return min + (rnd % range_size); + } + } +} + +} // Anonymous namespace + +u64 KSystemControl::GenerateRandomU64() { + static std::random_device device; + static std::mt19937 gen(device()); + static std::uniform_int_distribution distribution(1, std::numeric_limits::max()); + return distribution(gen); +} + +u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) { + return GenerateUniformRange(min, max, GenerateRandomU64); +} + +} // namespace Kernel::Board::Nintendo::Nx diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.h b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h new file mode 100644 index 000000000..3fde61971 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h @@ -0,0 +1,22 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Kernel::Board::Nintendo::Nx { + +class KSystemControl { +public: + class Init { + public: + static bool ShouldIncreaseThreadResourceLimit(); + }; + + static u64 GenerateRandomRange(u64 min, u64 max); + static u64 GenerateRandomU64(); +}; + +} // namespace Kernel::Board::Nintendo::Nx diff --git a/src/core/hle/kernel/k_system_control.cpp b/src/core/hle/kernel/k_system_control.cpp deleted file mode 100644 index aa1682f69..000000000 --- a/src/core/hle/kernel/k_system_control.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "core/hle/kernel/k_system_control.h" - -namespace Kernel { - -namespace { -template -u64 GenerateUniformRange(u64 min, u64 max, F f) { - // Handle the case where the difference is too large to represent. - if (max == std::numeric_limits::max() && min == std::numeric_limits::min()) { - return f(); - } - - // Iterate until we get a value in range. - const u64 range_size = ((max + 1) - min); - const u64 effective_max = (std::numeric_limits::max() / range_size) * range_size; - while (true) { - if (const u64 rnd = f(); rnd < effective_max) { - return min + (rnd % range_size); - } - } -} - -} // Anonymous namespace - -u64 KSystemControl::GenerateRandomU64() { - static std::random_device device; - static std::mt19937 gen(device()); - static std::uniform_int_distribution distribution(1, std::numeric_limits::max()); - return distribution(gen); -} - -u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) { - return GenerateUniformRange(min, max, GenerateRandomU64); -} - -} // namespace Kernel diff --git a/src/core/hle/kernel/k_system_control.h b/src/core/hle/kernel/k_system_control.h index 1d5b64ffa..d755082c2 100644 --- a/src/core/hle/kernel/k_system_control.h +++ b/src/core/hle/kernel/k_system_control.h @@ -6,14 +6,18 @@ #include "common/common_types.h" -namespace Kernel { +#define BOARD_NINTENDO_NX + +#ifdef BOARD_NINTENDO_NX -class KSystemControl { -public: - KSystemControl() = default; +#include "core/hle/kernel/board/nintendo/nx/k_system_control.h" - static u64 GenerateRandomRange(u64 min, u64 max); - static u64 GenerateRandomU64(); -}; +namespace Kernel { + +using Kernel::Board::Nintendo::Nx::KSystemControl; } // namespace Kernel + +#else +#error "Unknown board for KSystemControl" +#endif -- cgit v1.2.3 From 10265ad0e4fbc5e54c1607d18eded80d8340606c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 20 Mar 2021 00:00:49 -0700 Subject: hle: kernel: board: Add secure_monitor module. --- src/core/CMakeLists.txt | 1 + .../hle/kernel/board/nintendo/nx/secure_monitor.h | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/core/hle/kernel/board/nintendo/nx/secure_monitor.h (limited to 'src/core/hle/kernel/board') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fdd084537..b09938de9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -143,6 +143,7 @@ add_library(core STATIC hle/ipc_helpers.h hle/kernel/board/nintendo/nx/k_system_control.cpp hle/kernel/board/nintendo/nx/k_system_control.h + hle/kernel/board/nintendo/nx/secure_monitor.h hle/kernel/client_port.cpp hle/kernel/client_port.h hle/kernel/client_session.cpp diff --git a/src/core/hle/kernel/board/nintendo/nx/secure_monitor.h b/src/core/hle/kernel/board/nintendo/nx/secure_monitor.h new file mode 100644 index 000000000..0c366b252 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/secure_monitor.h @@ -0,0 +1,26 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Kernel::Board::Nintendo::Nx::Smc { + +enum MemorySize { + MemorySize_4GB = 0, + MemorySize_6GB = 1, + MemorySize_8GB = 2, +}; + +enum MemoryArrangement { + MemoryArrangement_4GB = 0, + MemoryArrangement_4GBForAppletDev = 1, + MemoryArrangement_4GBForSystemDev = 2, + MemoryArrangement_6GB = 3, + MemoryArrangement_6GBForAppletDev = 4, + MemoryArrangement_8GB = 5, +}; + +} // namespace Kernel::Board::Nintendo::Nx::Smc -- cgit v1.2.3 From edbc505e52c8dacce91c7f89c798ae1b6da801e7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 20 Mar 2021 00:23:06 -0700 Subject: hle: kernel: board: k_system_control: Extend to include memory region sizes. --- src/common/common_sizes.h | 10 ++ .../kernel/board/nintendo/nx/k_system_control.cpp | 120 ++++++++++++++++++++- .../kernel/board/nintendo/nx/k_system_control.h | 6 ++ 3 files changed, 135 insertions(+), 1 deletion(-) (limited to 'src/core/hle/kernel/board') diff --git a/src/common/common_sizes.h b/src/common/common_sizes.h index 26425a57d..a6500bddd 100644 --- a/src/common/common_sizes.h +++ b/src/common/common_sizes.h @@ -12,11 +12,21 @@ enum : u64 { Size_4_MB = 4ULL * Size_1_MB, Size_14_MB = 14ULL * Size_1_MB, Size_32_MB = 32ULL * Size_1_MB, + Size_33_MB = 33ULL * Size_1_MB, Size_128_MB = 128ULL * Size_1_MB, + Size_448_MB = 448ULL * Size_1_MB, + Size_507_MB = 507ULL * Size_1_MB, + Size_562_MB = 562ULL * Size_1_MB, + Size_1554_MB = 1554ULL * Size_1_MB, + Size_2048_MB = 2048ULL * Size_1_MB, + Size_2193_MB = 2193ULL * Size_1_MB, + Size_3285_MB = 3285ULL * Size_1_MB, + Size_4916_MB = 4916ULL * Size_1_MB, Size_1_GB = 0x40000000ULL, Size_2_GB = 2ULL * Size_1_GB, Size_4_GB = 4ULL * Size_1_GB, Size_6_GB = 6ULL * Size_1_GB, + Size_8_GB = 8ULL * Size_1_GB, Size_64_GB = 64ULL * Size_1_GB, Size_512_GB = 512ULL * Size_1_GB, Invalid = std::numeric_limits::max(), diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp index 0f41c4110..a48d0c11e 100644 --- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -4,14 +4,132 @@ #include -#include "core/hle/kernel/k_system_control.h" +#include "common/common_sizes.h" +#include "core/hle/kernel/board/nintendo/nx/k_system_control.h" +#include "core/hle/kernel/board/nintendo/nx/secure_monitor.h" +#include "core/hle/kernel/k_trace.h" namespace Kernel::Board::Nintendo::Nx { +namespace impl { + +constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeVi = 0x2238 * 4 * 1024; +constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeNvservices = 0x710 * 4 * 1024; +constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4 * 1024; + +} // namespace impl + +constexpr inline const std::size_t RequiredNonSecureSystemMemorySize = + impl::RequiredNonSecureSystemMemorySizeVi + impl::RequiredNonSecureSystemMemorySizeNvservices + + impl::RequiredNonSecureSystemMemorySizeMisc; + +namespace { + +u32 GetMemoryModeForInit() { + return 0x01; +} + +u32 GetMemorySizeForInit() { + return 0; +} + +Smc::MemoryArrangement GetMemoryArrangeForInit() { + switch (GetMemoryModeForInit() & 0x3F) { + case 0x01: + default: + return Smc::MemoryArrangement_4GB; + case 0x02: + return Smc::MemoryArrangement_4GBForAppletDev; + case 0x03: + return Smc::MemoryArrangement_4GBForSystemDev; + case 0x11: + return Smc::MemoryArrangement_6GB; + case 0x12: + return Smc::MemoryArrangement_6GBForAppletDev; + case 0x21: + return Smc::MemoryArrangement_8GB; + } +} +} // namespace + +// Initialization. +size_t KSystemControl::Init::GetIntendedMemorySize() { + switch (GetMemorySizeForInit()) { + case Smc::MemorySize_4GB: + default: // All invalid modes should go to 4GB. + return Size_4_GB; + case Smc::MemorySize_6GB: + return Size_6_GB; + case Smc::MemorySize_8GB: + return Size_8_GB; + } +} + +PAddr KSystemControl::Init::GetKernelPhysicalBaseAddress(u64 base_address) { + return base_address; +} + bool KSystemControl::Init::ShouldIncreaseThreadResourceLimit() { return true; } +std::size_t KSystemControl::Init::GetApplicationPoolSize() { + // Get the base pool size. + const size_t base_pool_size = []() -> size_t { + switch (GetMemoryArrangeForInit()) { + case Smc::MemoryArrangement_4GB: + default: + return Size_3285_MB; + case Smc::MemoryArrangement_4GBForAppletDev: + return Size_2048_MB; + case Smc::MemoryArrangement_4GBForSystemDev: + return Size_3285_MB; + case Smc::MemoryArrangement_6GB: + return Size_4916_MB; + case Smc::MemoryArrangement_6GBForAppletDev: + return Size_3285_MB; + case Smc::MemoryArrangement_8GB: + return Size_4916_MB; + } + }(); + + // Return (possibly) adjusted size. + return base_pool_size; +} + +size_t KSystemControl::Init::GetAppletPoolSize() { + // Get the base pool size. + const size_t base_pool_size = []() -> size_t { + switch (GetMemoryArrangeForInit()) { + case Smc::MemoryArrangement_4GB: + default: + return Size_507_MB; + case Smc::MemoryArrangement_4GBForAppletDev: + return Size_1554_MB; + case Smc::MemoryArrangement_4GBForSystemDev: + return Size_448_MB; + case Smc::MemoryArrangement_6GB: + return Size_562_MB; + case Smc::MemoryArrangement_6GBForAppletDev: + return Size_2193_MB; + case Smc::MemoryArrangement_8GB: + return Size_2193_MB; + } + }(); + + // Return (possibly) adjusted size. + constexpr size_t ExtraSystemMemoryForAtmosphere = Size_33_MB; + return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize; +} + +size_t KSystemControl::Init::GetMinimumNonSecureSystemPoolSize() { + // Verify that our minimum is at least as large as Nintendo's. + constexpr size_t MinimumSize = RequiredNonSecureSystemMemorySize; + static_assert(MinimumSize >= 0x29C8000); + + return MinimumSize; +} + namespace { template u64 GenerateUniformRange(u64 min, u64 max, F f) { diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.h b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h index 3fde61971..52f230ced 100644 --- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.h +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h @@ -12,7 +12,13 @@ class KSystemControl { public: class Init { public: + // Initialization. + static std::size_t GetIntendedMemorySize(); + static PAddr GetKernelPhysicalBaseAddress(u64 base_address); static bool ShouldIncreaseThreadResourceLimit(); + static std::size_t GetApplicationPoolSize(); + static std::size_t GetAppletPoolSize(); + static std::size_t GetMinimumNonSecureSystemPoolSize(); }; static u64 GenerateRandomRange(u64 min, u64 max); -- cgit v1.2.3 From ab5995c7ae878fcf3b9a0c537f0e37377f206d76 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 23 Mar 2021 18:31:46 -0700 Subject: common: common_sizes: Move sizes to the Common namespace. --- src/common/common_sizes.h | 4 +++ .../kernel/board/nintendo/nx/k_system_control.cpp | 32 +++++++++++----------- src/core/hle/kernel/k_address_space_info.cpp | 29 ++++++++++---------- src/core/hle/kernel/k_memory_layout.h | 16 +++++------ src/core/hle/kernel/kernel.cpp | 14 +++++----- 5 files changed, 50 insertions(+), 45 deletions(-) (limited to 'src/core/hle/kernel/board') diff --git a/src/common/common_sizes.h b/src/common/common_sizes.h index 5dc039c94..7e9fd968b 100644 --- a/src/common/common_sizes.h +++ b/src/common/common_sizes.h @@ -8,6 +8,8 @@ #include "common/common_types.h" +namespace Common { + enum : u64 { Size_1_KB = 0x400ULL, Size_64_KB = 64ULL * Size_1_KB, @@ -37,3 +39,5 @@ enum : u64 { Size_512_GB = 512ULL * Size_1_GB, Size_Invalid = std::numeric_limits::max(), }; + +} // namespace Common diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp index a48d0c11e..919a6b943 100644 --- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -57,11 +57,11 @@ size_t KSystemControl::Init::GetIntendedMemorySize() { switch (GetMemorySizeForInit()) { case Smc::MemorySize_4GB: default: // All invalid modes should go to 4GB. - return Size_4_GB; + return Common::Size_4_GB; case Smc::MemorySize_6GB: - return Size_6_GB; + return Common::Size_6_GB; case Smc::MemorySize_8GB: - return Size_8_GB; + return Common::Size_8_GB; } } @@ -79,17 +79,17 @@ std::size_t KSystemControl::Init::GetApplicationPoolSize() { switch (GetMemoryArrangeForInit()) { case Smc::MemoryArrangement_4GB: default: - return Size_3285_MB; + return Common::Size_3285_MB; case Smc::MemoryArrangement_4GBForAppletDev: - return Size_2048_MB; + return Common::Size_2048_MB; case Smc::MemoryArrangement_4GBForSystemDev: - return Size_3285_MB; + return Common::Size_3285_MB; case Smc::MemoryArrangement_6GB: - return Size_4916_MB; + return Common::Size_4916_MB; case Smc::MemoryArrangement_6GBForAppletDev: - return Size_3285_MB; + return Common::Size_3285_MB; case Smc::MemoryArrangement_8GB: - return Size_4916_MB; + return Common::Size_4916_MB; } }(); @@ -103,22 +103,22 @@ size_t KSystemControl::Init::GetAppletPoolSize() { switch (GetMemoryArrangeForInit()) { case Smc::MemoryArrangement_4GB: default: - return Size_507_MB; + return Common::Size_507_MB; case Smc::MemoryArrangement_4GBForAppletDev: - return Size_1554_MB; + return Common::Size_1554_MB; case Smc::MemoryArrangement_4GBForSystemDev: - return Size_448_MB; + return Common::Size_448_MB; case Smc::MemoryArrangement_6GB: - return Size_562_MB; + return Common::Size_562_MB; case Smc::MemoryArrangement_6GBForAppletDev: - return Size_2193_MB; + return Common::Size_2193_MB; case Smc::MemoryArrangement_8GB: - return Size_2193_MB; + return Common::Size_2193_MB; } }(); // Return (possibly) adjusted size. - constexpr size_t ExtraSystemMemoryForAtmosphere = Size_33_MB; + constexpr size_t ExtraSystemMemoryForAtmosphere = Common::Size_33_MB; return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize; } diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp index 89906954d..c7549f7a2 100644 --- a/src/core/hle/kernel/k_address_space_info.cpp +++ b/src/core/hle/kernel/k_address_space_info.cpp @@ -14,24 +14,25 @@ namespace { // clang-format off constexpr std::array AddressSpaceInfos{{ - { .bit_width = 32, .address = Size_2_MB , .size = Size_1_GB - Size_2_MB , .type = KAddressSpaceInfo::Type::MapSmall, }, - { .bit_width = 32, .address = Size_1_GB , .size = Size_4_GB - Size_1_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, - { .bit_width = 32, .address = Size_Invalid, .size = Size_1_GB , .type = KAddressSpaceInfo::Type::Heap, }, - { .bit_width = 32, .address = Size_Invalid, .size = Size_1_GB , .type = KAddressSpaceInfo::Type::Alias, }, - { .bit_width = 36, .address = Size_128_MB , .size = Size_2_GB - Size_128_MB, .type = KAddressSpaceInfo::Type::MapSmall, }, - { .bit_width = 36, .address = Size_2_GB , .size = Size_64_GB - Size_2_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, - { .bit_width = 36, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, - { .bit_width = 36, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Alias, }, - { .bit_width = 39, .address = Size_128_MB , .size = Size_512_GB - Size_128_MB, .type = KAddressSpaceInfo::Type::Map39Bit, }, - { .bit_width = 39, .address = Size_Invalid, .size = Size_64_GB , .type = KAddressSpaceInfo::Type::MapSmall }, - { .bit_width = 39, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, - { .bit_width = 39, .address = Size_Invalid, .size = Size_64_GB , .type = KAddressSpaceInfo::Type::Alias, }, - { .bit_width = 39, .address = Size_Invalid, .size = Size_2_GB , .type = KAddressSpaceInfo::Type::Stack, }, + { .bit_width = 32, .address = Common::Size_2_MB , .size = Common::Size_1_GB - Common::Size_2_MB , .type = KAddressSpaceInfo::Type::MapSmall, }, + { .bit_width = 32, .address = Common::Size_1_GB , .size = Common::Size_4_GB - Common::Size_1_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, + { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Alias, }, + { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Heap, }, + { .bit_width = 36, .address = Common::Size_128_MB , .size = Common::Size_2_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::MapSmall, }, + { .bit_width = 36, .address = Common::Size_2_GB , .size = Common::Size_64_GB - Common::Size_2_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, + { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, + { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Alias, }, + { .bit_width = 39, .address = Common::Size_128_MB , .size = Common::Size_512_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::Map39Bit, }, + { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::MapSmall }, + { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, + { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::Alias, }, + { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_2_GB , .type = KAddressSpaceInfo::Type::Stack, }, }}; // clang-format on constexpr bool IsAllowedIndexForAddress(std::size_t index) { - return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid; + return index < AddressSpaceInfos.size() && + AddressSpaceInfos[index].address != Common::Size_Invalid; } using IndexArray = diff --git a/src/core/hle/kernel/k_memory_layout.h b/src/core/hle/kernel/k_memory_layout.h index b3e057326..590dc449a 100644 --- a/src/core/hle/kernel/k_memory_layout.h +++ b/src/core/hle/kernel/k_memory_layout.h @@ -14,20 +14,20 @@ namespace Kernel { -constexpr std::size_t L1BlockSize = Size_1_GB; -constexpr std::size_t L2BlockSize = Size_2_MB; +constexpr std::size_t L1BlockSize = Common::Size_1_GB; +constexpr std::size_t L2BlockSize = Common::Size_2_MB; constexpr std::size_t GetMaximumOverheadSize(std::size_t size) { return (Common::DivideUp(size, L1BlockSize) + Common::DivideUp(size, L2BlockSize)) * PageSize; } -constexpr std::size_t MainMemorySize = Size_4_GB; -constexpr std::size_t MainMemorySizeMax = Size_8_GB; +constexpr std::size_t MainMemorySize = Common::Size_4_GB; +constexpr std::size_t MainMemorySizeMax = Common::Size_8_GB; constexpr std::size_t ReservedEarlyDramSize = 0x60000; constexpr std::size_t DramPhysicalAddress = 0x80000000; -constexpr std::size_t KernelAslrAlignment = Size_2_MB; +constexpr std::size_t KernelAslrAlignment = Common::Size_2_MB; constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39; constexpr std::size_t KernelPhysicalAddressSpaceWidth = 1ULL << 48; @@ -51,10 +51,10 @@ constexpr std::size_t KernelPhysicalAddressSpaceSize = constexpr std::size_t KernelPhysicalAddressCodeBase = DramPhysicalAddress + ReservedEarlyDramSize; constexpr std::size_t KernelPageTableHeapSize = GetMaximumOverheadSize(MainMemorySizeMax); -constexpr std::size_t KernelInitialPageHeapSize = Size_128_KB; +constexpr std::size_t KernelInitialPageHeapSize = Common::Size_128_KB; -constexpr std::size_t KernelSlabHeapDataSize = Size_5_MB; -constexpr std::size_t KernelSlabHeapGapsSize = Size_2_MB - Size_64_KB; +constexpr std::size_t KernelSlabHeapDataSize = Common::Size_5_MB; +constexpr std::size_t KernelSlabHeapGapsSize = Common::Size_2_MB - Common::Size_64_KB; constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize; // NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 9360710de..e994e8bed 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -289,8 +289,8 @@ struct KernelCore::Impl { const VAddr code_end_virt_addr = KernelVirtualAddressCodeEnd; // Setup the containing kernel region. - constexpr size_t KernelRegionSize = Size_1_GB; - constexpr size_t KernelRegionAlign = Size_1_GB; + constexpr size_t KernelRegionSize = Common::Size_1_GB; + constexpr size_t KernelRegionAlign = Common::Size_1_GB; constexpr VAddr kernel_region_start = Common::AlignDown(code_start_virt_addr, KernelRegionAlign); size_t kernel_region_size = KernelRegionSize; @@ -337,7 +337,7 @@ struct KernelCore::Impl { // Decide on the actual size for the misc region. constexpr size_t MiscRegionAlign = KernelAslrAlignment; - constexpr size_t MiscRegionMinimumSize = Size_32_MB; + constexpr size_t MiscRegionMinimumSize = Common::Size_32_MB; const size_t misc_region_size = Common::AlignUp( std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign); ASSERT(misc_region_size > 0); @@ -350,7 +350,7 @@ struct KernelCore::Impl { misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc)); // Setup the stack region. - constexpr size_t StackRegionSize = Size_14_MB; + constexpr size_t StackRegionSize = Common::Size_14_MB; constexpr size_t StackRegionAlign = KernelAslrAlignment; const VAddr stack_region_start = memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( @@ -382,7 +382,7 @@ struct KernelCore::Impl { slab_region_start, slab_region_size, KMemoryRegionType_KernelSlab)); // Setup the temp region. - constexpr size_t TempRegionSize = Size_128_MB; + constexpr size_t TempRegionSize = Common::Size_128_MB; constexpr size_t TempRegionAlign = KernelAslrAlignment; const VAddr temp_region_start = memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( @@ -438,7 +438,7 @@ struct KernelCore::Impl { // Determine size available for kernel page table heaps, requiring > 8 MB. const PAddr resource_end_phys_addr = slab_start_phys_addr + resource_region_size; const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr; - ASSERT(page_table_heap_size / Size_4_MB > 2); + ASSERT(page_table_heap_size / Common::Size_4_MB > 2); // Insert a physical region for the kernel page table heap region ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert( @@ -463,7 +463,7 @@ struct KernelCore::Impl { ASSERT(linear_extents.GetEndAddress() != 0); // Setup the linear mapping region. - constexpr size_t LinearRegionAlign = Size_1_GB; + constexpr size_t LinearRegionAlign = Common::Size_1_GB; const PAddr aligned_linear_phys_start = Common::AlignDown(linear_extents.GetAddress(), LinearRegionAlign); const size_t linear_region_size = -- cgit v1.2.3 From a32190d0c2198d66657db33409348f067ada27d3 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 23 Mar 2021 18:33:29 -0700 Subject: hle: kernel: k_system_control: Remove unnecessary inline. --- src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/hle/kernel/board') diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp index 919a6b943..86472b5ce 100644 --- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -13,13 +13,13 @@ namespace Kernel::Board::Nintendo::Nx { namespace impl { -constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeVi = 0x2238 * 4 * 1024; -constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeNvservices = 0x710 * 4 * 1024; -constexpr inline const std::size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4 * 1024; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeVi = 0x2238 * 4 * 1024; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeNvservices = 0x710 * 4 * 1024; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4 * 1024; } // namespace impl -constexpr inline const std::size_t RequiredNonSecureSystemMemorySize = +constexpr const std::size_t RequiredNonSecureSystemMemorySize = impl::RequiredNonSecureSystemMemorySizeVi + impl::RequiredNonSecureSystemMemorySizeNvservices + impl::RequiredNonSecureSystemMemorySizeMisc; -- cgit v1.2.3