blob: af1fbab66e18848a73b679f1620117c10cd49f3d [file] [log] [blame]
Pavithra Barithaya51efaf82020-04-02 02:42:27 -05001#pragma once
2
3#include "dbus_impl_requester.hpp"
4#include "utils.hpp"
5
Deepak Kodihalli87514cc2020-04-16 09:08:38 -05006#include <map>
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -05007#include <memory>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -05008#include <sdeventplus/event.hpp>
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -05009#include <sdeventplus/source/event.hpp>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050010#include <vector>
11
12#include "libpldm/base.h"
13#include "libpldm/platform.h"
14
15using namespace pldm::dbus_api;
16
17namespace pldm
18{
19
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050020using EntityType = uint16_t;
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050021// vector which would hold the PDR record handle data returned by
22// pldmPDRRepositoryChgEvent event data
23using ChangeEntry = uint32_t;
24using PDRRecordHandles = std::vector<ChangeEntry>;
25
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050026/** @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 */
35class 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 Kodihalli87514cc2020-04-16 09:08:38 -050050 * @param[in] tree - pointer to BMC's entity association tree
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050051 * @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 Kodihalli87514cc2020-04-16 09:08:38 -050055 pldm_entity_association_tree* entityTree,
56 Requester& requester);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050057
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 Kodihalli8cb6f662020-04-10 02:55:43 -050062 void fetchPDR(std::vector<uint32_t>&& recordHandles);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050063
64 private:
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050065 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -050071 /** @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 Barithaya51efaf82020-04-02 02:42:27 -050086 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -050096 /** @brief Pointer to BMC's entity association tree */
97 pldm_entity_association_tree* entityTree;
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050098 /** @brief reference to Requester object, primarily used to access API to
99 * obtain PLDM instance id.
100 */
101 Requester& requester;
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500102 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -0500106 /** @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 Barithaya51efaf82020-04-02 02:42:27 -0500110};
111
112} // namespace pldm