Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 1 | #include "occ_device.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 | |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 3 | #include "occ_status.hpp" |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 4 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 5 | #include <iostream> |
| 6 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 7 | namespace open_power |
| 8 | { |
| 9 | namespace occ |
| 10 | { |
| 11 | |
| 12 | fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind"; |
| 13 | fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind"; |
| 14 | |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 15 | std::string Device::getPathBack(const fs::path& path) |
| 16 | { |
| 17 | if (path.empty()) |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 18 | { |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 19 | return std::string(); |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 20 | } |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 21 | |
| 22 | // Points to the last element in the path |
| 23 | auto conf = --path.end(); |
| 24 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 25 | if (conf->empty() && conf != path.begin()) |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 26 | { |
| 27 | return *(--conf); |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | return *conf; |
| 32 | } |
| 33 | } |
| 34 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 35 | bool Device::master() const |
| 36 | { |
| 37 | int master; |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 38 | auto masterFile = devPath / "occ_master"; |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 39 | 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 James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 51 | void Device::throttleProcTempCallback(bool error) |
| 52 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 53 | statusObject.throttleProcTemp(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void Device::throttleProcPowerCallback(bool error) |
| 57 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 58 | statusObject.throttleProcPower(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void Device::throttleMemTempCallback(bool error) |
| 62 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 63 | statusObject.throttleMemTemp(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 66 | } // namespace occ |
| 67 | } // namespace open_power |