blob: a5287eafdfbb221844805568c0d48edc003b2a31 [file] [log] [blame]
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -05001#pragma once
2
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -05003#include "xyz/openbmc_project/Logging/Entry/server.hpp"
4
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -05005#include <phal_exception.H>
6
7#include <nlohmann/json.hpp>
8
9#include <string>
10#include <vector>
11namespace openpower::dump::pel
12{
13
14using FFDCData = std::vector<std::pair<std::string, std::string>>;
15
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -050016using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
17
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050018using json = nlohmann::json;
19
20using namespace openpower::phal;
21
22/**
23 * @brief Create SBE boot error PEL and return id
24 *
25 * @param[in] event - the event type
26 * @param[in] sbeError - SBE error object
27 * @param[in] ffdcData - failure data to append to PEL
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -050028 * @param[in] severity - severity of the log
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050029 * @return Platform log id
30 */
31uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
Dhruvaraj Subhashchandranf9f65b82022-10-13 06:46:43 -050032 const FFDCData& ffdcData,
33 const Severity severity = Severity::Error);
Dhruvaraj Subhashchandran6feeebd2021-10-19 05:03:59 -050034
35/**
36 * @class FFDCFile
37 * @brief This class is used to create ffdc data file and to get fd
38 */
39class FFDCFile
40{
41 public:
42 FFDCFile() = delete;
43 FFDCFile(const FFDCFile&) = delete;
44 FFDCFile& operator=(const FFDCFile&) = delete;
45 FFDCFile(FFDCFile&&) = delete;
46 FFDCFile& operator=(FFDCFile&&) = delete;
47
48 /**
49 * Used to pass json object to create unique ffdc file by using
50 * passed json data.
51 */
52 explicit FFDCFile(const json& pHALCalloutData);
53
54 /**
55 * Used to remove created ffdc file.
56 */
57 ~FFDCFile();
58
59 /**
60 * Used to get created ffdc file file descriptor id.
61 *
62 * @return file descriptor id
63 */
64 int getFileFD() const;
65
66 private:
67 /**
68 * Used to store callout ffdc data from passed json object.
69 */
70 std::string calloutData;
71
72 /**
73 * Used to store unique ffdc file name.
74 */
75 std::string calloutFile;
76
77 /**
78 * Used to store created ffdc file descriptor id.
79 */
80 int fileFD;
81
82 /**
83 * Used to create ffdc file to pass PEL api for creating
84 * pel records.
85 *
86 * @return NULL
87 */
88 void prepareFFDCFile();
89
90 /**
91 * Create unique ffdc file.
92 *
93 * @return NULL
94 */
95 void createCalloutFile();
96
97 /**
98 * Used write json object value into created file.
99 *
100 * @return NULL
101 */
102 void writeCalloutData();
103
104 /**
105 * Used set ffdc file seek position begining to consume by PEL
106 *
107 * @return NULL
108 */
109 void setCalloutFileSeekPos();
110
111 /**
112 * Used to remove created ffdc file.
113 *
114 * @return NULL
115 */
116 void removeCalloutFile();
117
118}; // FFDCFile end
119
120} // namespace openpower::dump::pel