1 #pragma once 2 #include "manager.hpp" 3 #include "types.hpp" 4 5 #include <sdbusplus/asio/connection.hpp> 6 #include <sdbusplus/bus.hpp> 7 8 namespace vpd 9 { 10 11 /** 12 * @brief Interface class for BIOS handling. 13 * 14 * The class layout has the virtual methods required to be implemented by any 15 * concrete class that intends to use the feature provided via BIOS handler 16 * class. 17 */ 18 class BiosHandlerInterface 19 { 20 public: 21 /** 22 * @brief API to back up or restore BIOS attributes. 23 * 24 * Concrete class should implement the API and read the backed up data from 25 * its designated location and take a call if it should be backed up or 26 * restored. 27 */ 28 virtual void backUpOrRestoreBiosAttributes() = 0; 29 30 /** 31 * @brief Callback API to be triggered on BIOS attribute change. 32 * 33 * Concrete class should implement the API to extract the attribute and its 34 * value from DBus message broadcasted on BIOS attribute change. 35 * The definition should be overridden in concrete class to deal with BIOS 36 * attributes interested in. 37 * 38 * @param[in] i_msg - The callback message. 39 */ 40 virtual void biosAttributesCallback(sdbusplus::message_t& i_msg) = 0; 41 }; 42 43 /** 44 * @brief IBM specifc BIOS handler class. 45 */ 46 class IbmBiosHandler : public BiosHandlerInterface 47 { 48 public: 49 /** 50 * @brief Construct a new IBM BIOS Handler object 51 * 52 * This constructor constructs a new IBM BIOS Handler object 53 * @param[in] i_manager - Manager object. 54 */ IbmBiosHandler(const std::shared_ptr<Manager> & i_manager)55 explicit IbmBiosHandler(const std::shared_ptr<Manager>& i_manager) : 56 m_manager(i_manager) 57 {} 58 59 /** 60 * @brief API to back up or restore BIOS attributes. 61 * 62 * The API will read the backed up data from the VPD keyword and based on 63 * its value, either backs up or restores the data. 64 */ 65 virtual void backUpOrRestoreBiosAttributes(); 66 67 /** 68 * @brief Callback API to be triggered on BIOS attribute change. 69 * 70 * The API to extract the required attribute and its value from DBus message 71 * broadcasted on BIOS attribute change. 72 * 73 * @param[in] i_msg - The callback message. 74 */ 75 virtual void biosAttributesCallback(sdbusplus::message_t& i_msg); 76 77 private: 78 /** 79 * @brief API to read given attribute from BIOS table. 80 * 81 * @param[in] attributeName - Attribute to be read. 82 * @return - Bios attribute current value. 83 */ 84 types::BiosAttributeCurrentValue readBiosAttribute( 85 const std::string& attributeName); 86 87 /** 88 * @brief API to process "hb_field_core_override" attribute. 89 * 90 * The API checks value stored in VPD. If found default then the BIOS value 91 * is saved to VPD else VPD value is restored in BIOS pending attribute 92 * table. 93 */ 94 void processFieldCoreOverride(); 95 96 /** 97 * @brief API to save FCO data into VPD. 98 * 99 * @param[in] i_fcoInBios - FCO value. 100 */ 101 void saveFcoToVpd(int64_t i_fcoInBios); 102 103 /** 104 * @brief API to save given value to "hb_field_core_override" attribute. 105 * 106 * @param[in] i_fcoVal - FCO value. 107 */ 108 void saveFcoToBios(const types::BinaryVector& i_fcoVal); 109 110 /** 111 * @brief API to save AMM data into VPD. 112 * 113 * @param[in] i_memoryMirrorMode - Memory mirror mode value. 114 */ 115 void saveAmmToVpd(const std::string& i_memoryMirrorMode); 116 117 /** 118 * @brief API to save given value to "hb_memory_mirror_mode" attribute. 119 * 120 * @param[in] i_ammVal - AMM value. 121 */ 122 void saveAmmToBios(const uint8_t& i_ammVal); 123 124 /** 125 * @brief API to process "hb_memory_mirror_mode" attribute. 126 * 127 * The API checks value stored in VPD. If found default then the BIOS value 128 * is saved to VPD else VPD value is restored in BIOS pending attribute 129 * table. 130 */ 131 void processActiveMemoryMirror(); 132 133 /** 134 * @brief API to process "pvm_create_default_lpar" attribute. 135 * 136 * The API reads the value from VPD and restore it to the BIOS attribute 137 * in BIOS pending attribute table. 138 */ 139 void processCreateDefaultLpar(); 140 141 /** 142 * @brief API to save given value to "pvm_create_default_lpar" attribute. 143 * 144 * @param[in] i_createDefaultLparVal - Value to be saved; 145 */ 146 void saveCreateDefaultLparToBios(const std::string& i_createDefaultLparVal); 147 148 /** 149 * @brief API to save given value to VPD. 150 * 151 * @param[in] i_createDefaultLparVal - Value to be saved. 152 * 153 */ 154 void saveCreateDefaultLparToVpd(const std::string& i_createDefaultLparVal); 155 156 /** 157 * @brief API to process "pvm_clear_nvram" attribute. 158 * 159 * The API reads the value from VPD and restores it to the BIOS pending 160 * attribute table. 161 */ 162 void processClearNvram(); 163 164 /** 165 * @brief API to save given value to "pvm_clear_nvram" attribute. 166 * 167 * @param[in] i_clearNvramVal - Value to be saved. 168 */ 169 void saveClearNvramToBios(const std::string& i_clearNvramVal); 170 171 /** 172 * @brief API to save given value to VPD. 173 * 174 * @param[in] i_clearNvramVal - Value to be saved. 175 */ 176 void saveClearNvramToVpd(const std::string& i_clearNvramVal); 177 178 /** 179 * @brief API to process "pvm_keep_and_clear" attribute. 180 * 181 * The API reads the value from VPD and restore it to the BIOS pending 182 * attribute table. 183 */ 184 void processKeepAndClear(); 185 186 /** 187 * @brief API to save given value to "pvm_keep_and_clear" attribute. 188 * 189 * @param[in] i_KeepAndClearVal - Value to be saved. 190 */ 191 void saveKeepAndClearToBios(const std::string& i_KeepAndClearVal); 192 193 /** 194 * @brief API to save given value to VPD. 195 * 196 * @param[in] i_KeepAndClearVal - Value to be saved. 197 */ 198 void saveKeepAndClearToVpd(const std::string& i_KeepAndClearVal); 199 200 // const reference to shared pointer to Manager object. 201 const std::shared_ptr<Manager>& m_manager; 202 }; 203 204 /** 205 * @brief A class to operate upon BIOS attributes. 206 * 207 * The class along with specific BIOS handler class(es), provides a feature 208 * where specific BIOS attributes identified by the concrete specific class can 209 * be listened for any change and can be backed up to a desired location or 210 * restored back to the BIOS table. 211 * 212 * To use the feature, "BiosHandlerInterface" should be implemented by a 213 * concrete class and the same should be used to instantiate BiosHandler. 214 * 215 * This class registers call back to listen to PLDM service as it is being used 216 * for reading/writing BIOS attributes. 217 * 218 * The feature can be used in a factory reset scenario where backed up values 219 * can be used to restore BIOS. 220 * 221 */ 222 template <typename T> 223 class BiosHandler 224 { 225 public: 226 // deleted APIs 227 BiosHandler() = delete; 228 BiosHandler(const BiosHandler&) = delete; 229 BiosHandler& operator=(const BiosHandler&) = delete; 230 BiosHandler& operator=(BiosHandler&&) = delete; 231 ~BiosHandler() = default; 232 233 /** 234 * @brief Constructor. 235 * 236 * @param[in] i_connection - Asio connection object. 237 * @param[in] i_manager - Manager object. 238 */ BiosHandler(const std::shared_ptr<sdbusplus::asio::connection> & i_connection,const std::shared_ptr<Manager> & i_manager)239 BiosHandler( 240 const std::shared_ptr<sdbusplus::asio::connection>& i_connection, 241 const std::shared_ptr<Manager>& i_manager) : m_asioConn(i_connection) 242 { 243 m_specificBiosHandler = std::make_shared<T>(i_manager); 244 checkAndListenPldmService(); 245 } 246 247 private: 248 /** 249 * @brief API to check if PLDM service is running and run BIOS sync. 250 * 251 * This API checks if the PLDM service is running and if yes it will start 252 * an immediate sync of BIOS attributes. If the service is not running, it 253 * registers a listener to be notified when the service starts so that a 254 * restore can be performed. 255 */ 256 void checkAndListenPldmService(); 257 258 /** 259 * @brief Register listener for BIOS attribute property change. 260 * 261 * The VPD manager needs to listen for property change of certain BIOS 262 * attributes that are backed in VPD. When the attributes change, the new 263 * value is written back to the VPD keywords that backs them up. 264 */ 265 void listenBiosAttributes(); 266 267 // Reference to the connection. 268 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConn; 269 270 // shared pointer to specific BIOS handler. 271 std::shared_ptr<T> m_specificBiosHandler; 272 }; 273 } // namespace vpd 274