| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #pragma once |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 2 | |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 3 | #include "collect_slot_vpd.hpp" |
| 4 | #include "common/utils.hpp" |
| Rahul D S | 161e45d | 2025-11-06 17:34:43 +0530 | [diff] [blame] | 5 | #include "file_table.hpp" |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 6 | #include "inband_code_update.hpp" |
| Archana Kakani | 97a0f48 | 2025-03-10 05:39:38 -0500 | [diff] [blame] | 7 | #include "libpldmresponder/bios_config.hpp" |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 8 | #include "libpldmresponder/oem_handler.hpp" |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 9 | #include "libpldmresponder/pdr_utils.hpp" |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 10 | #include "libpldmresponder/platform.hpp" |
| Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 11 | #include "requester/handler.hpp" |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 12 | |
| George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 13 | #include <libpldm/entity.h> |
| Andrew Jeffery | 21f128d | 2024-01-15 15:34:26 +1030 | [diff] [blame] | 14 | #include <libpldm/oem/ibm/state_set.h> |
| George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 15 | #include <libpldm/platform.h> |
| Jayashankar Padath | fdf6da7 | 2025-04-14 10:54:58 -0500 | [diff] [blame^] | 16 | #include <libpldm/state_set.h> |
| George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 17 | |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 18 | #include <sdbusplus/bus/match.hpp> |
| 19 | #include <sdeventplus/event.hpp> |
| 20 | #include <sdeventplus/utility/timer.hpp> |
| Alexander Hansen | 24c04d5 | 2025-11-11 14:46:21 +0100 | [diff] [blame] | 21 | #include <xyz/openbmc_project/State/Host/client.hpp> |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 22 | |
| Christian Geddes | 7f9523c | 2021-08-03 13:44:38 -0500 | [diff] [blame] | 23 | typedef ibm_oem_pldm_state_set_firmware_update_state_values CodeUpdateState; |
| 24 | |
| Alexander Hansen | 24c04d5 | 2025-11-11 14:46:21 +0100 | [diff] [blame] | 25 | using HostState = sdbusplus::common::xyz::openbmc_project::state::Host; |
| 26 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 27 | namespace pldm |
| 28 | { |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 29 | namespace responder |
| 30 | { |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 31 | using ObjectPath = std::string; |
| 32 | using AssociatedEntityMap = std::map<ObjectPath, pldm_entity>; |
| Archana Kakani | 97a0f48 | 2025-03-10 05:39:38 -0500 | [diff] [blame] | 33 | using namespace pldm::bios; |
| 34 | using namespace pldm::utils; |
| 35 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 36 | namespace oem_ibm_platform |
| 37 | { |
| Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 38 | constexpr uint16_t ENTITY_INSTANCE_0 = 0; |
| 39 | constexpr uint16_t ENTITY_INSTANCE_1 = 1; |
| 40 | |
| Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 41 | constexpr uint32_t BMC_PDR_START_RANGE = 0x00000000; |
| 42 | constexpr uint32_t BMC_PDR_END_RANGE = 0x00FFFFFF; |
| 43 | constexpr uint32_t HOST_PDR_START_RANGE = 0x01000000; |
| 44 | constexpr uint32_t HOST_PDR_END_RANGE = 0x01FFFFFF; |
| 45 | |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 46 | const pldm::pdr::TerminusID HYPERVISOR_TID = 208; |
| 47 | |
| 48 | static constexpr uint8_t HEARTBEAT_TIMEOUT_DELTA = 10; |
| 49 | |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 50 | enum SetEventReceiverCount |
| 51 | { |
| 52 | SET_EVENT_RECEIVER_SENT = 0x2, |
| 53 | }; |
| 54 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 55 | class Handler : public oem_platform::Handler |
| 56 | { |
| 57 | public: |
| 58 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 59 | pldm::responder::CodeUpdate* codeUpdate, |
| 60 | pldm::responder::SlotHandler* slotHandler, int mctp_fd, |
| Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 61 | uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb, |
| Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 62 | sdeventplus::Event& event, |
| Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 63 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 64 | oem_platform::Handler(dBusIntf), codeUpdate(codeUpdate), |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 65 | slotHandler(slotHandler), platformHandler(nullptr), mctp_fd(mctp_fd), |
| 66 | mctp_eid(mctp_eid), instanceIdDb(instanceIdDb), event(event), |
| 67 | handler(handler), |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 68 | timer(event, std::bind(std::mem_fn(&Handler::setSurvTimer), this, |
| 69 | HYPERVISOR_TID, false)), |
| 70 | hostTransitioningToOff(true) |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 71 | { |
| 72 | codeUpdate->setVersions(); |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 73 | setEventReceiverCnt = 0; |
| 74 | |
| 75 | using namespace sdbusplus::bus::match::rules; |
| Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 76 | hostOffMatch = std::make_unique<sdbusplus::bus::match_t>( |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 77 | pldm::utils::DBusHandler::getBus(), |
| 78 | propertiesChanged("/xyz/openbmc_project/state/host0", |
| Alexander Hansen | 24c04d5 | 2025-11-11 14:46:21 +0100 | [diff] [blame] | 79 | HostState::interface), |
| Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 80 | [this](sdbusplus::message_t& msg) { |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 81 | pldm::utils::DbusChangedProps props{}; |
| 82 | std::string intf; |
| 83 | msg.read(intf, props); |
| Alexander Hansen | 24c04d5 | 2025-11-11 14:46:21 +0100 | [diff] [blame] | 84 | const auto itr = |
| 85 | props.find(HostState::property_names::current_host_state); |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 86 | if (itr != props.end()) |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 87 | { |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 88 | pldm::utils::PropertyValue value = itr->second; |
| 89 | auto propVal = std::get<std::string>(value); |
| 90 | if (propVal == |
| 91 | "xyz.openbmc_project.State.Host.HostState.Off") |
| 92 | { |
| 93 | hostOff = true; |
| 94 | setEventReceiverCnt = 0; |
| 95 | disableWatchDogTimer(); |
| 96 | startStopTimer(false); |
| Rahul D S | 161e45d | 2025-11-06 17:34:43 +0530 | [diff] [blame] | 97 | pldm::filetable::clearFileTable(); |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 98 | } |
| 99 | else if (propVal == |
| 100 | "xyz.openbmc_project.State.Host.HostState.Running") |
| 101 | { |
| 102 | hostOff = false; |
| 103 | hostTransitioningToOff = false; |
| 104 | } |
| 105 | else if ( |
| 106 | propVal == |
| 107 | "xyz.openbmc_project.State.Host.HostState.TransitioningToOff") |
| 108 | { |
| 109 | hostTransitioningToOff = true; |
| 110 | } |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 111 | } |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 112 | }); |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 113 | |
| Patrick Williams | 4f152f9 | 2024-06-18 02:38:34 -0500 | [diff] [blame] | 114 | powerStateOffMatch = std::make_unique<sdbusplus::bus::match_t>( |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 115 | pldm::utils::DBusHandler::getBus(), |
| 116 | propertiesChanged("/xyz/openbmc_project/state/chassis0", |
| 117 | "xyz.openbmc_project.State.Chassis"), |
| Archana Kakani | 5055425 | 2025-03-17 01:37:29 -0500 | [diff] [blame] | 118 | [this](sdbusplus::message_t& msg) { |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 119 | pldm::utils::DbusChangedProps props{}; |
| 120 | std::string intf; |
| 121 | msg.read(intf, props); |
| 122 | const auto itr = props.find("CurrentPowerState"); |
| 123 | if (itr != props.end()) |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 124 | { |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 125 | pldm::utils::PropertyValue value = itr->second; |
| 126 | auto propVal = std::get<std::string>(value); |
| 127 | if (propVal == |
| 128 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 129 | { |
| Archana Kakani | 5055425 | 2025-03-17 01:37:29 -0500 | [diff] [blame] | 130 | handleBootTypesAtChassisOff(); |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 131 | static constexpr auto searchpath = |
| 132 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
| 133 | int depth = 0; |
| 134 | std::vector<std::string> powerInterface = { |
| 135 | "xyz.openbmc_project.State.Decorator.PowerState"}; |
| 136 | pldm::utils::GetSubTreeResponse response = |
| 137 | pldm::utils::DBusHandler().getSubtree( |
| 138 | searchpath, depth, powerInterface); |
| 139 | for (const auto& [objPath, serviceMap] : response) |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 140 | { |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 141 | pldm::utils::DBusMapping dbusMapping{ |
| 142 | objPath, |
| 143 | "xyz.openbmc_project.State.Decorator.PowerState", |
| 144 | "PowerState", "string"}; |
| 145 | value = |
| 146 | "xyz.openbmc_project.State.Decorator.PowerState.State.Off"; |
| 147 | try |
| 148 | { |
| 149 | pldm::utils::DBusHandler().setDbusProperty( |
| 150 | dbusMapping, value); |
| 151 | } |
| 152 | catch (const std::exception& e) |
| 153 | { |
| 154 | error( |
| 155 | "Unable to set the slot power state to Off error - {ERROR}", |
| 156 | "ERROR", e); |
| 157 | } |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | } |
| Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 161 | }); |
| Jayashankar Padath | fdf6da7 | 2025-04-14 10:54:58 -0500 | [diff] [blame^] | 162 | |
| Archana Kakani | e26d13f | 2025-03-09 23:17:46 -0500 | [diff] [blame] | 163 | updateBIOSMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 164 | pldm::utils::DBusHandler::getBus(), |
| 165 | propertiesChanged("/xyz/openbmc_project/bios_config/manager", |
| 166 | "xyz.openbmc_project.BIOSConfig.Manager"), |
| 167 | [codeUpdate](sdbusplus::message_t& msg) { |
| 168 | constexpr auto propertyName = "PendingAttributes"; |
| 169 | using Value = |
| 170 | std::variant<std::string, PendingAttributes, BaseBIOSTable>; |
| 171 | using Properties = std::map<pldm::utils::DbusProp, Value>; |
| 172 | Properties props{}; |
| 173 | std::string intf; |
| 174 | msg.read(intf, props); |
| 175 | auto valPropMap = props.find(propertyName); |
| 176 | if (valPropMap == props.end()) |
| 177 | { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | PendingAttributes pendingAttributes = |
| 182 | std::get<PendingAttributes>(valPropMap->second); |
| 183 | for (auto it : pendingAttributes) |
| 184 | { |
| 185 | if (it.first == "fw_boot_side") |
| 186 | { |
| 187 | auto& [attributeType, attributevalue] = it.second; |
| 188 | std::string nextBootSideAttr = |
| 189 | std::get<std::string>(attributevalue); |
| 190 | std::string nextBootSide = |
| 191 | (nextBootSideAttr == "Perm" ? Pside : Tside); |
| 192 | codeUpdate->setNextBootSide(nextBootSide); |
| 193 | } |
| 194 | } |
| 195 | }); |
| Jayashankar Padath | fdf6da7 | 2025-04-14 10:54:58 -0500 | [diff] [blame^] | 196 | |
| 197 | platformSAIMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 198 | pldm::utils::DBusHandler::getBus(), |
| 199 | propertiesChanged( |
| 200 | "/xyz/openbmc_project/led/groups/partition_system_attention_indicator", |
| 201 | "xyz.openbmc_project.Led.Group"), |
| 202 | [this](sdbusplus::message_t& msg) { |
| 203 | pldm::utils::DbusChangedProps props{}; |
| 204 | std::string intf; |
| 205 | msg.read(intf, props); |
| 206 | const auto itr = props.find("Asserted"); |
| 207 | if (itr != props.end()) |
| 208 | { |
| 209 | processSAIUpdate(); |
| 210 | } |
| 211 | }); |
| 212 | |
| 213 | partitionSAIMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 214 | pldm::utils::DBusHandler::getBus(), |
| 215 | propertiesChanged( |
| 216 | "/xyz/openbmc_project/led/groups/platform_system_attention_indicator", |
| 217 | "xyz.openbmc_project.Led.Group"), |
| 218 | [this](sdbusplus::message_t& msg) { |
| 219 | pldm::utils::DbusChangedProps props{}; |
| 220 | std::string intf; |
| 221 | msg.read(intf, props); |
| 222 | const auto itr = props.find("Asserted"); |
| 223 | if (itr != props.end()) |
| 224 | { |
| 225 | processSAIUpdate(); |
| 226 | } |
| 227 | }); |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | int getOemStateSensorReadingsHandler( |
| Kamalkumar Patel | 7d427f1 | 2024-05-16 03:44:00 -0500 | [diff] [blame] | 231 | pldm::pdr::EntityType entityType, |
| 232 | pldm::pdr::EntityInstance entityInstance, |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 233 | pldm::pdr::ContainerID containerId, pldm::pdr::StateSetId stateSetId, |
| 234 | pldm::pdr::CompositeCount compSensorCnt, uint16_t sensorId, |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 235 | std::vector<get_sensor_state_field>& stateField); |
| 236 | |
| Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 237 | int oemSetStateEffecterStatesHandler( |
| Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 238 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 239 | uint8_t compEffecterCnt, |
| 240 | std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 241 | |
| 242 | /** @brief Method to set the platform handler in the |
| 243 | * oem_ibm_handler class |
| 244 | * @param[in] handler - pointer to PLDM platform handler |
| 245 | */ |
| 246 | void setPlatformHandler(pldm::responder::platform::Handler* handler); |
| 247 | |
| Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 248 | /** @brief Method to fetch the effecter ID of the code update PDRs |
| 249 | * |
| 250 | * @return platformHandler->getNextEffecterId() - returns the |
| 251 | * effecter ID from the platform handler |
| 252 | */ |
| Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 253 | virtual uint16_t getNextEffecterId() |
| Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 254 | { |
| 255 | return platformHandler->getNextEffecterId(); |
| 256 | } |
| 257 | |
| 258 | /** @brief Method to fetch the sensor ID of the code update PDRs |
| 259 | * |
| 260 | * @return platformHandler->getNextSensorId() - returns the |
| 261 | * Sensor ID from the platform handler |
| 262 | */ |
| Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 263 | virtual uint16_t getNextSensorId() |
| Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 264 | { |
| 265 | return platformHandler->getNextSensorId(); |
| 266 | } |
| 267 | |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 268 | /** @brief Get std::map associated with the entity |
| 269 | * key: object path |
| 270 | * value: pldm_entity |
| 271 | * |
| 272 | * @return std::map<ObjectPath, pldm_entity> |
| 273 | */ |
| 274 | virtual const AssociatedEntityMap& getAssociateEntityMap() |
| 275 | { |
| 276 | return platformHandler->getAssociateEntityMap(); |
| 277 | } |
| 278 | |
| Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 279 | /** @brief Method to Generate the OEM PDRs |
| 280 | * |
| 281 | * @param[in] repo - instance of concrete implementation of Repo |
| 282 | */ |
| 283 | void buildOEMPDR(pdr_utils::Repo& repo); |
| 284 | |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 285 | /** @brief Method to send code update event to host |
| 286 | * @param[in] sensorId - sendor ID |
| 287 | * @param[in] sensorEventClass - event class of sensor |
| 288 | * @param[in] sensorOffset - sensor offset |
| 289 | * @param[in] eventState - new code update event state |
| 290 | * @param[in] prevEventState - previous code update event state |
| 291 | * @return none |
| 292 | */ |
| 293 | void sendStateSensorEvent(uint16_t sensorId, |
| 294 | enum sensor_event_class_states sensorEventClass, |
| 295 | uint8_t sensorOffset, uint8_t eventState, |
| 296 | uint8_t prevEventState); |
| 297 | |
| 298 | /** @brief Method to send encoded request msg of code update event to host |
| 299 | * @param[in] requestMsg - encoded request msg |
| Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 300 | * @param[in] instanceId - instance id of the message |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 301 | * @return PLDM status code |
| 302 | */ |
| Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 303 | int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 304 | |
| Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 305 | /** @brief _processEndUpdate processes the actual work that needs |
| 306 | * to be carried out after EndUpdate effecter is set. This is done async |
| 307 | * after sending response for EndUpdate set effecter |
| 308 | * @param[in] source - sdeventplus event source |
| 309 | */ |
| 310 | void _processEndUpdate(sdeventplus::source::EventBase& source); |
| 311 | |
| 312 | /** @brief _processStartUpdate processes the actual work that needs |
| 313 | * to be carried out after StartUpdate effecter is set. This is done async |
| 314 | * after sending response for StartUpdate set effecter |
| 315 | * @param[in] source - sdeventplus event source |
| 316 | */ |
| 317 | void _processStartUpdate(sdeventplus::source::EventBase& source); |
| 318 | |
| Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 319 | /** @brief _processSystemReboot processes the actual work that needs to be |
| 320 | * carried out after the System Power State effecter is set to reboot |
| 321 | * the system |
| 322 | * @param[in] source - sdeventplus event source |
| 323 | */ |
| 324 | void _processSystemReboot(sdeventplus::source::EventBase& source); |
| 325 | |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 326 | /*keeps track how many times setEventReceiver is sent */ |
| 327 | void countSetEventReceiver() |
| 328 | { |
| 329 | setEventReceiverCnt++; |
| 330 | } |
| 331 | |
| 332 | /* disables watchdog if running and Host is up */ |
| 333 | void checkAndDisableWatchDog(); |
| 334 | |
| Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 335 | /** @brief To check if the watchdog app is running |
| 336 | * |
| 337 | * @return the running status of watchdog app |
| 338 | */ |
| 339 | bool watchDogRunning(); |
| 340 | |
| 341 | /** @brief Method to reset the Watchdog timer on receiving platform Event |
| 342 | * Message for heartbeat elapsed time from Hostboot |
| 343 | */ |
| 344 | void resetWatchDogTimer(); |
| 345 | |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 346 | /** @brief To disable to the watchdog timer on host poweron completion*/ |
| 347 | void disableWatchDogTimer(); |
| 348 | |
| Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 349 | /** @brief to check the BMC state*/ |
| 350 | int checkBMCState(); |
| 351 | |
| Kamalkumar Patel | 15ce5a1 | 2024-05-07 11:45:11 -0500 | [diff] [blame] | 352 | /** @brief update the dbus object paths */ |
| 353 | void updateOemDbusPaths(std::string& dbusPath); |
| 354 | |
| Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 355 | /** @brief Method to fetch the last BMC record from the PDR repo |
| 356 | * |
| 357 | * @param[in] repo - pointer to BMC's primary PDR repo |
| 358 | * |
| 359 | * @return the last BMC record from the repo |
| 360 | */ |
| 361 | const pldm_pdr_record* fetchLastBMCRecord(const pldm_pdr* repo); |
| 362 | |
| 363 | /** @brief Method to check if the record handle passed is in remote PDR |
| 364 | * record handle range |
| 365 | * |
| 366 | * @param[in] record_handle - record handle of the PDR |
| 367 | * |
| 368 | * @return true if record handle passed is in host PDR record handle range |
| 369 | */ |
| 370 | bool checkRecordHandleInRange(const uint32_t& record_handle); |
| 371 | |
| Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 372 | /** *brief Method to call the setEventReceiver command*/ |
| 373 | void processSetEventReceiver(); |
| 374 | |
| 375 | /** @brief Method to call the setEventReceiver through the platform |
| 376 | * handler |
| 377 | */ |
| 378 | virtual void setEventReceiver() |
| 379 | { |
| 380 | platformHandler->setEventReceiver(); |
| 381 | } |
| 382 | |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 383 | /** @brief Method to Enable/Disable timer to see if remote terminus sends |
| 384 | * the surveillance ping and logs informational error if remote terminus |
| 385 | * fails to send the surveillance pings |
| 386 | * |
| 387 | * @param[in] tid - TID of the remote terminus |
| 388 | * @param[in] value - true or false, to indicate if the timer is |
| 389 | * running or not |
| 390 | */ |
| 391 | void setSurvTimer(uint8_t tid, bool value); |
| 392 | |
| Archana Kakani | 5055425 | 2025-03-17 01:37:29 -0500 | [diff] [blame] | 393 | /** @brief To handle the boot types bios attributes at power on*/ |
| 394 | void handleBootTypesAtPowerOn(); |
| 395 | |
| 396 | /** @brief To handle the boot types bios attributes at shutdown*/ |
| 397 | void handleBootTypesAtChassisOff(); |
| 398 | |
| 399 | /** @brief To set the boot types bios attributes based on the RestartCause |
| 400 | * of host |
| 401 | * |
| 402 | * @param[in] RestartCause - Host restart cause |
| 403 | */ |
| 404 | void setBootTypesBiosAttr(const std::string& restartCause); |
| 405 | |
| Jayashankar Padath | fdf6da7 | 2025-04-14 10:54:58 -0500 | [diff] [blame^] | 406 | /** @brief To turn off Real SAI effecter*/ |
| 407 | void turnOffRealSAIEffecter(); |
| 408 | |
| 409 | /** @brief Fetch Real SAI status based on the partition SAI and platform SAI |
| 410 | * sensor states. Real SAI is turned on if any of the partition or platform |
| 411 | * SAI turned on else Real SAI is turned off |
| 412 | * @return Real SAI sensor state PLDM_SENSOR_WARNING/PLDM_SENSOR_NORMAL |
| 413 | */ |
| 414 | uint8_t fetchRealSAIStatus(); |
| 415 | |
| 416 | /** @brief Method to process virtual platform/partition SAI update*/ |
| 417 | void processSAIUpdate(); |
| 418 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 419 | ~Handler() = default; |
| 420 | |
| 421 | pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 422 | |
| 423 | pldm::responder::SlotHandler* |
| 424 | slotHandler; //!< pointer to SlotHandler object |
| 425 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 426 | pldm::responder::platform::Handler* |
| 427 | platformHandler; //!< pointer to PLDM platform handler |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 428 | |
| 429 | /** @brief fd of MCTP communications socket */ |
| 430 | int mctp_fd; |
| 431 | |
| 432 | /** @brief MCTP EID of host firmware */ |
| 433 | uint8_t mctp_eid; |
| 434 | |
| Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 435 | /** @brief reference to an InstanceIdDb object, used to obtain a PLDM |
| 436 | * instance id. */ |
| 437 | pldm::InstanceIdDb& instanceIdDb; |
| Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 438 | /** @brief sdeventplus event source */ |
| 439 | std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent; |
| 440 | std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent; |
| Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 441 | std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent; |
| Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 442 | |
| Manojkiran Eda | a31ceb9 | 2021-07-22 09:19:02 +0530 | [diff] [blame] | 443 | /** @brief Effecterid to dbus object path map |
| 444 | */ |
| 445 | std::unordered_map<uint16_t, std::string> effecterIdToDbusMap; |
| 446 | |
| Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 447 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 448 | * work |
| 449 | */ |
| 450 | sdeventplus::Event& event; |
| Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 451 | |
| 452 | private: |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 453 | /** @brief Method to reset or stop the surveillance timer |
| 454 | * |
| 455 | * @param[in] value - true or false, to indicate if the timer |
| 456 | * should be reset or turned off |
| 457 | */ |
| 458 | void startStopTimer(bool value); |
| 459 | |
| Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 460 | /** @brief D-Bus property changed signal match for CurrentPowerState*/ |
| Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 461 | std::unique_ptr<sdbusplus::bus::match_t> chassisOffMatch; |
| Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 462 | |
| 463 | /** @brief PLDM request handler */ |
| 464 | pldm::requester::Handler<pldm::requester::Request>* handler; |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 465 | |
| 466 | /** @brief D-Bus property changed signal match */ |
| Archana Kakani | e26d13f | 2025-03-09 23:17:46 -0500 | [diff] [blame] | 467 | std::unique_ptr<sdbusplus::bus::match_t> updateBIOSMatch; |
| 468 | |
| 469 | /** @brief D-Bus property changed signal match */ |
| Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 470 | std::unique_ptr<sdbusplus::bus::match_t> hostOffMatch; |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 471 | |
| Pavithra Barithaya | 0fd6a09 | 2024-05-31 08:24:27 -0500 | [diff] [blame] | 472 | /** @brief D-Bus property changed signal match */ |
| 473 | std::unique_ptr<sdbusplus::bus::match_t> powerStateOffMatch; |
| 474 | |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 475 | /** @brief Timer used for monitoring surveillance pings from host */ |
| 476 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 477 | |
| Jayashankar Padath | fdf6da7 | 2025-04-14 10:54:58 -0500 | [diff] [blame^] | 478 | /** @brief D-Bus Interface added signal match for virtual platform SAI */ |
| 479 | std::unique_ptr<sdbusplus::bus::match_t> platformSAIMatch; |
| 480 | |
| 481 | /** @brief D-Bus Interface added signal match for virtual partition SAI */ |
| 482 | std::unique_ptr<sdbusplus::bus::match_t> partitionSAIMatch; |
| 483 | |
| 484 | /** @brief Real SAI sensor id*/ |
| 485 | uint16_t realSAISensorId; |
| 486 | |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 487 | bool hostOff = true; |
| 488 | |
| Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 489 | bool hostTransitioningToOff; |
| 490 | |
| Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 491 | int setEventReceiverCnt = 0; |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 492 | }; |
| 493 | |
| Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 494 | /** @brief Method to encode code update event msg |
| 495 | * @param[in] eventType - type of event |
| 496 | * @param[in] eventDataVec - vector of event data to be sent to host |
| 497 | * @param[in/out] requestMsg - request msg to be encoded |
| 498 | * @param[in] instanceId - instance ID |
| 499 | * @return PLDM status code |
| 500 | */ |
| 501 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 502 | std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
| 503 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 504 | } // namespace oem_ibm_platform |
| 505 | |
| Archana Kakani | 97a0f48 | 2025-03-10 05:39:38 -0500 | [diff] [blame] | 506 | namespace oem_ibm_bios |
| 507 | { |
| 508 | /** @brief The file where bootside data will be saved */ |
| 509 | constexpr auto bootSideDirPath = "/var/lib/pldm/bootSide"; |
| 510 | |
| 511 | class Handler : public oem_bios::Handler |
| 512 | { |
| 513 | public: |
| 514 | Handler() {} |
| 515 | |
| 516 | void processOEMBaseBiosTable(const BaseBIOSTable& biosTable) |
| 517 | { |
| 518 | for (const auto& [attrName, biostabObj] : biosTable) |
| 519 | { |
| 520 | // The additional check to see if /var/lib/pldm/bootSide file exists |
| 521 | // is added to make sure we are doing the fw_boot_side setting after |
| 522 | // the base bios table is initialised. |
| 523 | if ((attrName == "fw_boot_side") && fs::exists(bootSideDirPath)) |
| 524 | { |
| 525 | PendingAttributesList biosAttrList; |
| 526 | |
| 527 | std::string nextBootSide = |
| 528 | std::get<std::string>(std::get<5>(biostabObj)); |
| 529 | |
| 530 | std::string currNextBootSide; |
| 531 | auto attributeValue = |
| 532 | getBiosAttrValue<std::string>("fw_boot_side"); |
| 533 | |
| 534 | if (attributeValue.has_value()) |
| 535 | { |
| 536 | currNextBootSide = attributeValue.value(); |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | info( |
| 541 | "Boot side is not initialized yet, so setting default value"); |
| 542 | currNextBootSide = "Temp"; |
| 543 | } |
| 544 | |
| 545 | if (currNextBootSide != nextBootSide) |
| 546 | { |
| 547 | biosAttrList.emplace_back(std::make_pair( |
| 548 | attrName, |
| 549 | std::make_tuple(EnumAttribute, nextBootSide))); |
| 550 | setBiosAttr(biosAttrList); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | }; |
| 556 | |
| 557 | } // namespace oem_ibm_bios |
| 558 | |
| Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 559 | } // namespace responder |
| 560 | |
| 561 | } // namespace pldm |