xref: /openbmc/openpower-proc-control/extensions/phal/common_utils.cpp (revision e0dd7af42a30b89e9f820c999bfe4a9bacc2a01d)
1*c3d6b876SJayanth Othayoth #include "extensions/phal/common_utils.hpp"
2*c3d6b876SJayanth Othayoth 
325e39c84SJayanth Othayoth #include "attributes_info.H"
425e39c84SJayanth Othayoth 
5*c3d6b876SJayanth Othayoth #include "extensions/phal/pdbg_utils.hpp"
625e39c84SJayanth Othayoth #include "extensions/phal/phal_error.hpp"
725e39c84SJayanth Othayoth 
825e39c84SJayanth Othayoth #include <libekb.H>
925e39c84SJayanth Othayoth 
1025e39c84SJayanth Othayoth #include <phosphor-logging/log.hpp>
1125e39c84SJayanth Othayoth 
1225e39c84SJayanth Othayoth namespace openpower
1325e39c84SJayanth Othayoth {
1425e39c84SJayanth Othayoth namespace phal
1525e39c84SJayanth Othayoth {
1625e39c84SJayanth Othayoth 
1725e39c84SJayanth Othayoth using namespace phosphor::logging;
1825e39c84SJayanth Othayoth 
phal_init(enum ipl_mode mode)1925e39c84SJayanth Othayoth void phal_init(enum ipl_mode mode)
2025e39c84SJayanth Othayoth {
2125e39c84SJayanth Othayoth     // TODO: Setting boot error callback should not be in common code
2225e39c84SJayanth Othayoth     //       because, we wont get proper reason in PEL for failure.
2325e39c84SJayanth Othayoth     //       So, need to make code like caller of this function pass error
2425e39c84SJayanth Othayoth     //       handling callback.
2525e39c84SJayanth Othayoth     // add callback methods for debug traces and for boot failures
2625e39c84SJayanth Othayoth     openpower::pel::addBootErrorCallbacks();
2725e39c84SJayanth Othayoth 
2825e39c84SJayanth Othayoth     // PDBG_DTB environment variable set to CEC device tree path
292de8c8d2SJayanth Othayoth     setDevtreeEnv();
3025e39c84SJayanth Othayoth 
3125e39c84SJayanth Othayoth     if (!pdbg_targets_init(NULL))
3225e39c84SJayanth Othayoth     {
3325e39c84SJayanth Othayoth         log<level::ERR>("pdbg_targets_init failed");
3425e39c84SJayanth Othayoth         throw std::runtime_error("pdbg target initialization failed");
3525e39c84SJayanth Othayoth     }
3625e39c84SJayanth Othayoth 
3725e39c84SJayanth Othayoth     if (libekb_init())
3825e39c84SJayanth Othayoth     {
3925e39c84SJayanth Othayoth         log<level::ERR>("libekb_init failed");
4025e39c84SJayanth Othayoth         throw std::runtime_error("libekb initialization failed");
4125e39c84SJayanth Othayoth     }
4225e39c84SJayanth Othayoth 
4325e39c84SJayanth Othayoth     if (ipl_init(mode) != 0)
4425e39c84SJayanth Othayoth     {
4525e39c84SJayanth Othayoth         log<level::ERR>("ipl_init failed");
4625e39c84SJayanth Othayoth         throw std::runtime_error("libipl initialization failed");
4725e39c84SJayanth Othayoth     }
4825e39c84SJayanth Othayoth }
4925e39c84SJayanth Othayoth 
isPrimaryProc(struct pdbg_target * procTarget)5025e39c84SJayanth Othayoth bool isPrimaryProc(struct pdbg_target* procTarget)
5125e39c84SJayanth Othayoth {
5225e39c84SJayanth Othayoth     ATTR_PROC_MASTER_TYPE_Type type;
5325e39c84SJayanth Othayoth 
5425e39c84SJayanth Othayoth     // Get processor type (Primary or Secondary)
5525e39c84SJayanth Othayoth     if (DT_GET_PROP(ATTR_PROC_MASTER_TYPE, procTarget, type))
5625e39c84SJayanth Othayoth     {
5725e39c84SJayanth Othayoth         log<level::ERR>("Attribute [ATTR_PROC_MASTER_TYPE] get failed");
5825e39c84SJayanth Othayoth         throw std::runtime_error(
5925e39c84SJayanth Othayoth             "Attribute [ATTR_PROC_MASTER_TYPE] get failed");
6025e39c84SJayanth Othayoth     }
6125e39c84SJayanth Othayoth 
6225e39c84SJayanth Othayoth     /* Attribute value 0 corresponds to primary processor */
6325e39c84SJayanth Othayoth     if (type == ENUM_ATTR_PROC_MASTER_TYPE_ACTING_MASTER)
6425e39c84SJayanth Othayoth     {
6525e39c84SJayanth Othayoth         return true;
6625e39c84SJayanth Othayoth     }
6725e39c84SJayanth Othayoth     else
6825e39c84SJayanth Othayoth     {
6925e39c84SJayanth Othayoth         return false;
7025e39c84SJayanth Othayoth     }
7125e39c84SJayanth Othayoth }
7225e39c84SJayanth Othayoth 
7325e39c84SJayanth Othayoth } // namespace phal
7425e39c84SJayanth Othayoth } // namespace openpower
75