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