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 "manager.hpp" 21 #include "pldm_interface.hpp" 22 23 #include <fmt/format.h> 24 25 #include <phosphor-logging/log.hpp> 26 27 namespace openpower 28 { 29 namespace pels 30 { 31 32 using namespace phosphor::logging; 33 34 std::unique_ptr<Manager> manager; 35 36 DISABLE_LOG_ENTRY_CAPS() 37 38 void pelStartup(internal::Manager& logManager) 39 { 40 EventLogger::LogFunction logger = std::bind( 41 std::mem_fn(&internal::Manager::create), &logManager, 42 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); 43 44 std::unique_ptr<DataInterfaceBase> dataIface = 45 std::make_unique<DataInterface>(logManager.getBus()); 46 47 #ifndef DONT_SEND_PELS_TO_HOST 48 std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>( 49 logManager.getBus().get_event(), *(dataIface.get())); 50 51 manager = std::make_unique<Manager>(logManager, std::move(dataIface), 52 std::move(logger), 53 std::move(hostIface)); 54 #else 55 manager = std::make_unique<Manager>(logManager, std::move(dataIface), 56 std::move(logger)); 57 #endif 58 59 #ifdef PEL_ENABLE_PHAL 60 // PDBG_DTB environment variable set to CEC device tree path 61 static constexpr auto PDBG_DTB_PATH = 62 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE"; 63 64 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1)) 65 { 66 // Log message and continue, 67 // This is to help continue creating PEL in raw format. 68 log<level::ERR>( 69 fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno)) 70 .c_str()); 71 } 72 #endif 73 } 74 75 REGISTER_EXTENSION_FUNCTION(pelStartup) 76 77 void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp, 78 Entry::Level severity, const AdditionalDataArg& additionalData, 79 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc) 80 { 81 manager->create(message, id, timestamp, severity, additionalData, assocs, 82 ffdc); 83 } 84 85 REGISTER_EXTENSION_FUNCTION(pelCreate) 86 87 void pelDelete(uint32_t id) 88 { 89 return manager->erase(id); 90 } 91 92 REGISTER_EXTENSION_FUNCTION(pelDelete) 93 94 void pelDeleteProhibited(uint32_t id, bool& prohibited) 95 { 96 prohibited = manager->isDeleteProhibited(id); 97 } 98 99 REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited) 100 101 } // namespace pels 102 } // namespace openpower 103