Add PEL creation for SBE chip-op failures

This commit introduces a new function within the SBE dump collection
mechanism to create PELs) when chip operations on SBE fail.

Test:
Make sure the PELs are logged during chip-op failure

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I23f78b702f4a2b9cf01315c3fbb487dc428bd2a0
diff --git a/dump/create_pel.hpp b/dump/create_pel.hpp
new file mode 100644
index 0000000..13d30ff
--- /dev/null
+++ b/dump/create_pel.hpp
@@ -0,0 +1,114 @@
+#pragma once
+
+#include <phal_exception.H>
+
+#include <nlohmann/json.hpp>
+
+#include <string>
+#include <vector>
+namespace openpower::dump::pel
+{
+
+using FFDCData = std::vector<std::pair<std::string, std::string>>;
+
+using json = nlohmann::json;
+
+using namespace openpower::phal;
+
+/**
+ * @brief Create SBE boot error PEL and return id
+ *
+ * @param[in] event - the event type
+ * @param[in] sbeError - SBE error object
+ * @param[in] ffdcData - failure data to append to PEL
+ * @return Platform log id
+ */
+uint32_t createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
+                           const FFDCData& ffdcData);
+
+/**
+ * @class FFDCFile
+ * @brief This class is used to create ffdc data file and to get fd
+ */
+class FFDCFile
+{
+  public:
+    FFDCFile() = delete;
+    FFDCFile(const FFDCFile&) = delete;
+    FFDCFile& operator=(const FFDCFile&) = delete;
+    FFDCFile(FFDCFile&&) = delete;
+    FFDCFile& operator=(FFDCFile&&) = delete;
+
+    /**
+     * Used to pass json object to create unique ffdc file by using
+     * passed json data.
+     */
+    explicit FFDCFile(const json& pHALCalloutData);
+
+    /**
+     * Used to remove created ffdc file.
+     */
+    ~FFDCFile();
+
+    /**
+     * Used to get created ffdc file file descriptor id.
+     *
+     * @return file descriptor id
+     */
+    int getFileFD() const;
+
+  private:
+    /**
+     * Used to store callout ffdc data from passed json object.
+     */
+    std::string calloutData;
+
+    /**
+     * Used to store unique ffdc file name.
+     */
+    std::string calloutFile;
+
+    /**
+     * Used to store created ffdc file descriptor id.
+     */
+    int fileFD;
+
+    /**
+     * Used to create ffdc file to pass PEL api for creating
+     * pel records.
+     *
+     * @return NULL
+     */
+    void prepareFFDCFile();
+
+    /**
+     * Create unique ffdc file.
+     *
+     * @return NULL
+     */
+    void createCalloutFile();
+
+    /**
+     * Used write json object value into created file.
+     *
+     * @return NULL
+     */
+    void writeCalloutData();
+
+    /**
+     * Used set ffdc file seek position begining to consume by PEL
+     *
+     * @return NULL
+     */
+    void setCalloutFileSeekPos();
+
+    /**
+     * Used to remove created ffdc file.
+     *
+     * @return NULL
+     */
+    void removeCalloutFile();
+
+}; // FFDCFile end
+
+} // namespace openpower::dump::pel