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  */
33 void createErrorPEL(const std::string& event, const json& calloutData = {},
34                     const FFDCData& ffdcData = {});
35 
36 /**
37  * @brief Create SBE boot error PEL and return id
38  *
39  * @param[in] event - the event type
40  * @param[in] sbeError - SBE error object
41  * @param[in] ffdcData - failure data to append to PEL
42  * @param[in] procTarget - pdbg processor target
43  * @param[in] severity - severity of the log
44  * @return Platform log id
45  */
46 uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
47                            const FFDCData& ffdcData,
48                            struct pdbg_target* procTarget,
49                            const Severity severity = Severity::Error);
50 
51 /**
52  * @brief Create a PEL for the specified event type and additional data
53  *
54  *  @param[in]  event - the event type
55  *  @param[in] ffdcData - failure data to append to PEL
56  */
57 void createPEL(const std::string& event, const FFDCData& ffdcData = {});
58 
59 /**
60  * @class FFDCFile
61  * @brief This class is used to create ffdc data file and to get fd
62  */
63 class 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
146