Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 1 | extern "C" |
| 2 | { |
| 3 | #include <libpdbg.h> |
| 4 | } |
Andrew Geissler | 5c3f925 | 2021-06-10 10:53:05 -0500 | [diff] [blame^] | 5 | #include "attributes_info.H" |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 6 | |
| 7 | #include "phalerror/phal_error.hpp" |
| 8 | #include "procedures/phal/common_utils.hpp" |
| 9 | |
Jayanth Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 10 | #include <fmt/format.h> |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 11 | #include <libekb.H> |
| 12 | |
| 13 | #include <phosphor-logging/log.hpp> |
| 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace phal |
| 18 | { |
| 19 | |
| 20 | using namespace phosphor::logging; |
| 21 | |
| 22 | void 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 Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 31 | // 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 Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 43 | 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 Geissler | 5c3f925 | 2021-06-10 10:53:05 -0500 | [diff] [blame^] | 62 | /** |
| 63 | * @brief Check if primary processor or not |
| 64 | * |
| 65 | * @return True/False |
| 66 | */ |
| 67 | bool 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 Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 90 | } // namespace phal |
| 91 | } // namespace openpower |