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> |
| 10 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 11 | #include <iostream> |
| 12 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 13 | PHOSPHOR_LOG2_USING; |
| 14 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 15 | namespace pldm |
| 16 | { |
| 17 | namespace responder |
| 18 | { |
| 19 | namespace platform |
| 20 | { |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 21 | int sendBiosAttributeUpdateEvent( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 22 | uint8_t eid, pldm::InstanceIdDb* instanceIdDb, |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 23 | const std::vector<uint16_t>& handles, |
| 24 | pldm::requester::Handler<pldm::requester::Request>* handler) |
| 25 | { |
| 26 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 27 | constexpr auto hostStateInterface = |
| 28 | "xyz.openbmc_project.State.Boot.Progress"; |
| 29 | constexpr auto hostStateProperty = "BootProgress"; |
| 30 | |
| 31 | try |
| 32 | { |
| 33 | auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant( |
| 34 | hostStatePath, hostStateProperty, hostStateInterface); |
| 35 | const auto& currHostState = std::get<std::string>(propVal); |
| 36 | if ((currHostState != "xyz.openbmc_project.State.Boot.Progress." |
| 37 | "ProgressStages.SystemInitComplete") && |
| 38 | (currHostState != "xyz.openbmc_project.State.Boot.Progress." |
| 39 | "ProgressStages.OSRunning") && |
| 40 | (currHostState != "xyz.openbmc_project.State.Boot.Progress." |
Andrew Geissler | f2704dc | 2022-05-23 16:09:45 -0400 | [diff] [blame] | 41 | "ProgressStages.SystemSetup")) |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 42 | { |
| 43 | return PLDM_SUCCESS; |
| 44 | } |
| 45 | } |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 46 | catch ( |
| 47 | const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound& |
| 48 | e) |
| 49 | { |
| 50 | /* Exception is expected to happen in the case when state manager is |
| 51 | * started after pldm, this is expected to happen in reboot case |
| 52 | * where host is considered to be up. As host is up pldm is expected |
| 53 | * to send attribute update event to host so this is not an error |
| 54 | * case */ |
| 55 | } |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 56 | catch (const sdbusplus::exception_t& e) |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 57 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 58 | error( |
| 59 | "Error in getting current host state, {EXCEP_NAME} Continue sending the bios attribute update event ...", |
| 60 | "EXCEP_NAME", e.name()); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 63 | auto instanceId = instanceIdDb->next(eid); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 64 | |
| 65 | std::vector<uint8_t> requestMsg( |
| 66 | sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) - |
| 67 | 1 + (handles.size() * sizeof(uint16_t)), |
| 68 | 0); |
| 69 | |
| 70 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 71 | |
| 72 | auto rc = encode_bios_attribute_update_event_req( |
Manojkiran Eda | 6a49bb0 | 2022-09-02 05:35:26 -0500 | [diff] [blame] | 73 | instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID, |
| 74 | handles.size(), reinterpret_cast<const uint8_t*>(handles.data()), |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 75 | requestMsg.size() - sizeof(pldm_msg_hdr), request); |
| 76 | if (rc != PLDM_SUCCESS) |
| 77 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 78 | error( |
| 79 | "BIOS Attribute update event message encode failure. PLDM error code = {RC}", |
| 80 | "RC", lg2::hex, rc); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 81 | instanceIdDb->free(eid, instanceId); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 82 | return rc; |
| 83 | } |
| 84 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 85 | auto platformEventMessageResponseHandler = |
| 86 | [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) { |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 87 | if (response == nullptr || !respMsgLen) |
| 88 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 89 | error("Failed to receive response for platform event message"); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | uint8_t completionCode{}; |
| 93 | uint8_t status{}; |
| 94 | auto rc = decode_platform_event_message_resp(response, respMsgLen, |
| 95 | &completionCode, &status); |
| 96 | if (rc || completionCode) |
| 97 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 98 | error( |
| 99 | "Failed to decode BIOS Attribute update platform_event_message_resp: rc = {RC}, cc= {CC}", |
| 100 | "RC", rc, "CC", static_cast<unsigned>(completionCode)); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 101 | } |
| 102 | }; |
| 103 | rc = handler->registerRequest( |
| 104 | eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, |
| 105 | std::move(requestMsg), std::move(platformEventMessageResponseHandler)); |
| 106 | if (rc) |
| 107 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 108 | error( |
| 109 | "Failed to send BIOS Attribute update the platform event message"); |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | return rc; |
| 113 | } |
| 114 | |
| 115 | } // namespace platform |
| 116 | |
| 117 | } // namespace responder |
| 118 | |
| 119 | } // namespace pldm |