1fa5e4d32SSunny Srivastava #include "config.h"
2fa5e4d32SSunny Srivastava
3fa5e4d32SSunny Srivastava #include "bios_handler.hpp"
4fa5e4d32SSunny Srivastava
5fa5e4d32SSunny Srivastava #include "constants.hpp"
6fa5e4d32SSunny Srivastava #include "logger.hpp"
7fa5e4d32SSunny Srivastava
8fa5e4d32SSunny Srivastava #include <sdbusplus/bus/match.hpp>
9fa5e4d32SSunny Srivastava #include <utility/common_utility.hpp>
10fa5e4d32SSunny Srivastava #include <utility/dbus_utility.hpp>
11fa5e4d32SSunny Srivastava
12fa5e4d32SSunny Srivastava #include <string>
13fa5e4d32SSunny Srivastava
14fa5e4d32SSunny Srivastava namespace vpd
15fa5e4d32SSunny Srivastava {
16fa5e4d32SSunny Srivastava // Template declaration to define APIs.
17fa5e4d32SSunny Srivastava template class BiosHandler<IbmBiosHandler>;
18fa5e4d32SSunny Srivastava
19fa5e4d32SSunny Srivastava template <typename T>
checkAndListenPldmService()20a0ead8dfSSunny Srivastava void BiosHandler<T>::checkAndListenPldmService()
215de031d9SSunny Srivastava {
225de031d9SSunny Srivastava // Setup a call back match on NameOwnerChanged to determine when PLDM is
235de031d9SSunny Srivastava // up.
24fa5e4d32SSunny Srivastava static std::shared_ptr<sdbusplus::bus::match_t> l_nameOwnerMatch =
25fa5e4d32SSunny Srivastava std::make_shared<sdbusplus::bus::match_t>(
26fa5e4d32SSunny Srivastava *m_asioConn,
27fa5e4d32SSunny Srivastava sdbusplus::bus::match::rules::nameOwnerChanged(
28fa5e4d32SSunny Srivastava constants::pldmServiceName),
29fa5e4d32SSunny Srivastava [this](sdbusplus::message_t& l_msg) {
30fa5e4d32SSunny Srivastava if (l_msg.is_method_error())
31fa5e4d32SSunny Srivastava {
32fa5e4d32SSunny Srivastava logging::logMessage(
33fa5e4d32SSunny Srivastava "Error in reading PLDM name owner changed signal.");
34fa5e4d32SSunny Srivastava return;
35fa5e4d32SSunny Srivastava }
36fa5e4d32SSunny Srivastava
37fa5e4d32SSunny Srivastava std::string l_name;
38fa5e4d32SSunny Srivastava std::string l_newOwner;
39fa5e4d32SSunny Srivastava std::string l_oldOwner;
40fa5e4d32SSunny Srivastava
41fa5e4d32SSunny Srivastava l_msg.read(l_name, l_oldOwner, l_newOwner);
42fa5e4d32SSunny Srivastava
43fa5e4d32SSunny Srivastava if (!l_newOwner.empty() &&
44fa5e4d32SSunny Srivastava (l_name.compare(constants::pldmServiceName) ==
45fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS))
46fa5e4d32SSunny Srivastava {
47fa5e4d32SSunny Srivastava m_specificBiosHandler->backUpOrRestoreBiosAttributes();
48fa5e4d32SSunny Srivastava
49fa5e4d32SSunny Srivastava // Start listener now that we have done the restore.
50fa5e4d32SSunny Srivastava listenBiosAttributes();
51fa5e4d32SSunny Srivastava
52fa5e4d32SSunny Srivastava // We don't need the match anymore
53fa5e4d32SSunny Srivastava l_nameOwnerMatch.reset();
54fa5e4d32SSunny Srivastava }
55fa5e4d32SSunny Srivastava });
56fa5e4d32SSunny Srivastava
57fa5e4d32SSunny Srivastava // Based on PLDM service status reset owner match registered above and
58fa5e4d32SSunny Srivastava // trigger BIOS attribute sync.
59fa5e4d32SSunny Srivastava if (dbusUtility::isServiceRunning(constants::pldmServiceName))
60fa5e4d32SSunny Srivastava {
61fa5e4d32SSunny Srivastava l_nameOwnerMatch.reset();
62fa5e4d32SSunny Srivastava m_specificBiosHandler->backUpOrRestoreBiosAttributes();
63fa5e4d32SSunny Srivastava
64fa5e4d32SSunny Srivastava // Start listener now that we have done the restore.
65fa5e4d32SSunny Srivastava listenBiosAttributes();
66fa5e4d32SSunny Srivastava }
67fa5e4d32SSunny Srivastava }
68fa5e4d32SSunny Srivastava
69fa5e4d32SSunny Srivastava template <typename T>
listenBiosAttributes()70fa5e4d32SSunny Srivastava void BiosHandler<T>::listenBiosAttributes()
71fa5e4d32SSunny Srivastava {
72fa5e4d32SSunny Srivastava static std::shared_ptr<sdbusplus::bus::match_t> l_biosMatch =
73fa5e4d32SSunny Srivastava std::make_shared<sdbusplus::bus::match_t>(
74fa5e4d32SSunny Srivastava *m_asioConn,
75fa5e4d32SSunny Srivastava sdbusplus::bus::match::rules::propertiesChanged(
76fa5e4d32SSunny Srivastava constants::biosConfigMgrObjPath,
77fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface),
78fa5e4d32SSunny Srivastava [this](sdbusplus::message_t& l_msg) {
79fa5e4d32SSunny Srivastava m_specificBiosHandler->biosAttributesCallback(l_msg);
80fa5e4d32SSunny Srivastava });
81fa5e4d32SSunny Srivastava }
82fa5e4d32SSunny Srivastava
biosAttributesCallback(sdbusplus::message_t & i_msg)83fa5e4d32SSunny Srivastava void IbmBiosHandler::biosAttributesCallback(sdbusplus::message_t& i_msg)
84fa5e4d32SSunny Srivastava {
85fa5e4d32SSunny Srivastava if (i_msg.is_method_error())
86fa5e4d32SSunny Srivastava {
87fa5e4d32SSunny Srivastava logging::logMessage("Error in reading BIOS attribute signal. ");
88fa5e4d32SSunny Srivastava return;
89fa5e4d32SSunny Srivastava }
90fa5e4d32SSunny Srivastava
91fa5e4d32SSunny Srivastava std::string l_objPath;
92fa5e4d32SSunny Srivastava types::BiosBaseTableType l_propMap;
93fa5e4d32SSunny Srivastava i_msg.read(l_objPath, l_propMap);
94fa5e4d32SSunny Srivastava
95fa5e4d32SSunny Srivastava for (auto l_property : l_propMap)
96fa5e4d32SSunny Srivastava {
97fa5e4d32SSunny Srivastava if (l_property.first != "BaseBIOSTable")
98fa5e4d32SSunny Srivastava {
99fa5e4d32SSunny Srivastava // Looking for change in Base BIOS table only.
100fa5e4d32SSunny Srivastava continue;
101fa5e4d32SSunny Srivastava }
102fa5e4d32SSunny Srivastava
103fa5e4d32SSunny Srivastava if (auto l_attributeList =
104fa5e4d32SSunny Srivastava std::get_if<std::map<std::string, types::BiosProperty>>(
105fa5e4d32SSunny Srivastava &(l_property.second)))
106fa5e4d32SSunny Srivastava {
107fa5e4d32SSunny Srivastava for (const auto& l_attribute : *l_attributeList)
108fa5e4d32SSunny Srivastava {
109fa5e4d32SSunny Srivastava if (auto l_val = std::get_if<std::string>(
110fa5e4d32SSunny Srivastava &(std::get<5>(std::get<1>(l_attribute)))))
111fa5e4d32SSunny Srivastava {
112fa5e4d32SSunny Srivastava std::string l_attributeName = std::get<0>(l_attribute);
113fa5e4d32SSunny Srivastava if (l_attributeName == "hb_memory_mirror_mode")
114fa5e4d32SSunny Srivastava {
115fa5e4d32SSunny Srivastava saveAmmToVpd(*l_val);
116fa5e4d32SSunny Srivastava }
117fa5e4d32SSunny Srivastava
118fa5e4d32SSunny Srivastava if (l_attributeName == "pvm_keep_and_clear")
119fa5e4d32SSunny Srivastava {
120fa5e4d32SSunny Srivastava saveKeepAndClearToVpd(*l_val);
121fa5e4d32SSunny Srivastava }
122fa5e4d32SSunny Srivastava
123fa5e4d32SSunny Srivastava if (l_attributeName == "pvm_create_default_lpar")
124fa5e4d32SSunny Srivastava {
125fa5e4d32SSunny Srivastava saveCreateDefaultLparToVpd(*l_val);
126fa5e4d32SSunny Srivastava }
127fa5e4d32SSunny Srivastava
128fa5e4d32SSunny Srivastava if (l_attributeName == "pvm_clear_nvram")
129fa5e4d32SSunny Srivastava {
130fa5e4d32SSunny Srivastava saveClearNvramToVpd(*l_val);
131fa5e4d32SSunny Srivastava }
132fa5e4d32SSunny Srivastava
133fa5e4d32SSunny Srivastava continue;
134fa5e4d32SSunny Srivastava }
135fa5e4d32SSunny Srivastava
136fa5e4d32SSunny Srivastava if (auto l_val = std::get_if<int64_t>(
137fa5e4d32SSunny Srivastava &(std::get<5>(std::get<1>(l_attribute)))))
138fa5e4d32SSunny Srivastava {
139fa5e4d32SSunny Srivastava std::string l_attributeName = std::get<0>(l_attribute);
140fa5e4d32SSunny Srivastava if (l_attributeName == "hb_field_core_override")
141fa5e4d32SSunny Srivastava {
142fa5e4d32SSunny Srivastava saveFcoToVpd(*l_val);
143fa5e4d32SSunny Srivastava }
144fa5e4d32SSunny Srivastava }
145fa5e4d32SSunny Srivastava }
146fa5e4d32SSunny Srivastava }
147fa5e4d32SSunny Srivastava else
148fa5e4d32SSunny Srivastava {
149b7818d1fSSunny Srivastava logging::logMessage("Invalid type received for BIOS table.");
150b7818d1fSSunny Srivastava EventLogger::createSyncPel(
151b7818d1fSSunny Srivastava types::ErrorType::FirmwareError, types::SeverityType::Warning,
152b7818d1fSSunny Srivastava __FILE__, __FUNCTION__, 0,
153b7818d1fSSunny Srivastava std::string("Invalid type received for BIOS table."),
154b7818d1fSSunny Srivastava std::nullopt, std::nullopt, std::nullopt, std::nullopt);
155fa5e4d32SSunny Srivastava break;
156fa5e4d32SSunny Srivastava }
157fa5e4d32SSunny Srivastava }
158fa5e4d32SSunny Srivastava }
159fa5e4d32SSunny Srivastava
backUpOrRestoreBiosAttributes()160fa5e4d32SSunny Srivastava void IbmBiosHandler::backUpOrRestoreBiosAttributes()
161fa5e4d32SSunny Srivastava {
162fa5e4d32SSunny Srivastava // process FCO
163fa5e4d32SSunny Srivastava processFieldCoreOverride();
164fa5e4d32SSunny Srivastava
165fa5e4d32SSunny Srivastava // process AMM
166fa5e4d32SSunny Srivastava processActiveMemoryMirror();
167fa5e4d32SSunny Srivastava
168fa5e4d32SSunny Srivastava // process LPAR
169fa5e4d32SSunny Srivastava processCreateDefaultLpar();
170fa5e4d32SSunny Srivastava
171fa5e4d32SSunny Srivastava // process clear NVRAM
172fa5e4d32SSunny Srivastava processClearNvram();
173fa5e4d32SSunny Srivastava
174fa5e4d32SSunny Srivastava // process keep and clear
175fa5e4d32SSunny Srivastava processKeepAndClear();
176fa5e4d32SSunny Srivastava }
177fa5e4d32SSunny Srivastava
readBiosAttribute(const std::string & i_attributeName)17843fedabcSPatrick Williams types::BiosAttributeCurrentValue IbmBiosHandler::readBiosAttribute(
17943fedabcSPatrick Williams const std::string& i_attributeName)
180fa5e4d32SSunny Srivastava {
181fa5e4d32SSunny Srivastava types::BiosAttributeCurrentValue l_attrValueVariant =
182fa5e4d32SSunny Srivastava dbusUtility::biosGetAttributeMethodCall(i_attributeName);
183fa5e4d32SSunny Srivastava
184fa5e4d32SSunny Srivastava return l_attrValueVariant;
185fa5e4d32SSunny Srivastava }
186fa5e4d32SSunny Srivastava
processFieldCoreOverride()187fa5e4d32SSunny Srivastava void IbmBiosHandler::processFieldCoreOverride()
188fa5e4d32SSunny Srivastava {
189fa5e4d32SSunny Srivastava // TODO: Should we avoid doing this at runtime?
190fa5e4d32SSunny Srivastava
191fa5e4d32SSunny Srivastava // Read required keyword from Dbus.
192fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
193fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
194fa5e4d32SSunny Srivastava constants::vsysInf, constants::kwdRG);
195fa5e4d32SSunny Srivastava
196fa5e4d32SSunny Srivastava if (auto l_fcoInVpd = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
197fa5e4d32SSunny Srivastava {
198fa5e4d32SSunny Srivastava // default length of the keyword is 4 bytes.
199fa5e4d32SSunny Srivastava if (l_fcoInVpd->size() != constants::VALUE_4)
200fa5e4d32SSunny Srivastava {
201fa5e4d32SSunny Srivastava logging::logMessage(
202fa5e4d32SSunny Srivastava "Invalid value read for FCO from D-Bus. Skipping.");
203fa5e4d32SSunny Srivastava }
204fa5e4d32SSunny Srivastava
205fa5e4d32SSunny Srivastava // If FCO in VPD contains anything other that ASCII Space, restore to
206fa5e4d32SSunny Srivastava // BIOS
207fa5e4d32SSunny Srivastava if (std::any_of(l_fcoInVpd->cbegin(), l_fcoInVpd->cend(),
208fa5e4d32SSunny Srivastava [](uint8_t l_val) {
209fa5e4d32SSunny Srivastava return l_val != constants::ASCII_OF_SPACE;
210fa5e4d32SSunny Srivastava }))
211fa5e4d32SSunny Srivastava {
212fa5e4d32SSunny Srivastava // Restore the data to BIOS.
213fa5e4d32SSunny Srivastava saveFcoToBios(*l_fcoInVpd);
214fa5e4d32SSunny Srivastava }
215fa5e4d32SSunny Srivastava else
216fa5e4d32SSunny Srivastava {
217fa5e4d32SSunny Srivastava types::BiosAttributeCurrentValue l_attrValueVariant =
218fa5e4d32SSunny Srivastava readBiosAttribute("hb_field_core_override");
219fa5e4d32SSunny Srivastava
220fa5e4d32SSunny Srivastava if (auto l_fcoInBios = std::get_if<int64_t>(&l_attrValueVariant))
221fa5e4d32SSunny Srivastava {
222fa5e4d32SSunny Srivastava // save the BIOS data to VPD
223fa5e4d32SSunny Srivastava saveFcoToVpd(*l_fcoInBios);
224fa5e4d32SSunny Srivastava
225fa5e4d32SSunny Srivastava return;
226fa5e4d32SSunny Srivastava }
227fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for FCO from BIOS.");
228fa5e4d32SSunny Srivastava }
229fa5e4d32SSunny Srivastava return;
230fa5e4d32SSunny Srivastava }
231fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for FCO from VPD.");
232fa5e4d32SSunny Srivastava }
233fa5e4d32SSunny Srivastava
saveFcoToVpd(int64_t i_fcoInBios)234fa5e4d32SSunny Srivastava void IbmBiosHandler::saveFcoToVpd(int64_t i_fcoInBios)
235fa5e4d32SSunny Srivastava {
236fa5e4d32SSunny Srivastava if (i_fcoInBios < 0)
237fa5e4d32SSunny Srivastava {
238fa5e4d32SSunny Srivastava logging::logMessage("Invalid FCO value in BIOS. Skip updating to VPD");
239fa5e4d32SSunny Srivastava return;
240fa5e4d32SSunny Srivastava }
241fa5e4d32SSunny Srivastava
242fa5e4d32SSunny Srivastava // Read required keyword from Dbus.
243fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
244fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
245fa5e4d32SSunny Srivastava constants::vsysInf, constants::kwdRG);
246fa5e4d32SSunny Srivastava
247fa5e4d32SSunny Srivastava if (auto l_fcoInVpd = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
248fa5e4d32SSunny Srivastava {
249fa5e4d32SSunny Srivastava // default length of the keyword is 4 bytes.
250fa5e4d32SSunny Srivastava if (l_fcoInVpd->size() != constants::VALUE_4)
251fa5e4d32SSunny Srivastava {
252fa5e4d32SSunny Srivastava logging::logMessage(
253fa5e4d32SSunny Srivastava "Invalid value read for FCO from D-Bus. Skipping.");
254fa5e4d32SSunny Srivastava return;
255fa5e4d32SSunny Srivastava }
256fa5e4d32SSunny Srivastava
257fa5e4d32SSunny Srivastava // convert to VPD value type
258fa5e4d32SSunny Srivastava types::BinaryVector l_biosValInVpdFormat = {
259fa5e4d32SSunny Srivastava 0, 0, 0, static_cast<uint8_t>(i_fcoInBios)};
260fa5e4d32SSunny Srivastava
261fa5e4d32SSunny Srivastava // Update only when the data are different.
262fa5e4d32SSunny Srivastava if (std::memcmp(l_biosValInVpdFormat.data(), l_fcoInVpd->data(),
263fa5e4d32SSunny Srivastava constants::VALUE_4) != constants::SUCCESS)
264fa5e4d32SSunny Srivastava {
265fa5e4d32SSunny Srivastava if (constants::FAILURE ==
266fa5e4d32SSunny Srivastava m_manager->updateKeyword(
267fa5e4d32SSunny Srivastava SYSTEM_VPD_FILE_PATH,
268*2bcbaa1fSJinu Thomas types::IpzData(constants::recVSYS, constants::kwdRG,
269fa5e4d32SSunny Srivastava l_biosValInVpdFormat)))
270fa5e4d32SSunny Srivastava {
271fa5e4d32SSunny Srivastava logging::logMessage(
272fa5e4d32SSunny Srivastava "Failed to update " + std::string(constants::kwdRG) +
273fa5e4d32SSunny Srivastava " keyword to VPD.");
274fa5e4d32SSunny Srivastava }
275fa5e4d32SSunny Srivastava }
276fa5e4d32SSunny Srivastava }
277fa5e4d32SSunny Srivastava else
278fa5e4d32SSunny Srivastava {
279fa5e4d32SSunny Srivastava logging::logMessage("Invalid type read for FCO from DBus.");
280fa5e4d32SSunny Srivastava }
281fa5e4d32SSunny Srivastava }
282fa5e4d32SSunny Srivastava
saveFcoToBios(const types::BinaryVector & i_fcoVal)283fa5e4d32SSunny Srivastava void IbmBiosHandler::saveFcoToBios(const types::BinaryVector& i_fcoVal)
284fa5e4d32SSunny Srivastava {
285fa5e4d32SSunny Srivastava if (i_fcoVal.size() != constants::VALUE_4)
286fa5e4d32SSunny Srivastava {
287fa5e4d32SSunny Srivastava logging::logMessage("Bad size for FCO received. Skip writing to BIOS");
288fa5e4d32SSunny Srivastava return;
289fa5e4d32SSunny Srivastava }
290fa5e4d32SSunny Srivastava
291fa5e4d32SSunny Srivastava types::PendingBIOSAttrs l_pendingBiosAttribute;
292fa5e4d32SSunny Srivastava l_pendingBiosAttribute.push_back(std::make_pair(
293fa5e4d32SSunny Srivastava "hb_field_core_override",
294fa5e4d32SSunny Srivastava std::make_tuple(
295fa5e4d32SSunny Srivastava "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Integer",
296fa5e4d32SSunny Srivastava i_fcoVal.at(constants::VALUE_3))));
297fa5e4d32SSunny Srivastava
298c532b188SRekhaAparna01 if (!dbusUtility::writeDbusProperty(
299fa5e4d32SSunny Srivastava constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
300fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface, "PendingAttributes",
301c532b188SRekhaAparna01 l_pendingBiosAttribute))
302fa5e4d32SSunny Srivastava {
303fa5e4d32SSunny Srivastava // TODO: Should we log informational PEL here as well?
304fa5e4d32SSunny Srivastava logging::logMessage(
305c532b188SRekhaAparna01 "DBus call to update FCO value in pending attribute failed. ");
306fa5e4d32SSunny Srivastava }
307fa5e4d32SSunny Srivastava }
308fa5e4d32SSunny Srivastava
saveAmmToVpd(const std::string & i_memoryMirrorMode)309fa5e4d32SSunny Srivastava void IbmBiosHandler::saveAmmToVpd(const std::string& i_memoryMirrorMode)
310fa5e4d32SSunny Srivastava {
311fa5e4d32SSunny Srivastava if (i_memoryMirrorMode.empty())
312fa5e4d32SSunny Srivastava {
313fa5e4d32SSunny Srivastava logging::logMessage(
314fa5e4d32SSunny Srivastava "Empty memory mirror mode value from BIOS. Skip writing to VPD");
315fa5e4d32SSunny Srivastava return;
316fa5e4d32SSunny Srivastava }
317fa5e4d32SSunny Srivastava
318fa5e4d32SSunny Srivastava // Read existing value.
319fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
320fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
3212bbe7f35SJinu Joy Thomas constants::vsysInf, constants::kwdAMM);
322fa5e4d32SSunny Srivastava
323fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
324fa5e4d32SSunny Srivastava {
325fa5e4d32SSunny Srivastava auto l_ammValInVpd = *l_pVal;
326fa5e4d32SSunny Srivastava
327fa5e4d32SSunny Srivastava types::BinaryVector l_valToUpdateInVpd{
328fa5e4d32SSunny Srivastava (i_memoryMirrorMode == "Enabled" ? constants::AMM_ENABLED_IN_VPD
329fa5e4d32SSunny Srivastava : constants::AMM_DISABLED_IN_VPD)};
330fa5e4d32SSunny Srivastava
331fa5e4d32SSunny Srivastava // Check if value is already updated on VPD.
332fa5e4d32SSunny Srivastava if (l_ammValInVpd.at(0) == l_valToUpdateInVpd.at(0))
333fa5e4d32SSunny Srivastava {
334fa5e4d32SSunny Srivastava return;
335fa5e4d32SSunny Srivastava }
336fa5e4d32SSunny Srivastava
337fa5e4d32SSunny Srivastava if (constants::FAILURE ==
338fa5e4d32SSunny Srivastava m_manager->updateKeyword(
339fa5e4d32SSunny Srivastava SYSTEM_VPD_FILE_PATH,
340*2bcbaa1fSJinu Thomas types::IpzData(constants::recVSYS, constants::kwdAMM,
3412bbe7f35SJinu Joy Thomas l_valToUpdateInVpd)))
342fa5e4d32SSunny Srivastava {
343fa5e4d32SSunny Srivastava logging::logMessage(
344fa5e4d32SSunny Srivastava "Failed to update " + std::string(constants::kwdAMM) +
345fa5e4d32SSunny Srivastava " keyword to VPD");
346fa5e4d32SSunny Srivastava }
347fa5e4d32SSunny Srivastava }
348fa5e4d32SSunny Srivastava else
349fa5e4d32SSunny Srivastava {
350fa5e4d32SSunny Srivastava // TODO: Add PEL
351fa5e4d32SSunny Srivastava logging::logMessage(
352fa5e4d32SSunny Srivastava "Invalid type read for memory mirror mode value from DBus. Skip writing to VPD");
353fa5e4d32SSunny Srivastava }
354fa5e4d32SSunny Srivastava }
355fa5e4d32SSunny Srivastava
saveAmmToBios(const uint8_t & i_ammVal)3563aca2931SAnupama B R void IbmBiosHandler::saveAmmToBios(const uint8_t& i_ammVal)
357fa5e4d32SSunny Srivastava {
358fa5e4d32SSunny Srivastava const std::string l_valtoUpdate =
3593aca2931SAnupama B R (i_ammVal == constants::VALUE_2) ? "Enabled" : "Disabled";
360fa5e4d32SSunny Srivastava
361fa5e4d32SSunny Srivastava types::PendingBIOSAttrs l_pendingBiosAttribute;
362fa5e4d32SSunny Srivastava l_pendingBiosAttribute.push_back(std::make_pair(
363fa5e4d32SSunny Srivastava "hb_memory_mirror_mode",
364fa5e4d32SSunny Srivastava std::make_tuple(
365fa5e4d32SSunny Srivastava "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
366fa5e4d32SSunny Srivastava l_valtoUpdate)));
367fa5e4d32SSunny Srivastava
368c532b188SRekhaAparna01 if (!dbusUtility::writeDbusProperty(
369fa5e4d32SSunny Srivastava constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
370fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface, "PendingAttributes",
371c532b188SRekhaAparna01 l_pendingBiosAttribute))
372fa5e4d32SSunny Srivastava {
373fa5e4d32SSunny Srivastava // TODO: Should we log informational PEL here as well?
374fa5e4d32SSunny Srivastava logging::logMessage(
375c532b188SRekhaAparna01 "DBus call to update AMM value in pending attribute failed.");
376fa5e4d32SSunny Srivastava }
377fa5e4d32SSunny Srivastava }
378fa5e4d32SSunny Srivastava
processActiveMemoryMirror()379fa5e4d32SSunny Srivastava void IbmBiosHandler::processActiveMemoryMirror()
380fa5e4d32SSunny Srivastava {
381fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
382fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
3832bbe7f35SJinu Joy Thomas constants::vsysInf, constants::kwdAMM);
384fa5e4d32SSunny Srivastava
385fa5e4d32SSunny Srivastava if (auto pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
386fa5e4d32SSunny Srivastava {
387fa5e4d32SSunny Srivastava auto l_ammValInVpd = *pVal;
388fa5e4d32SSunny Srivastava
389fa5e4d32SSunny Srivastava // Check if active memory mirror value is default in VPD.
390fa5e4d32SSunny Srivastava if (l_ammValInVpd.at(0) == constants::VALUE_0)
391fa5e4d32SSunny Srivastava {
392fa5e4d32SSunny Srivastava types::BiosAttributeCurrentValue l_attrValueVariant =
393fa5e4d32SSunny Srivastava readBiosAttribute("hb_memory_mirror_mode");
394fa5e4d32SSunny Srivastava
395fa5e4d32SSunny Srivastava if (auto pVal = std::get_if<std::string>(&l_attrValueVariant))
396fa5e4d32SSunny Srivastava {
397fa5e4d32SSunny Srivastava saveAmmToVpd(*pVal);
398fa5e4d32SSunny Srivastava return;
399fa5e4d32SSunny Srivastava }
400fa5e4d32SSunny Srivastava logging::logMessage(
401fa5e4d32SSunny Srivastava "Invalid type recieved for auto memory mirror mode from BIOS.");
402fa5e4d32SSunny Srivastava return;
403fa5e4d32SSunny Srivastava }
404fa5e4d32SSunny Srivastava else
405fa5e4d32SSunny Srivastava {
4063aca2931SAnupama B R saveAmmToBios(l_ammValInVpd.at(0));
407fa5e4d32SSunny Srivastava }
408fa5e4d32SSunny Srivastava return;
409fa5e4d32SSunny Srivastava }
410fa5e4d32SSunny Srivastava logging::logMessage(
411fa5e4d32SSunny Srivastava "Invalid type recieved for auto memory mirror mode from VPD.");
412fa5e4d32SSunny Srivastava }
413fa5e4d32SSunny Srivastava
saveCreateDefaultLparToVpd(const std::string & i_createDefaultLparVal)414fa5e4d32SSunny Srivastava void IbmBiosHandler::saveCreateDefaultLparToVpd(
415fa5e4d32SSunny Srivastava const std::string& i_createDefaultLparVal)
416fa5e4d32SSunny Srivastava {
417fa5e4d32SSunny Srivastava if (i_createDefaultLparVal.empty())
418fa5e4d32SSunny Srivastava {
419fa5e4d32SSunny Srivastava logging::logMessage(
420fa5e4d32SSunny Srivastava "Empty value received for Lpar from BIOS. Skip writing in VPD.");
421fa5e4d32SSunny Srivastava return;
422fa5e4d32SSunny Srivastava }
423fa5e4d32SSunny Srivastava
424fa5e4d32SSunny Srivastava // Read required keyword from DBus as we need to set only a Bit.
425fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
426fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
42771fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdClearNVRAM_CreateLPAR);
428fa5e4d32SSunny Srivastava
429fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
430fa5e4d32SSunny Srivastava {
431fa5e4d32SSunny Srivastava commonUtility::toLower(
432fa5e4d32SSunny Srivastava const_cast<std::string&>(i_createDefaultLparVal));
433fa5e4d32SSunny Srivastava
434fa5e4d32SSunny Srivastava // Check for second bit. Bit set for enabled else disabled.
435fa5e4d32SSunny Srivastava if (((((*l_pVal).at(0) & 0x02) == 0x02) &&
436fa5e4d32SSunny Srivastava (i_createDefaultLparVal.compare("enabled") ==
437fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)) ||
438fa5e4d32SSunny Srivastava ((((*l_pVal).at(0) & 0x02) == 0x00) &&
439fa5e4d32SSunny Srivastava (i_createDefaultLparVal.compare("disabled") ==
440fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)))
441fa5e4d32SSunny Srivastava {
442fa5e4d32SSunny Srivastava // Values are same, Don;t update.
443fa5e4d32SSunny Srivastava return;
444fa5e4d32SSunny Srivastava }
445fa5e4d32SSunny Srivastava
446fa5e4d32SSunny Srivastava types::BinaryVector l_valToUpdateInVpd;
447fa5e4d32SSunny Srivastava if (i_createDefaultLparVal.compare("enabled") ==
448fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)
449fa5e4d32SSunny Srivastava {
450fa5e4d32SSunny Srivastava // 2nd Bit is used to store the value.
451fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back((*l_pVal).at(0) | 0x02);
452fa5e4d32SSunny Srivastava }
453fa5e4d32SSunny Srivastava else
454fa5e4d32SSunny Srivastava {
455fa5e4d32SSunny Srivastava // 2nd Bit is used to store the value.
456fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back((*l_pVal).at(0) & ~(0x02));
457fa5e4d32SSunny Srivastava }
458fa5e4d32SSunny Srivastava
45971fd279cSJinu Joy Thomas if (-1 == m_manager->updateKeyword(
460fa5e4d32SSunny Srivastava SYSTEM_VPD_FILE_PATH,
46171fd279cSJinu Joy Thomas types::IpzData(constants::vsysInf,
46271fd279cSJinu Joy Thomas constants::kwdClearNVRAM_CreateLPAR,
463fa5e4d32SSunny Srivastava l_valToUpdateInVpd)))
464fa5e4d32SSunny Srivastava {
465fa5e4d32SSunny Srivastava logging::logMessage(
466fa5e4d32SSunny Srivastava "Failed to update " +
467fa5e4d32SSunny Srivastava std::string(constants::kwdClearNVRAM_CreateLPAR) +
468fa5e4d32SSunny Srivastava " keyword to VPD");
469fa5e4d32SSunny Srivastava }
470fa5e4d32SSunny Srivastava
471fa5e4d32SSunny Srivastava return;
472fa5e4d32SSunny Srivastava }
473fa5e4d32SSunny Srivastava logging::logMessage(
474fa5e4d32SSunny Srivastava "Invalid type recieved for create default Lpar from VPD.");
475fa5e4d32SSunny Srivastava }
476fa5e4d32SSunny Srivastava
saveCreateDefaultLparToBios(const std::string & i_createDefaultLparVal)477fa5e4d32SSunny Srivastava void IbmBiosHandler::saveCreateDefaultLparToBios(
478fa5e4d32SSunny Srivastava const std::string& i_createDefaultLparVal)
479fa5e4d32SSunny Srivastava {
480fa5e4d32SSunny Srivastava // checking for exact length as it is a string and can have garbage value.
481fa5e4d32SSunny Srivastava if (i_createDefaultLparVal.size() != constants::VALUE_1)
482fa5e4d32SSunny Srivastava {
483fa5e4d32SSunny Srivastava logging::logMessage(
484fa5e4d32SSunny Srivastava "Bad size for Create default LPAR in VPD. Skip writing to BIOS.");
485fa5e4d32SSunny Srivastava return;
486fa5e4d32SSunny Srivastava }
487fa5e4d32SSunny Srivastava
488fa5e4d32SSunny Srivastava std::string l_valtoUpdate =
489fa5e4d32SSunny Srivastava (i_createDefaultLparVal.at(0) & 0x02) ? "Enabled" : "Disabled";
490fa5e4d32SSunny Srivastava
491fa5e4d32SSunny Srivastava types::PendingBIOSAttrs l_pendingBiosAttribute;
492fa5e4d32SSunny Srivastava l_pendingBiosAttribute.push_back(std::make_pair(
493fa5e4d32SSunny Srivastava "pvm_create_default_lpar",
494fa5e4d32SSunny Srivastava std::make_tuple(
495fa5e4d32SSunny Srivastava "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
496fa5e4d32SSunny Srivastava l_valtoUpdate)));
497fa5e4d32SSunny Srivastava
498c532b188SRekhaAparna01 if (!dbusUtility::writeDbusProperty(
499fa5e4d32SSunny Srivastava constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
500fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface, "PendingAttributes",
501c532b188SRekhaAparna01 l_pendingBiosAttribute))
502fa5e4d32SSunny Srivastava {
503fa5e4d32SSunny Srivastava logging::logMessage(
504c532b188SRekhaAparna01 "DBus call to update lpar value in pending attribute failed.");
505fa5e4d32SSunny Srivastava }
506fa5e4d32SSunny Srivastava
507fa5e4d32SSunny Srivastava return;
508fa5e4d32SSunny Srivastava }
509fa5e4d32SSunny Srivastava
processCreateDefaultLpar()510fa5e4d32SSunny Srivastava void IbmBiosHandler::processCreateDefaultLpar()
511fa5e4d32SSunny Srivastava {
512fa5e4d32SSunny Srivastava // Read required keyword from DBus.
513fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
514fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
51571fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdClearNVRAM_CreateLPAR);
516fa5e4d32SSunny Srivastava
517fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
518fa5e4d32SSunny Srivastava {
519fa5e4d32SSunny Srivastava saveCreateDefaultLparToBios(std::to_string(l_pVal->at(0)));
520fa5e4d32SSunny Srivastava return;
521fa5e4d32SSunny Srivastava }
522fa5e4d32SSunny Srivastava logging::logMessage(
523fa5e4d32SSunny Srivastava "Invalid type recieved for create default Lpar from VPD.");
524fa5e4d32SSunny Srivastava }
525fa5e4d32SSunny Srivastava
saveClearNvramToVpd(const std::string & i_clearNvramVal)526fa5e4d32SSunny Srivastava void IbmBiosHandler::saveClearNvramToVpd(const std::string& i_clearNvramVal)
527fa5e4d32SSunny Srivastava {
528fa5e4d32SSunny Srivastava if (i_clearNvramVal.empty())
529fa5e4d32SSunny Srivastava {
530fa5e4d32SSunny Srivastava logging::logMessage(
531fa5e4d32SSunny Srivastava "Empty value received for clear NVRAM from BIOS. Skip updating to VPD.");
532fa5e4d32SSunny Srivastava return;
533fa5e4d32SSunny Srivastava }
534fa5e4d32SSunny Srivastava
535fa5e4d32SSunny Srivastava // Read required keyword from DBus as we need to set only a Bit.
536fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
537fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
53871fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdClearNVRAM_CreateLPAR);
539fa5e4d32SSunny Srivastava
540fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
541fa5e4d32SSunny Srivastava {
542fa5e4d32SSunny Srivastava commonUtility::toLower(const_cast<std::string&>(i_clearNvramVal));
543fa5e4d32SSunny Srivastava
544fa5e4d32SSunny Srivastava // Check for third bit. Bit set for enabled else disabled.
545fa5e4d32SSunny Srivastava if (((((*l_pVal).at(0) & 0x04) == 0x04) &&
546fa5e4d32SSunny Srivastava (i_clearNvramVal.compare("enabled") ==
547fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)) ||
548fa5e4d32SSunny Srivastava ((((*l_pVal).at(0) & 0x04) == 0x00) &&
549fa5e4d32SSunny Srivastava (i_clearNvramVal.compare("disabled") ==
550fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)))
551fa5e4d32SSunny Srivastava {
552fa5e4d32SSunny Srivastava // Don't update, values are same.
553fa5e4d32SSunny Srivastava return;
554fa5e4d32SSunny Srivastava }
555fa5e4d32SSunny Srivastava
556fa5e4d32SSunny Srivastava types::BinaryVector l_valToUpdateInVpd;
557fa5e4d32SSunny Srivastava if (i_clearNvramVal.compare("enabled") == constants::STR_CMP_SUCCESS)
558fa5e4d32SSunny Srivastava {
559fa5e4d32SSunny Srivastava // 3rd bit is used to store the value.
560fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back(
561fa5e4d32SSunny Srivastava (*l_pVal).at(0) | constants::VALUE_4);
562fa5e4d32SSunny Srivastava }
563fa5e4d32SSunny Srivastava else
564fa5e4d32SSunny Srivastava {
565fa5e4d32SSunny Srivastava // 3rd bit is used to store the value.
566fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back(
567fa5e4d32SSunny Srivastava (*l_pVal).at(0) & ~(constants::VALUE_4));
568fa5e4d32SSunny Srivastava }
569fa5e4d32SSunny Srivastava
57071fd279cSJinu Joy Thomas if (-1 == m_manager->updateKeyword(
571fa5e4d32SSunny Srivastava SYSTEM_VPD_FILE_PATH,
57271fd279cSJinu Joy Thomas types::IpzData(constants::vsysInf,
57371fd279cSJinu Joy Thomas constants::kwdClearNVRAM_CreateLPAR,
574fa5e4d32SSunny Srivastava l_valToUpdateInVpd)))
575fa5e4d32SSunny Srivastava {
576fa5e4d32SSunny Srivastava logging::logMessage(
577fa5e4d32SSunny Srivastava "Failed to update " +
578fa5e4d32SSunny Srivastava std::string(constants::kwdClearNVRAM_CreateLPAR) +
579fa5e4d32SSunny Srivastava " keyword to VPD");
580fa5e4d32SSunny Srivastava }
581fa5e4d32SSunny Srivastava
582fa5e4d32SSunny Srivastava return;
583fa5e4d32SSunny Srivastava }
584fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for clear NVRAM from VPD.");
585fa5e4d32SSunny Srivastava }
586fa5e4d32SSunny Srivastava
saveClearNvramToBios(const std::string & i_clearNvramVal)587fa5e4d32SSunny Srivastava void IbmBiosHandler::saveClearNvramToBios(const std::string& i_clearNvramVal)
588fa5e4d32SSunny Srivastava {
589fa5e4d32SSunny Srivastava // Check for the exact length as it is a string and it can have a garbage
590fa5e4d32SSunny Srivastava // value.
591fa5e4d32SSunny Srivastava if (i_clearNvramVal.size() != constants::VALUE_1)
592fa5e4d32SSunny Srivastava {
593fa5e4d32SSunny Srivastava logging::logMessage(
594fa5e4d32SSunny Srivastava "Bad size for clear NVRAM in VPD. Skip writing to BIOS.");
595fa5e4d32SSunny Srivastava return;
596fa5e4d32SSunny Srivastava }
597fa5e4d32SSunny Srivastava
598fa5e4d32SSunny Srivastava // 3rd bit is used to store clear NVRAM value.
599fa5e4d32SSunny Srivastava std::string l_valtoUpdate =
600fa5e4d32SSunny Srivastava (i_clearNvramVal.at(0) & constants::VALUE_4) ? "Enabled" : "Disabled";
601fa5e4d32SSunny Srivastava
602fa5e4d32SSunny Srivastava types::PendingBIOSAttrs l_pendingBiosAttribute;
603fa5e4d32SSunny Srivastava l_pendingBiosAttribute.push_back(std::make_pair(
604fa5e4d32SSunny Srivastava "pvm_clear_nvram",
605fa5e4d32SSunny Srivastava std::make_tuple(
606fa5e4d32SSunny Srivastava "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
607fa5e4d32SSunny Srivastava l_valtoUpdate)));
608fa5e4d32SSunny Srivastava
609c532b188SRekhaAparna01 if (!dbusUtility::writeDbusProperty(
610fa5e4d32SSunny Srivastava constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
611fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface, "PendingAttributes",
612c532b188SRekhaAparna01 l_pendingBiosAttribute))
613fa5e4d32SSunny Srivastava {
614fa5e4d32SSunny Srivastava logging::logMessage(
615c532b188SRekhaAparna01 "DBus call to update NVRAM value in pending attribute failed.");
616fa5e4d32SSunny Srivastava }
617fa5e4d32SSunny Srivastava }
618fa5e4d32SSunny Srivastava
processClearNvram()619fa5e4d32SSunny Srivastava void IbmBiosHandler::processClearNvram()
620fa5e4d32SSunny Srivastava {
621fa5e4d32SSunny Srivastava // Read required keyword from VPD.
622fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
623fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
62471fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdClearNVRAM_CreateLPAR);
625fa5e4d32SSunny Srivastava
626fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
627fa5e4d32SSunny Srivastava {
628fa5e4d32SSunny Srivastava saveClearNvramToBios(std::to_string(l_pVal->at(0)));
629fa5e4d32SSunny Srivastava return;
630fa5e4d32SSunny Srivastava }
631fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for clear NVRAM from VPD.");
632fa5e4d32SSunny Srivastava }
633fa5e4d32SSunny Srivastava
saveKeepAndClearToVpd(const std::string & i_KeepAndClearVal)634fa5e4d32SSunny Srivastava void IbmBiosHandler::saveKeepAndClearToVpd(const std::string& i_KeepAndClearVal)
635fa5e4d32SSunny Srivastava {
636fa5e4d32SSunny Srivastava if (i_KeepAndClearVal.empty())
637fa5e4d32SSunny Srivastava {
638fa5e4d32SSunny Srivastava logging::logMessage(
639fa5e4d32SSunny Srivastava "Empty value received for keep and clear from BIOS. Skip updating to VPD.");
640fa5e4d32SSunny Srivastava return;
641fa5e4d32SSunny Srivastava }
642fa5e4d32SSunny Srivastava
643fa5e4d32SSunny Srivastava // Read required keyword from DBus as we need to set only a Bit.
644fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
645fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
64671fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdKeepAndClear);
647fa5e4d32SSunny Srivastava
648fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
649fa5e4d32SSunny Srivastava {
650fa5e4d32SSunny Srivastava commonUtility::toLower(const_cast<std::string&>(i_KeepAndClearVal));
651fa5e4d32SSunny Srivastava
652fa5e4d32SSunny Srivastava // Check for first bit. Bit set for enabled else disabled.
653fa5e4d32SSunny Srivastava if (((((*l_pVal).at(0) & 0x01) == 0x01) &&
654fa5e4d32SSunny Srivastava (i_KeepAndClearVal.compare("enabled") ==
655fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)) ||
656fa5e4d32SSunny Srivastava ((((*l_pVal).at(0) & 0x01) == 0x00) &&
657fa5e4d32SSunny Srivastava (i_KeepAndClearVal.compare("disabled") ==
658fa5e4d32SSunny Srivastava constants::STR_CMP_SUCCESS)))
659fa5e4d32SSunny Srivastava {
660fa5e4d32SSunny Srivastava // Don't update, values are same.
661fa5e4d32SSunny Srivastava return;
662fa5e4d32SSunny Srivastava }
663fa5e4d32SSunny Srivastava
664fa5e4d32SSunny Srivastava types::BinaryVector l_valToUpdateInVpd;
665fa5e4d32SSunny Srivastava if (i_KeepAndClearVal.compare("enabled") == constants::STR_CMP_SUCCESS)
666fa5e4d32SSunny Srivastava {
667fa5e4d32SSunny Srivastava // 1st bit is used to store the value.
668fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back(
669fa5e4d32SSunny Srivastava (*l_pVal).at(0) | constants::VALUE_1);
670fa5e4d32SSunny Srivastava }
671fa5e4d32SSunny Srivastava else
672fa5e4d32SSunny Srivastava {
673fa5e4d32SSunny Srivastava // 1st bit is used to store the value.
674fa5e4d32SSunny Srivastava l_valToUpdateInVpd.emplace_back(
675fa5e4d32SSunny Srivastava (*l_pVal).at(0) & ~(constants::VALUE_1));
676fa5e4d32SSunny Srivastava }
677fa5e4d32SSunny Srivastava
67871fd279cSJinu Joy Thomas if (-1 ==
67971fd279cSJinu Joy Thomas m_manager->updateKeyword(
680fa5e4d32SSunny Srivastava SYSTEM_VPD_FILE_PATH,
68171fd279cSJinu Joy Thomas types::IpzData(constants::vsysInf, constants::kwdKeepAndClear,
682fa5e4d32SSunny Srivastava l_valToUpdateInVpd)))
683fa5e4d32SSunny Srivastava {
684fa5e4d32SSunny Srivastava logging::logMessage(
685fa5e4d32SSunny Srivastava "Failed to update " + std::string(constants::kwdKeepAndClear) +
686fa5e4d32SSunny Srivastava " keyword to VPD");
687fa5e4d32SSunny Srivastava }
688fa5e4d32SSunny Srivastava
689fa5e4d32SSunny Srivastava return;
690fa5e4d32SSunny Srivastava }
691fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for keep and clear from VPD.");
692fa5e4d32SSunny Srivastava }
693fa5e4d32SSunny Srivastava
saveKeepAndClearToBios(const std::string & i_KeepAndClearVal)69443fedabcSPatrick Williams void IbmBiosHandler::saveKeepAndClearToBios(
69543fedabcSPatrick Williams const std::string& i_KeepAndClearVal)
696fa5e4d32SSunny Srivastava {
697fa5e4d32SSunny Srivastava // checking for exact length as it is a string and can have garbage value.
698fa5e4d32SSunny Srivastava if (i_KeepAndClearVal.size() != constants::VALUE_1)
699fa5e4d32SSunny Srivastava {
700fa5e4d32SSunny Srivastava logging::logMessage(
701fa5e4d32SSunny Srivastava "Bad size for keep and clear in VPD. Skip writing to BIOS.");
702fa5e4d32SSunny Srivastava return;
703fa5e4d32SSunny Srivastava }
704fa5e4d32SSunny Srivastava
705fa5e4d32SSunny Srivastava // 1st bit is used to store keep and clear value.
706fa5e4d32SSunny Srivastava std::string l_valtoUpdate =
707fa5e4d32SSunny Srivastava (i_KeepAndClearVal.at(0) & constants::VALUE_1) ? "Enabled" : "Disabled";
708fa5e4d32SSunny Srivastava
709fa5e4d32SSunny Srivastava types::PendingBIOSAttrs l_pendingBiosAttribute;
710fa5e4d32SSunny Srivastava l_pendingBiosAttribute.push_back(std::make_pair(
711fa5e4d32SSunny Srivastava "pvm_keep_and_clear",
712fa5e4d32SSunny Srivastava std::make_tuple(
713fa5e4d32SSunny Srivastava "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
714fa5e4d32SSunny Srivastava l_valtoUpdate)));
715fa5e4d32SSunny Srivastava
716c532b188SRekhaAparna01 if (!dbusUtility::writeDbusProperty(
717fa5e4d32SSunny Srivastava constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
718fa5e4d32SSunny Srivastava constants::biosConfigMgrInterface, "PendingAttributes",
719c532b188SRekhaAparna01 l_pendingBiosAttribute))
720fa5e4d32SSunny Srivastava {
721fa5e4d32SSunny Srivastava logging::logMessage(
722c532b188SRekhaAparna01 "DBus call to update keep and clear value in pending attribute failed.");
723fa5e4d32SSunny Srivastava }
724fa5e4d32SSunny Srivastava }
725fa5e4d32SSunny Srivastava
processKeepAndClear()726fa5e4d32SSunny Srivastava void IbmBiosHandler::processKeepAndClear()
727fa5e4d32SSunny Srivastava {
728fa5e4d32SSunny Srivastava // Read required keyword from VPD.
729fa5e4d32SSunny Srivastava auto l_kwdValueVariant = dbusUtility::readDbusProperty(
730fa5e4d32SSunny Srivastava constants::pimServiceName, constants::systemVpdInvPath,
73171fd279cSJinu Joy Thomas constants::vsysInf, constants::kwdKeepAndClear);
732fa5e4d32SSunny Srivastava
733fa5e4d32SSunny Srivastava if (auto l_pVal = std::get_if<types::BinaryVector>(&l_kwdValueVariant))
734fa5e4d32SSunny Srivastava {
735fa5e4d32SSunny Srivastava saveKeepAndClearToBios(std::to_string(l_pVal->at(0)));
736fa5e4d32SSunny Srivastava return;
737fa5e4d32SSunny Srivastava }
738fa5e4d32SSunny Srivastava logging::logMessage("Invalid type recieved for keep and clear from VPD.");
739fa5e4d32SSunny Srivastava }
740fa5e4d32SSunny Srivastava } // namespace vpd
741