blob: 4ea7b2f1f696e0d87f15f11e87d170f9bac052c0 [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 Williams6da4f912023-05-10 07:50:53 -050086 auto platformEventMessageResponseHandler =
87 [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
Patrick Williams70a47ba2021-09-02 09:53:31 -050088 if (response == nullptr || !respMsgLen)
89 {
Riya Dixit49cfb132023-03-02 04:26:53 -060090 error("Failed to receive response for platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -050091 return;
92 }
93 uint8_t completionCode{};
94 uint8_t status{};
95 auto rc = decode_platform_event_message_resp(response, respMsgLen,
96 &completionCode, &status);
97 if (rc || completionCode)
98 {
Riya Dixit49cfb132023-03-02 04:26:53 -060099 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500100 "Failed to decode BIOS Attribute update platform event message response with response code '{RC}' and completion code '{CC}'",
Riya Dixit49cfb132023-03-02 04:26:53 -0600101 "RC", rc, "CC", static_cast<unsigned>(completionCode));
Patrick Williams70a47ba2021-09-02 09:53:31 -0500102 }
103 };
104 rc = handler->registerRequest(
105 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
106 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
107 if (rc)
108 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600109 error(
Riya Dixitfc84f632024-04-06 14:00:02 -0500110 "Failed to send BIOS Attribute update the platform event message, response code '{RC}'",
111 "RC", rc);
Patrick Williams70a47ba2021-09-02 09:53:31 -0500112 }
113
114 return rc;
115}
116
117} // namespace platform
118
119} // namespace responder
120
121} // namespace pldm