blob: 481417b23c3a8c8cc01592d0b793b6c12b774f7d [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 Othayoth8fe9ff92021-11-14 09:15:59 -060020 * @brief Create PEL with additional parameters and callout
Brad Bishopf6783cd2020-10-27 19:25:09 -040021 *
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060022 * @param[in] event - the event type
Brad Bishopf6783cd2020-10-27 19:25:09 -040023 * @param[in] calloutData - callout data to append to PEL
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060024 * @param[in] ffdcData - failure data to append to PEL
Brad Bishopf6783cd2020-10-27 19:25:09 -040025 */
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060026void createErrorPEL(const std::string& event, const json& calloutData = {},
27 const FFDCData& ffdcData = {});
Brad Bishopf6783cd2020-10-27 19:25:09 -040028
29/**
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050030 * @brief Create SBE boot error PEL and return id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050031 *
32 * @param[in] event - the event type
33 * @param[in] sbeError - SBE error object
34 * @param[in] ffdcData - failure data to append to PEL
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050035 * @return Platform log id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050036 */
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050037uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
38 const FFDCData& ffdcData);
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050039
40/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050041 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050042 *
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050043 * @param[in] event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050044 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050045 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050046void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050047
48/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040049 * @class FFDCFile
50 * @brief This class is used to create ffdc data file and to get fd
51 */
52class FFDCFile
53{
54 public:
55 FFDCFile() = delete;
56 FFDCFile(const FFDCFile&) = delete;
57 FFDCFile& operator=(const FFDCFile&) = delete;
58 FFDCFile(FFDCFile&&) = delete;
59 FFDCFile& operator=(FFDCFile&&) = delete;
60
61 /**
62 * Used to pass json object to create unique ffdc file by using
63 * passed json data.
64 */
65 explicit FFDCFile(const json& pHALCalloutData);
66
67 /**
68 * Used to remove created ffdc file.
69 */
70 ~FFDCFile();
71
72 /**
73 * Used to get created ffdc file file descriptor id.
74 *
75 * @return file descriptor id
76 */
77 int getFileFD() const;
78
79 private:
80 /**
81 * Used to store callout ffdc data from passed json object.
82 */
83 std::string calloutData;
84
85 /**
86 * Used to store unique ffdc file name.
87 */
88 std::string calloutFile;
89
90 /**
91 * Used to store created ffdc file descriptor id.
92 */
93 int fileFD;
94
95 /**
96 * Used to create ffdc file to pass PEL api for creating
97 * pel records.
98 *
99 * @return NULL
100 */
101 void prepareFFDCFile();
102
103 /**
104 * Create unique ffdc file.
105 *
106 * @return NULL
107 */
108 void createCalloutFile();
109
110 /**
111 * Used write json object value into created file.
112 *
113 * @return NULL
114 */
115 void writeCalloutData();
116
117 /**
118 * Used set ffdc file seek position begining to consume by PEL
119 *
120 * @return NULL
121 */
122 void setCalloutFileSeekPos();
123
124 /**
125 * Used to remove created ffdc file.
126 *
127 * @return NULL
128 */
129 void removeCalloutFile();
130
131}; // FFDCFile end
132
133} // namespace pel
134} // namespace openpower