mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-28 05:34:11 -04:00
exo2: implement SmcIramCopy/reboot to payload/rcm
This commit is contained in:
parent
bb6671a94a
commit
6c145d76c7
31 changed files with 868 additions and 47 deletions
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "../secmon_map.hpp"
|
||||
#include "secmon_page_mapper.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
namespace impl {
|
||||
|
||||
void *PageMapperImpl::GetPointerTo(uintptr_t phys, size_t size) const {
|
||||
/* Ensure we stay within the page. */
|
||||
if (util::AlignDown(phys, 4_KB) != this->physical_address) {
|
||||
return nullptr;
|
||||
}
|
||||
if (size != 0) {
|
||||
if (util::AlignDown(phys + size - 1, 4_KB) != this->physical_address) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return reinterpret_cast<void *>(phys + (this->virtual_address - this->physical_address));
|
||||
}
|
||||
|
||||
bool PageMapperImpl::CopyToUser(uintptr_t dst_phys, const void *src, size_t size) const {
|
||||
void * const dst = this->GetPointerTo(dst_phys, size);
|
||||
if (dst == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::memcpy(dst, src, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PageMapperImpl::CopyFromUser(void *dst, uintptr_t src_phys, size_t size) const {
|
||||
const void * const src = this->GetPointerTo(src_phys, size);
|
||||
if (src == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::memcpy(dst, src, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool UserPageMapper::Map() {
|
||||
return this->MapImpl<MapSmcUserPage>();
|
||||
}
|
||||
|
||||
bool AtmosphereIramPageMapper::Map() {
|
||||
return this->MapImpl<MapAtmosphereIramPage>();
|
||||
}
|
||||
|
||||
bool AtmosphereUserPageMapper::Map() {
|
||||
return this->MapImpl<MapAtmosphereUserPage>();
|
||||
}
|
||||
|
||||
AtmosphereIramPageMapper::~AtmosphereIramPageMapper() {
|
||||
this->UnmapImpl<UnmapAtmosphereIramPage>();
|
||||
}
|
||||
|
||||
AtmosphereUserPageMapper::~AtmosphereUserPageMapper() {
|
||||
this->UnmapImpl<UnmapAtmosphereUserPage>();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <exosphere.hpp>
|
||||
#include "secmon_smc_common.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class PageMapperImpl {
|
||||
private:
|
||||
uintptr_t physical_address;
|
||||
uintptr_t virtual_address;
|
||||
public:
|
||||
constexpr PageMapperImpl(uintptr_t phys) : physical_address(util::AlignDown(phys, 4_KB)), virtual_address() { /* ... */ }
|
||||
|
||||
void *GetPointerTo(uintptr_t phys, size_t size) const;
|
||||
bool CopyToUser(uintptr_t dst_phys, const void *src, size_t size) const;
|
||||
bool CopyFromUser(void *dst, uintptr_t src_phys, size_t size) const;
|
||||
|
||||
template<auto F>
|
||||
bool MapImpl() {
|
||||
this->virtual_address = F(this->physical_address);
|
||||
return this->virtual_address != 0;
|
||||
}
|
||||
|
||||
template<auto F>
|
||||
void UnmapImpl() {
|
||||
F();
|
||||
this->virtual_address = 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class UserPageMapper : public impl::PageMapperImpl {
|
||||
public:
|
||||
constexpr UserPageMapper(uintptr_t phys) : PageMapperImpl(phys) { /* ... */ }
|
||||
|
||||
bool Map();
|
||||
};
|
||||
|
||||
class AtmosphereIramPageMapper : public impl::PageMapperImpl {
|
||||
public:
|
||||
constexpr AtmosphereIramPageMapper(uintptr_t phys) : PageMapperImpl(phys) { /* ... */ }
|
||||
~AtmosphereIramPageMapper();
|
||||
|
||||
bool Map();
|
||||
};
|
||||
|
||||
class AtmosphereUserPageMapper : public impl::PageMapperImpl {
|
||||
public:
|
||||
constexpr AtmosphereUserPageMapper(uintptr_t phys) : PageMapperImpl(phys) { /* ... */ }
|
||||
~AtmosphereUserPageMapper();
|
||||
|
||||
bool Map();
|
||||
};
|
||||
|
||||
}
|
|
@ -17,10 +17,10 @@
|
|||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_key_storage.hpp"
|
||||
#include "../secmon_misc.hpp"
|
||||
#include "../secmon_page_mapper.hpp"
|
||||
#include "secmon_smc_aes.hpp"
|
||||
#include "secmon_smc_device_unique_data.hpp"
|
||||
#include "secmon_smc_se_lock.hpp"
|
||||
#include "secmon_page_mapper.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
#include <exosphere.hpp>
|
||||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_misc.hpp"
|
||||
#include "secmon_page_mapper.hpp"
|
||||
#include "../secmon_page_mapper.hpp"
|
||||
#include "../secmon_user_power_management.hpp"
|
||||
#include "secmon_smc_info.hpp"
|
||||
#include "secmon_smc_power_management.hpp"
|
||||
|
||||
|
@ -269,17 +270,40 @@ namespace ams::secmon::smc {
|
|||
}
|
||||
|
||||
SmcResult SetConfig(SmcArguments &args) {
|
||||
const auto soc_type = GetSocType();
|
||||
|
||||
switch (static_cast<ConfigItem>(args.r[1])) {
|
||||
case ConfigItem::IsChargerHiZModeEnabled:
|
||||
/* Configure the HiZ mode. */
|
||||
SetChargerHiZModeEnabled(static_cast<bool>(args.r[3]));
|
||||
break;
|
||||
case ConfigItem::ExosphereNeedsReboot:
|
||||
/* TODO */
|
||||
return SmcResult::NotImplemented;
|
||||
if (soc_type == fuse::SocType_Erista) {
|
||||
switch (static_cast<UserRebootType>(args.r[3])) {
|
||||
case UserRebootType_None:
|
||||
break;
|
||||
case UserRebootType_ToRcm:
|
||||
PerformUserRebootToRcm();
|
||||
break;
|
||||
case UserRebootType_ToPayload:
|
||||
PerformUserRebootToPayload();
|
||||
break;
|
||||
default:
|
||||
return SmcResult::InvalidArgument;
|
||||
}
|
||||
} else /* if (soc_type == fuse::SocType_Mariko) */ {
|
||||
return SmcResult::NotImplemented;
|
||||
}
|
||||
break;
|
||||
case ConfigItem::ExosphereNeedsShutdown:
|
||||
/* TODO */
|
||||
return SmcResult::NotImplemented;
|
||||
if (soc_type == fuse::SocType_Erista) {
|
||||
if (args.r[3] != 0) {
|
||||
PerformUserShutDown();
|
||||
}
|
||||
} else /* if (soc_type == fuse::SocType_Mariko) */ {
|
||||
return SmcResult::NotImplemented;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return SmcResult::InvalidArgument;
|
||||
}
|
||||
|
|
|
@ -15,14 +15,56 @@
|
|||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_page_mapper.hpp"
|
||||
#include "secmon_smc_memory_access.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
namespace {
|
||||
|
||||
enum IramCopyType {
|
||||
IramCopyType_FromIramToDram = 0,
|
||||
IramCopyType_FromDramToIram = 1,
|
||||
IramCopyType_Count,
|
||||
};
|
||||
|
||||
struct IramCopyOption {
|
||||
using CopyType = util::BitPack32::Field<0, 1, IramCopyType>;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/* This is an atmosphere extension smc. */
|
||||
SmcResult SmcIramCopy(SmcArguments &args) {
|
||||
/* TODO */
|
||||
return SmcResult::NotImplemented;
|
||||
/* Decode arguments. */
|
||||
const uintptr_t dram_address = args.r[1];
|
||||
const uintptr_t iram_address = args.r[2];
|
||||
const size_t size = args.r[3];
|
||||
const util::BitPack32 option = { static_cast<u32>(args.r[4]) };
|
||||
|
||||
const auto copy_type = option.Get<IramCopyOption::CopyType>();
|
||||
|
||||
/* Validate arguments. */
|
||||
SMC_R_UNLESS(copy_type < IramCopyType_Count, InvalidArgument);
|
||||
|
||||
{
|
||||
/* Map the pages. */
|
||||
AtmosphereUserPageMapper dram_mapper(dram_address);
|
||||
AtmosphereIramPageMapper iram_mapper(iram_address);
|
||||
SMC_R_UNLESS(dram_mapper.Map(), InvalidArgument);
|
||||
SMC_R_UNLESS(iram_mapper.Map(), InvalidArgument);
|
||||
|
||||
/* Get the ranges we're copying. */
|
||||
const void * const src = (copy_type == IramCopyType_FromIramToDram) ? iram_mapper.GetPointerTo(iram_address, size) : dram_mapper.GetPointerTo(dram_address, size);
|
||||
void * const dst = (copy_type == IramCopyType_FromIramToDram) ? dram_mapper.GetPointerTo(dram_address, size) : iram_mapper.GetPointerTo(iram_address, size);
|
||||
SMC_R_UNLESS(src != nullptr, InvalidArgument);
|
||||
SMC_R_UNLESS(dst != nullptr, InvalidArgument);
|
||||
|
||||
/* Copy the data. */
|
||||
std::memcpy(dst, src, size);
|
||||
}
|
||||
|
||||
return SmcResult::Success;
|
||||
}
|
||||
|
||||
SmcResult SmcWriteAddress(SmcArguments &args) {
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_page_mapper.hpp"
|
||||
#include "secmon_smc_result.hpp"
|
||||
#include "secmon_page_mapper.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include <exosphere.hpp>
|
||||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_key_storage.hpp"
|
||||
#include "../secmon_page_mapper.hpp"
|
||||
#include "secmon_smc_aes.hpp"
|
||||
#include "secmon_smc_rsa.hpp"
|
||||
#include "secmon_smc_se_lock.hpp"
|
||||
#include "secmon_page_mapper.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue