Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/async.hpp> |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include <functional> |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | |
| 10 | namespace phosphor::software::cpld |
| 11 | { |
| 12 | |
| 13 | class CPLDInterface |
| 14 | { |
| 15 | public: |
| 16 | CPLDInterface(sdbusplus::async::context& ctx, const std::string& chipname, |
| 17 | uint16_t bus, uint8_t address) : |
| 18 | ctx(ctx), chipname(chipname), bus(bus), address(address) |
| 19 | {} |
| 20 | |
| 21 | virtual ~CPLDInterface() = default; |
| 22 | CPLDInterface(const CPLDInterface&) = delete; |
| 23 | CPLDInterface& operator=(const CPLDInterface&) = delete; |
| 24 | CPLDInterface(CPLDInterface&&) = delete; |
| 25 | CPLDInterface& operator=(CPLDInterface&&) = delete; |
| 26 | |
| 27 | virtual sdbusplus::async::task<bool> updateFirmware( |
| 28 | bool force, const uint8_t* image, size_t imageSize, |
| 29 | std::function<bool(int)> progress = nullptr) = 0; |
| 30 | |
| 31 | virtual sdbusplus::async::task<bool> getVersion(std::string& version) = 0; |
| 32 | |
| 33 | protected: |
| 34 | sdbusplus::async::context& ctx; |
| 35 | std::string chipname; |
| 36 | uint16_t bus; |
| 37 | uint8_t address; |
| 38 | }; |
| 39 | |
| 40 | class CPLDFactory |
| 41 | { |
| 42 | public: |
| 43 | using Creator = std::function<std::unique_ptr<CPLDInterface>( |
| 44 | sdbusplus::async::context& ctx, const std::string& chipName, |
| 45 | uint16_t bus, uint8_t address)>; |
| 46 | using ConfigProvider = std::function<std::vector<std::string>()>; |
| 47 | |
| 48 | static CPLDFactory& instance(); |
| 49 | |
| 50 | void registerCPLD(const std::string& vendorName, Creator creator); |
| 51 | |
| 52 | std::unique_ptr<CPLDInterface> create( |
| 53 | const std::string& vendorName, sdbusplus::async::context& ctx, |
| 54 | const std::string& chipName, uint16_t bus, uint8_t address) const; |
| 55 | |
| 56 | std::vector<std::string> getConfigs(); |
| 57 | |
| 58 | private: |
| 59 | std::unordered_map<std::string, Creator> creators; |
| 60 | }; |
| 61 | |
| 62 | } // namespace phosphor::software::cpld |