blob: 985daa7273eae17d1544964c5d52f04562d23f68 [file] [log] [blame]
Santosh Puranikf2d3b532022-04-19 06:44:07 -05001#pragma once
2
3#include "types.hpp"
4
5#include <stdint.h>
6
7#include <string>
8
9namespace sdbusplus
10{
11namespace bus
12{
13class bus;
14} // namespace bus
15} // namespace sdbusplus
16
17namespace sdbusplus
18{
19namespace message
20{
21class message;
22} // namespace message
23} // namespace sdbusplus
24
25namespace openpower
26{
27namespace vpd
28{
29namespace manager
30{
31
32class 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 */
47class 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 Williams2eb01762022-07-22 19:26:56 -050058 BiosHandler(sdbusplus::bus_t& bus, Manager& manager) :
Santosh Puranikf2d3b532022-04-19 06:44:07 -050059 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 Williams2eb01762022-07-22 19:26:56 -050092 void biosAttribsCallback(sdbusplus::message_t& msg);
Santosh Puranikf2d3b532022-04-19 06:44:07 -050093
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 Puranikb2c2ccc2022-05-14 05:15:44 -0500116 * @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 Puranika97b63e2022-05-20 05:22:27 -0500138 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500149 * @brief Writes Memory mirror mode to BIOS
150 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500151 * 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 Puranikf2d3b532022-04-19 06:44:07 -0500153 *
154 * @param[in] ammVal - The mirror mode as read from VPD.
Santosh Puranika97b63e2022-05-20 05:22:27 -0500155 * @param[in] ammInBIOS - The mirror mode in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500156 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500157 void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500158
159 /**
160 * @brief Writes Field Core Override to BIOS
161 *
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500162 * 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 Puranikf2d3b532022-04-19 06:44:07 -0500164 *
165 * @param[in] fcoVal - The FCO value as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500166 * @param[in] fcoInBIOS - The FCO value already in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500167 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500168 void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500169
170 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500171 * @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 Puranika97b63e2022-05-20 05:22:27 -0500176 * @param[in] keepAndClear - The keep and clear as read from VPD.
177 * @param[in] keepAndClearInBIOS - The keep and clear in the BIOS table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500178 */
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 Puranika97b63e2022-05-20 05:22:27 -0500188 * @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 Puranikb2c2ccc2022-05-14 05:15:44 -0500191 */
192 void
193 saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar,
194 const std::string& createDefaultLparInBIOS);
195
196 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500197 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500209 * @brief Reads the hb_memory_mirror_mode attribute
210 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500211 * @return std::string - The AMM BIOS attribute. Empty string on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500212 */
213 std::string readBIOSAMM();
214
215 /**
216 * @brief Reads the hb_field_core_override attribute
217 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500218 * @return int64_t - The FCO BIOS attribute. -1 on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500219 */
220 int64_t readBIOSFCO();
221
222 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500223 * @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 Puranika97b63e2022-05-20 05:22:27 -0500239 * @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 Puranikf2d3b532022-04-19 06:44:07 -0500247 * @brief Restore BIOS attributes
248 *
249 * This function checks if we are coming out of a factory reset. If yes,
Santosh Puranika97b63e2022-05-20 05:22:27 -0500250 * it checks the VPD cache for valid backed up copy of the applicable
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500251 * 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 Williams2eb01762022-07-22 19:26:56 -0500259 sdbusplus::bus_t& bus;
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500260
261 /**
262 * @brief Reference to the manager.
263 */
264 Manager& manager;
265}; // class BiosHandler
266} // namespace manager
267} // namespace vpd
268} // namespace openpower