16552de05SJayanth Othayoth #pragma once 26552de05SJayanth Othayoth 32b30dea1SMarri Devender Rao #include "xyz/openbmc_project/Logging/Entry/server.hpp" 42b30dea1SMarri Devender Rao 52eb31ad2SJayanth Othayoth #include <phal_exception.H> 62eb31ad2SJayanth Othayoth 76552de05SJayanth Othayoth #include <nlohmann/json.hpp> 86552de05SJayanth Othayoth 96552de05SJayanth Othayoth #include <string> 106552de05SJayanth Othayoth #include <vector> 11*e5ba5fd0SJayanth Othayoth 12*e5ba5fd0SJayanth Othayoth extern "C" 13*e5ba5fd0SJayanth Othayoth { 14*e5ba5fd0SJayanth Othayoth #include <libpdbg.h> 15*e5ba5fd0SJayanth Othayoth } 166552de05SJayanth Othayoth namespace openpower 176552de05SJayanth Othayoth { 186552de05SJayanth Othayoth namespace pel 196552de05SJayanth Othayoth { 206552de05SJayanth Othayoth using FFDCData = std::vector<std::pair<std::string, std::string>>; 216552de05SJayanth Othayoth 226552de05SJayanth Othayoth using json = nlohmann::json; 236552de05SJayanth Othayoth 242eb31ad2SJayanth Othayoth using namespace openpower::phal; 252b30dea1SMarri Devender Rao using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level; 266552de05SJayanth Othayoth /** 278fe9ff91SJayanth Othayoth * @brief Create PEL with additional parameters and callout 286552de05SJayanth Othayoth * 298fe9ff91SJayanth Othayoth * @param[in] event - the event type 306552de05SJayanth Othayoth * @param[in] calloutData - callout data to append to PEL 318fe9ff91SJayanth Othayoth * @param[in] ffdcData - failure data to append to PEL 326552de05SJayanth Othayoth */ 338fe9ff91SJayanth Othayoth void createErrorPEL(const std::string& event, const json& calloutData = {}, 348fe9ff91SJayanth Othayoth const FFDCData& ffdcData = {}); 356552de05SJayanth Othayoth 366552de05SJayanth Othayoth /** 37fe37aea0SJayanth Othayoth * @brief Create SBE boot error PEL and return id 382eb31ad2SJayanth Othayoth * 392eb31ad2SJayanth Othayoth * @param[in] event - the event type 402eb31ad2SJayanth Othayoth * @param[in] sbeError - SBE error object 412eb31ad2SJayanth Othayoth * @param[in] ffdcData - failure data to append to PEL 42*e5ba5fd0SJayanth Othayoth * @param[in] procTarget - pdbg processor target 432b30dea1SMarri Devender Rao * @param[in] severity - severity of the log 44fe37aea0SJayanth Othayoth * @return Platform log id 452eb31ad2SJayanth Othayoth */ 46fe37aea0SJayanth Othayoth uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError, 472b30dea1SMarri Devender Rao const FFDCData& ffdcData, 48*e5ba5fd0SJayanth Othayoth struct pdbg_target* procTarget, 492b30dea1SMarri Devender Rao const Severity severity = Severity::Error); 502eb31ad2SJayanth Othayoth 512eb31ad2SJayanth Othayoth /** 52a8d2f710SJayanth Othayoth * @brief Create a PEL for the specified event type and additional data 536552de05SJayanth Othayoth * 542eb31ad2SJayanth Othayoth * @param[in] event - the event type 55a8d2f710SJayanth Othayoth * @param[in] ffdcData - failure data to append to PEL 566552de05SJayanth Othayoth */ 57a8d2f710SJayanth Othayoth void createPEL(const std::string& event, const FFDCData& ffdcData = {}); 586552de05SJayanth Othayoth 596552de05SJayanth Othayoth /** 606552de05SJayanth Othayoth * @class FFDCFile 616552de05SJayanth Othayoth * @brief This class is used to create ffdc data file and to get fd 626552de05SJayanth Othayoth */ 636552de05SJayanth Othayoth class FFDCFile 646552de05SJayanth Othayoth { 656552de05SJayanth Othayoth public: 666552de05SJayanth Othayoth FFDCFile() = delete; 676552de05SJayanth Othayoth FFDCFile(const FFDCFile&) = delete; 686552de05SJayanth Othayoth FFDCFile& operator=(const FFDCFile&) = delete; 696552de05SJayanth Othayoth FFDCFile(FFDCFile&&) = delete; 706552de05SJayanth Othayoth FFDCFile& operator=(FFDCFile&&) = delete; 716552de05SJayanth Othayoth 726552de05SJayanth Othayoth /** 736552de05SJayanth Othayoth * Used to pass json object to create unique ffdc file by using 746552de05SJayanth Othayoth * passed json data. 756552de05SJayanth Othayoth */ 766552de05SJayanth Othayoth explicit FFDCFile(const json& pHALCalloutData); 776552de05SJayanth Othayoth 786552de05SJayanth Othayoth /** 796552de05SJayanth Othayoth * Used to remove created ffdc file. 806552de05SJayanth Othayoth */ 816552de05SJayanth Othayoth ~FFDCFile(); 826552de05SJayanth Othayoth 836552de05SJayanth Othayoth /** 846552de05SJayanth Othayoth * Used to get created ffdc file file descriptor id. 856552de05SJayanth Othayoth * 866552de05SJayanth Othayoth * @return file descriptor id 876552de05SJayanth Othayoth */ 886552de05SJayanth Othayoth int getFileFD() const; 896552de05SJayanth Othayoth 906552de05SJayanth Othayoth private: 916552de05SJayanth Othayoth /** 926552de05SJayanth Othayoth * Used to store callout ffdc data from passed json object. 936552de05SJayanth Othayoth */ 946552de05SJayanth Othayoth std::string calloutData; 956552de05SJayanth Othayoth 966552de05SJayanth Othayoth /** 976552de05SJayanth Othayoth * Used to store unique ffdc file name. 986552de05SJayanth Othayoth */ 996552de05SJayanth Othayoth std::string calloutFile; 1006552de05SJayanth Othayoth 1016552de05SJayanth Othayoth /** 1026552de05SJayanth Othayoth * Used to store created ffdc file descriptor id. 1036552de05SJayanth Othayoth */ 1046552de05SJayanth Othayoth int fileFD; 1056552de05SJayanth Othayoth 1066552de05SJayanth Othayoth /** 1076552de05SJayanth Othayoth * Used to create ffdc file to pass PEL api for creating 1086552de05SJayanth Othayoth * pel records. 1096552de05SJayanth Othayoth * 1106552de05SJayanth Othayoth * @return NULL 1116552de05SJayanth Othayoth */ 1126552de05SJayanth Othayoth void prepareFFDCFile(); 1136552de05SJayanth Othayoth 1146552de05SJayanth Othayoth /** 1156552de05SJayanth Othayoth * Create unique ffdc file. 1166552de05SJayanth Othayoth * 1176552de05SJayanth Othayoth * @return NULL 1186552de05SJayanth Othayoth */ 1196552de05SJayanth Othayoth void createCalloutFile(); 1206552de05SJayanth Othayoth 1216552de05SJayanth Othayoth /** 1226552de05SJayanth Othayoth * Used write json object value into created file. 1236552de05SJayanth Othayoth * 1246552de05SJayanth Othayoth * @return NULL 1256552de05SJayanth Othayoth */ 1266552de05SJayanth Othayoth void writeCalloutData(); 1276552de05SJayanth Othayoth 1286552de05SJayanth Othayoth /** 1296552de05SJayanth Othayoth * Used set ffdc file seek position begining to consume by PEL 1306552de05SJayanth Othayoth * 1316552de05SJayanth Othayoth * @return NULL 1326552de05SJayanth Othayoth */ 1336552de05SJayanth Othayoth void setCalloutFileSeekPos(); 1346552de05SJayanth Othayoth 1356552de05SJayanth Othayoth /** 1366552de05SJayanth Othayoth * Used to remove created ffdc file. 1376552de05SJayanth Othayoth * 1386552de05SJayanth Othayoth * @return NULL 1396552de05SJayanth Othayoth */ 1406552de05SJayanth Othayoth void removeCalloutFile(); 1416552de05SJayanth Othayoth 1426552de05SJayanth Othayoth }; // FFDCFile end 1436552de05SJayanth Othayoth 1446552de05SJayanth Othayoth } // namespace pel 1456552de05SJayanth Othayoth } // namespace openpower 146