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