blob: 47c1e5395fae896dcdd0a637d1db132d44f53e28 [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
Andrew Jefferya330b2f2023-05-04 14:55:37 +093064 auto instanceId = instanceIdDb->next(eid);
Patrick Williams70a47ba2021-09-02 09:53:31 -050065
66 std::vector<uint8_t> requestMsg(
67 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
68 1 + (handles.size() * sizeof(uint16_t)),
69 0);
70
71 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
72
73 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050074 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
75 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050076 requestMsg.size() - sizeof(pldm_msg_hdr), request);
77 if (rc != PLDM_SUCCESS)
78 {
Riya Dixit49cfb132023-03-02 04:26:53 -060079 error(
Riya Dixitfc84f632024-04-06 14:00:02 -050080 "Failed to encode BIOS Attribute update event message, response code '{RC}'",
Riya Dixit49cfb132023-03-02 04:26:53 -060081 "RC", lg2::hex, rc);
Andrew Jefferya330b2f2023-05-04 14:55:37 +093082 instanceIdDb->free(eid, instanceId);
Patrick Williams70a47ba2021-09-02 09:53:31 -050083 return rc;
84 }
85
Patrick Williams16c2a0a2024-08-16 15:20:59 -040086 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
87 const pldm_msg* response,
88 size_t respMsgLen) {
Patrick Williams70a47ba2021-09-02 09:53:31 -050089 if (response == nullptr || !respMsgLen)
90 {
Riya Dixit49cfb132023-03-02 04:26:53 -060091 error("Failed to receive response for platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -050092 return;
93 }
94 uint8_t completionCode{};
95 uint8_t status{};
96 auto rc = decode_platform_event_message_resp(response, respMsgLen,
97 &completionCode, &status);
98 if (rc || completionCode)
99 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600100 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500101 "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 -0500102 "RC", rc, "CC", completionCode);
Patrick Williams70a47ba2021-09-02 09:53:31 -0500103 }
104 };
105 rc = handler->registerRequest(
106 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
107 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
108 if (rc)
109 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600110 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500111 "Failed to send BIOS Attribute update the platform event message, response code '{RC}'",
112 "RC", rc);
Patrick Williams70a47ba2021-09-02 09:53:31 -0500113 }
114
115 return rc;
116}
117
118} // namespace platform
119
120} // namespace responder
121
122} // namespace pldm