| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
|  | 3 | #include "dbus_impl_requester.hpp" | 
|  | 4 | #include "utils.hpp" | 
|  | 5 |  | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 6 | #include <map> | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 7 | #include <memory> | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 8 | #include <sdeventplus/event.hpp> | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 9 | #include <sdeventplus/source/event.hpp> | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 10 | #include <vector> | 
|  | 11 |  | 
|  | 12 | #include "libpldm/base.h" | 
|  | 13 | #include "libpldm/platform.h" | 
|  | 14 |  | 
|  | 15 | using namespace pldm::dbus_api; | 
|  | 16 |  | 
|  | 17 | namespace pldm | 
|  | 18 | { | 
|  | 19 |  | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 20 | using EntityType = uint16_t; | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 21 | // vector which would hold the PDR record handle data returned by | 
|  | 22 | // pldmPDRRepositoryChgEvent event data | 
|  | 23 | using ChangeEntry = uint32_t; | 
|  | 24 | using PDRRecordHandles = std::vector<ChangeEntry>; | 
|  | 25 |  | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 26 | /** @class HostPDRHandler | 
|  | 27 | *  @brief This class can fetch and process PDRs from host firmware | 
|  | 28 | *  @details Provides an API to fetch PDRs from the host firmware. Upon | 
|  | 29 | *  receiving the PDRs, they are stored into the BMC's primary PDR repo. | 
|  | 30 | *  Adjustments are made to entity association PDRs received from the host, | 
|  | 31 | *  because they need to be assimilated into the BMC's entity association | 
|  | 32 | *  tree. A PLDM event containing the record handles of the updated entity | 
|  | 33 | *  association PDRs is sent to the host. | 
|  | 34 | */ | 
|  | 35 | class HostPDRHandler | 
|  | 36 | { | 
|  | 37 | public: | 
|  | 38 | HostPDRHandler() = delete; | 
|  | 39 | HostPDRHandler(const HostPDRHandler&) = delete; | 
|  | 40 | HostPDRHandler(HostPDRHandler&&) = delete; | 
|  | 41 | HostPDRHandler& operator=(const HostPDRHandler&) = delete; | 
|  | 42 | HostPDRHandler& operator=(HostPDRHandler&&) = delete; | 
|  | 43 | ~HostPDRHandler() = default; | 
|  | 44 |  | 
|  | 45 | /** @brief Constructor | 
|  | 46 | *  @param[in] mctp_fd - fd of MCTP communications socket | 
|  | 47 | *  @param[in] mctp_eid - MCTP EID of host firmware | 
|  | 48 | *  @param[in] event - reference of main event loop of pldmd | 
|  | 49 | *  @param[in] repo - pointer to BMC's primary PDR repo | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 50 | *  @param[in] tree - pointer to BMC's entity association tree | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 51 | *  @param[in] requester - reference to Requester object | 
|  | 52 | */ | 
|  | 53 | explicit HostPDRHandler(int mctp_fd, uint8_t mctp_eid, | 
|  | 54 | sdeventplus::Event& event, pldm_pdr* repo, | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 55 | pldm_entity_association_tree* entityTree, | 
|  | 56 | Requester& requester); | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 57 |  | 
|  | 58 | /** @brief fetch PDRs from host firmware. See @class. | 
|  | 59 | *  @param[in] recordHandles - list of record handles pointing to host's | 
|  | 60 | *             PDRs that need to be fetched. | 
|  | 61 | */ | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 62 | void fetchPDR(std::vector<uint32_t>&& recordHandles); | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 63 |  | 
|  | 64 | private: | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 65 | /** @brief fetchPDR schedules work on the event loop, this method does the | 
|  | 66 | *  actual work. This is so that the PDR exchg with the host is async. | 
|  | 67 | *  @param[in] source - sdeventplus event source | 
|  | 68 | */ | 
|  | 69 | void _fetchPDR(sdeventplus::source::EventBase& source); | 
|  | 70 |  | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 71 | /** @brief Merge host firmware's entity association PDRs into BMC's | 
|  | 72 | *  @details A merge operation involves adding a pldm_entity under the | 
|  | 73 | *  appropriate parent, and updating container ids. | 
|  | 74 | *  @param[in] pdr - entity association pdr | 
|  | 75 | */ | 
|  | 76 | void mergeEntityAssociations(const std::vector<uint8_t>& pdr); | 
|  | 77 |  | 
|  | 78 | /** @brief Find parent of input entity type, from the entity association | 
|  | 79 | *  tree | 
|  | 80 | *  @param[in] type - PLDM entity type | 
|  | 81 | *  @param[out] parent - PLDM entity information of parent | 
|  | 82 | *  @return bool - true if parent found, false otherwise | 
|  | 83 | */ | 
|  | 84 | bool getParent(EntityType type, pldm_entity& parent); | 
|  | 85 |  | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 86 | /** @brief fd of MCTP communications socket */ | 
|  | 87 | int mctp_fd; | 
|  | 88 | /** @brief MCTP EID of host firmware */ | 
|  | 89 | uint8_t mctp_eid; | 
|  | 90 | /** @brief reference of main event loop of pldmd, primarily used to schedule | 
|  | 91 | *  work. | 
|  | 92 | */ | 
|  | 93 | sdeventplus::Event& event; | 
|  | 94 | /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */ | 
|  | 95 | pldm_pdr* repo; | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 96 | /** @brief Pointer to BMC's entity association tree */ | 
|  | 97 | pldm_entity_association_tree* entityTree; | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 98 | /** @brief reference to Requester object, primarily used to access API to | 
|  | 99 | *  obtain PLDM instance id. | 
|  | 100 | */ | 
|  | 101 | Requester& requester; | 
| Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 102 | /** @brief sdeventplus event source */ | 
|  | 103 | std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent; | 
|  | 104 | /** @brief list of PDR record handles pointing to host's PDRs */ | 
|  | 105 | PDRRecordHandles pdrRecordHandles; | 
| Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame^] | 106 | /** @brief maps an entity type to parent pldm_entity from the BMC's entity | 
|  | 107 | *  association tree | 
|  | 108 | */ | 
|  | 109 | std::map<EntityType, pldm_entity> parents; | 
| Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 110 | }; | 
|  | 111 |  | 
|  | 112 | } // namespace pldm |