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