blob: 850afdb431e134c90428a44e178db1ad273ef850 [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 */
Pavithra Barithayae8beb892020-04-14 23:24:25 -050062
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050063 void fetchPDR(std::vector<uint32_t>&& recordHandles);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050064
Pavithra Barithayae8beb892020-04-14 23:24:25 -050065 /** @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 Barithaya51efaf82020-04-02 02:42:27 -050074 private:
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050075 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -050081 /** @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 Barithaya51efaf82020-04-02 02:42:27 -050096 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -0500106 /** @brief Pointer to BMC's entity association tree */
107 pldm_entity_association_tree* entityTree;
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500108 /** @brief reference to Requester object, primarily used to access API to
109 * obtain PLDM instance id.
110 */
111 Requester& requester;
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500112 /** @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 Kodihalli87514cc2020-04-16 09:08:38 -0500116 /** @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 Kodihalli6b1d1ca2020-04-27 07:24:51 -0500120 /** @brief D-Bus property changed signal match */
121 std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch;
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500122};
123
124} // namespace pldm