Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types.hpp" |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 10 | namespace openpower |
| 11 | { |
| 12 | namespace vpd |
| 13 | { |
| 14 | namespace manager |
| 15 | { |
| 16 | |
| 17 | class Manager; |
| 18 | /** |
| 19 | * @brief A class that handles changes to BIOS attributes backed by VPD. |
| 20 | * |
| 21 | * This class has APIs that handle updates to BIOS attributes that need to |
| 22 | * be backed up to VPD. It mainly does the following: |
| 23 | * 1) Checks if the VPD keywords that BIOS attributes are backed to are |
| 24 | * uninitialized. If so, it initializes them. |
| 25 | * 2) Listens for changes to BIOS attributes and synchronizes them to the |
| 26 | * appropriate VPD keyword. |
| 27 | * |
| 28 | * Since on a factory reset like scenario, the BIOS attributes are initialized |
| 29 | * by PLDM, this code waits until PLDM has grabbed a bus name before attempting |
| 30 | * any syncs. |
| 31 | */ |
| 32 | class BiosHandler |
| 33 | { |
| 34 | public: |
| 35 | // Some default and deleted constructors and assignments. |
| 36 | BiosHandler() = delete; |
| 37 | BiosHandler(const BiosHandler&) = delete; |
| 38 | BiosHandler& operator=(const BiosHandler&) = delete; |
| 39 | BiosHandler(Manager&&) = delete; |
| 40 | BiosHandler& operator=(BiosHandler&&) = delete; |
| 41 | ~BiosHandler() = default; |
| 42 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 43 | BiosHandler(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 44 | Manager& manager) : |
| 45 | conn(conn), |
| 46 | manager(manager) |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 47 | { |
| 48 | checkAndListenPLDMService(); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | /** |
| 53 | * @brief Check if PLDM service is running and run BIOS sync |
| 54 | * |
| 55 | * This API checks if the PLDM service is running and if yes it will start |
| 56 | * an immediate sync of BIOS attributes. If the service is not running, it |
| 57 | * registers a listener to be notified when the service starts so that a |
| 58 | * restore can be performed. |
| 59 | */ |
| 60 | void checkAndListenPLDMService(); |
| 61 | |
| 62 | /** |
| 63 | * @brief Register listener for changes to BIOS Attributes. |
| 64 | * |
| 65 | * The VPD manager needs to listen to changes to certain BIOS attributes |
| 66 | * that are backed by VPD. When the attributes we are interested in |
| 67 | * change, the VPD manager will make sure that we write them back to the |
| 68 | * VPD keywords that back them up. |
| 69 | */ |
| 70 | void listenBiosAttribs(); |
| 71 | |
| 72 | /** |
| 73 | * @brief Callback for BIOS Attribute changes |
| 74 | * |
| 75 | * Checks if the BIOS attribute(s) changed are those backed up by VPD. If |
| 76 | * yes, it will update the VPD with the new attribute value. |
| 77 | * @param[in] msg - The callback message. |
| 78 | */ |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 79 | void biosAttribsCallback(sdbusplus::message_t& msg); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * @brief Persistently saves the Memory mirror mode |
| 83 | * |
| 84 | * Memory mirror mode setting is saved to the UTIL/D0 keyword in the |
| 85 | * motherboard VPD. If the mirror mode in BIOS is "Disabled", set D0 to 1, |
| 86 | * if "Enabled" set D0 to 2 |
| 87 | * |
| 88 | * @param[in] mirrorMode - The mirror mode BIOS attribute. |
| 89 | */ |
| 90 | void saveAMMToVPD(const std::string& mirrorMode); |
| 91 | |
| 92 | /** |
| 93 | * @brief Persistently saves the Field Core Override setting |
| 94 | * |
| 95 | * Saves the field core override value (FCO) into the VSYS/RG keyword in |
| 96 | * the motherboard VPD. |
| 97 | * |
| 98 | * @param[in] fcoVal - The FCO value as an integer. |
| 99 | */ |
| 100 | void saveFCOToVPD(int64_t fcoVal); |
| 101 | |
| 102 | /** |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 103 | * @brief Persistently saves the Keep and Clear setting |
| 104 | * |
| 105 | * Keep and clear setting is saved to the UTIL/D1 keyword's 0th bit in the |
| 106 | * motherboard VPD. If the keep and clear in BIOS is "Disabled", set D1:0 to |
| 107 | * 0, if "Enabled" set D1:0 to 1 |
| 108 | * |
| 109 | * @param[in] keepAndClear - The keep and clear BIOS attribute. |
| 110 | */ |
| 111 | void saveKeepAndClearToVPD(const std::string& keepAndClear); |
| 112 | |
| 113 | /** |
| 114 | * @brief Persistently saves the Create default LPAR setting |
| 115 | * |
| 116 | * Create default LPAR setting is saved to the UTIL/D1 keyword's 1st bit in |
| 117 | * the motherboard VPD. If the create default LPAR in BIOS is "Disabled", |
| 118 | * set D1:1 to 0, if "Enabled" set D1:1 to 1 |
| 119 | * |
| 120 | * @param[in] createDefaultLpar - The mirror mode BIOS attribute. |
| 121 | */ |
| 122 | void saveCreateDefaultLparToVPD(const std::string& createDefaultLpar); |
| 123 | |
| 124 | /** |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 125 | * @brief Persistently saves the Clear NVRAM setting |
| 126 | * |
| 127 | * Create default LPAR setting is saved to the UTIL/D1 keyword's 2nd bit in |
| 128 | * the motherboard VPD. If the clear NVRAM in BIOS is "Disabled", |
| 129 | * set D1:2 to 0, if "Enabled" set D1:2 to 1 |
| 130 | * |
| 131 | * @param[in] createDefaultLpar - The mirror mode BIOS attribute. |
| 132 | */ |
| 133 | void saveClearNVRAMToVPD(const std::string& clearNVRAM); |
| 134 | |
| 135 | /** |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 136 | * @brief Writes Memory mirror mode to BIOS |
| 137 | * |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 138 | * Writes to the hb_memory_mirror_mode BIOS attribute, if the value is |
| 139 | * not already the same as we are trying to write. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 140 | * |
| 141 | * @param[in] ammVal - The mirror mode as read from VPD. |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 142 | * @param[in] ammInBIOS - The mirror mode in the BIOS table. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 143 | */ |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 144 | void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * @brief Writes Field Core Override to BIOS |
| 148 | * |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 149 | * Writes to the hb_field_core_override BIOS attribute, if the value is not |
| 150 | * already the same as we are trying to write. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 151 | * |
| 152 | * @param[in] fcoVal - The FCO value as read from VPD. |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 153 | * @param[in] fcoInBIOS - The FCO value already in the BIOS table. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 154 | */ |
Santosh Puranik | f7f8da6 | 2022-05-06 13:01:19 -0500 | [diff] [blame] | 155 | void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS); |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 156 | |
| 157 | /** |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 158 | * @brief Writes Keep and clear setting to BIOS |
| 159 | * |
| 160 | * Writes to the pvm_keep_and_clear BIOS attribute, if the value is |
| 161 | * not already the same as we are trying to write. |
| 162 | * |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 163 | * @param[in] keepAndClear - The keep and clear as read from VPD. |
| 164 | * @param[in] keepAndClearInBIOS - The keep and clear in the BIOS table. |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 165 | */ |
| 166 | void saveKeepAndClearToBIOS(const std::string& keepAndClear, |
| 167 | const std::string& keepAndClearInBIOS); |
| 168 | |
| 169 | /** |
| 170 | * @brief Writes Create default LPAR setting to BIOS |
| 171 | * |
| 172 | * Writes to the pvm_create_default_lpar BIOS attribute, if the value is |
| 173 | * not already the same as we are trying to write. |
| 174 | * |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 175 | * @param[in] createDefaultLpar - The create default LPAR as read from VPD. |
| 176 | * @param[in] createDefaultLparInBIOS - The create default LPAR in the BIOS |
| 177 | * table. |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 178 | */ |
| 179 | void |
| 180 | saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar, |
| 181 | const std::string& createDefaultLparInBIOS); |
| 182 | |
| 183 | /** |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 184 | * @brief Writes Clear NVRAM setting to BIOS |
| 185 | * |
| 186 | * Writes to the pvm_clear_nvram BIOS attribute, if the value is |
| 187 | * not already the same as we are trying to write. |
| 188 | * |
| 189 | * @param[in] clearNVRAM - The clear NVRAM as read from VPD. |
| 190 | * @param[in] clearNVRAMInBIOS - The clear NVRAM in the BIOS table. |
| 191 | */ |
| 192 | void saveClearNVRAMToBIOS(const std::string& clearNVRAM, |
| 193 | const std::string& clearNVRAMInBIOS); |
| 194 | |
| 195 | /** |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 196 | * @brief Reads the hb_memory_mirror_mode attribute |
| 197 | * |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 198 | * @return std::string - The AMM BIOS attribute. Empty string on failure. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 199 | */ |
| 200 | std::string readBIOSAMM(); |
| 201 | |
| 202 | /** |
| 203 | * @brief Reads the hb_field_core_override attribute |
| 204 | * |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 205 | * @return int64_t - The FCO BIOS attribute. -1 on failure. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 206 | */ |
| 207 | int64_t readBIOSFCO(); |
| 208 | |
| 209 | /** |
Santosh Puranik | b2c2ccc | 2022-05-14 05:15:44 -0500 | [diff] [blame] | 210 | * @brief Reads the pvm_keep_and_clear attribute |
| 211 | * |
| 212 | * @return std::string - The Keep and clear BIOS attribute. Empty string on |
| 213 | * failure. |
| 214 | */ |
| 215 | std::string readBIOSKeepAndClear(); |
| 216 | |
| 217 | /** |
| 218 | * @brief Reads the pvm_create_default_lpar attribute |
| 219 | * |
| 220 | * @return std::string - The Create default LPAR BIOS attribute. Empty |
| 221 | * string on failure. |
| 222 | */ |
| 223 | std::string readBIOSCreateDefaultLpar(); |
| 224 | |
| 225 | /** |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 226 | * @brief Reads the pvm_clear_nvram attribute |
| 227 | * |
| 228 | * @return std::string - The Clear NVRAM BIOS attribute. Empty |
| 229 | * string on failure. |
| 230 | */ |
| 231 | std::string readBIOSClearNVRAM(); |
| 232 | |
| 233 | /** |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 234 | * @brief Restore BIOS attributes |
| 235 | * |
| 236 | * This function checks if we are coming out of a factory reset. If yes, |
Santosh Puranik | a97b63e | 2022-05-20 05:22:27 -0500 | [diff] [blame] | 237 | * it checks the VPD cache for valid backed up copy of the applicable |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 238 | * BIOS attributes. If valid values are found in the VPD, it will apply |
| 239 | * those to the BIOS attributes. |
| 240 | */ |
| 241 | void restoreBIOSAttribs(); |
| 242 | |
| 243 | /** |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 244 | * @brief Reference to the connection. |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 245 | */ |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 246 | std::shared_ptr<sdbusplus::asio::connection>& conn; |
Santosh Puranik | f2d3b53 | 2022-04-19 06:44:07 -0500 | [diff] [blame] | 247 | |
| 248 | /** |
| 249 | * @brief Reference to the manager. |
| 250 | */ |
| 251 | Manager& manager; |
| 252 | }; // class BiosHandler |
| 253 | } // namespace manager |
| 254 | } // namespace vpd |
| 255 | } // namespace openpower |