Jayanth Othayoth | c3d6b87 | 2021-07-28 05:07:25 -0500 | [diff] [blame^] | 1 | #include "extensions/phal/common_utils.hpp" |
| 2 | |
Andrew Geissler | 5c3f925 | 2021-06-10 10:53:05 -0500 | [diff] [blame] | 3 | #include "attributes_info.H" |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 4 | |
Jayanth Othayoth | c3d6b87 | 2021-07-28 05:07:25 -0500 | [diff] [blame^] | 5 | #include "extensions/phal/pdbg_utils.hpp" |
Jayanth Othayoth | 6552de0 | 2021-07-12 00:55:57 -0500 | [diff] [blame] | 6 | #include "extensions/phal/phal_error.hpp" |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 7 | |
Jayanth Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 8 | #include <fmt/format.h> |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 9 | #include <libekb.H> |
| 10 | |
| 11 | #include <phosphor-logging/log.hpp> |
| 12 | |
| 13 | namespace openpower |
| 14 | { |
| 15 | namespace phal |
| 16 | { |
| 17 | |
| 18 | using namespace phosphor::logging; |
| 19 | |
| 20 | void 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 Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 29 | // PDBG_DTB environment variable set to CEC device tree path |
Jayanth Othayoth | 2de8c8d | 2021-07-16 06:40:33 -0500 | [diff] [blame] | 30 | setDevtreeEnv(); |
Jayanth Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 31 | |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 32 | 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 Geissler | 5c3f925 | 2021-06-10 10:53:05 -0500 | [diff] [blame] | 51 | bool 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 Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 74 | } // namespace phal |
| 75 | } // namespace openpower |