blob: ca37aced0704c9674dc4ccfcb6daf686c5ef094b [file] [log] [blame]
Chirag Sharmaa2576932020-12-05 23:17:41 -06001extern "C"
2{
3#include <libpdbg.h>
4}
Andrew Geissler5c3f9252021-06-10 10:53:05 -05005#include "attributes_info.H"
Chirag Sharmaa2576932020-12-05 23:17:41 -06006
7#include "phalerror/phal_error.hpp"
8#include "procedures/phal/common_utils.hpp"
9
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -050010#include <fmt/format.h>
Chirag Sharmaa2576932020-12-05 23:17:41 -060011#include <libekb.H>
12
13#include <phosphor-logging/log.hpp>
14
15namespace openpower
16{
17namespace phal
18{
19
20using namespace phosphor::logging;
21
22void phal_init(enum ipl_mode mode)
23{
24 // TODO: Setting boot error callback should not be in common code
25 // because, we wont get proper reason in PEL for failure.
26 // So, need to make code like caller of this function pass error
27 // handling callback.
28 // add callback methods for debug traces and for boot failures
29 openpower::pel::addBootErrorCallbacks();
30
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -050031 // PDBG_DTB environment variable set to CEC device tree path
32 static constexpr auto PDBG_DTB_PATH =
33 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
34
35 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
36 {
37 log<level::ERR>(
38 fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno))
39 .c_str());
40 throw std::runtime_error("Failed to set PDBG_DTB");
41 }
42
Chirag Sharmaa2576932020-12-05 23:17:41 -060043 if (!pdbg_targets_init(NULL))
44 {
45 log<level::ERR>("pdbg_targets_init failed");
46 throw std::runtime_error("pdbg target initialization failed");
47 }
48
49 if (libekb_init())
50 {
51 log<level::ERR>("libekb_init failed");
52 throw std::runtime_error("libekb initialization failed");
53 }
54
55 if (ipl_init(mode) != 0)
56 {
57 log<level::ERR>("ipl_init failed");
58 throw std::runtime_error("libipl initialization failed");
59 }
60}
61
Andrew Geissler5c3f9252021-06-10 10:53:05 -050062/**
63 * @brief Check if primary processor or not
64 *
65 * @return True/False
66 */
67bool isPrimaryProc(struct pdbg_target* procTarget)
68{
69 ATTR_PROC_MASTER_TYPE_Type type;
70
71 // Get processor type (Primary or Secondary)
72 if (DT_GET_PROP(ATTR_PROC_MASTER_TYPE, procTarget, type))
73 {
74 log<level::ERR>("Attribute [ATTR_PROC_MASTER_TYPE] get failed");
75 throw std::runtime_error(
76 "Attribute [ATTR_PROC_MASTER_TYPE] get failed");
77 }
78
79 /* Attribute value 0 corresponds to primary processor */
80 if (type == ENUM_ATTR_PROC_MASTER_TYPE_ACTING_MASTER)
81 {
82 return true;
83 }
84 else
85 {
86 return false;
87 }
88}
89
Chirag Sharmaa2576932020-12-05 23:17:41 -060090} // namespace phal
91} // namespace openpower