blob: ef4cfa41f237f9045fba33e0784befc0b4862a0c [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>
Patrick Williamsc78d8872023-05-10 07:50:56 -05008
Santosh Puranikf2d3b532022-04-19 06:44:07 -05009#include <string>
10
Santosh Puranikf2d3b532022-04-19 06:44:07 -050011namespace openpower
12{
13namespace vpd
14{
15namespace manager
16{
17
18class Manager;
19/**
20 * @brief A class that handles changes to BIOS attributes backed by VPD.
21 *
22 * This class has APIs that handle updates to BIOS attributes that need to
23 * be backed up to VPD. It mainly does the following:
24 * 1) Checks if the VPD keywords that BIOS attributes are backed to are
25 * uninitialized. If so, it initializes them.
26 * 2) Listens for changes to BIOS attributes and synchronizes them to the
27 * appropriate VPD keyword.
28 *
29 * Since on a factory reset like scenario, the BIOS attributes are initialized
30 * by PLDM, this code waits until PLDM has grabbed a bus name before attempting
31 * any syncs.
32 */
33class BiosHandler
34{
35 public:
36 // Some default and deleted constructors and assignments.
37 BiosHandler() = delete;
38 BiosHandler(const BiosHandler&) = delete;
39 BiosHandler& operator=(const BiosHandler&) = delete;
40 BiosHandler(Manager&&) = delete;
41 BiosHandler& operator=(BiosHandler&&) = delete;
42 ~BiosHandler() = default;
43
Sunny Srivastava523af2e2022-02-14 07:30:10 -060044 BiosHandler(std::shared_ptr<sdbusplus::asio::connection>& conn,
45 Manager& manager) :
46 conn(conn),
47 manager(manager)
Santosh Puranikf2d3b532022-04-19 06:44:07 -050048 {
49 checkAndListenPLDMService();
50 }
51
52 private:
53 /**
54 * @brief Check if PLDM service is running and run BIOS sync
55 *
56 * This API checks if the PLDM service is running and if yes it will start
57 * an immediate sync of BIOS attributes. If the service is not running, it
58 * registers a listener to be notified when the service starts so that a
59 * restore can be performed.
60 */
61 void checkAndListenPLDMService();
62
63 /**
64 * @brief Register listener for changes to BIOS Attributes.
65 *
66 * The VPD manager needs to listen to changes to certain BIOS attributes
67 * that are backed by VPD. When the attributes we are interested in
68 * change, the VPD manager will make sure that we write them back to the
69 * VPD keywords that back them up.
70 */
71 void listenBiosAttribs();
72
73 /**
74 * @brief Callback for BIOS Attribute changes
75 *
76 * Checks if the BIOS attribute(s) changed are those backed up by VPD. If
77 * yes, it will update the VPD with the new attribute value.
78 * @param[in] msg - The callback message.
79 */
Patrick Williams2eb01762022-07-22 19:26:56 -050080 void biosAttribsCallback(sdbusplus::message_t& msg);
Santosh Puranikf2d3b532022-04-19 06:44:07 -050081
82 /**
83 * @brief Persistently saves the Memory mirror mode
84 *
85 * Memory mirror mode setting is saved to the UTIL/D0 keyword in the
86 * motherboard VPD. If the mirror mode in BIOS is "Disabled", set D0 to 1,
87 * if "Enabled" set D0 to 2
88 *
89 * @param[in] mirrorMode - The mirror mode BIOS attribute.
90 */
91 void saveAMMToVPD(const std::string& mirrorMode);
92
93 /**
94 * @brief Persistently saves the Field Core Override setting
95 *
96 * Saves the field core override value (FCO) into the VSYS/RG keyword in
97 * the motherboard VPD.
98 *
99 * @param[in] fcoVal - The FCO value as an integer.
100 */
101 void saveFCOToVPD(int64_t fcoVal);
102
103 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500104 * @brief Persistently saves the Keep and Clear setting
105 *
106 * Keep and clear setting is saved to the UTIL/D1 keyword's 0th bit in the
107 * motherboard VPD. If the keep and clear in BIOS is "Disabled", set D1:0 to
108 * 0, if "Enabled" set D1:0 to 1
109 *
110 * @param[in] keepAndClear - The keep and clear BIOS attribute.
111 */
112 void saveKeepAndClearToVPD(const std::string& keepAndClear);
113
114 /**
115 * @brief Persistently saves the Create default LPAR setting
116 *
117 * Create default LPAR setting is saved to the UTIL/D1 keyword's 1st bit in
118 * the motherboard VPD. If the create default LPAR in BIOS is "Disabled",
119 * set D1:1 to 0, if "Enabled" set D1:1 to 1
120 *
121 * @param[in] createDefaultLpar - The mirror mode BIOS attribute.
122 */
123 void saveCreateDefaultLparToVPD(const std::string& createDefaultLpar);
124
125 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500126 * @brief Persistently saves the Clear NVRAM setting
127 *
128 * Create default LPAR setting is saved to the UTIL/D1 keyword's 2nd bit in
129 * the motherboard VPD. If the clear NVRAM in BIOS is "Disabled",
130 * set D1:2 to 0, if "Enabled" set D1:2 to 1
131 *
132 * @param[in] createDefaultLpar - The mirror mode BIOS attribute.
133 */
134 void saveClearNVRAMToVPD(const std::string& clearNVRAM);
135
136 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500137 * @brief Writes Memory mirror mode to BIOS
138 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500139 * Writes to the hb_memory_mirror_mode BIOS attribute, if the value is
140 * not already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500141 *
142 * @param[in] ammVal - The mirror mode as read from VPD.
Santosh Puranika97b63e2022-05-20 05:22:27 -0500143 * @param[in] ammInBIOS - The mirror mode in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500144 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500145 void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500146
147 /**
148 * @brief Writes Field Core Override to BIOS
149 *
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500150 * Writes to the hb_field_core_override BIOS attribute, if the value is not
151 * already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500152 *
153 * @param[in] fcoVal - The FCO value as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500154 * @param[in] fcoInBIOS - The FCO value already in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500155 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500156 void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500157
158 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500159 * @brief Writes Keep and clear setting to BIOS
160 *
161 * Writes to the pvm_keep_and_clear BIOS attribute, if the value is
162 * not already the same as we are trying to write.
163 *
Santosh Puranika97b63e2022-05-20 05:22:27 -0500164 * @param[in] keepAndClear - The keep and clear as read from VPD.
165 * @param[in] keepAndClearInBIOS - The keep and clear in the BIOS table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500166 */
167 void saveKeepAndClearToBIOS(const std::string& keepAndClear,
168 const std::string& keepAndClearInBIOS);
169
170 /**
171 * @brief Writes Create default LPAR setting to BIOS
172 *
173 * Writes to the pvm_create_default_lpar BIOS attribute, if the value is
174 * not already the same as we are trying to write.
175 *
Santosh Puranika97b63e2022-05-20 05:22:27 -0500176 * @param[in] createDefaultLpar - The create default LPAR as read from VPD.
177 * @param[in] createDefaultLparInBIOS - The create default LPAR in the BIOS
178 * table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500179 */
180 void
181 saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar,
182 const std::string& createDefaultLparInBIOS);
183
184 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500185 * @brief Writes Clear NVRAM setting to BIOS
186 *
187 * Writes to the pvm_clear_nvram BIOS attribute, if the value is
188 * not already the same as we are trying to write.
189 *
190 * @param[in] clearNVRAM - The clear NVRAM as read from VPD.
191 * @param[in] clearNVRAMInBIOS - The clear NVRAM in the BIOS table.
192 */
193 void saveClearNVRAMToBIOS(const std::string& clearNVRAM,
194 const std::string& clearNVRAMInBIOS);
195
196 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500197 * @brief Reads the hb_memory_mirror_mode attribute
198 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500199 * @return std::string - The AMM BIOS attribute. Empty string on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500200 */
201 std::string readBIOSAMM();
202
203 /**
204 * @brief Reads the hb_field_core_override attribute
205 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500206 * @return int64_t - The FCO BIOS attribute. -1 on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500207 */
208 int64_t readBIOSFCO();
209
210 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500211 * @brief Reads the pvm_keep_and_clear attribute
212 *
213 * @return std::string - The Keep and clear BIOS attribute. Empty string on
214 * failure.
215 */
216 std::string readBIOSKeepAndClear();
217
218 /**
219 * @brief Reads the pvm_create_default_lpar attribute
220 *
221 * @return std::string - The Create default LPAR BIOS attribute. Empty
222 * string on failure.
223 */
224 std::string readBIOSCreateDefaultLpar();
225
226 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500227 * @brief Reads the pvm_clear_nvram attribute
228 *
229 * @return std::string - The Clear NVRAM BIOS attribute. Empty
230 * string on failure.
231 */
232 std::string readBIOSClearNVRAM();
233
234 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500235 * @brief Restore BIOS attributes
236 *
237 * This function checks if we are coming out of a factory reset. If yes,
Santosh Puranika97b63e2022-05-20 05:22:27 -0500238 * it checks the VPD cache for valid backed up copy of the applicable
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500239 * BIOS attributes. If valid values are found in the VPD, it will apply
240 * those to the BIOS attributes.
241 */
242 void restoreBIOSAttribs();
243
244 /**
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600245 * @brief Reference to the connection.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500246 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600247 std::shared_ptr<sdbusplus::asio::connection>& conn;
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500248
249 /**
250 * @brief Reference to the manager.
251 */
252 Manager& manager;
253}; // class BiosHandler
254} // namespace manager
255} // namespace vpd
Patrick Williamsc78d8872023-05-10 07:50:56 -0500256} // namespace openpower