blob: c95c0f39980fc7664109af1891701661593f993e [file] [log] [blame]
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05301#include "occ_device.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Eddie Jamescbad2192021-10-07 09:39:39 -05003#include "occ_manager.hpp"
Eddie James482e31f2017-09-14 13:17:17 -05004#include "occ_status.hpp"
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05305
Gunnar Mills94df8c92018-09-14 14:50:03 -05006#include <iostream>
7
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05308namespace open_power
9{
10namespace occ
11{
12
13fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
14fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";
15
Eddie James774f9af2019-03-19 20:58:53 +000016std::string Device::getPathBack(const fs::path& path)
17{
18 if (path.empty())
George Liubcef3b42021-09-10 12:39:02 +080019 {
Eddie James774f9af2019-03-19 20:58:53 +000020 return std::string();
George Liubcef3b42021-09-10 12:39:02 +080021 }
Eddie James774f9af2019-03-19 20:58:53 +000022
23 // Points to the last element in the path
24 auto conf = --path.end();
25
George Liubcef3b42021-09-10 12:39:02 +080026 if (conf->empty() && conf != path.begin())
Eddie James774f9af2019-03-19 20:58:53 +000027 {
28 return *(--conf);
29 }
30 else
31 {
32 return *conf;
33 }
34}
35
Edward A. James636577f2017-10-06 10:53:55 -050036bool Device::master() const
37{
38 int master;
Eddie James774f9af2019-03-19 20:58:53 +000039 auto masterFile = devPath / "occ_master";
Edward A. James636577f2017-10-06 10:53:55 -050040 std::ifstream file(masterFile, std::ios::in);
41
42 if (!file)
43 {
44 return false;
45 }
46
47 file >> master;
48 file.close();
49 return (master != 0);
50}
51
Eddie Jamescbad2192021-10-07 09:39:39 -050052void Device::errorCallback(bool error)
53{
54 if (error)
55 {
56 statusObject.deviceError();
57 }
58}
59
60#ifdef PLDM
61void Device::timeoutCallback(bool error)
62{
63 if (error)
64 {
65 managerObject.sbeTimeout(instance);
66 }
67}
68#endif
69
Eddie James482e31f2017-09-14 13:17:17 -050070void Device::throttleProcTempCallback(bool error)
71{
Gunnar Mills94df8c92018-09-14 14:50:03 -050072 statusObject.throttleProcTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050073}
74
75void Device::throttleProcPowerCallback(bool error)
76{
Gunnar Mills94df8c92018-09-14 14:50:03 -050077 statusObject.throttleProcPower(error);
Eddie James482e31f2017-09-14 13:17:17 -050078}
79
80void Device::throttleMemTempCallback(bool error)
81{
Gunnar Mills94df8c92018-09-14 14:50:03 -050082 statusObject.throttleMemTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050083}
84
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053085} // namespace occ
86} // namespace open_power