blob: adee3c7b309143ced1efb2143e92dd2666f67926 [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,
Patrick Williams08dc31c2024-08-16 15:21:06 -040045 Manager& manager) : conn(conn), manager(manager)
Santosh Puranikf2d3b532022-04-19 06:44:07 -050046 {
47 checkAndListenPLDMService();
48 }
49
50 private:
51 /**
52 * @brief Check if PLDM service is running and run BIOS sync
53 *
54 * This API checks if the PLDM service is running and if yes it will start
55 * an immediate sync of BIOS attributes. If the service is not running, it
56 * registers a listener to be notified when the service starts so that a
57 * restore can be performed.
58 */
59 void checkAndListenPLDMService();
60
61 /**
62 * @brief Register listener for changes to BIOS Attributes.
63 *
64 * The VPD manager needs to listen to changes to certain BIOS attributes
65 * that are backed by VPD. When the attributes we are interested in
66 * change, the VPD manager will make sure that we write them back to the
67 * VPD keywords that back them up.
68 */
69 void listenBiosAttribs();
70
71 /**
72 * @brief Callback for BIOS Attribute changes
73 *
74 * Checks if the BIOS attribute(s) changed are those backed up by VPD. If
75 * yes, it will update the VPD with the new attribute value.
76 * @param[in] msg - The callback message.
77 */
Patrick Williams2eb01762022-07-22 19:26:56 -050078 void biosAttribsCallback(sdbusplus::message_t& msg);
Santosh Puranikf2d3b532022-04-19 06:44:07 -050079
80 /**
81 * @brief Persistently saves the Memory mirror mode
82 *
83 * Memory mirror mode setting is saved to the UTIL/D0 keyword in the
84 * motherboard VPD. If the mirror mode in BIOS is "Disabled", set D0 to 1,
85 * if "Enabled" set D0 to 2
86 *
87 * @param[in] mirrorMode - The mirror mode BIOS attribute.
88 */
89 void saveAMMToVPD(const std::string& mirrorMode);
90
91 /**
92 * @brief Persistently saves the Field Core Override setting
93 *
94 * Saves the field core override value (FCO) into the VSYS/RG keyword in
95 * the motherboard VPD.
96 *
97 * @param[in] fcoVal - The FCO value as an integer.
98 */
99 void saveFCOToVPD(int64_t fcoVal);
100
101 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500102 * @brief Persistently saves the Keep and Clear setting
103 *
104 * Keep and clear setting is saved to the UTIL/D1 keyword's 0th bit in the
105 * motherboard VPD. If the keep and clear in BIOS is "Disabled", set D1:0 to
106 * 0, if "Enabled" set D1:0 to 1
107 *
108 * @param[in] keepAndClear - The keep and clear BIOS attribute.
109 */
110 void saveKeepAndClearToVPD(const std::string& keepAndClear);
111
112 /**
113 * @brief Persistently saves the Create default LPAR setting
114 *
115 * Create default LPAR setting is saved to the UTIL/D1 keyword's 1st bit in
116 * the motherboard VPD. If the create default LPAR in BIOS is "Disabled",
117 * set D1:1 to 0, if "Enabled" set D1:1 to 1
118 *
119 * @param[in] createDefaultLpar - The mirror mode BIOS attribute.
120 */
121 void saveCreateDefaultLparToVPD(const std::string& createDefaultLpar);
122
123 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500124 * @brief Persistently saves the Clear NVRAM setting
125 *
126 * Create default LPAR setting is saved to the UTIL/D1 keyword's 2nd bit in
127 * the motherboard VPD. If the clear NVRAM in BIOS is "Disabled",
128 * set D1:2 to 0, if "Enabled" set D1:2 to 1
129 *
130 * @param[in] createDefaultLpar - The mirror mode BIOS attribute.
131 */
132 void saveClearNVRAMToVPD(const std::string& clearNVRAM);
133
134 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500135 * @brief Writes Memory mirror mode to BIOS
136 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500137 * Writes to the hb_memory_mirror_mode BIOS attribute, if the value is
138 * not already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500139 *
140 * @param[in] ammVal - The mirror mode as read from VPD.
Santosh Puranika97b63e2022-05-20 05:22:27 -0500141 * @param[in] ammInBIOS - The mirror mode in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500142 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500143 void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500144
145 /**
146 * @brief Writes Field Core Override to BIOS
147 *
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500148 * Writes to the hb_field_core_override BIOS attribute, if the value is not
149 * already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500150 *
151 * @param[in] fcoVal - The FCO value as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500152 * @param[in] fcoInBIOS - The FCO value already in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500153 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500154 void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500155
156 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500157 * @brief Writes Keep and clear setting to BIOS
158 *
159 * Writes to the pvm_keep_and_clear BIOS attribute, if the value is
160 * not already the same as we are trying to write.
161 *
Santosh Puranika97b63e2022-05-20 05:22:27 -0500162 * @param[in] keepAndClear - The keep and clear as read from VPD.
163 * @param[in] keepAndClearInBIOS - The keep and clear in the BIOS table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500164 */
165 void saveKeepAndClearToBIOS(const std::string& keepAndClear,
166 const std::string& keepAndClearInBIOS);
167
168 /**
169 * @brief Writes Create default LPAR setting to BIOS
170 *
171 * Writes to the pvm_create_default_lpar BIOS attribute, if the value is
172 * not already the same as we are trying to write.
173 *
Santosh Puranika97b63e2022-05-20 05:22:27 -0500174 * @param[in] createDefaultLpar - The create default LPAR as read from VPD.
175 * @param[in] createDefaultLparInBIOS - The create default LPAR in the BIOS
176 * table.
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500177 */
178 void
179 saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar,
180 const std::string& createDefaultLparInBIOS);
181
182 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500183 * @brief Writes Clear NVRAM setting to BIOS
184 *
185 * Writes to the pvm_clear_nvram BIOS attribute, if the value is
186 * not already the same as we are trying to write.
187 *
188 * @param[in] clearNVRAM - The clear NVRAM as read from VPD.
189 * @param[in] clearNVRAMInBIOS - The clear NVRAM in the BIOS table.
190 */
191 void saveClearNVRAMToBIOS(const std::string& clearNVRAM,
192 const std::string& clearNVRAMInBIOS);
193
194 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500195 * @brief Reads the hb_memory_mirror_mode attribute
196 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500197 * @return std::string - The AMM BIOS attribute. Empty string on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500198 */
199 std::string readBIOSAMM();
200
201 /**
202 * @brief Reads the hb_field_core_override attribute
203 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500204 * @return int64_t - The FCO BIOS attribute. -1 on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500205 */
206 int64_t readBIOSFCO();
207
208 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500209 * @brief Reads the pvm_keep_and_clear attribute
210 *
211 * @return std::string - The Keep and clear BIOS attribute. Empty string on
212 * failure.
213 */
214 std::string readBIOSKeepAndClear();
215
216 /**
217 * @brief Reads the pvm_create_default_lpar attribute
218 *
219 * @return std::string - The Create default LPAR BIOS attribute. Empty
220 * string on failure.
221 */
222 std::string readBIOSCreateDefaultLpar();
223
224 /**
Santosh Puranika97b63e2022-05-20 05:22:27 -0500225 * @brief Reads the pvm_clear_nvram attribute
226 *
227 * @return std::string - The Clear NVRAM BIOS attribute. Empty
228 * string on failure.
229 */
230 std::string readBIOSClearNVRAM();
231
232 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500233 * @brief Restore BIOS attributes
234 *
235 * This function checks if we are coming out of a factory reset. If yes,
Santosh Puranika97b63e2022-05-20 05:22:27 -0500236 * it checks the VPD cache for valid backed up copy of the applicable
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500237 * BIOS attributes. If valid values are found in the VPD, it will apply
238 * those to the BIOS attributes.
239 */
240 void restoreBIOSAttribs();
241
242 /**
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600243 * @brief Reference to the connection.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500244 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600245 std::shared_ptr<sdbusplus::asio::connection>& conn;
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500246
247 /**
248 * @brief Reference to the manager.
249 */
250 Manager& manager;
251}; // class BiosHandler
252} // namespace manager
253} // namespace vpd
Patrick Williamsc78d8872023-05-10 07:50:56 -0500254} // namespace openpower