Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 1 | #include "platform_oem_ibm.hpp" |
| 2 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 3 | #include "common/utils.hpp" |
| 4 | #include "libpldmresponder/pdr.hpp" |
| 5 | |
Andrew Jeffery | 21f128d | 2024-01-15 15:34:26 +1030 | [diff] [blame] | 6 | #include <libpldm/oem/ibm/platform.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 7 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/error.hpp> |
Pavithra Barithaya | 7b4d59a | 2024-02-05 09:09:30 -0600 | [diff] [blame] | 10 | #include <xyz/openbmc_project/State/Boot/Progress/client.hpp> |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 11 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 12 | PHOSPHOR_LOG2_USING; |
| 13 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 14 | namespace pldm |
| 15 | { |
| 16 | namespace responder |
| 17 | { |
| 18 | namespace platform |
| 19 | { |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 20 | int sendBiosAttributeUpdateEvent( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 21 | uint8_t eid, pldm::InstanceIdDb* instanceIdDb, |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 22 | const std::vector<uint16_t>& handles, |
| 23 | pldm::requester::Handler<pldm::requester::Request>* handler) |
| 24 | { |
Pavithra Barithaya | 7b4d59a | 2024-02-05 09:09:30 -0600 | [diff] [blame] | 25 | using BootProgress = |
| 26 | sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>; |
| 27 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 28 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 29 | constexpr auto hostStateProperty = "BootProgress"; |
| 30 | |
| 31 | try |
| 32 | { |
| 33 | auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant( |
Pavithra Barithaya | 7b4d59a | 2024-02-05 09:09:30 -0600 | [diff] [blame] | 34 | hostStatePath, hostStateProperty, BootProgress::interface); |
Patrick Williams | e4e2e82 | 2024-02-07 11:00:52 -0600 | [diff] [blame] | 35 | |
| 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 Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 44 | { |
| 45 | return PLDM_SUCCESS; |
| 46 | } |
| 47 | } |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 48 | catch ( |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 49 | const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&) |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 50 | { |
| 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 57 | catch (const sdbusplus::exception_t& e) |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 58 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 59 | error( |
Riya Dixit | fc84f63 | 2024-04-06 14:00:02 -0500 | [diff] [blame] | 60 | "Error in getting current remote terminus state, error - '{ERROR}' Continue sending the bios attribute update event ...", |
| 61 | "ERROR", e); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 64 | auto instanceId = instanceIdDb->next(eid); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 65 | |
| 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 Eda | 6a49bb0 | 2022-09-02 05:35:26 -0500 | [diff] [blame] | 74 | instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID, |
| 75 | handles.size(), reinterpret_cast<const uint8_t*>(handles.data()), |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 76 | requestMsg.size() - sizeof(pldm_msg_hdr), request); |
| 77 | if (rc != PLDM_SUCCESS) |
| 78 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 79 | error( |
Riya Dixit | fc84f63 | 2024-04-06 14:00:02 -0500 | [diff] [blame] | 80 | "Failed to encode BIOS Attribute update event message, response code '{RC}'", |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 81 | "RC", lg2::hex, rc); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 82 | instanceIdDb->free(eid, instanceId); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 83 | return rc; |
| 84 | } |
| 85 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 86 | auto platformEventMessageResponseHandler = |
| 87 | [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) { |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 88 | if (response == nullptr || !respMsgLen) |
| 89 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 90 | error("Failed to receive response for platform event message"); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 91 | 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 99 | error( |
Riya Dixit | fc84f63 | 2024-04-06 14:00:02 -0500 | [diff] [blame] | 100 | "Failed to decode BIOS Attribute update platform event message response with response code '{RC}' and completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame^] | 101 | "RC", rc, "CC", completionCode); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 102 | } |
| 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 109 | error( |
Riya Dixit | fc84f63 | 2024-04-06 14:00:02 -0500 | [diff] [blame] | 110 | "Failed to send BIOS Attribute update the platform event message, response code '{RC}'", |
| 111 | "RC", rc); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return rc; |
| 115 | } |
| 116 | |
| 117 | } // namespace platform |
| 118 | |
| 119 | } // namespace responder |
| 120 | |
| 121 | } // namespace pldm |