blob: 0b58212f8ecb884522156d81c31d2ba2001b9cd4 [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 Spinlerd96fa602022-12-15 11:11:26 -060020#include "journal.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050021#include "manager.hpp"
Matt Spinler17ed2ed2019-12-12 14:12:23 -060022#include "pldm_interface.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050023
Arya K Padman5bc26532024-04-10 06:19:25 -050024#include <phosphor-logging/lg2.hpp>
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050025
Jayanth Othayoth1aa90d42023-09-13 04:25:45 -050026#include <format>
27
Arya K Padmand8ae6182024-07-19 06:25:10 -050028#ifdef PEL_ENABLE_PHAL
29#include "libekb.H"
30#include "libpdbg.h"
31#endif
32
Matt Spinler99c2b402019-05-23 14:29:16 -050033namespace openpower
34{
35namespace pels
36{
37
38using namespace phosphor::logging;
39
Matt Spinler4e8078c2019-07-09 13:22:32 -050040std::unique_ptr<Manager> manager;
41
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050042DISABLE_LOG_ENTRY_CAPS()
Matt Spinlerb9883ea2020-07-07 15:08:35 -050043
Matt Spinler99c2b402019-05-23 14:29:16 -050044void pelStartup(internal::Manager& logManager)
45{
Paul Fertser221b79b2024-03-04 15:40:23 +000046 EventLogger::LogFunction logger =
47 std::bind(std::mem_fn(&internal::Manager::create), &logManager,
48 std::placeholders::_1, std::placeholders::_2,
49 std::placeholders::_3, phosphor::logging::FFDCEntries{});
Matt Spinlerf682b402019-12-18 13:48:08 -060050
Matt Spinlerc8705e22019-09-11 12:36:07 -050051 std::unique_ptr<DataInterfaceBase> dataIface =
52 std::make_unique<DataInterface>(logManager.getBus());
53
Matt Spinlerd96fa602022-12-15 11:11:26 -060054 std::unique_ptr<JournalBase> journal = std::make_unique<Journal>();
55
Matt Spinler17ed2ed2019-12-12 14:12:23 -060056#ifndef DONT_SEND_PELS_TO_HOST
57 std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>(
58 logManager.getBus().get_event(), *(dataIface.get()));
59
Patrick Williams2544b412022-10-04 08:41:06 -050060 manager = std::make_unique<Manager>(logManager, std::move(dataIface),
Matt Spinlerd96fa602022-12-15 11:11:26 -060061 std::move(logger), std::move(journal),
Patrick Williams2544b412022-10-04 08:41:06 -050062 std::move(hostIface));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060063#else
Matt Spinlerf682b402019-12-18 13:48:08 -060064 manager = std::make_unique<Manager>(logManager, std::move(dataIface),
Matt Spinlerd96fa602022-12-15 11:11:26 -060065 std::move(logger), std::move(journal));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060066#endif
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050067
Jayanth Othayoth92b20662021-11-05 00:09:15 -050068#ifdef PEL_ENABLE_PHAL
Jayanth Othayothd421ae22021-06-15 10:59:16 -050069 // PDBG_DTB environment variable set to CEC device tree path
70 static constexpr auto PDBG_DTB_PATH =
71 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
72
73 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
74 {
75 // Log message and continue,
76 // This is to help continue creating PEL in raw format.
Arya K Padman5bc26532024-04-10 06:19:25 -050077 lg2::error("Failed to set PDBG_DTB: ({ERRNO})", "ERRNO",
78 strerror(errno));
Jayanth Othayothd421ae22021-06-15 10:59:16 -050079 }
Arya K Padmand8ae6182024-07-19 06:25:10 -050080
81 if (!pdbg_targets_init(NULL))
82 {
83 lg2::error("pdbg_targets_init failed");
84 return;
85 }
86
87 if (libekb_init())
88 {
89 lg2::error("libekb_init failed, skipping ffdc processing");
90 return;
91 }
92
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050093#endif
Matt Spinler99c2b402019-05-23 14:29:16 -050094}
95
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050096REGISTER_EXTENSION_FUNCTION(pelStartup)
Matt Spinler99c2b402019-05-23 14:29:16 -050097
98void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
99 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500100 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -0500101{
Matt Spinler56ad2a02020-03-26 14:00:52 -0500102 manager->create(message, id, timestamp, severity, additionalData, assocs,
103 ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500104}
105
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500106REGISTER_EXTENSION_FUNCTION(pelCreate)
Matt Spinler99c2b402019-05-23 14:29:16 -0500107
108void pelDelete(uint32_t id)
109{
Matt Spinler4e8078c2019-07-09 13:22:32 -0500110 return manager->erase(id);
Matt Spinler99c2b402019-05-23 14:29:16 -0500111}
112
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500113REGISTER_EXTENSION_FUNCTION(pelDelete)
Matt Spinler99c2b402019-05-23 14:29:16 -0500114
115void pelDeleteProhibited(uint32_t id, bool& prohibited)
116{
Matt Spinler4e8078c2019-07-09 13:22:32 -0500117 prohibited = manager->isDeleteProhibited(id);
Matt Spinler99c2b402019-05-23 14:29:16 -0500118}
119
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500120REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited)
Matt Spinler99c2b402019-05-23 14:29:16 -0500121
122} // namespace pels
123} // namespace openpower