diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-06-28 19:17:28 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-07-06 14:56:34 +0000 |
commit | 32e84e98efd51509aa18ab2f3538bcbc6689bb0d (patch) | |
tree | d19c0e92e84fc4bdda35fcf4811341706e3136ff /occ_device.hpp | |
parent | 307d80b3d78efc669f38a63938371adcc6934391 (diff) | |
download | openpower-occ-control-32e84e98efd51509aa18ab2f3538bcbc6689bb0d.tar.gz openpower-occ-control-32e84e98efd51509aa18ab2f3538bcbc6689bb0d.zip |
Add Support to do device bind and unbind based on OCC status
Fixes openbmc/openbmc#1698
Change-Id: Iaa33c3065b0358b62e3ec7e39d4b57c6b9d181e1
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_device.hpp')
-rw-r--r-- | occ_device.hpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/occ_device.hpp b/occ_device.hpp new file mode 100644 index 0000000..dc057be --- /dev/null +++ b/occ_device.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include <fstream> +#include <experimental/filesystem> +#include "config.h" +namespace open_power +{ +namespace occ +{ + +namespace fs = std::experimental::filesystem; + +/** @class Device + * @brief Binds and unbinds the OCC driver upon request + */ +class Device +{ + public: + Device() = delete; + ~Device() = default; + Device(const Device&) = delete; + Device& operator=(const Device&) = delete; + Device(Device&&) = default; + Device& operator=(Device&&) = default; + + /** @brief Constructs the Device object + * + * @param[in] name - OCC instance name + */ + Device(const std::string& name) : + config(name + '-' + "dev0") + { + // Nothing to do here + } + + /** @brief Binds device to the OCC driver */ + inline void bind() + { + return write(bindPath, config); + } + + /** @brief Un-binds device from the OCC driver */ + inline void unBind() + { + return write(unBindPath, config); + } + + private: + /** @brief Config value to be used to do bind and unbind */ + const std::string config; + + /** @brief To bind the device to the OCC driver, do: + * Write occ<#>-dev0 to: /sys/bus/platform/drivers/occ-hwmon/bind + */ + static fs::path bindPath; + + /** @brief To un-bind the device from the OCC driver, do: + * Write occ<#>-dev0 to: /sys/bus/platform/drivers/occ-hwmon/unbind + */ + static fs::path unBindPath; + + /** @brief file writer to achieve bind and unbind + * + * @param[in] filename - Name of file to be written + * @param[in] data - Data to be written to + * @return - None + */ + void write(const fs::path& fileName, const std::string& data) + { + // If there is an error, move the exception all the way up + std::ofstream file(fileName, std::ios::out); + file << data; + file.close(); + return; + } +}; + +} // namespace occ +} // namespace open_power |