blob: 53b8751a3fb7788730b4ebe0c34bbfeafa0fa180 [file] [log] [blame]
Brad Bishopf6783cd2020-10-27 19:25:09 -04001#pragma once
2
Marri Devender Rao2b30dea2021-12-17 02:38:30 -06003#include "xyz/openbmc_project/Logging/Entry/server.hpp"
4
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -05005#include <phal_exception.H>
6
Brad Bishopf6783cd2020-10-27 19:25:09 -04007#include <nlohmann/json.hpp>
Brad Bishop5e5d4452020-10-27 19:46:13 -04008
Brad Bishopf6783cd2020-10-27 19:25:09 -04009#include <string>
10#include <vector>
11namespace openpower
12{
Brad Bishopf6783cd2020-10-27 19:25:09 -040013namespace pel
14{
15using FFDCData = std::vector<std::pair<std::string, std::string>>;
16
17using json = nlohmann::json;
18
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050019using namespace openpower::phal;
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060020using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
Brad Bishopf6783cd2020-10-27 19:25:09 -040021/**
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060022 * @brief Create PEL with additional parameters and callout
Brad Bishopf6783cd2020-10-27 19:25:09 -040023 *
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060024 * @param[in] event - the event type
Brad Bishopf6783cd2020-10-27 19:25:09 -040025 * @param[in] calloutData - callout data to append to PEL
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060026 * @param[in] ffdcData - failure data to append to PEL
Brad Bishopf6783cd2020-10-27 19:25:09 -040027 */
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060028void createErrorPEL(const std::string& event, const json& calloutData = {},
29 const FFDCData& ffdcData = {});
Brad Bishopf6783cd2020-10-27 19:25:09 -040030
31/**
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050032 * @brief Create SBE boot error PEL and return id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050033 *
34 * @param[in] event - the event type
35 * @param[in] sbeError - SBE error object
36 * @param[in] ffdcData - failure data to append to PEL
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060037 * @param[in] severity - severity of the log
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050038 * @return Platform log id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050039 */
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050040uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060041 const FFDCData& ffdcData,
42 const Severity severity = Severity::Error);
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050043
44/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050045 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050046 *
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050047 * @param[in] event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050048 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050049 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050050void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050051
52/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040053 * @class FFDCFile
54 * @brief This class is used to create ffdc data file and to get fd
55 */
56class FFDCFile
57{
58 public:
59 FFDCFile() = delete;
60 FFDCFile(const FFDCFile&) = delete;
61 FFDCFile& operator=(const FFDCFile&) = delete;
62 FFDCFile(FFDCFile&&) = delete;
63 FFDCFile& operator=(FFDCFile&&) = delete;
64
65 /**
66 * Used to pass json object to create unique ffdc file by using
67 * passed json data.
68 */
69 explicit FFDCFile(const json& pHALCalloutData);
70
71 /**
72 * Used to remove created ffdc file.
73 */
74 ~FFDCFile();
75
76 /**
77 * Used to get created ffdc file file descriptor id.
78 *
79 * @return file descriptor id
80 */
81 int getFileFD() const;
82
83 private:
84 /**
85 * Used to store callout ffdc data from passed json object.
86 */
87 std::string calloutData;
88
89 /**
90 * Used to store unique ffdc file name.
91 */
92 std::string calloutFile;
93
94 /**
95 * Used to store created ffdc file descriptor id.
96 */
97 int fileFD;
98
99 /**
100 * Used to create ffdc file to pass PEL api for creating
101 * pel records.
102 *
103 * @return NULL
104 */
105 void prepareFFDCFile();
106
107 /**
108 * Create unique ffdc file.
109 *
110 * @return NULL
111 */
112 void createCalloutFile();
113
114 /**
115 * Used write json object value into created file.
116 *
117 * @return NULL
118 */
119 void writeCalloutData();
120
121 /**
122 * Used set ffdc file seek position begining to consume by PEL
123 *
124 * @return NULL
125 */
126 void setCalloutFileSeekPos();
127
128 /**
129 * Used to remove created ffdc file.
130 *
131 * @return NULL
132 */
133 void removeCalloutFile();
134
135}; // FFDCFile end
136
137} // namespace pel
138} // namespace openpower