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/log.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 = std::bind( 42 std::mem_fn(&internal::Manager::create), &logManager, 43 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); 44 45 std::unique_ptr<DataInterfaceBase> dataIface = 46 std::make_unique<DataInterface>(logManager.getBus()); 47 48 std::unique_ptr<JournalBase> journal = std::make_unique<Journal>(); 49 50 #ifndef DONT_SEND_PELS_TO_HOST 51 std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>( 52 logManager.getBus().get_event(), *(dataIface.get())); 53 54 manager = std::make_unique<Manager>(logManager, std::move(dataIface), 55 std::move(logger), std::move(journal), 56 std::move(hostIface)); 57 #else 58 manager = std::make_unique<Manager>(logManager, std::move(dataIface), 59 std::move(logger), std::move(journal)); 60 #endif 61 62 #ifdef PEL_ENABLE_PHAL 63 // PDBG_DTB environment variable set to CEC device tree path 64 static constexpr auto PDBG_DTB_PATH = 65 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE"; 66 67 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1)) 68 { 69 // Log message and continue, 70 // This is to help continue creating PEL in raw format. 71 log<level::ERR>( 72 std::format("Failed to set PDBG_DTB: ({})", strerror(errno)) 73 .c_str()); 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