Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 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 | */ |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 16 | #include "data_interface.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 17 | #include "elog_entry.hpp" |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 18 | #include "event_logger.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 19 | #include "extensions.hpp" |
Matt Spinler | d96fa60 | 2022-12-15 11:11:26 -0600 | [diff] [blame] | 20 | #include "journal.hpp" |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 21 | #include "manager.hpp" |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 22 | #include "pldm_interface.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 23 | |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | 4d779b2 | 2021-06-03 05:45:13 -0500 | [diff] [blame] | 25 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 26 | #include <format> |
| 27 | |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame^] | 28 | #ifdef PEL_ENABLE_PHAL |
| 29 | #include "libekb.H" |
| 30 | #include "libpdbg.h" |
| 31 | #endif |
| 32 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 33 | namespace openpower |
| 34 | { |
| 35 | namespace pels |
| 36 | { |
| 37 | |
| 38 | using namespace phosphor::logging; |
| 39 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 40 | std::unique_ptr<Manager> manager; |
| 41 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 42 | DISABLE_LOG_ENTRY_CAPS() |
Matt Spinler | b9883ea | 2020-07-07 15:08:35 -0500 | [diff] [blame] | 43 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 44 | void pelStartup(internal::Manager& logManager) |
| 45 | { |
Paul Fertser | 221b79b | 2024-03-04 15:40:23 +0000 | [diff] [blame] | 46 | 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 Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 50 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 51 | std::unique_ptr<DataInterfaceBase> dataIface = |
| 52 | std::make_unique<DataInterface>(logManager.getBus()); |
| 53 | |
Matt Spinler | d96fa60 | 2022-12-15 11:11:26 -0600 | [diff] [blame] | 54 | std::unique_ptr<JournalBase> journal = std::make_unique<Journal>(); |
| 55 | |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 56 | #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 Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 60 | manager = std::make_unique<Manager>(logManager, std::move(dataIface), |
Matt Spinler | d96fa60 | 2022-12-15 11:11:26 -0600 | [diff] [blame] | 61 | std::move(logger), std::move(journal), |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 62 | std::move(hostIface)); |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 63 | #else |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 64 | manager = std::make_unique<Manager>(logManager, std::move(dataIface), |
Matt Spinler | d96fa60 | 2022-12-15 11:11:26 -0600 | [diff] [blame] | 65 | std::move(logger), std::move(journal)); |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 66 | #endif |
Jayanth Othayoth | 4d779b2 | 2021-06-03 05:45:13 -0500 | [diff] [blame] | 67 | |
Jayanth Othayoth | 92b2066 | 2021-11-05 00:09:15 -0500 | [diff] [blame] | 68 | #ifdef PEL_ENABLE_PHAL |
Jayanth Othayoth | d421ae2 | 2021-06-15 10:59:16 -0500 | [diff] [blame] | 69 | // 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 Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 77 | lg2::error("Failed to set PDBG_DTB: ({ERRNO})", "ERRNO", |
| 78 | strerror(errno)); |
Jayanth Othayoth | d421ae2 | 2021-06-15 10:59:16 -0500 | [diff] [blame] | 79 | } |
Arya K Padman | d8ae618 | 2024-07-19 06:25:10 -0500 | [diff] [blame^] | 80 | |
| 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 Othayoth | 4d779b2 | 2021-06-03 05:45:13 -0500 | [diff] [blame] | 93 | #endif |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 96 | REGISTER_EXTENSION_FUNCTION(pelStartup) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 97 | |
| 98 | void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp, |
| 99 | Entry::Level severity, const AdditionalDataArg& additionalData, |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 100 | const AssociationEndpointsArg& assocs, const FFDCArg& ffdc) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 101 | { |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 102 | manager->create(message, id, timestamp, severity, additionalData, assocs, |
| 103 | ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 106 | REGISTER_EXTENSION_FUNCTION(pelCreate) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 107 | |
| 108 | void pelDelete(uint32_t id) |
| 109 | { |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 110 | return manager->erase(id); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 113 | REGISTER_EXTENSION_FUNCTION(pelDelete) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 114 | |
| 115 | void pelDeleteProhibited(uint32_t id, bool& prohibited) |
| 116 | { |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 117 | prohibited = manager->isDeleteProhibited(id); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 120 | REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 121 | |
| 122 | } // namespace pels |
| 123 | } // namespace openpower |