blob: 5d9eea53a2e3702c5704644ce5e5fb1e39febc1b [file] [log] [blame]
Patrick Williams70a47ba2021-09-02 09:53:31 -05001#include "platform_oem_ibm.hpp"
2
Patrick Williams70a47ba2021-09-02 09:53:31 -05003#include "common/utils.hpp"
4#include "libpldmresponder/pdr.hpp"
5
Andrew Jeffery21f128d2024-01-15 15:34:26 +10306#include <libpldm/oem/ibm/platform.h>
George Liuc453e162022-12-21 17:16:23 +08007
Riya Dixit49cfb132023-03-02 04:26:53 -06008#include <phosphor-logging/lg2.hpp>
ArchanaKakanidcf77d62022-08-29 07:04:09 -05009#include <xyz/openbmc_project/Common/error.hpp>
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060010#include <xyz/openbmc_project/State/Boot/Progress/client.hpp>
ArchanaKakanidcf77d62022-08-29 07:04:09 -050011
Patrick Williams70a47ba2021-09-02 09:53:31 -050012#include <iostream>
13
Riya Dixit49cfb132023-03-02 04:26:53 -060014PHOSPHOR_LOG2_USING;
15
Patrick Williams70a47ba2021-09-02 09:53:31 -050016namespace pldm
17{
18namespace responder
19{
20namespace platform
21{
Patrick Williams70a47ba2021-09-02 09:53:31 -050022int sendBiosAttributeUpdateEvent(
Andrew Jefferya330b2f2023-05-04 14:55:37 +093023 uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
Patrick Williams70a47ba2021-09-02 09:53:31 -050024 const std::vector<uint16_t>& handles,
25 pldm::requester::Handler<pldm::requester::Request>* handler)
26{
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060027 using BootProgress =
28 sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>;
29
Patrick Williams70a47ba2021-09-02 09:53:31 -050030 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
Patrick Williams70a47ba2021-09-02 09:53:31 -050031 constexpr auto hostStateProperty = "BootProgress";
32
33 try
34 {
35 auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060036 hostStatePath, hostStateProperty, BootProgress::interface);
Patrick Williams70a47ba2021-09-02 09:53:31 -050037 const auto& currHostState = std::get<std::string>(propVal);
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060038 if ((sdbusplus::message::convert_from_string<
39 BootProgress::ProgressStages>(currHostState) !=
40 BootProgress::ProgressStages::SystemInitComplete) &&
41 (sdbusplus::message::convert_from_string<
42 BootProgress::ProgressStages>(currHostState) !=
43 BootProgress::ProgressStages::OSRunning) &&
44 (sdbusplus::message::convert_from_string<
45 BootProgress::ProgressStages>(currHostState) !=
46 BootProgress::ProgressStages::SystemSetup))
Patrick Williams70a47ba2021-09-02 09:53:31 -050047 {
48 return PLDM_SUCCESS;
49 }
50 }
ArchanaKakanidcf77d62022-08-29 07:04:09 -050051 catch (
Kamalkumar Patel58cbcaf2023-10-06 03:48:25 -050052 const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&)
ArchanaKakanidcf77d62022-08-29 07:04:09 -050053 {
54 /* Exception is expected to happen in the case when state manager is
55 * started after pldm, this is expected to happen in reboot case
56 * where host is considered to be up. As host is up pldm is expected
57 * to send attribute update event to host so this is not an error
58 * case */
59 }
Patrick Williams84b790c2022-07-22 19:26:56 -050060 catch (const sdbusplus::exception_t& e)
Patrick Williams70a47ba2021-09-02 09:53:31 -050061 {
Riya Dixit49cfb132023-03-02 04:26:53 -060062 error(
63 "Error in getting current host state, {EXCEP_NAME} Continue sending the bios attribute update event ...",
64 "EXCEP_NAME", e.name());
Patrick Williams70a47ba2021-09-02 09:53:31 -050065 }
66
Andrew Jefferya330b2f2023-05-04 14:55:37 +093067 auto instanceId = instanceIdDb->next(eid);
Patrick Williams70a47ba2021-09-02 09:53:31 -050068
69 std::vector<uint8_t> requestMsg(
70 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
71 1 + (handles.size() * sizeof(uint16_t)),
72 0);
73
74 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
75
76 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050077 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
78 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050079 requestMsg.size() - sizeof(pldm_msg_hdr), request);
80 if (rc != PLDM_SUCCESS)
81 {
Riya Dixit49cfb132023-03-02 04:26:53 -060082 error(
83 "BIOS Attribute update event message encode failure. PLDM error code = {RC}",
84 "RC", lg2::hex, rc);
Andrew Jefferya330b2f2023-05-04 14:55:37 +093085 instanceIdDb->free(eid, instanceId);
Patrick Williams70a47ba2021-09-02 09:53:31 -050086 return rc;
87 }
88
Patrick Williams6da4f912023-05-10 07:50:53 -050089 auto platformEventMessageResponseHandler =
90 [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
Patrick Williams70a47ba2021-09-02 09:53:31 -050091 if (response == nullptr || !respMsgLen)
92 {
Riya Dixit49cfb132023-03-02 04:26:53 -060093 error("Failed to receive response for platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -050094 return;
95 }
96 uint8_t completionCode{};
97 uint8_t status{};
98 auto rc = decode_platform_event_message_resp(response, respMsgLen,
99 &completionCode, &status);
100 if (rc || completionCode)
101 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600102 error(
103 "Failed to decode BIOS Attribute update platform_event_message_resp: rc = {RC}, cc= {CC}",
104 "RC", rc, "CC", static_cast<unsigned>(completionCode));
Patrick Williams70a47ba2021-09-02 09:53:31 -0500105 }
106 };
107 rc = handler->registerRequest(
108 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
109 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
110 if (rc)
111 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600112 error(
113 "Failed to send BIOS Attribute update the platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -0500114 }
115
116 return rc;
117}
118
119} // namespace platform
120
121} // namespace responder
122
123} // namespace pldm