1 #pragma once 2 3 #include "xyz/openbmc_project/Logging/Entry/server.hpp" 4 5 #include <phal_exception.H> 6 7 #include <nlohmann/json.hpp> 8 9 #include <string> 10 #include <vector> 11 12 extern "C" 13 { 14 #include <libpdbg.h> 15 } 16 namespace openpower 17 { 18 namespace pel 19 { 20 using FFDCData = std::vector<std::pair<std::string, std::string>>; 21 22 using json = nlohmann::json; 23 24 using namespace openpower::phal; 25 using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level; 26 /** 27 * @brief Create PEL with additional parameters and callout 28 * 29 * @param[in] event - the event type 30 * @param[in] calloutData - callout data to append to PEL 31 * @param[in] ffdcData - failure data to append to PEL 32 * @param[in] severity - severity of the log default to Informational 33 */ 34 void createErrorPEL(const std::string& event, const json& calloutData = {}, 35 const FFDCData& ffdcData = {}, 36 const Severity severity = Severity::Informational); 37 38 /** 39 * @brief Create SBE boot error PEL and return id 40 * 41 * @param[in] event - the event type 42 * @param[in] sbeError - SBE error object 43 * @param[in] ffdcData - failure data to append to PEL 44 * @param[in] procTarget - pdbg processor target 45 * @param[in] severity - severity of the log 46 * @return Platform log id 47 */ 48 uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError, 49 const FFDCData& ffdcData, 50 struct pdbg_target* procTarget, 51 const Severity severity = Severity::Error); 52 53 /** 54 * @brief Create a PEL for the specified event type and additional data 55 * 56 * @param[in] event - the event type 57 * @param[in] ffdcData - failure data to append to PEL 58 * @param[in] severity - severity of the log 59 */ 60 void createPEL(const std::string& event, const FFDCData& ffdcData = {}, 61 const Severity severity = Severity::Error); 62 63 /** 64 * @class FFDCFile 65 * @brief This class is used to create ffdc data file and to get fd 66 */ 67 class FFDCFile 68 { 69 public: 70 FFDCFile() = delete; 71 FFDCFile(const FFDCFile&) = delete; 72 FFDCFile& operator=(const FFDCFile&) = delete; 73 FFDCFile(FFDCFile&&) = delete; 74 FFDCFile& operator=(FFDCFile&&) = delete; 75 76 /** 77 * Used to pass json object to create unique ffdc file by using 78 * passed json data. 79 */ 80 explicit FFDCFile(const json& pHALCalloutData); 81 82 /** 83 * Used to remove created ffdc file. 84 */ 85 ~FFDCFile(); 86 87 /** 88 * Used to get created ffdc file file descriptor id. 89 * 90 * @return file descriptor id 91 */ 92 int getFileFD() const; 93 94 private: 95 /** 96 * Used to store callout ffdc data from passed json object. 97 */ 98 std::string calloutData; 99 100 /** 101 * Used to store unique ffdc file name. 102 */ 103 std::string calloutFile; 104 105 /** 106 * Used to store created ffdc file descriptor id. 107 */ 108 int fileFD; 109 110 /** 111 * Used to create ffdc file to pass PEL api for creating 112 * pel records. 113 * 114 * @return NULL 115 */ 116 void prepareFFDCFile(); 117 118 /** 119 * Create unique ffdc file. 120 * 121 * @return NULL 122 */ 123 void createCalloutFile(); 124 125 /** 126 * Used write json object value into created file. 127 * 128 * @return NULL 129 */ 130 void writeCalloutData(); 131 132 /** 133 * Used set ffdc file seek position begining to consume by PEL 134 * 135 * @return NULL 136 */ 137 void setCalloutFileSeekPos(); 138 139 /** 140 * Used to remove created ffdc file. 141 * 142 * @return NULL 143 */ 144 void removeCalloutFile(); 145 146 }; // FFDCFile end 147 148 } // namespace pel 149 } // namespace openpower 150