blob: dc5462fbdc7a1ef241ab36567fadb74000c96cbe [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 Kodihalli8cb6f662020-04-10 02:55:43 -05006#include <memory>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -05007#include <sdeventplus/event.hpp>
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -05008#include <sdeventplus/source/event.hpp>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -05009#include <vector>
10
11#include "libpldm/base.h"
12#include "libpldm/platform.h"
13
14using namespace pldm::dbus_api;
15
16namespace pldm
17{
18
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050019// vector which would hold the PDR record handle data returned by
20// pldmPDRRepositoryChgEvent event data
21using ChangeEntry = uint32_t;
22using PDRRecordHandles = std::vector<ChangeEntry>;
23
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050024/** @class HostPDRHandler
25 * @brief This class can fetch and process PDRs from host firmware
26 * @details Provides an API to fetch PDRs from the host firmware. Upon
27 * receiving the PDRs, they are stored into the BMC's primary PDR repo.
28 * Adjustments are made to entity association PDRs received from the host,
29 * because they need to be assimilated into the BMC's entity association
30 * tree. A PLDM event containing the record handles of the updated entity
31 * association PDRs is sent to the host.
32 */
33class HostPDRHandler
34{
35 public:
36 HostPDRHandler() = delete;
37 HostPDRHandler(const HostPDRHandler&) = delete;
38 HostPDRHandler(HostPDRHandler&&) = delete;
39 HostPDRHandler& operator=(const HostPDRHandler&) = delete;
40 HostPDRHandler& operator=(HostPDRHandler&&) = delete;
41 ~HostPDRHandler() = default;
42
43 /** @brief Constructor
44 * @param[in] mctp_fd - fd of MCTP communications socket
45 * @param[in] mctp_eid - MCTP EID of host firmware
46 * @param[in] event - reference of main event loop of pldmd
47 * @param[in] repo - pointer to BMC's primary PDR repo
48 * @param[in] requester - reference to Requester object
49 */
50 explicit HostPDRHandler(int mctp_fd, uint8_t mctp_eid,
51 sdeventplus::Event& event, pldm_pdr* repo,
52 Requester& requester) :
53 mctp_fd(mctp_fd),
54 mctp_eid(mctp_eid), event(event), repo(repo), requester(requester)
55 {
56 }
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 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
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050071 /** @brief fd of MCTP communications socket */
72 int mctp_fd;
73 /** @brief MCTP EID of host firmware */
74 uint8_t mctp_eid;
75 /** @brief reference of main event loop of pldmd, primarily used to schedule
76 * work.
77 */
78 sdeventplus::Event& event;
79 /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */
80 pldm_pdr* repo;
81 /** @brief reference to Requester object, primarily used to access API to
82 * obtain PLDM instance id.
83 */
84 Requester& requester;
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -050085 /** @brief sdeventplus event source */
86 std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent;
87 /** @brief list of PDR record handles pointing to host's PDRs */
88 PDRRecordHandles pdrRecordHandles;
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050089};
90
91} // namespace pldm