blob: c8ead0c098e985b04d468b141dd78c1a53a80fe7 [file] [log] [blame]
/**
* Copyright (C) 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <libpdbg.h>
#include <phosphor-logging/log.hpp>
#include <thread>
#include <vector>
namespace openpower
{
namespace p9
{
/**
* @brief Calls sbe_enter_mpipl on the SBE in the provided target.
* @return void
*/
void sbeEnterMpReboot(struct pdbg_target* tgt)
{
using namespace phosphor::logging;
int error = 0;
if ((error = sbe_mpipl_enter(tgt)) < 0)
{
log<level::ERR>("Failed to initiate memory preserving reboot");
// TODO Create a PEL in the future for this failure case.
throw std::system_error(error, std::generic_category(),
"Failed to initiate memory preserving reboot");
}
}
/**
* @brief initiate memory preserving reboot on each SBE.
* @return void
*/
void enterMpReboot()
{
using namespace phosphor::logging;
struct pdbg_target* target;
std::vector<std::thread> threads;
pdbg_targets_init(NULL);
log<level::INFO>("Starting memory preserving reboot");
pdbg_for_each_class_target("pib", target)
{
if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
{
continue;
}
std::thread t(sbeEnterMpReboot, target);
threads.push_back(std::move(t));
}
for (auto& t : threads)
{
t.join();
}
}
REGISTER_PROCEDURE("enterMpReboot", enterMpReboot);
} // namespace p9
} // namespace openpower