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