blob: 0663b01811b7409139dd0e6ca773c78c04c16626 [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
Riya Dixit49cfb132023-03-02 04:26:53 -060012PHOSPHOR_LOG2_USING;
13
Patrick Williams70a47ba2021-09-02 09:53:31 -050014namespace pldm
15{
16namespace responder
17{
18namespace platform
19{
Patrick Williams70a47ba2021-09-02 09:53:31 -050020int sendBiosAttributeUpdateEvent(
Andrew Jefferya330b2f2023-05-04 14:55:37 +093021 uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
Patrick Williams70a47ba2021-09-02 09:53:31 -050022 const std::vector<uint16_t>& handles,
23 pldm::requester::Handler<pldm::requester::Request>* handler)
24{
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060025 using BootProgress =
26 sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>;
27
Patrick Williams70a47ba2021-09-02 09:53:31 -050028 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
Patrick Williams70a47ba2021-09-02 09:53:31 -050029 constexpr auto hostStateProperty = "BootProgress";
30
31 try
32 {
33 auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
Pavithra Barithaya7b4d59a2024-02-05 09:09:30 -060034 hostStatePath, hostStateProperty, BootProgress::interface);
Patrick Williamse4e2e822024-02-07 11:00:52 -060035
36 using Stages = BootProgress::ProgressStages;
37 auto currHostState = sdbusplus::message::convert_from_string<Stages>(
38 std::get<std::string>(propVal))
39 .value();
40
41 if (currHostState != Stages::SystemInitComplete &&
42 currHostState != Stages::OSRunning &&
43 currHostState != Stages::SystemSetup)
Patrick Williams70a47ba2021-09-02 09:53:31 -050044 {
45 return PLDM_SUCCESS;
46 }
47 }
ArchanaKakanidcf77d62022-08-29 07:04:09 -050048 catch (
Kamalkumar Patel58cbcaf2023-10-06 03:48:25 -050049 const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&)
ArchanaKakanidcf77d62022-08-29 07:04:09 -050050 {
51 /* Exception is expected to happen in the case when state manager is
52 * started after pldm, this is expected to happen in reboot case
53 * where host is considered to be up. As host is up pldm is expected
54 * to send attribute update event to host so this is not an error
55 * case */
56 }
Patrick Williams84b790c2022-07-22 19:26:56 -050057 catch (const sdbusplus::exception_t& e)
Patrick Williams70a47ba2021-09-02 09:53:31 -050058 {
Riya Dixit49cfb132023-03-02 04:26:53 -060059 error(
Riya Dixitfc84f632024-04-06 14:00:02 -050060 "Error in getting current remote terminus state, error - '{ERROR}' Continue sending the bios attribute update event ...",
61 "ERROR", e);
Patrick Williams70a47ba2021-09-02 09:53:31 -050062 }
63
Eric Yang70262ed2025-07-02 06:35:03 +000064 auto instanceIdResult = pldm::utils::getInstanceId(instanceIdDb->next(eid));
65 if (!instanceIdResult)
66 {
67 return PLDM_ERROR;
68 }
69 auto instanceId = instanceIdResult.value();
Patrick Williams70a47ba2021-09-02 09:53:31 -050070
71 std::vector<uint8_t> requestMsg(
72 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
73 1 + (handles.size() * sizeof(uint16_t)),
74 0);
75
76 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
77
78 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050079 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
80 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050081 requestMsg.size() - sizeof(pldm_msg_hdr), request);
82 if (rc != PLDM_SUCCESS)
83 {
Riya Dixit49cfb132023-03-02 04:26:53 -060084 error(
Riya Dixitfc84f632024-04-06 14:00:02 -050085 "Failed to encode BIOS Attribute update event message, response code '{RC}'",
Riya Dixit49cfb132023-03-02 04:26:53 -060086 "RC", lg2::hex, rc);
Andrew Jefferya330b2f2023-05-04 14:55:37 +093087 instanceIdDb->free(eid, instanceId);
Patrick Williams70a47ba2021-09-02 09:53:31 -050088 return rc;
89 }
90
Patrick Williams16c2a0a2024-08-16 15:20:59 -040091 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
92 const pldm_msg* response,
93 size_t respMsgLen) {
Patrick Williams70a47ba2021-09-02 09:53:31 -050094 if (response == nullptr || !respMsgLen)
95 {
Riya Dixit49cfb132023-03-02 04:26:53 -060096 error("Failed to receive response for platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -050097 return;
98 }
99 uint8_t completionCode{};
100 uint8_t status{};
101 auto rc = decode_platform_event_message_resp(response, respMsgLen,
102 &completionCode, &status);
103 if (rc || completionCode)
104 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600105 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500106 "Failed to decode BIOS Attribute update platform event message response with response code '{RC}' and completion code '{CC}'",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500107 "RC", rc, "CC", completionCode);
Patrick Williams70a47ba2021-09-02 09:53:31 -0500108 }
109 };
110 rc = handler->registerRequest(
111 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
112 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
113 if (rc)
114 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600115 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500116 "Failed to send BIOS Attribute update the platform event message, response code '{RC}'",
117 "RC", rc);
Patrick Williams70a47ba2021-09-02 09:53:31 -0500118 }
119
120 return rc;
121}
122
123} // namespace platform
124
125} // namespace responder
126
127} // namespace pldm