Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server/object.hpp> |
| 5 | #include <sdeventplus/clock.hpp> |
| 6 | #include <sdeventplus/event.hpp> |
| 7 | #include <sdeventplus/utility/timer.hpp> |
| 8 | #include <xyz/openbmc_project/Memory/MemoryECC/server.hpp> |
| 9 | |
Eddie James | 28b153c | 2024-07-22 11:37:09 -0500 | [diff] [blame^] | 10 | #include <chrono> |
| 11 | |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace memory |
| 15 | { |
| 16 | |
| 17 | template <typename... T> |
Patrick Williams | c5d295b | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 18 | using ServerObject = typename sdbusplus::server::object_t<T...>; |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 19 | |
| 20 | using EccInterface = sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC; |
| 21 | using EccObject = ServerObject<EccInterface>; |
| 22 | /** @class |
| 23 | * @brief Manages ECC |
| 24 | */ |
Patrick Williams | 527190b | 2023-05-10 07:51:28 -0500 | [diff] [blame] | 25 | class ECC : |
| 26 | sdbusplus::server::object_t< |
| 27 | sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC> |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 28 | { |
| 29 | public: |
| 30 | ECC() = delete; |
| 31 | ~ECC() = default; |
| 32 | ECC(const ECC&) = delete; |
| 33 | ECC& operator=(const ECC&) = delete; |
| 34 | ECC(ECC&&) = default; |
| 35 | ECC& operator=(ECC&&) = default; |
| 36 | |
| 37 | /** @brief Constructs |
| 38 | * |
| 39 | * @param[in] bus - Handle to system dbus |
| 40 | * @param[in] objPath - The Dbus path |
| 41 | */ |
Patrick Williams | c5d295b | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 42 | ECC(sdbusplus::bus_t& bus, const std::string& objPath) : |
| 43 | sdbusplus::server::object_t< |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 44 | sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC>( |
| 45 | bus, objPath.c_str()), |
| 46 | _bus(bus), _event(sdeventplus::Event::get_default()), |
Patrick Williams | 1e8c42c | 2024-08-16 15:22:09 -0400 | [diff] [blame] | 47 | _timer(_event, std::bind(&ECC::read, this)) { |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 48 | // Nothing to do here |
| 49 | }; |
| 50 | |
| 51 | int64_t previousCeCounter = 0; |
| 52 | int64_t previousUeCounter = 0; |
| 53 | int64_t maxECCLog = 0; |
Eddie James | 28b153c | 2024-07-22 11:37:09 -0500 | [diff] [blame^] | 54 | #ifdef ECC_PHOSPHOR_LOGGING |
| 55 | int64_t startCeCount = 0; |
| 56 | bool maxCeLimitReached = false; |
| 57 | std::chrono::system_clock::time_point maxCeLimitReachedTime{}; |
| 58 | #endif |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 59 | |
| 60 | void run(); |
| 61 | void controlEDACReport(std::string); |
| 62 | |
| 63 | private: |
| 64 | /** @brief sdbusplus bus client connection. */ |
Patrick Williams | c5d295b | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 65 | sdbusplus::bus_t& _bus; |
Will Liang | a1d4202 | 2019-06-13 14:17:12 +0800 | [diff] [blame] | 66 | /** @brief the Event Loop structure */ |
| 67 | sdeventplus::Event _event; |
| 68 | /** @brief Read Timer */ |
| 69 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer; |
| 70 | /** @brief Read sysfs entries */ |
| 71 | void read(); |
| 72 | |
| 73 | /** @brief Set up D-Bus object init */ |
| 74 | void init(); |
| 75 | |
| 76 | std::string getValue(std::string); |
| 77 | |
| 78 | void writeValue(std::string, std::string); |
| 79 | // set ce_count to dbus |
| 80 | int checkCeCount(); |
| 81 | // set ue_count to dbus |
| 82 | int checkUeCount(); |
| 83 | // set eccErrorCount to dbus |
| 84 | void checkEccLogFull(int64_t, int64_t); |
| 85 | |
| 86 | void resetCounter(); |
| 87 | // set maxECCLog value |
| 88 | void getMaxLogValue(); |
| 89 | |
| 90 | void addSELLog(std::string, std::string, std::vector<uint8_t>, bool, |
| 91 | uint16_t); |
| 92 | }; |
| 93 | |
| 94 | } // namespace memory |
| 95 | } // namespace phosphor |