blob: e6d49a5d0fa3cd5c970b806d5fbe61d02cadb8db [file] [log] [blame]
Brad Bishopf6783cd2020-10-27 19:25:09 -04001#pragma once
2
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -05003#include <phal_exception.H>
4
Brad Bishopf6783cd2020-10-27 19:25:09 -04005#include <nlohmann/json.hpp>
Brad Bishop5e5d4452020-10-27 19:46:13 -04006
Brad Bishopf6783cd2020-10-27 19:25:09 -04007#include <string>
8#include <vector>
9namespace openpower
10{
Brad Bishopf6783cd2020-10-27 19:25:09 -040011namespace pel
12{
13using FFDCData = std::vector<std::pair<std::string, std::string>>;
14
15using json = nlohmann::json;
16
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050017using namespace openpower::phal;
18
Brad Bishopf6783cd2020-10-27 19:25:09 -040019/**
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050020 * @brief Create boot error PEL
Brad Bishopf6783cd2020-10-27 19:25:09 -040021 *
22 * @param[in] ffdcData - failure data to append to PEL
23 * @param[in] calloutData - callout data to append to PEL
24 */
25void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
26
27/**
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050028 * @brief Create SBE boot error PEL
29 *
30 * @param[in] event - the event type
31 * @param[in] sbeError - SBE error object
32 * @param[in] ffdcData - failure data to append to PEL
33 */
34void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
35 const FFDCData& ffdcData);
36
37/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050038 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050039 *
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050040 * @param[in] event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050041 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050042 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050043void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050044
45/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040046 * @class FFDCFile
47 * @brief This class is used to create ffdc data file and to get fd
48 */
49class FFDCFile
50{
51 public:
52 FFDCFile() = delete;
53 FFDCFile(const FFDCFile&) = delete;
54 FFDCFile& operator=(const FFDCFile&) = delete;
55 FFDCFile(FFDCFile&&) = delete;
56 FFDCFile& operator=(FFDCFile&&) = delete;
57
58 /**
59 * Used to pass json object to create unique ffdc file by using
60 * passed json data.
61 */
62 explicit FFDCFile(const json& pHALCalloutData);
63
64 /**
65 * Used to remove created ffdc file.
66 */
67 ~FFDCFile();
68
69 /**
70 * Used to get created ffdc file file descriptor id.
71 *
72 * @return file descriptor id
73 */
74 int getFileFD() const;
75
76 private:
77 /**
78 * Used to store callout ffdc data from passed json object.
79 */
80 std::string calloutData;
81
82 /**
83 * Used to store unique ffdc file name.
84 */
85 std::string calloutFile;
86
87 /**
88 * Used to store created ffdc file descriptor id.
89 */
90 int fileFD;
91
92 /**
93 * Used to create ffdc file to pass PEL api for creating
94 * pel records.
95 *
96 * @return NULL
97 */
98 void prepareFFDCFile();
99
100 /**
101 * Create unique ffdc file.
102 *
103 * @return NULL
104 */
105 void createCalloutFile();
106
107 /**
108 * Used write json object value into created file.
109 *
110 * @return NULL
111 */
112 void writeCalloutData();
113
114 /**
115 * Used set ffdc file seek position begining to consume by PEL
116 *
117 * @return NULL
118 */
119 void setCalloutFileSeekPos();
120
121 /**
122 * Used to remove created ffdc file.
123 *
124 * @return NULL
125 */
126 void removeCalloutFile();
127
128}; // FFDCFile end
129
130} // namespace pel
131} // namespace openpower