blob: 47717b98edc9457ed874014026075bb9e58972ad [file] [log] [blame]
Jayanth Othayothc3d6b872021-07-28 05:07:25 -05001#include "extensions/phal/common_utils.hpp"
2
Andrew Geissler5c3f9252021-06-10 10:53:05 -05003#include "attributes_info.H"
Chirag Sharmaa2576932020-12-05 23:17:41 -06004
Jayanth Othayothc3d6b872021-07-28 05:07:25 -05005#include "extensions/phal/pdbg_utils.hpp"
Jayanth Othayoth6552de02021-07-12 00:55:57 -05006#include "extensions/phal/phal_error.hpp"
Chirag Sharmaa2576932020-12-05 23:17:41 -06007
8#include <libekb.H>
9
10#include <phosphor-logging/log.hpp>
11
12namespace openpower
13{
14namespace phal
15{
16
17using namespace phosphor::logging;
18
19void phal_init(enum ipl_mode mode)
20{
21 // TODO: Setting boot error callback should not be in common code
22 // because, we wont get proper reason in PEL for failure.
23 // So, need to make code like caller of this function pass error
24 // handling callback.
25 // add callback methods for debug traces and for boot failures
26 openpower::pel::addBootErrorCallbacks();
27
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -050028 // PDBG_DTB environment variable set to CEC device tree path
Jayanth Othayoth2de8c8d2021-07-16 06:40:33 -050029 setDevtreeEnv();
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -050030
Chirag Sharmaa2576932020-12-05 23:17:41 -060031 if (!pdbg_targets_init(NULL))
32 {
33 log<level::ERR>("pdbg_targets_init failed");
34 throw std::runtime_error("pdbg target initialization failed");
35 }
36
37 if (libekb_init())
38 {
39 log<level::ERR>("libekb_init failed");
40 throw std::runtime_error("libekb initialization failed");
41 }
42
43 if (ipl_init(mode) != 0)
44 {
45 log<level::ERR>("ipl_init failed");
46 throw std::runtime_error("libipl initialization failed");
47 }
48}
49
Andrew Geissler5c3f9252021-06-10 10:53:05 -050050bool isPrimaryProc(struct pdbg_target* procTarget)
51{
52 ATTR_PROC_MASTER_TYPE_Type type;
53
54 // Get processor type (Primary or Secondary)
55 if (DT_GET_PROP(ATTR_PROC_MASTER_TYPE, procTarget, type))
56 {
57 log<level::ERR>("Attribute [ATTR_PROC_MASTER_TYPE] get failed");
58 throw std::runtime_error(
59 "Attribute [ATTR_PROC_MASTER_TYPE] get failed");
60 }
61
62 /* Attribute value 0 corresponds to primary processor */
63 if (type == ENUM_ATTR_PROC_MASTER_TYPE_ACTING_MASTER)
64 {
65 return true;
66 }
67 else
68 {
69 return false;
70 }
71}
72
Chirag Sharmaa2576932020-12-05 23:17:41 -060073} // namespace phal
74} // namespace openpower