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 "journal.hpp" 21 #include "manager.hpp" 22 #include "pldm_interface.hpp" 23 24 #include <phosphor-logging/lg2.hpp> 25 26 #include <format> 27 28 namespace openpower 29 { 30 namespace pels 31 { 32 33 using namespace phosphor::logging; 34 35 std::unique_ptr<Manager> manager; 36 37 DISABLE_LOG_ENTRY_CAPS() 38 39 void pelStartup(internal::Manager& logManager) 40 { 41 EventLogger::LogFunction logger = 42 std::bind(std::mem_fn(&internal::Manager::create), &logManager, 43 std::placeholders::_1, std::placeholders::_2, 44 std::placeholders::_3, phosphor::logging::FFDCEntries{}); 45 46 std::unique_ptr<DataInterfaceBase> dataIface = 47 std::make_unique<DataInterface>(logManager.getBus()); 48 49 std::unique_ptr<JournalBase> journal = std::make_unique<Journal>(); 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 = std::make_unique<Manager>(logManager, std::move(dataIface), 56 std::move(logger), std::move(journal), 57 std::move(hostIface)); 58 #else 59 manager = std::make_unique<Manager>(logManager, std::move(dataIface), 60 std::move(logger), std::move(journal)); 61 #endif 62 63 #ifdef PEL_ENABLE_PHAL 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 lg2::error("Failed to set PDBG_DTB: ({ERRNO})", "ERRNO", 73 strerror(errno)); 74 } 75 #endif 76 } 77 78 REGISTER_EXTENSION_FUNCTION(pelStartup) 79 80 void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp, 81 Entry::Level severity, const AdditionalDataArg& additionalData, 82 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc) 83 { 84 manager->create(message, id, timestamp, severity, additionalData, assocs, 85 ffdc); 86 } 87 88 REGISTER_EXTENSION_FUNCTION(pelCreate) 89 90 void pelDelete(uint32_t id) 91 { 92 return manager->erase(id); 93 } 94 95 REGISTER_EXTENSION_FUNCTION(pelDelete) 96 97 void pelDeleteProhibited(uint32_t id, bool& prohibited) 98 { 99 prohibited = manager->isDeleteProhibited(id); 100 } 101 102 REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited) 103 104 } // namespace pels 105 } // namespace openpower 106