blob: 2ee5f3459824d3852a1315d3214e3df8ac96e43c [file] [log] [blame]
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05301#include "occ_device.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Eddie James482e31f2017-09-14 13:17:17 -05003#include "occ_status.hpp"
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05304
Gunnar Mills94df8c92018-09-14 14:50:03 -05005#include <iostream>
6
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05307namespace open_power
8{
9namespace occ
10{
11
12fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
13fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";
14
Eddie James774f9af2019-03-19 20:58:53 +000015std::string Device::getPathBack(const fs::path& path)
16{
17 if (path.empty())
George Liubcef3b42021-09-10 12:39:02 +080018 {
Eddie James774f9af2019-03-19 20:58:53 +000019 return std::string();
George Liubcef3b42021-09-10 12:39:02 +080020 }
Eddie James774f9af2019-03-19 20:58:53 +000021
22 // Points to the last element in the path
23 auto conf = --path.end();
24
George Liubcef3b42021-09-10 12:39:02 +080025 if (conf->empty() && conf != path.begin())
Eddie James774f9af2019-03-19 20:58:53 +000026 {
27 return *(--conf);
28 }
29 else
30 {
31 return *conf;
32 }
33}
34
Edward A. James636577f2017-10-06 10:53:55 -050035bool Device::master() const
36{
37 int master;
Eddie James774f9af2019-03-19 20:58:53 +000038 auto masterFile = devPath / "occ_master";
Edward A. James636577f2017-10-06 10:53:55 -050039 std::ifstream file(masterFile, std::ios::in);
40
41 if (!file)
42 {
43 return false;
44 }
45
46 file >> master;
47 file.close();
48 return (master != 0);
49}
50
Eddie James482e31f2017-09-14 13:17:17 -050051void Device::throttleProcTempCallback(bool error)
52{
Gunnar Mills94df8c92018-09-14 14:50:03 -050053 statusObject.throttleProcTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050054}
55
56void Device::throttleProcPowerCallback(bool error)
57{
Gunnar Mills94df8c92018-09-14 14:50:03 -050058 statusObject.throttleProcPower(error);
Eddie James482e31f2017-09-14 13:17:17 -050059}
60
61void Device::throttleMemTempCallback(bool error)
62{
Gunnar Mills94df8c92018-09-14 14:50:03 -050063 statusObject.throttleMemTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050064}
65
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053066} // namespace occ
67} // namespace open_power