blob: 06c2ef8cab86299528a59f37a0e5165476fe0a9b [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
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 */
Matt Spinlerc8705e22019-09-11 12:36:07 -050016#include "data_interface.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050017#include "elog_entry.hpp"
Matt Spinlerf682b402019-12-18 13:48:08 -060018#include "event_logger.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050019#include "extensions.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050020#include "manager.hpp"
Matt Spinler17ed2ed2019-12-12 14:12:23 -060021#include "pldm_interface.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050022
Jayanth Othayothd421ae22021-06-15 10:59:16 -050023#include <fmt/format.h>
24
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050025#include <phosphor-logging/log.hpp>
26
27#ifdef SBE_FFDC_SUPPORTED
Jayanth Othayothc74c2202021-06-04 06:42:43 -050028#include <libekb.H>
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050029#include <libpdbg.h>
30#endif
31
Matt Spinler99c2b402019-05-23 14:29:16 -050032namespace openpower
33{
34namespace pels
35{
36
37using namespace phosphor::logging;
38
Matt Spinler4e8078c2019-07-09 13:22:32 -050039std::unique_ptr<Manager> manager;
40
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050041DISABLE_LOG_ENTRY_CAPS()
Matt Spinlerb9883ea2020-07-07 15:08:35 -050042
Matt Spinler99c2b402019-05-23 14:29:16 -050043void pelStartup(internal::Manager& logManager)
44{
Matt Spinlerf682b402019-12-18 13:48:08 -060045 EventLogger::LogFunction logger = std::bind(
46 std::mem_fn(&internal::Manager::create), &logManager,
47 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
48
Matt Spinlerc8705e22019-09-11 12:36:07 -050049 std::unique_ptr<DataInterfaceBase> dataIface =
50 std::make_unique<DataInterface>(logManager.getBus());
51
Matt Spinler17ed2ed2019-12-12 14:12:23 -060052#ifndef DONT_SEND_PELS_TO_HOST
53 std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>(
54 logManager.getBus().get_event(), *(dataIface.get()));
55
Matt Spinlerf682b402019-12-18 13:48:08 -060056 manager =
57 std::make_unique<Manager>(logManager, std::move(dataIface),
58 std::move(logger), std::move(hostIface));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060059#else
Matt Spinlerf682b402019-12-18 13:48:08 -060060 manager = std::make_unique<Manager>(logManager, std::move(dataIface),
61 std::move(logger));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060062#endif
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050063
64#ifdef SBE_FFDC_SUPPORTED
Jayanth Othayothd421ae22021-06-15 10:59:16 -050065 // PDBG_DTB environment variable set to CEC device tree path
66 static constexpr auto PDBG_DTB_PATH =
67 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
68
69 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
70 {
71 // Log message and continue,
72 // This is to help continue creating PEL in raw format.
73 log<level::ERR>(
74 fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno))
75 .c_str());
76 }
77
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050078 if (!pdbg_targets_init(NULL))
79 {
80 log<level::ERR>("pdbg_targets_init failed");
81 throw std::runtime_error("pdbg target initialization failed");
82 }
Jayanth Othayothc74c2202021-06-04 06:42:43 -050083
84 if (libekb_init())
85 {
86 log<level::ERR>("libekb_init failed");
87 throw std::runtime_error("libekb initialization failed");
88 }
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050089#endif
Matt Spinler99c2b402019-05-23 14:29:16 -050090}
91
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050092REGISTER_EXTENSION_FUNCTION(pelStartup)
Matt Spinler99c2b402019-05-23 14:29:16 -050093
94void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
95 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050096 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050097{
Matt Spinler56ad2a02020-03-26 14:00:52 -050098 manager->create(message, id, timestamp, severity, additionalData, assocs,
99 ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500100}
101
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500102REGISTER_EXTENSION_FUNCTION(pelCreate)
Matt Spinler99c2b402019-05-23 14:29:16 -0500103
104void pelDelete(uint32_t id)
105{
Matt Spinler4e8078c2019-07-09 13:22:32 -0500106 return manager->erase(id);
Matt Spinler99c2b402019-05-23 14:29:16 -0500107}
108
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500109REGISTER_EXTENSION_FUNCTION(pelDelete)
Matt Spinler99c2b402019-05-23 14:29:16 -0500110
111void pelDeleteProhibited(uint32_t id, bool& prohibited)
112{
Matt Spinler4e8078c2019-07-09 13:22:32 -0500113 prohibited = manager->isDeleteProhibited(id);
Matt Spinler99c2b402019-05-23 14:29:16 -0500114}
115
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500116REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited)
Matt Spinler99c2b402019-05-23 14:29:16 -0500117
118} // namespace pels
119} // namespace openpower