phal: Added proc-pre-poweroff support

Changes:
-Adding new service which will be called during
chassis poweroff.

Test:
-Did poweroff to check, if the service file
is getting picked up or not and new added
procedure is getting called.

Signed-off-by: Chirag Sharma <chirshar@in.ibm.com>
Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Change-Id: Ic533433c4771216e5681b61cccf154f7ed029457
diff --git a/procedures/phal/proc_pre_poweroff.cpp b/procedures/phal/proc_pre_poweroff.cpp
new file mode 100644
index 0000000..3997b19
--- /dev/null
+++ b/procedures/phal/proc_pre_poweroff.cpp
@@ -0,0 +1,49 @@
+#include "phalerror/phal_error.hpp"
+#include "procedures/phal/common_utils.hpp"
+#include "registration.hpp"
+
+#include <libekb.H>
+
+#include <phosphor-logging/log.hpp>
+
+namespace openpower
+{
+namespace phal
+{
+
+using namespace phosphor::logging;
+
+void prePoweroff(void)
+{
+    try
+    {
+        phal_init();
+    }
+    catch (const std::exception& ex)
+    {
+        log<level::ERR>("Exception raised during init PHAL",
+                        entry("EXCEPTION=%s", ex.what()));
+        openpower::pel::detail::processBootErrorCallback(false);
+        // Dont throw exception on failure because, we need to proceed
+        // further eventhough there is failure for proc-pre-poweroff
+        return;
+    }
+
+    // To clear trace if success
+    openpower::pel::detail::processBootErrorCallback(true);
+
+    // callback method will be called upon failure which will create the PEL
+    int rc = ipl_pre_poweroff();
+    if (rc)
+    {
+        log<level::ERR>("pre_poweroff failed");
+        // Dont throw exception on failure because, we need to proceed
+        // further eventhough there is failure for proc-pre-poweroff
+        return;
+    }
+}
+
+REGISTER_PROCEDURE("prePoweroff", prePoweroff)
+
+} // namespace phal
+} // namespace openpower