From ee3a7e7740a5e8f84b4102e97f0a96122e6031a6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 15 Nov 2020 00:45:41 -0800 Subject: [PATCH] exo: disable untranslated gpu accesses on mariko --- exosphere/program/source/secmon_setup.cpp | 13 +++++++++++++ exosphere/warmboot/source/warmboot_main.cpp | 2 ++ .../libvapours/include/vapours/tegra/tegra_mc.hpp | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/exosphere/program/source/secmon_setup.cpp b/exosphere/program/source/secmon_setup.cpp index 5e33002b8..0136a72d8 100644 --- a/exosphere/program/source/secmon_setup.cpp +++ b/exosphere/program/source/secmon_setup.cpp @@ -814,6 +814,16 @@ namespace ams::secmon { reg::Read(MC + MC_IRAM_REG_CTRL); } + void DisableUntranslatedDeviceMemoryAccess() { + /* If we can (mariko only), disable GMMU accesses that bypass the SMMU. */ + /* Additionally, force all untranslated acccesses to hit one of the carveouts. */ + if (GetSocType() == fuse::SocType_Mariko) { + reg::Write(MC + MC_UNTRANSLATED_REGION_CHECK, MC_REG_BITS_ENUM(UNTRANSLATED_REGION_CHECK_UNTRANSLATED_REGION_CHECK_ACCESS, DISABLED), + MC_REG_BITS_ENUM(UNTRANSLATED_REGION_CHECK_REQUIRE_UNTRANSLATED_CLIENTS_HIT_CARVEOUT, ENABLED), + MC_REG_BITS_ENUM(UNTRANSLATED_REGION_CHECK_REQUIRE_UNTRANSLATED_GPU_HIT_CARVEOUT, ENABLED)); + } + } + void FinalizeCarveoutSecureScratchRegisters() { /* Define carveout scratch values. */ constexpr uintptr_t WarmbootCarveoutAddress = MemoryRegionDram.GetAddress(); @@ -1145,6 +1155,9 @@ namespace ams::secmon { /* Disable the ARC. */ DisableArc(); + /* Disable untranslated memory accesses by devices. */ + DisableUntranslatedDeviceMemoryAccess(); + /* Further protections aren't applied on <= 1.0.0. */ if (GetTargetFirmware() <= TargetFirmware_1_0_0) { return; diff --git a/exosphere/warmboot/source/warmboot_main.cpp b/exosphere/warmboot/source/warmboot_main.cpp index 8da3af85f..e006ce8b7 100644 --- a/exosphere/warmboot/source/warmboot_main.cpp +++ b/exosphere/warmboot/source/warmboot_main.cpp @@ -103,4 +103,6 @@ namespace ams::diag { warmboot::ExceptionHandler(); } + #include + } diff --git a/libraries/libvapours/include/vapours/tegra/tegra_mc.hpp b/libraries/libvapours/include/vapours/tegra/tegra_mc.hpp index 093842554..3b44a2769 100644 --- a/libraries/libvapours/include/vapours/tegra/tegra_mc.hpp +++ b/libraries/libvapours/include/vapours/tegra/tegra_mc.hpp @@ -163,6 +163,7 @@ #define MC_EMEM_ARB_TIMING_CCDMW (0x6C4) #define MC_EMEM_ARB_REFPB_HP_CTRL (0x6F0) #define MC_EMEM_ARB_REFPB_BANK_CTRL (0x6F4) +#define MC_UNTRANSLATED_REGION_CHECK (0x948) #define MC_PTSA_GRANT_DECREMENT (0x960) #define MC_CLIENT_HOTRESET_CTRL_1 (0x970) #define MC_CLIENT_HOTRESET_STATUS_1 (0x974) @@ -553,3 +554,6 @@ DEFINE_MC_REG(IRAM_TOM_IRAM_TOM, 12, BITSIZEOF(u32) - 12); DEFINE_MC_REG_BIT_ENUM(IRAM_REG_CTRL_IRAM_CFG_WRITE_ACCESS, 0, ENABLED, DISABLED); +DEFINE_MC_REG_BIT_ENUM(UNTRANSLATED_REGION_CHECK_UNTRANSLATED_REGION_CHECK_ACCESS, 0, ENABLED, DISABLED); +DEFINE_MC_REG_BIT_ENUM(UNTRANSLATED_REGION_CHECK_REQUIRE_UNTRANSLATED_CLIENTS_HIT_CARVEOUT, 8, DISABLED, ENABLED); +DEFINE_MC_REG_BIT_ENUM(UNTRANSLATED_REGION_CHECK_REQUIRE_UNTRANSLATED_GPU_HIT_CARVEOUT, 9, DISABLED, ENABLED);