Revamped code for VPD parser
The commit removes all the pre-existing code from the branch
and pushes the revamped code.
Major modification includes:
- Movement from multi exe to single daemon model.
- Multithreaded approach to parse FRU VPD.
- Better error handling.
- Refactored code for performance optimization.
Note: This code supports all the existing functionalities as it is.
Change-Id: I1ddce1f0725ac59020b72709689a1013643bda8b
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/bios_handler.hpp b/vpd-manager/include/bios_handler.hpp
new file mode 100644
index 0000000..916811e
--- /dev/null
+++ b/vpd-manager/include/bios_handler.hpp
@@ -0,0 +1,273 @@
+#pragma once
+#include "manager.hpp"
+#include "types.hpp"
+
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace vpd
+{
+
+/**
+ * @brief Interface class for BIOS handling.
+ *
+ * The class layout has the virtual methods required to be implemented by any
+ * concrete class that intends to use the feature provided via BIOS handler
+ * class.
+ */
+class BiosHandlerInterface
+{
+ public:
+ /**
+ * @brief API to back up or restore BIOS attributes.
+ *
+ * Concrete class should implement the API and read the backed up data from
+ * its designated location and take a call if it should be backed up or
+ * restored.
+ */
+ virtual void backUpOrRestoreBiosAttributes() = 0;
+
+ /**
+ * @brief Callback API to be triggered on BIOS attribute change.
+ *
+ * Concrete class should implement the API to extract the attribute and its
+ * value from DBus message broadcasted on BIOS attribute change.
+ * The definition should be overridden in concrete class to deal with BIOS
+ * attributes interested in.
+ *
+ * @param[in] i_msg - The callback message.
+ */
+ virtual void biosAttributesCallback(sdbusplus::message_t& i_msg) = 0;
+};
+
+/**
+ * @brief IBM specifc BIOS handler class.
+ */
+class IbmBiosHandler : public BiosHandlerInterface
+{
+ public:
+ /**
+ * @brief Construct a new IBM BIOS Handler object
+ *
+ * This constructor constructs a new IBM BIOS Handler object
+ * @param[in] i_manager - Manager object.
+ */
+ explicit IbmBiosHandler(const std::shared_ptr<Manager>& i_manager) :
+ m_manager(i_manager)
+ {}
+
+ /**
+ * @brief API to back up or restore BIOS attributes.
+ *
+ * The API will read the backed up data from the VPD keyword and based on
+ * its value, either backs up or restores the data.
+ */
+ virtual void backUpOrRestoreBiosAttributes();
+
+ /**
+ * @brief Callback API to be triggered on BIOS attribute change.
+ *
+ * The API to extract the required attribute and its value from DBus message
+ * broadcasted on BIOS attribute change.
+ *
+ * @param[in] i_msg - The callback message.
+ */
+ virtual void biosAttributesCallback(sdbusplus::message_t& i_msg);
+
+ private:
+ /**
+ * @brief API to read given attribute from BIOS table.
+ *
+ * @param[in] attributeName - Attribute to be read.
+ * @return - Bios attribute current value.
+ */
+ types::BiosAttributeCurrentValue
+ readBiosAttribute(const std::string& attributeName);
+
+ /**
+ * @brief API to process "hb_field_core_override" attribute.
+ *
+ * The API checks value stored in VPD. If found default then the BIOS value
+ * is saved to VPD else VPD value is restored in BIOS pending attribute
+ * table.
+ */
+ void processFieldCoreOverride();
+
+ /**
+ * @brief API to save FCO data into VPD.
+ *
+ * @param[in] i_fcoInBios - FCO value.
+ */
+ void saveFcoToVpd(int64_t i_fcoInBios);
+
+ /**
+ * @brief API to save given value to "hb_field_core_override" attribute.
+ *
+ * @param[in] i_fcoVal - FCO value.
+ */
+ void saveFcoToBios(const types::BinaryVector& i_fcoVal);
+
+ /**
+ * @brief API to save AMM data into VPD.
+ *
+ * @param[in] i_memoryMirrorMode - Memory mirror mode value.
+ */
+ void saveAmmToVpd(const std::string& i_memoryMirrorMode);
+
+ /**
+ * @brief API to save given value to "hb_memory_mirror_mode" attribute.
+ *
+ * @param[in] i_ammVal - AMM value.
+ */
+ void saveAmmToBios(const std::string& i_ammVal);
+
+ /**
+ * @brief API to process "hb_memory_mirror_mode" attribute.
+ *
+ * The API checks value stored in VPD. If found default then the BIOS value
+ * is saved to VPD else VPD value is restored in BIOS pending attribute
+ * table.
+ */
+ void processActiveMemoryMirror();
+
+ /**
+ * @brief API to process "pvm_create_default_lpar" attribute.
+ *
+ * The API reads the value from VPD and restore it to the BIOS attribute
+ * in BIOS pending attribute table.
+ */
+ void processCreateDefaultLpar();
+
+ /**
+ * @brief API to save given value to "pvm_create_default_lpar" attribute.
+ *
+ * @param[in] i_createDefaultLparVal - Value to be saved;
+ */
+ void saveCreateDefaultLparToBios(const std::string& i_createDefaultLparVal);
+
+ /**
+ * @brief API to save given value to VPD.
+ *
+ * @param[in] i_createDefaultLparVal - Value to be saved.
+ *
+ */
+ void saveCreateDefaultLparToVpd(const std::string& i_createDefaultLparVal);
+
+ /**
+ * @brief API to process "pvm_clear_nvram" attribute.
+ *
+ * The API reads the value from VPD and restores it to the BIOS pending
+ * attribute table.
+ */
+ void processClearNvram();
+
+ /**
+ * @brief API to save given value to "pvm_clear_nvram" attribute.
+ *
+ * @param[in] i_clearNvramVal - Value to be saved.
+ */
+ void saveClearNvramToBios(const std::string& i_clearNvramVal);
+
+ /**
+ * @brief API to save given value to VPD.
+ *
+ * @param[in] i_clearNvramVal - Value to be saved.
+ */
+ void saveClearNvramToVpd(const std::string& i_clearNvramVal);
+
+ /**
+ * @brief API to process "pvm_keep_and_clear" attribute.
+ *
+ * The API reads the value from VPD and restore it to the BIOS pending
+ * attribute table.
+ */
+ void processKeepAndClear();
+
+ /**
+ * @brief API to save given value to "pvm_keep_and_clear" attribute.
+ *
+ * @param[in] i_KeepAndClearVal - Value to be saved.
+ */
+ void saveKeepAndClearToBios(const std::string& i_KeepAndClearVal);
+
+ /**
+ * @brief API to save given value to VPD.
+ *
+ * @param[in] i_KeepAndClearVal - Value to be saved.
+ */
+ void saveKeepAndClearToVpd(const std::string& i_KeepAndClearVal);
+
+ // const reference to shared pointer to Manager object.
+ const std::shared_ptr<Manager>& m_manager;
+};
+
+/**
+ * @brief A class to operate upon BIOS attributes.
+ *
+ * The class along with specific BIOS handler class(es), provides a feature
+ * where specific BIOS attributes identified by the concrete specific class can
+ * be listened for any change and can be backed up to a desired location or
+ * restored back to the BIOS table.
+ *
+ * To use the feature, "BiosHandlerInterface" should be implemented by a
+ * concrete class and the same should be used to instantiate BiosHandler.
+ *
+ * This class registers call back to listen to PLDM service as it is being used
+ * for reading/writing BIOS attributes.
+ *
+ * The feature can be used in a factory reset scenario where backed up values
+ * can be used to restore BIOS.
+ *
+ */
+template <typename T>
+class BiosHandler
+{
+ public:
+ // deleted APIs
+ BiosHandler() = delete;
+ BiosHandler(const BiosHandler&) = delete;
+ BiosHandler& operator=(const BiosHandler&) = delete;
+ BiosHandler& operator=(BiosHandler&&) = delete;
+ ~BiosHandler() = default;
+
+ /**
+ * @brief Constructor.
+ *
+ * @param[in] i_connection - Asio connection object.
+ * @param[in] i_manager - Manager object.
+ */
+ BiosHandler(
+ const std::shared_ptr<sdbusplus::asio::connection>& i_connection,
+ const std::shared_ptr<Manager>& i_manager) : m_asioConn(i_connection)
+ {
+ m_specificBiosHandler = std::make_shared<T>(i_manager);
+ checkAndListenPldmService();
+ }
+
+ private:
+ /**
+ * @brief API to check if PLDM service is running and run BIOS sync.
+ *
+ * This API checks if the PLDM service is running and if yes it will start
+ * an immediate sync of BIOS attributes. If the service is not running, it
+ * registers a listener to be notified when the service starts so that a
+ * restore can be performed.
+ */
+ void checkAndListenPldmService();
+
+ /**
+ * @brief Register listener for BIOS attribute property change.
+ *
+ * The VPD manager needs to listen for property change of certain BIOS
+ * attributes that are backed in VPD. When the attributes change, the new
+ * value is written back to the VPD keywords that backs them up.
+ */
+ void listenBiosAttributes();
+
+ // Reference to the connection.
+ const std::shared_ptr<sdbusplus::asio::connection>& m_asioConn;
+
+ // shared pointer to specific BIOS handler.
+ std::shared_ptr<T> m_specificBiosHandler;
+};
+} // namespace vpd