blob: ffd131587f87efaedbd96af1ba9744be10bf07b3 [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>
Jayanth Othayothe5ba5fd2022-01-27 09:29:01 -060011
12extern "C"
13{
14#include <libpdbg.h>
15}
Brad Bishopf6783cd2020-10-27 19:25:09 -040016namespace openpower
17{
Brad Bishopf6783cd2020-10-27 19:25:09 -040018namespace pel
19{
20using FFDCData = std::vector<std::pair<std::string, std::string>>;
21
22using json = nlohmann::json;
23
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050024using namespace openpower::phal;
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060025using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
Brad Bishopf6783cd2020-10-27 19:25:09 -040026/**
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060027 * @brief Create PEL with additional parameters and callout
Brad Bishopf6783cd2020-10-27 19:25:09 -040028 *
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060029 * @param[in] event - the event type
Brad Bishopf6783cd2020-10-27 19:25:09 -040030 * @param[in] calloutData - callout data to append to PEL
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060031 * @param[in] ffdcData - failure data to append to PEL
Marri Devender Rao4d5b5bf2022-05-23 09:23:31 -050032 * @param[in] severity - severity of the log default to Informational
Brad Bishopf6783cd2020-10-27 19:25:09 -040033 */
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060034void createErrorPEL(const std::string& event, const json& calloutData = {},
Marri Devender Rao4d5b5bf2022-05-23 09:23:31 -050035 const FFDCData& ffdcData = {},
36 const Severity severity = Severity::Informational);
Brad Bishopf6783cd2020-10-27 19:25:09 -040037
38/**
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050039 * @brief Create SBE boot error PEL and return id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050040 *
41 * @param[in] event - the event type
42 * @param[in] sbeError - SBE error object
43 * @param[in] ffdcData - failure data to append to PEL
Jayanth Othayothe5ba5fd2022-01-27 09:29:01 -060044 * @param[in] procTarget - pdbg processor target
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060045 * @param[in] severity - severity of the log
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050046 * @return Platform log id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050047 */
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050048uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060049 const FFDCData& ffdcData,
Jayanth Othayothe5ba5fd2022-01-27 09:29:01 -060050 struct pdbg_target* procTarget,
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060051 const Severity severity = Severity::Error);
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050052
53/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050054 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050055 *
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050056 * @param[in] event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050057 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050058 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050059void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050060
61/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040062 * @class FFDCFile
63 * @brief This class is used to create ffdc data file and to get fd
64 */
65class FFDCFile
66{
67 public:
68 FFDCFile() = delete;
69 FFDCFile(const FFDCFile&) = delete;
70 FFDCFile& operator=(const FFDCFile&) = delete;
71 FFDCFile(FFDCFile&&) = delete;
72 FFDCFile& operator=(FFDCFile&&) = delete;
73
74 /**
75 * Used to pass json object to create unique ffdc file by using
76 * passed json data.
77 */
78 explicit FFDCFile(const json& pHALCalloutData);
79
80 /**
81 * Used to remove created ffdc file.
82 */
83 ~FFDCFile();
84
85 /**
86 * Used to get created ffdc file file descriptor id.
87 *
88 * @return file descriptor id
89 */
90 int getFileFD() const;
91
92 private:
93 /**
94 * Used to store callout ffdc data from passed json object.
95 */
96 std::string calloutData;
97
98 /**
99 * Used to store unique ffdc file name.
100 */
101 std::string calloutFile;
102
103 /**
104 * Used to store created ffdc file descriptor id.
105 */
106 int fileFD;
107
108 /**
109 * Used to create ffdc file to pass PEL api for creating
110 * pel records.
111 *
112 * @return NULL
113 */
114 void prepareFFDCFile();
115
116 /**
117 * Create unique ffdc file.
118 *
119 * @return NULL
120 */
121 void createCalloutFile();
122
123 /**
124 * Used write json object value into created file.
125 *
126 * @return NULL
127 */
128 void writeCalloutData();
129
130 /**
131 * Used set ffdc file seek position begining to consume by PEL
132 *
133 * @return NULL
134 */
135 void setCalloutFileSeekPos();
136
137 /**
138 * Used to remove created ffdc file.
139 *
140 * @return NULL
141 */
142 void removeCalloutFile();
143
144}; // FFDCFile end
145
146} // namespace pel
147} // namespace openpower