xref: /openbmc/phosphor-logging/extensions/openpower-pels/entry_points.cpp (revision 8bcadac750d90427bfc4b282be47114c3dc415b1)
1 /**
2  * Copyright © 2019 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "data_interface.hpp"
17 #include "elog_entry.hpp"
18 #include "event_logger.hpp"
19 #include "extensions.hpp"
20 #include "manager.hpp"
21 #include "pldm_interface.hpp"
22 
23 #include <fmt/format.h>
24 
25 #include <phosphor-logging/log.hpp>
26 
27 #ifdef SBE_FFDC_SUPPORTED
28 #include <libekb.H>
29 #endif
30 
31 namespace openpower
32 {
33 namespace pels
34 {
35 
36 using namespace phosphor::logging;
37 
38 std::unique_ptr<Manager> manager;
39 
40 DISABLE_LOG_ENTRY_CAPS()
41 
42 void pelStartup(internal::Manager& logManager)
43 {
44     EventLogger::LogFunction logger = std::bind(
45         std::mem_fn(&internal::Manager::create), &logManager,
46         std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
47 
48     std::unique_ptr<DataInterfaceBase> dataIface =
49         std::make_unique<DataInterface>(logManager.getBus());
50 
51 #ifndef DONT_SEND_PELS_TO_HOST
52     std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>(
53         logManager.getBus().get_event(), *(dataIface.get()));
54 
55     manager =
56         std::make_unique<Manager>(logManager, std::move(dataIface),
57                                   std::move(logger), std::move(hostIface));
58 #else
59     manager = std::make_unique<Manager>(logManager, std::move(dataIface),
60                                         std::move(logger));
61 #endif
62 
63 #ifdef SBE_FFDC_SUPPORTED
64     // PDBG_DTB environment variable set to CEC device tree path
65     static constexpr auto PDBG_DTB_PATH =
66         "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
67 
68     if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
69     {
70         // Log message and continue,
71         // This is to help continue creating PEL in raw format.
72         log<level::ERR>(
73             fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno))
74                 .c_str());
75     }
76 
77     if (libekb_init())
78     {
79         log<level::ERR>("libekb_init failed");
80         throw std::runtime_error("libekb initialization failed");
81     }
82 #endif
83 }
84 
85 REGISTER_EXTENSION_FUNCTION(pelStartup)
86 
87 void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
88                Entry::Level severity, const AdditionalDataArg& additionalData,
89                const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
90 {
91     manager->create(message, id, timestamp, severity, additionalData, assocs,
92                     ffdc);
93 }
94 
95 REGISTER_EXTENSION_FUNCTION(pelCreate)
96 
97 void pelDelete(uint32_t id)
98 {
99     return manager->erase(id);
100 }
101 
102 REGISTER_EXTENSION_FUNCTION(pelDelete)
103 
104 void pelDeleteProhibited(uint32_t id, bool& prohibited)
105 {
106     prohibited = manager->isDeleteProhibited(id);
107 }
108 
109 REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited)
110 
111 } // namespace pels
112 } // namespace openpower
113