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>
11e5ba5fd0SJayanth Othayoth 
12e5ba5fd0SJayanth Othayoth extern "C"
13e5ba5fd0SJayanth Othayoth {
14e5ba5fd0SJayanth Othayoth #include <libpdbg.h>
15e5ba5fd0SJayanth 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
324d5b5bfeSMarri Devender Rao  * @param[in] severity - severity of the log default to Informational
336552de05SJayanth Othayoth  */
348fe9ff91SJayanth Othayoth void createErrorPEL(const std::string& event, const json& calloutData = {},
354d5b5bfeSMarri Devender Rao                     const FFDCData& ffdcData = {},
364d5b5bfeSMarri Devender Rao                     const Severity severity = Severity::Informational);
376552de05SJayanth Othayoth 
386552de05SJayanth Othayoth /**
39fe37aea0SJayanth Othayoth  * @brief Create SBE boot error PEL and return id
402eb31ad2SJayanth Othayoth  *
412eb31ad2SJayanth Othayoth  * @param[in] event - the event type
422eb31ad2SJayanth Othayoth  * @param[in] sbeError - SBE error object
432eb31ad2SJayanth Othayoth  * @param[in] ffdcData - failure data to append to PEL
44e5ba5fd0SJayanth Othayoth  * @param[in] procTarget - pdbg processor target
452b30dea1SMarri Devender Rao  * @param[in] severity - severity of the log
46fe37aea0SJayanth Othayoth  * @return Platform log id
472eb31ad2SJayanth Othayoth  */
48fe37aea0SJayanth Othayoth uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
492b30dea1SMarri Devender Rao                            const FFDCData& ffdcData,
50e5ba5fd0SJayanth Othayoth                            struct pdbg_target* procTarget,
512b30dea1SMarri Devender Rao                            const Severity severity = Severity::Error);
522eb31ad2SJayanth Othayoth 
532eb31ad2SJayanth Othayoth /**
54a8d2f710SJayanth Othayoth  * @brief Create a PEL for the specified event type and additional data
556552de05SJayanth Othayoth  *
562eb31ad2SJayanth Othayoth  *  @param[in]  event - the event type
57a8d2f710SJayanth Othayoth  *  @param[in] ffdcData - failure data to append to PEL
58*be14ec2dSMatt Spinler  *  @param[in] severity - severity of the log
596552de05SJayanth Othayoth  */
60*be14ec2dSMatt Spinler void createPEL(const std::string& event, const FFDCData& ffdcData = {},
61*be14ec2dSMatt Spinler                const Severity severity = Severity::Error);
626552de05SJayanth Othayoth 
636552de05SJayanth Othayoth /**
646552de05SJayanth Othayoth  * @class FFDCFile
656552de05SJayanth Othayoth  * @brief This class is used to create ffdc data file and to get fd
666552de05SJayanth Othayoth  */
676552de05SJayanth Othayoth class FFDCFile
686552de05SJayanth Othayoth {
696552de05SJayanth Othayoth   public:
706552de05SJayanth Othayoth     FFDCFile() = delete;
716552de05SJayanth Othayoth     FFDCFile(const FFDCFile&) = delete;
726552de05SJayanth Othayoth     FFDCFile& operator=(const FFDCFile&) = delete;
736552de05SJayanth Othayoth     FFDCFile(FFDCFile&&) = delete;
746552de05SJayanth Othayoth     FFDCFile& operator=(FFDCFile&&) = delete;
756552de05SJayanth Othayoth 
766552de05SJayanth Othayoth     /**
776552de05SJayanth Othayoth      * Used to pass json object to create unique ffdc file by using
786552de05SJayanth Othayoth      * passed json data.
796552de05SJayanth Othayoth      */
806552de05SJayanth Othayoth     explicit FFDCFile(const json& pHALCalloutData);
816552de05SJayanth Othayoth 
826552de05SJayanth Othayoth     /**
836552de05SJayanth Othayoth      * Used to remove created ffdc file.
846552de05SJayanth Othayoth      */
856552de05SJayanth Othayoth     ~FFDCFile();
866552de05SJayanth Othayoth 
876552de05SJayanth Othayoth     /**
886552de05SJayanth Othayoth      * Used to get created ffdc file file descriptor id.
896552de05SJayanth Othayoth      *
906552de05SJayanth Othayoth      * @return file descriptor id
916552de05SJayanth Othayoth      */
926552de05SJayanth Othayoth     int getFileFD() const;
936552de05SJayanth Othayoth 
946552de05SJayanth Othayoth   private:
956552de05SJayanth Othayoth     /**
966552de05SJayanth Othayoth      * Used to store callout ffdc data from passed json object.
976552de05SJayanth Othayoth      */
986552de05SJayanth Othayoth     std::string calloutData;
996552de05SJayanth Othayoth 
1006552de05SJayanth Othayoth     /**
1016552de05SJayanth Othayoth      * Used to store unique ffdc file name.
1026552de05SJayanth Othayoth      */
1036552de05SJayanth Othayoth     std::string calloutFile;
1046552de05SJayanth Othayoth 
1056552de05SJayanth Othayoth     /**
1066552de05SJayanth Othayoth      * Used to store created ffdc file descriptor id.
1076552de05SJayanth Othayoth      */
1086552de05SJayanth Othayoth     int fileFD;
1096552de05SJayanth Othayoth 
1106552de05SJayanth Othayoth     /**
1116552de05SJayanth Othayoth      * Used to create ffdc file to pass PEL api for creating
1126552de05SJayanth Othayoth      * pel records.
1136552de05SJayanth Othayoth      *
1146552de05SJayanth Othayoth      * @return NULL
1156552de05SJayanth Othayoth      */
1166552de05SJayanth Othayoth     void prepareFFDCFile();
1176552de05SJayanth Othayoth 
1186552de05SJayanth Othayoth     /**
1196552de05SJayanth Othayoth      * Create unique ffdc file.
1206552de05SJayanth Othayoth      *
1216552de05SJayanth Othayoth      * @return NULL
1226552de05SJayanth Othayoth      */
1236552de05SJayanth Othayoth     void createCalloutFile();
1246552de05SJayanth Othayoth 
1256552de05SJayanth Othayoth     /**
1266552de05SJayanth Othayoth      * Used write json object value into created file.
1276552de05SJayanth Othayoth      *
1286552de05SJayanth Othayoth      * @return NULL
1296552de05SJayanth Othayoth      */
1306552de05SJayanth Othayoth     void writeCalloutData();
1316552de05SJayanth Othayoth 
1326552de05SJayanth Othayoth     /**
1336552de05SJayanth Othayoth      * Used set ffdc file seek position begining to consume by PEL
1346552de05SJayanth Othayoth      *
1356552de05SJayanth Othayoth      * @return NULL
1366552de05SJayanth Othayoth      */
1376552de05SJayanth Othayoth     void setCalloutFileSeekPos();
1386552de05SJayanth Othayoth 
1396552de05SJayanth Othayoth     /**
1406552de05SJayanth Othayoth      * Used to remove created ffdc file.
1416552de05SJayanth Othayoth      *
1426552de05SJayanth Othayoth      * @return NULL
1436552de05SJayanth Othayoth      */
1446552de05SJayanth Othayoth     void removeCalloutFile();
1456552de05SJayanth Othayoth 
1466552de05SJayanth Othayoth }; // FFDCFile end
1476552de05SJayanth Othayoth 
1486552de05SJayanth Othayoth } // namespace pel
1496552de05SJayanth Othayoth } // namespace openpower
150