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 | */ |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 62 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 63 | void fetchPDR(std::vector<uint32_t>&& recordHandles); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 64 | |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 65 | /** @brief Send a PLDM event to host firmware containing a list of record |
| 66 | * handles of PDRs that the host firmware has to fetch. |
| 67 | * @param[in] pdrTypes - list of PDR types that need to be looked up in the |
| 68 | * BMC repo |
| 69 | * @param[in] eventDataFormat - format for PDRRepositoryChgEvent in DSP0248 |
| 70 | */ |
| 71 | void sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes, |
| 72 | uint8_t eventDataFormat); |
| 73 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 74 | private: |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 75 | /** @brief fetchPDR schedules work on the event loop, this method does the |
| 76 | * actual work. This is so that the PDR exchg with the host is async. |
| 77 | * @param[in] source - sdeventplus event source |
| 78 | */ |
| 79 | void _fetchPDR(sdeventplus::source::EventBase& source); |
| 80 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 81 | /** @brief Merge host firmware's entity association PDRs into BMC's |
| 82 | * @details A merge operation involves adding a pldm_entity under the |
| 83 | * appropriate parent, and updating container ids. |
| 84 | * @param[in] pdr - entity association pdr |
| 85 | */ |
| 86 | void mergeEntityAssociations(const std::vector<uint8_t>& pdr); |
| 87 | |
| 88 | /** @brief Find parent of input entity type, from the entity association |
| 89 | * tree |
| 90 | * @param[in] type - PLDM entity type |
| 91 | * @param[out] parent - PLDM entity information of parent |
| 92 | * @return bool - true if parent found, false otherwise |
| 93 | */ |
| 94 | bool getParent(EntityType type, pldm_entity& parent); |
| 95 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 96 | /** @brief fd of MCTP communications socket */ |
| 97 | int mctp_fd; |
| 98 | /** @brief MCTP EID of host firmware */ |
| 99 | uint8_t mctp_eid; |
| 100 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 101 | * work. |
| 102 | */ |
| 103 | sdeventplus::Event& event; |
| 104 | /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */ |
| 105 | pldm_pdr* repo; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 106 | /** @brief Pointer to BMC's entity association tree */ |
| 107 | pldm_entity_association_tree* entityTree; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 108 | /** @brief reference to Requester object, primarily used to access API to |
| 109 | * obtain PLDM instance id. |
| 110 | */ |
| 111 | Requester& requester; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 112 | /** @brief sdeventplus event source */ |
| 113 | std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent; |
| 114 | /** @brief list of PDR record handles pointing to host's PDRs */ |
| 115 | PDRRecordHandles pdrRecordHandles; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 116 | /** @brief maps an entity type to parent pldm_entity from the BMC's entity |
| 117 | * association tree |
| 118 | */ |
| 119 | std::map<EntityType, pldm_entity> parents; |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 120 | /** @brief D-Bus property changed signal match */ |
| 121 | std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | } // namespace pldm |