blob: dda120cc324ce960dde8ea1bb723fd5cad92b24d [file] [log] [blame]
Santosh Puranikf2d3b532022-04-19 06:44:07 -05001#pragma once
2
3#include "types.hpp"
4
5#include <stdint.h>
6
Sunny Srivastava523af2e2022-02-14 07:30:10 -06007#include <sdbusplus/asio/connection.hpp>
Santosh Puranikf2d3b532022-04-19 06:44:07 -05008#include <string>
9
Santosh Puranikf2d3b532022-04-19 06:44:07 -050010namespace openpower
11{
12namespace vpd
13{
14namespace manager
15{
16
17class 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 */
32class 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 Srivastava523af2e2022-02-14 07:30:10 -060043 BiosHandler(std::shared_ptr<sdbusplus::asio::connection>& conn,
44 Manager& manager) :
45 conn(conn),
46 manager(manager)
Santosh Puranikf2d3b532022-04-19 06:44:07 -050047 {
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 Williams2eb01762022-07-22 19:26:56 -050079 void biosAttribsCallback(sdbusplus::message_t& msg);
Santosh Puranikf2d3b532022-04-19 06:44:07 -050080
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 Puranikb2c2ccc2022-05-14 05:15:44 -0500103 * @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 Puranika97b63e2022-05-20 05:22:27 -0500125 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500136 * @brief Writes Memory mirror mode to BIOS
137 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500138 * 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 Puranikf2d3b532022-04-19 06:44:07 -0500140 *
141 * @param[in] ammVal - The mirror mode as read from VPD.
Santosh Puranika97b63e2022-05-20 05:22:27 -0500142 * @param[in] ammInBIOS - The mirror mode in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500143 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500144 void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500145
146 /**
147 * @brief Writes Field Core Override to BIOS
148 *
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500149 * 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 Puranikf2d3b532022-04-19 06:44:07 -0500151 *
152 * @param[in] fcoVal - The FCO value as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500153 * @param[in] fcoInBIOS - The FCO value already in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500154 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500155 void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500156
157 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500158 * @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 Puranika97b63e2022-05-20 05:22:27 -0500163 * @param[in] keepAndClear - The keep and clear as read from VPD.
164 * @param[in] keepAndClearInBIOS - The keep and clear in the BIOS table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500165 */
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 Puranika97b63e2022-05-20 05:22:27 -0500175 * @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 Puranikb2c2ccc2022-05-14 05:15:44 -0500178 */
179 void
180 saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar,
181 const std::string& createDefaultLparInBIOS);
182
183 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500184 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500196 * @brief Reads the hb_memory_mirror_mode attribute
197 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500198 * @return std::string - The AMM BIOS attribute. Empty string on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500199 */
200 std::string readBIOSAMM();
201
202 /**
203 * @brief Reads the hb_field_core_override attribute
204 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500205 * @return int64_t - The FCO BIOS attribute. -1 on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500206 */
207 int64_t readBIOSFCO();
208
209 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500210 * @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 Puranika97b63e2022-05-20 05:22:27 -0500226 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500234 * @brief Restore BIOS attributes
235 *
236 * This function checks if we are coming out of a factory reset. If yes,
Santosh Puranika97b63e2022-05-20 05:22:27 -0500237 * it checks the VPD cache for valid backed up copy of the applicable
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500238 * 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 Srivastava523af2e2022-02-14 07:30:10 -0600244 * @brief Reference to the connection.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500245 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600246 std::shared_ptr<sdbusplus::asio::connection>& conn;
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500247
248 /**
249 * @brief Reference to the manager.
250 */
251 Manager& manager;
252}; // class BiosHandler
253} // namespace manager
254} // namespace vpd
255} // namespace openpower