Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 3 | #include "libpldm/base.h" |
| 4 | #include "libpldm/platform.h" |
| 5 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 6 | #include "common/types.hpp" |
| 7 | #include "common/utils.hpp" |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 8 | #include "libpldmresponder/pdr_utils.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 9 | #include "pldmd/dbus_impl_requester.hpp" |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 10 | |
| 11 | #include <sdeventplus/event.hpp> |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 12 | #include <sdeventplus/source/event.hpp> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 13 | |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 14 | #include <deque> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 15 | #include <map> |
| 16 | #include <memory> |
| 17 | #include <vector> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 18 | |
| 19 | using namespace pldm::dbus_api; |
| 20 | |
| 21 | namespace pldm |
| 22 | { |
| 23 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 24 | using EntityType = uint16_t; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 25 | // vector which would hold the PDR record handle data returned by |
| 26 | // pldmPDRRepositoryChgEvent event data |
| 27 | using ChangeEntry = uint32_t; |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 28 | using PDRRecordHandles = std::deque<ChangeEntry>; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 29 | |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 30 | /** @struct SensorEntry |
| 31 | * |
| 32 | * SensorEntry is a unique key which maps a sensorEventType request in the |
| 33 | * PlatformEventMessage command to a host sensor PDR. This struct is a key |
| 34 | * in a std::map, so implemented operator==and operator<. |
| 35 | */ |
| 36 | struct SensorEntry |
| 37 | { |
| 38 | pdr::TerminusID terminusID; |
| 39 | pdr::SensorID sensorID; |
| 40 | |
| 41 | bool operator==(const SensorEntry& e) const |
| 42 | { |
| 43 | return ((terminusID == e.terminusID) && (sensorID == e.sensorID)); |
| 44 | } |
| 45 | |
| 46 | bool operator<(const SensorEntry& e) const |
| 47 | { |
| 48 | return ((terminusID < e.terminusID) || |
| 49 | ((terminusID == e.terminusID) && (sensorID < e.sensorID))); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | using HostStateSensorMap = std::map<SensorEntry, pdr::SensorInfo>; |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 54 | using PDRList = std::vector<std::vector<uint8_t>>; |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 55 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 56 | /** @class HostPDRHandler |
| 57 | * @brief This class can fetch and process PDRs from host firmware |
| 58 | * @details Provides an API to fetch PDRs from the host firmware. Upon |
| 59 | * receiving the PDRs, they are stored into the BMC's primary PDR repo. |
| 60 | * Adjustments are made to entity association PDRs received from the host, |
| 61 | * because they need to be assimilated into the BMC's entity association |
| 62 | * tree. A PLDM event containing the record handles of the updated entity |
| 63 | * association PDRs is sent to the host. |
| 64 | */ |
| 65 | class HostPDRHandler |
| 66 | { |
| 67 | public: |
| 68 | HostPDRHandler() = delete; |
| 69 | HostPDRHandler(const HostPDRHandler&) = delete; |
| 70 | HostPDRHandler(HostPDRHandler&&) = delete; |
| 71 | HostPDRHandler& operator=(const HostPDRHandler&) = delete; |
| 72 | HostPDRHandler& operator=(HostPDRHandler&&) = delete; |
| 73 | ~HostPDRHandler() = default; |
| 74 | |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 75 | using TLPDRMap = std::map<pdr::TerminusHandle, pdr::TerminusID>; |
| 76 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 77 | /** @brief Constructor |
| 78 | * @param[in] mctp_fd - fd of MCTP communications socket |
| 79 | * @param[in] mctp_eid - MCTP EID of host firmware |
| 80 | * @param[in] event - reference of main event loop of pldmd |
| 81 | * @param[in] repo - pointer to BMC's primary PDR repo |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 82 | * @param[in] tree - pointer to BMC's entity association tree |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 83 | * @param[in] requester - reference to Requester object |
| 84 | */ |
| 85 | explicit HostPDRHandler(int mctp_fd, uint8_t mctp_eid, |
| 86 | sdeventplus::Event& event, pldm_pdr* repo, |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 87 | pldm_entity_association_tree* entityTree, |
| 88 | Requester& requester); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 89 | |
| 90 | /** @brief fetch PDRs from host firmware. See @class. |
| 91 | * @param[in] recordHandles - list of record handles pointing to host's |
| 92 | * PDRs that need to be fetched. |
| 93 | */ |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 94 | |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 95 | void fetchPDR(PDRRecordHandles&& recordHandles); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 96 | |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 97 | /** @brief Send a PLDM event to host firmware containing a list of record |
| 98 | * handles of PDRs that the host firmware has to fetch. |
| 99 | * @param[in] pdrTypes - list of PDR types that need to be looked up in the |
| 100 | * BMC repo |
| 101 | * @param[in] eventDataFormat - format for PDRRepositoryChgEvent in DSP0248 |
| 102 | */ |
| 103 | void sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes, |
| 104 | uint8_t eventDataFormat); |
| 105 | |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 106 | /** @brief Lookup host sensor info corresponding to requested SensorEntry |
| 107 | * |
| 108 | * @param[in] entry - TerminusID and SensorID |
| 109 | * |
| 110 | * @return SensorInfo corresponding to the input paramter SensorEntry |
| 111 | * throw std::out_of_range exception if not found |
| 112 | */ |
| 113 | const pdr::SensorInfo& lookupSensorInfo(const SensorEntry& entry) const |
| 114 | { |
| 115 | return sensorMap.at(entry); |
| 116 | } |
| 117 | |
Sampa Misra | 868c879 | 2020-05-26 03:12:13 -0500 | [diff] [blame] | 118 | /** @brief Parse state sensor PDRs and populate the sensorMap lookup data |
| 119 | * structure |
| 120 | * |
| 121 | * @param[in] stateSensorPDRs - host state sensor PDRs |
| 122 | * @param[in] tlpdrInfo - terminus locator PDRs info |
| 123 | * |
| 124 | */ |
| 125 | void parseStateSensorPDRs(const PDRList& stateSensorPDRs, |
| 126 | const TLPDRMap& tlpdrInfo); |
| 127 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 128 | private: |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 129 | /** @brief fetchPDR schedules work on the event loop, this method does the |
| 130 | * actual work. This is so that the PDR exchg with the host is async. |
| 131 | * @param[in] source - sdeventplus event source |
| 132 | */ |
| 133 | void _fetchPDR(sdeventplus::source::EventBase& source); |
| 134 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 135 | /** @brief Merge host firmware's entity association PDRs into BMC's |
| 136 | * @details A merge operation involves adding a pldm_entity under the |
| 137 | * appropriate parent, and updating container ids. |
| 138 | * @param[in] pdr - entity association pdr |
| 139 | */ |
| 140 | void mergeEntityAssociations(const std::vector<uint8_t>& pdr); |
| 141 | |
| 142 | /** @brief Find parent of input entity type, from the entity association |
| 143 | * tree |
| 144 | * @param[in] type - PLDM entity type |
| 145 | * @param[out] parent - PLDM entity information of parent |
| 146 | * @return bool - true if parent found, false otherwise |
| 147 | */ |
| 148 | bool getParent(EntityType type, pldm_entity& parent); |
| 149 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 150 | /** @brief fd of MCTP communications socket */ |
| 151 | int mctp_fd; |
| 152 | /** @brief MCTP EID of host firmware */ |
| 153 | uint8_t mctp_eid; |
| 154 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 155 | * work. |
| 156 | */ |
| 157 | sdeventplus::Event& event; |
| 158 | /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */ |
| 159 | pldm_pdr* repo; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 160 | /** @brief Pointer to BMC's entity association tree */ |
| 161 | pldm_entity_association_tree* entityTree; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 162 | /** @brief reference to Requester object, primarily used to access API to |
| 163 | * obtain PLDM instance id. |
| 164 | */ |
| 165 | Requester& requester; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 166 | /** @brief sdeventplus event source */ |
| 167 | std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent; |
| 168 | /** @brief list of PDR record handles pointing to host's PDRs */ |
| 169 | PDRRecordHandles pdrRecordHandles; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 170 | /** @brief maps an entity type to parent pldm_entity from the BMC's entity |
| 171 | * association tree |
| 172 | */ |
| 173 | std::map<EntityType, pldm_entity> parents; |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 174 | /** @brief D-Bus property changed signal match */ |
| 175 | std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch; |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 176 | |
| 177 | /** @brief sensorMap is a lookup data structure that is build from the |
| 178 | * hostPDR that speeds up the lookup of <TerminusID, SensorID> in |
| 179 | * PlatformEventMessage command request. |
| 180 | */ |
| 181 | HostStateSensorMap sensorMap; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | } // namespace pldm |