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