blob: a6256f5044fd3e807aee976d9ffde0e7199e9056 [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
Matt Spinlerbe14ec22023-03-24 15:59:48 -050058 * @param[in] severity - severity of the log
Andrew Geissler61febf02021-06-22 17:19:32 -050059 */
Matt Spinlerbe14ec22023-03-24 15:59:48 -050060void createPEL(const std::string& event, const FFDCData& ffdcData = {},
61 const Severity severity = Severity::Error);
Andrew Geissler61febf02021-06-22 17:19:32 -050062
63/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040064 * @class FFDCFile
65 * @brief This class is used to create ffdc data file and to get fd
66 */
67class FFDCFile
68{
69 public:
70 FFDCFile() = delete;
71 FFDCFile(const FFDCFile&) = delete;
72 FFDCFile& operator=(const FFDCFile&) = delete;
73 FFDCFile(FFDCFile&&) = delete;
74 FFDCFile& operator=(FFDCFile&&) = delete;
75
76 /**
77 * Used to pass json object to create unique ffdc file by using
78 * passed json data.
79 */
80 explicit FFDCFile(const json& pHALCalloutData);
81
82 /**
83 * Used to remove created ffdc file.
84 */
85 ~FFDCFile();
86
87 /**
88 * Used to get created ffdc file file descriptor id.
89 *
90 * @return file descriptor id
91 */
92 int getFileFD() const;
93
94 private:
95 /**
96 * Used to store callout ffdc data from passed json object.
97 */
98 std::string calloutData;
99
100 /**
101 * Used to store unique ffdc file name.
102 */
103 std::string calloutFile;
104
105 /**
106 * Used to store created ffdc file descriptor id.
107 */
108 int fileFD;
109
110 /**
111 * Used to create ffdc file to pass PEL api for creating
112 * pel records.
113 *
114 * @return NULL
115 */
116 void prepareFFDCFile();
117
118 /**
119 * Create unique ffdc file.
120 *
121 * @return NULL
122 */
123 void createCalloutFile();
124
125 /**
126 * Used write json object value into created file.
127 *
128 * @return NULL
129 */
130 void writeCalloutData();
131
132 /**
133 * Used set ffdc file seek position begining to consume by PEL
134 *
135 * @return NULL
136 */
137 void setCalloutFileSeekPos();
138
139 /**
140 * Used to remove created ffdc file.
141 *
142 * @return NULL
143 */
144 void removeCalloutFile();
145
146}; // FFDCFile end
147
148} // namespace pel
149} // namespace openpower