blob: 86e331863b7f986aa43b3d094abc8ae7b1f4fda6 [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 Puranikf2d3b532022-04-19 06:44:07 -0500138 * @brief Writes Memory mirror mode to BIOS
139 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500140 * Writes to the hb_memory_mirror_mode BIOS attribute, if the value is
141 * not already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500142 *
143 * @param[in] ammVal - The mirror mode as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500144 * @param[in] ammInBIOS - The mirror more in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500145 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500146 void saveAMMToBIOS(const std::string& ammVal, const std::string& ammInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500147
148 /**
149 * @brief Writes Field Core Override to BIOS
150 *
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500151 * Writes to the hb_field_core_override BIOS attribute, if the value is not
152 * already the same as we are trying to write.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500153 *
154 * @param[in] fcoVal - The FCO value as read from VPD.
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500155 * @param[in] fcoInBIOS - The FCO value already in the BIOS table.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500156 */
Santosh Puranikf7f8da62022-05-06 13:01:19 -0500157 void saveFCOToBIOS(const std::string& fcoVal, int64_t fcoInBIOS);
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500158
159 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500160 * @brief Writes Keep and clear setting to BIOS
161 *
162 * Writes to the pvm_keep_and_clear BIOS attribute, if the value is
163 * not already the same as we are trying to write.
164 *
165 * @param[in] keepAndClear - The mirror mode as read from VPD.
166 * @param[in] keepAndClearInBIOS - The mirror more in the BIOS table.
167 */
168 void saveKeepAndClearToBIOS(const std::string& keepAndClear,
169 const std::string& keepAndClearInBIOS);
170
171 /**
172 * @brief Writes Create default LPAR setting to BIOS
173 *
174 * Writes to the pvm_create_default_lpar BIOS attribute, if the value is
175 * not already the same as we are trying to write.
176 *
177 * @param[in] createDefaultLpar - The mirror mode as read from VPD.
178 * @param[in] createDefaultLparInBIOS - The mirror more in the BIOS table.
179 */
180 void
181 saveCreateDefaultLparToBIOS(const std::string& createDefaultLpar,
182 const std::string& createDefaultLparInBIOS);
183
184 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500185 * @brief Reads the hb_memory_mirror_mode attribute
186 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500187 * @return std::string - The AMM BIOS attribute. Empty string on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500188 */
189 std::string readBIOSAMM();
190
191 /**
192 * @brief Reads the hb_field_core_override attribute
193 *
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500194 * @return int64_t - The FCO BIOS attribute. -1 on failure.
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500195 */
196 int64_t readBIOSFCO();
197
198 /**
Santosh Puranikb2c2ccc2022-05-14 05:15:44 -0500199 * @brief Reads the pvm_keep_and_clear attribute
200 *
201 * @return std::string - The Keep and clear BIOS attribute. Empty string on
202 * failure.
203 */
204 std::string readBIOSKeepAndClear();
205
206 /**
207 * @brief Reads the pvm_create_default_lpar attribute
208 *
209 * @return std::string - The Create default LPAR BIOS attribute. Empty
210 * string on failure.
211 */
212 std::string readBIOSCreateDefaultLpar();
213
214 /**
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500215 * @brief Restore BIOS attributes
216 *
217 * This function checks if we are coming out of a factory reset. If yes,
218 * it checks the VPD cache for valid backed up copy of the FCO and AMM
219 * BIOS attributes. If valid values are found in the VPD, it will apply
220 * those to the BIOS attributes.
221 */
222 void restoreBIOSAttribs();
223
224 /**
225 * @brief Reference to the bus.
226 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500227 sdbusplus::bus_t& bus;
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500228
229 /**
230 * @brief Reference to the manager.
231 */
232 Manager& manager;
233}; // class BiosHandler
234} // namespace manager
235} // namespace vpd
236} // namespace openpower