blob: c8ead0c098e985b04d468b141dd78c1a53a80fe7 [file] [log] [blame]
Dhruvaraj Subhashchandran08fc2642020-02-17 01:47:05 -06001/**
2 * Copyright (C) 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <libpdbg.h>
18
19#include <phosphor-logging/log.hpp>
20#include <thread>
21#include <vector>
22
23namespace openpower
24{
25namespace p9
26{
27
28/**
29 * @brief Calls sbe_enter_mpipl on the SBE in the provided target.
30 * @return void
31 */
32void sbeEnterMpReboot(struct pdbg_target* tgt)
33{
34 using namespace phosphor::logging;
35 int error = 0;
36 if ((error = sbe_mpipl_enter(tgt)) < 0)
37 {
38 log<level::ERR>("Failed to initiate memory preserving reboot");
39 // TODO Create a PEL in the future for this failure case.
40 throw std::system_error(error, std::generic_category(),
41 "Failed to initiate memory preserving reboot");
42 }
43}
44
45/**
46 * @brief initiate memory preserving reboot on each SBE.
47 * @return void
48 */
49void enterMpReboot()
50{
51 using namespace phosphor::logging;
52 struct pdbg_target* target;
53 std::vector<std::thread> threads;
54 pdbg_targets_init(NULL);
55
56 log<level::INFO>("Starting memory preserving reboot");
57 pdbg_for_each_class_target("pib", target)
58 {
59 if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
60 {
61 continue;
62 }
63 std::thread t(sbeEnterMpReboot, target);
64 threads.push_back(std::move(t));
65 }
66
67 for (auto& t : threads)
68 {
69 t.join();
70 }
71}
72
73REGISTER_PROCEDURE("enterMpReboot", enterMpReboot);
74
75} // namespace p9
76} // namespace openpower