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 | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame^] | 6 | #include <memory> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 7 | #include <sdeventplus/event.hpp> |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame^] | 8 | #include <sdeventplus/source/event.hpp> |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
| 11 | #include "libpldm/base.h" |
| 12 | #include "libpldm/platform.h" |
| 13 | |
| 14 | using namespace pldm::dbus_api; |
| 15 | |
| 16 | namespace pldm |
| 17 | { |
| 18 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame^] | 19 | // vector which would hold the PDR record handle data returned by |
| 20 | // pldmPDRRepositoryChgEvent event data |
| 21 | using ChangeEntry = uint32_t; |
| 22 | using PDRRecordHandles = std::vector<ChangeEntry>; |
| 23 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 24 | /** @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 | */ |
| 33 | class 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 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 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 71 | /** @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 Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame^] | 85 | /** @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 Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace pldm |