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 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/platform_oem_ibm.h> |
| 7 | #include <libpldm/pldm.h> |
| 8 | |
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 | |
| 13 | namespace pldm |
| 14 | { |
| 15 | namespace responder |
| 16 | { |
| 17 | namespace platform |
| 18 | { |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 19 | int sendBiosAttributeUpdateEvent( |
| 20 | uint8_t eid, dbus_api::Requester* requester, |
| 21 | const std::vector<uint16_t>& handles, |
| 22 | pldm::requester::Handler<pldm::requester::Request>* handler) |
| 23 | { |
| 24 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 25 | constexpr auto hostStateInterface = |
| 26 | "xyz.openbmc_project.State.Boot.Progress"; |
| 27 | constexpr auto hostStateProperty = "BootProgress"; |
| 28 | |
| 29 | try |
| 30 | { |
| 31 | auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant( |
| 32 | hostStatePath, hostStateProperty, hostStateInterface); |
| 33 | const auto& currHostState = std::get<std::string>(propVal); |
| 34 | if ((currHostState != "xyz.openbmc_project.State.Boot.Progress." |
| 35 | "ProgressStages.SystemInitComplete") && |
| 36 | (currHostState != "xyz.openbmc_project.State.Boot.Progress." |
| 37 | "ProgressStages.OSRunning") && |
| 38 | (currHostState != "xyz.openbmc_project.State.Boot.Progress." |
Andrew Geissler | f2704dc | 2022-05-23 16:09:45 -0400 | [diff] [blame] | 39 | "ProgressStages.OSStart") && |
| 40 | (currHostState != "xyz.openbmc_project.State.Boot.Progress." |
| 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 | { |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 58 | std::cerr << "Error in getting current host state, " << e.name() |
| 59 | << " Continue sending the bios attribute update event ... \n"; |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | auto instanceId = requester->getInstanceId(eid); |
| 63 | |
| 64 | std::vector<uint8_t> requestMsg( |
| 65 | sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) - |
| 66 | 1 + (handles.size() * sizeof(uint16_t)), |
| 67 | 0); |
| 68 | |
| 69 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 70 | |
| 71 | auto rc = encode_bios_attribute_update_event_req( |
Manojkiran Eda | 6a49bb0 | 2022-09-02 05:35:26 -0500 | [diff] [blame] | 72 | instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID, |
| 73 | handles.size(), reinterpret_cast<const uint8_t*>(handles.data()), |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 74 | requestMsg.size() - sizeof(pldm_msg_hdr), request); |
| 75 | if (rc != PLDM_SUCCESS) |
| 76 | { |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 77 | std::cerr |
| 78 | << "BIOS Attribute update event message encode failure. PLDM error code = " |
| 79 | << std::hex << std::showbase << rc << "\n"; |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 80 | requester->markFree(eid, instanceId); |
| 81 | return rc; |
| 82 | } |
| 83 | |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 84 | auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/, |
| 85 | const pldm_msg* response, |
| 86 | size_t respMsgLen) { |
| 87 | if (response == nullptr || !respMsgLen) |
| 88 | { |
| 89 | std::cerr |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 90 | << "Failed to receive response for BIOS Attribute update platform event message \n"; |
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 | { |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 99 | std::cerr |
| 100 | << "Failed to decode BIOS Attribute update platform_event_message_resp: " |
| 101 | << "rc=" << rc |
| 102 | << ", cc=" << static_cast<unsigned>(completionCode) |
| 103 | << std::endl; |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 104 | } |
| 105 | }; |
| 106 | rc = handler->registerRequest( |
| 107 | eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, |
| 108 | std::move(requestMsg), std::move(platformEventMessageResponseHandler)); |
| 109 | if (rc) |
| 110 | { |
ArchanaKakani | dcf77d6 | 2022-08-29 07:04:09 -0500 | [diff] [blame] | 111 | std::cerr |
| 112 | << "Failed to send BIOS Attribute update the platform event message \n"; |
Patrick Williams | 70a47ba | 2021-09-02 09:53:31 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return rc; |
| 116 | } |
| 117 | |
| 118 | } // namespace platform |
| 119 | |
| 120 | } // namespace responder |
| 121 | |
| 122 | } // namespace pldm |