blob: df990ddd9bc944c80b25c9a732ffcaff61120231 [file] [log] [blame]
Will Lianga1d42022019-06-13 14:17:12 +08001#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 James28b153c2024-07-22 11:37:09 -050010#include <chrono>
11
Will Lianga1d42022019-06-13 14:17:12 +080012namespace phosphor
13{
14namespace memory
15{
16
17template <typename... T>
Patrick Williamsc5d295b2022-11-26 09:41:58 -060018using ServerObject = typename sdbusplus::server::object_t<T...>;
Will Lianga1d42022019-06-13 14:17:12 +080019
20using EccInterface = sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC;
21using EccObject = ServerObject<EccInterface>;
22/** @class
23 * @brief Manages ECC
24 */
Patrick Williams527190b2023-05-10 07:51:28 -050025class ECC :
26 sdbusplus::server::object_t<
27 sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC>
Will Lianga1d42022019-06-13 14:17:12 +080028{
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 Williamsc5d295b2022-11-26 09:41:58 -060042 ECC(sdbusplus::bus_t& bus, const std::string& objPath) :
43 sdbusplus::server::object_t<
Will Lianga1d42022019-06-13 14:17:12 +080044 sdbusplus::xyz::openbmc_project::Memory::server::MemoryECC>(
45 bus, objPath.c_str()),
46 _bus(bus), _event(sdeventplus::Event::get_default()),
Patrick Williams1e8c42c2024-08-16 15:22:09 -040047 _timer(_event, std::bind(&ECC::read, this)) {
Will Lianga1d42022019-06-13 14:17:12 +080048 // Nothing to do here
49 };
50
51 int64_t previousCeCounter = 0;
52 int64_t previousUeCounter = 0;
53 int64_t maxECCLog = 0;
Eddie James28b153c2024-07-22 11:37:09 -050054#ifdef ECC_PHOSPHOR_LOGGING
55 int64_t startCeCount = 0;
56 bool maxCeLimitReached = false;
57 std::chrono::system_clock::time_point maxCeLimitReachedTime{};
58#endif
Will Lianga1d42022019-06-13 14:17:12 +080059
60 void run();
61 void controlEDACReport(std::string);
62
63 private:
64 /** @brief sdbusplus bus client connection. */
Patrick Williamsc5d295b2022-11-26 09:41:58 -060065 sdbusplus::bus_t& _bus;
Will Lianga1d42022019-06-13 14:17:12 +080066 /** @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