blob: 674381b4a43a7cb497c237dc938dfe2e7b409dca [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
Brad Bishopf6783cd2020-10-27 19:25:09 -040032 */
Jayanth Othayoth8fe9ff92021-11-14 09:15:59 -060033void createErrorPEL(const std::string& event, const json& calloutData = {},
34 const FFDCData& ffdcData = {});
Brad Bishopf6783cd2020-10-27 19:25:09 -040035
36/**
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050037 * @brief Create SBE boot error PEL and return id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050038 *
39 * @param[in] event - the event type
40 * @param[in] sbeError - SBE error object
41 * @param[in] ffdcData - failure data to append to PEL
Jayanth Othayothe5ba5fd2022-01-27 09:29:01 -060042 * @param[in] procTarget - pdbg processor target
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060043 * @param[in] severity - severity of the log
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050044 * @return Platform log id
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050045 */
Jayanth Othayothfe37aea2021-10-07 04:41:26 -050046uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060047 const FFDCData& ffdcData,
Jayanth Othayothe5ba5fd2022-01-27 09:29:01 -060048 struct pdbg_target* procTarget,
Marri Devender Rao2b30dea2021-12-17 02:38:30 -060049 const Severity severity = Severity::Error);
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050050
51/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050052 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050053 *
Jayanth Othayoth2eb31ad2021-09-20 07:13:28 -050054 * @param[in] event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050055 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050056 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050057void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050058
59/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040060 * @class FFDCFile
61 * @brief This class is used to create ffdc data file and to get fd
62 */
63class FFDCFile
64{
65 public:
66 FFDCFile() = delete;
67 FFDCFile(const FFDCFile&) = delete;
68 FFDCFile& operator=(const FFDCFile&) = delete;
69 FFDCFile(FFDCFile&&) = delete;
70 FFDCFile& operator=(FFDCFile&&) = delete;
71
72 /**
73 * Used to pass json object to create unique ffdc file by using
74 * passed json data.
75 */
76 explicit FFDCFile(const json& pHALCalloutData);
77
78 /**
79 * Used to remove created ffdc file.
80 */
81 ~FFDCFile();
82
83 /**
84 * Used to get created ffdc file file descriptor id.
85 *
86 * @return file descriptor id
87 */
88 int getFileFD() const;
89
90 private:
91 /**
92 * Used to store callout ffdc data from passed json object.
93 */
94 std::string calloutData;
95
96 /**
97 * Used to store unique ffdc file name.
98 */
99 std::string calloutFile;
100
101 /**
102 * Used to store created ffdc file descriptor id.
103 */
104 int fileFD;
105
106 /**
107 * Used to create ffdc file to pass PEL api for creating
108 * pel records.
109 *
110 * @return NULL
111 */
112 void prepareFFDCFile();
113
114 /**
115 * Create unique ffdc file.
116 *
117 * @return NULL
118 */
119 void createCalloutFile();
120
121 /**
122 * Used write json object value into created file.
123 *
124 * @return NULL
125 */
126 void writeCalloutData();
127
128 /**
129 * Used set ffdc file seek position begining to consume by PEL
130 *
131 * @return NULL
132 */
133 void setCalloutFileSeekPos();
134
135 /**
136 * Used to remove created ffdc file.
137 *
138 * @return NULL
139 */
140 void removeCalloutFile();
141
142}; // FFDCFile end
143
144} // namespace pel
145} // namespace openpower