blob: c1f39a6eacaf179f17c11701c834b33655c82e03 [file] [log] [blame]
Brad Bishop5e5d4452020-10-27 19:46:13 -04001extern "C"
2{
Ramesh Iyyarc98bab52020-04-16 04:04:29 -05003#include <libpdbg.h>
4}
5
Brad Bishop5e5d4452020-10-27 19:46:13 -04006#include "attributes_info.H"
7
Marri Devender Rao78479602020-01-06 03:45:11 -06008#include "phalerror/phal_error.hpp"
Chirag Sharmaa2576932020-12-05 23:17:41 -06009#include "procedures/phal/common_utils.hpp"
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050010
Ramesh Iyyarc98bab52020-04-16 04:04:29 -050011#include <libekb.H>
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050012
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -050013#include <ext_interface.hpp>
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050014#include <phosphor-logging/log.hpp>
15#include <registration.hpp>
16namespace openpower
17{
18namespace phal
19{
20
21using namespace phosphor::logging;
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050022
23/**
Lakshminarayana R. Kammath75912e82020-04-28 07:37:17 -050024 * @brief Check if master processor or not
25 *
26 * @return True/False
27 */
28bool isMasterProc(struct pdbg_target* procTarget)
29{
30 ATTR_PROC_MASTER_TYPE_Type type;
31
32 // Get processor type (Master or Alt-master)
33 if (DT_GET_PROP(ATTR_PROC_MASTER_TYPE, procTarget, type))
34 {
35 log<level::ERR>("Attribute [ATTR_PROC_MASTER_TYPE] get failed");
36 throw std::runtime_error(
37 "Attribute [ATTR_PROC_MASTER_TYPE] get failed");
38 }
39
40 /* Attribute value 0 corresponds to master processor */
41 if (type == 0)
42 {
43 return true;
44 }
45 else
46 {
47 return false;
48 }
49}
50
51/**
52 * @brief Select BOOT SEEPROM and Measurement SEEPROM(PRIMARY/BACKUP) on POWER
53 * processor position 0/1 depending on boot count before kicking off
54 * the boot.
55 *
56 * @return void
57 */
58void selectBootSeeprom()
59{
60 struct pdbg_target* procTarget;
61 ATTR_BACKUP_SEEPROM_SELECT_Enum bkpSeePromSelect;
62 ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_Enum bkpMeaSeePromSelect;
63
64 pdbg_for_each_class_target("proc", procTarget)
65 {
66 if (!isMasterProc(procTarget))
67 {
68 continue;
69 }
70
71 // Choose seeprom side to boot from based on boot count
72 if (getBootCount() > 0)
73 {
74 log<level::INFO>("Setting SBE seeprom side to 0",
75 entry("SBE_SIDE_SELECT=%d",
76 ENUM_ATTR_BACKUP_SEEPROM_SELECT_PRIMARY));
77
78 bkpSeePromSelect = ENUM_ATTR_BACKUP_SEEPROM_SELECT_PRIMARY;
79 bkpMeaSeePromSelect =
80 ENUM_ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_PRIMARY;
81 }
82 else
83 {
84 log<level::INFO>("Setting SBE seeprom side to 1",
85 entry("SBE_SIDE_SELECT=%d",
86 ENUM_ATTR_BACKUP_SEEPROM_SELECT_SECONDARY));
87 bkpSeePromSelect = ENUM_ATTR_BACKUP_SEEPROM_SELECT_SECONDARY;
88 bkpMeaSeePromSelect =
89 ENUM_ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT_SECONDARY;
90 }
91
92 // Set the Attribute as per bootcount policy for boot seeprom
93 if (DT_SET_PROP(ATTR_BACKUP_SEEPROM_SELECT, procTarget,
94 bkpSeePromSelect))
95 {
96 log<level::ERR>(
97 "Attribute [ATTR_BACKUP_SEEPROM_SELECT] set failed");
98 throw std::runtime_error(
99 "Attribute [ATTR_BACKUP_SEEPROM_SELECT] set failed");
100 }
101
102 // Set the Attribute as per bootcount policy for measurement seeprom
103 if (DT_SET_PROP(ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT, procTarget,
104 bkpMeaSeePromSelect))
105 {
106 log<level::ERR>(
107 "Attribute [ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT] set "
108 "failed");
109 throw std::runtime_error(
110 "Attribute [ATTR_BACKUP_MEASUREMENT_SEEPROM_SELECT] set "
111 "failed");
112 }
113 }
114}
115
116/**
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500117 * @brief Starts the self boot engine on POWER processor position 0
118 * to kick off a boot.
119 * @return void
120 */
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500121void startHost(enum ipl_type iplType = IPL_TYPE_NORMAL)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500122{
Chirag Sharmaa2576932020-12-05 23:17:41 -0600123 try
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500124 {
Chirag Sharmaa2576932020-12-05 23:17:41 -0600125 phal_init();
126 ipl_set_type(iplType);
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500127 }
Chirag Sharmaa2576932020-12-05 23:17:41 -0600128 catch (std::exception& ex)
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500129 {
Chirag Sharmaa2576932020-12-05 23:17:41 -0600130 log<level::ERR>("Exception raised during init PHAL",
131 entry("EXCEPTION=%s", ex.what()));
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500132 openpower::pel::detail::processBootErrorCallback(false);
Chirag Sharmaa2576932020-12-05 23:17:41 -0600133 throw std::runtime_error("PHAL initialization failed");
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500134 }
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500135
Ramesh Iyyarc98bab52020-04-16 04:04:29 -0500136 // To clear trace if success
137 openpower::pel::detail::processBootErrorCallback(true);
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500138
Marri Devender Rao78479602020-01-06 03:45:11 -0600139 // callback method will be called upon failure which will create the PEL
140 int rc = ipl_run_major(0);
141 if (rc > 0)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500142 {
143 log<level::ERR>("step 0 failed to start the host");
Marri Devender Rao78479602020-01-06 03:45:11 -0600144 throw std::runtime_error("Failed to execute host start boot step");
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500145 }
146}
147
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500148/**
149 * @brief Starts the reboot with type memory preserving reboot.
150 * @return void
151 */
152void startHostMpReboot()
153{
154 // set ipl type as mpipl
155 startHost(IPL_TYPE_MPIPL);
156}
157
158/**
159 * @brief Starts the normal boot type.
160 * @return void
161 */
162void startHostNormal()
163{
Dhruvaraj Subhashchandran3ae7ed42020-06-16 12:48:14 -0500164 // Run select seeprom before poweron
165 try
166 {
167 selectBootSeeprom();
168
169 // To clear trace as it is success
170 openpower::pel::detail::processBootErrorCallback(true);
171 }
172 catch (const std::exception& ex)
173 {
174 // create PEL in failure
175 openpower::pel::detail::processBootErrorCallback(false);
176 log<level::ERR>("SEEPROM selection failed", entry("ERR=%s", ex.what()));
177 throw ex;
178 }
179
Dhruvaraj Subhashchandranc2e42762020-06-17 00:30:12 -0500180 startHost();
181}
182
Brad Bishop63508a72020-10-27 18:55:01 -0400183REGISTER_PROCEDURE("startHost", startHostNormal)
184REGISTER_PROCEDURE("startHostMpReboot", startHostMpReboot)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500185
186} // namespace phal
187} // namespace openpower