xref: /openbmc/openpower-proc-control/extensions/phal/create_pel.hpp (revision 4d5b5bfe01c5eb83823e2a92d4b1a26455eb87ee)
1 #pragma once
2 
3 #include "xyz/openbmc_project/Logging/Entry/server.hpp"
4 
5 #include <phal_exception.H>
6 
7 #include <nlohmann/json.hpp>
8 
9 #include <string>
10 #include <vector>
11 
12 extern "C"
13 {
14 #include <libpdbg.h>
15 }
16 namespace openpower
17 {
18 namespace pel
19 {
20 using FFDCData = std::vector<std::pair<std::string, std::string>>;
21 
22 using json = nlohmann::json;
23 
24 using namespace openpower::phal;
25 using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
26 /**
27  * @brief Create PEL with additional parameters and callout
28  *
29  * @param[in] event - the event type
30  * @param[in] calloutData - callout data to append to PEL
31  * @param[in] ffdcData - failure data to append to PEL
32  * @param[in] severity - severity of the log default to Informational
33  */
34 void createErrorPEL(const std::string& event, const json& calloutData = {},
35                     const FFDCData& ffdcData = {},
36                     const Severity severity = Severity::Informational);
37 
38 /**
39  * @brief Create SBE boot error PEL and return id
40  *
41  * @param[in] event - the event type
42  * @param[in] sbeError - SBE error object
43  * @param[in] ffdcData - failure data to append to PEL
44  * @param[in] procTarget - pdbg processor target
45  * @param[in] severity - severity of the log
46  * @return Platform log id
47  */
48 uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
49                            const FFDCData& ffdcData,
50                            struct pdbg_target* procTarget,
51                            const Severity severity = Severity::Error);
52 
53 /**
54  * @brief Create a PEL for the specified event type and additional data
55  *
56  *  @param[in]  event - the event type
57  *  @param[in] ffdcData - failure data to append to PEL
58  */
59 void createPEL(const std::string& event, const FFDCData& ffdcData = {});
60 
61 /**
62  * @class FFDCFile
63  * @brief This class is used to create ffdc data file and to get fd
64  */
65 class 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
148