summaryrefslogtreecommitdiff
path: root/psu-manager
diff options
context:
space:
mode:
authorCheng C Yang <cheng.c.yang@intel.com>2019-07-27 02:22:19 +0300
committerCheng C Yang <cheng.c.yang@intel.com>2019-07-27 02:22:19 +0300
commit1c69184aba9f81df0bbb9993ba24347584f1f06e (patch)
tree6af15181a0ec024533ee95ca036d8847d4bce8df /psu-manager
parent4373d99e1edcbb4c7233abde3a5e53690693007b (diff)
downloadprovingground-1c69184aba9f81df0bbb9993ba24347584f1f06e.tar.xz
Update first patch for Cold Redundancy
Update first patch for PowerSupply Cold Redundancy feature. The first patch will get PSU information from entity manager and base on the information, create PSU class for Cold Redundancy. Tested: With later Cold Redundancy patch, basic function, keep alive and PSU status all can work correctly. Change-Id: Ib2279043c0cbfade9c02f4107ae2137af17ba942 Signed-off-by: Cheng C Yang <cheng.c.yang@intel.com>
Diffstat (limited to 'psu-manager')
-rw-r--r--psu-manager/.clang-format99
-rw-r--r--psu-manager/CMakeLists.txt54
-rw-r--r--psu-manager/LICENSE201
-rw-r--r--psu-manager/cmake-format.json13
-rw-r--r--psu-manager/include/coldRedundancy.hpp71
-rw-r--r--psu-manager/include/utility.hpp56
-rw-r--r--psu-manager/service_files/xyz.openbmc_project.coldredundancy.service12
-rw-r--r--psu-manager/src/coldRedundancy.cpp204
-rw-r--r--psu-manager/src/redundancyMain.cpp31
-rw-r--r--psu-manager/src/utility.cpp102
10 files changed, 843 insertions, 0 deletions
diff --git a/psu-manager/.clang-format b/psu-manager/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/psu-manager/.clang-format
@@ -0,0 +1,99 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/psu-manager/CMakeLists.txt b/psu-manager/CMakeLists.txt
new file mode 100644
index 0000000..d29d98a
--- /dev/null
+++ b/psu-manager/CMakeLists.txt
@@ -0,0 +1,54 @@
+cmake_minimum_required (VERSION 2.8.10 FATAL_ERROR)
+set (BUILD_SHARED_LIBRARIES OFF)
+include (ExternalProject)
+set (CMAKE_CXX_STANDARD 17)
+set (CMAKE_CXX_STANDARD_REQUIRED ON)
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs -Werror")
+
+set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+
+include_directories (
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/phosphor-dbus-interfaces
+)
+
+project (psumanager CXX)
+
+set (PSU_CR_SRC_FILES src/utility.cpp src/coldRedundancy.cpp)
+
+set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
+set (CR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
+
+add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
+add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
+add_definitions (-DBOOST_ALL_NO_LIB)
+add_definitions (-DBOOST_NO_RTTI)
+add_definitions (-DBOOST_NO_TYPEID)
+add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
+
+link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
+
+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+include_directories (${SDBUSPLUSPLUS_INCLUDE_DIRS})
+link_directories (${SDBUSPLUSPLUS_LIBRARY_DIRS})
+
+include_directories (${DBUSINTERFACE_INCLUDE_DIRS})
+link_directories (${DBUSINTERFACE_LIBRARY_DIRS})
+
+add_executable (psuredundancy ${PSU_CR_SRC_FILES} src/redundancyMain.cpp)
+add_dependencies (psuredundancy sdbusplus-project)
+target_link_libraries (psuredundancy ${CR_LINK_LIBS})
+target_link_libraries (psuredundancy i2c)
+target_link_libraries (psuredundancy phosphor_logging)
+target_link_libraries (psuredundancy phosphor_dbus)
+
+include_directories (${LOGGING_INCLUDE_DIRS})
+link_directories (${LOGGING_LIBRARY_DIRS})
+
+set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
+set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
+
+install (TARGETS psuredundancy DESTINATION bin)
+install (FILES
+ ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.coldredundancy.service
+ DESTINATION ${SERVICE_FILE_INSTALL_DIR})
diff --git a/psu-manager/LICENSE b/psu-manager/LICENSE
new file mode 100644
index 0000000..8dada3e
--- /dev/null
+++ b/psu-manager/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/psu-manager/cmake-format.json b/psu-manager/cmake-format.json
new file mode 100644
index 0000000..4a68fb7
--- /dev/null
+++ b/psu-manager/cmake-format.json
@@ -0,0 +1,13 @@
+{
+ "enum_char": ".",
+ "line_ending": "unix",
+ "bullet_char": "*",
+ "max_subargs_per_line": 99,
+ "command_case": "lower",
+ "tab_size": 4,
+ "line_width": 80,
+ "separate_fn_name_with_space": true,
+ "dangle_parens": true,
+ "separate_ctrl_name_with_space": true
+}
+
diff --git a/psu-manager/include/coldRedundancy.hpp b/psu-manager/include/coldRedundancy.hpp
new file mode 100644
index 0000000..9eba4e9
--- /dev/null
+++ b/psu-manager/include/coldRedundancy.hpp
@@ -0,0 +1,71 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <sdbusplus/asio/object_server.hpp>
+#include <utility.hpp>
+#include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp>
+
+const constexpr char* psuInterface =
+ "/xyz/openbmc_project/inventory/system/powersupply/";
+const constexpr int secondsInOneDay = 86400;
+const constexpr uint8_t bmcSpecific = 0;
+
+class ColdRedundancy
+ : sdbusplus::xyz::openbmc_project::Control::server::PowerSupplyRedundancy
+{
+ public:
+ ColdRedundancy(
+ boost::asio::io_service& io,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
+ ~ColdRedundancy() = default;
+
+ void
+ createPSU(boost::asio::io_service& io,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
+
+ private:
+ bool crSupported = true;
+ bool crEnabled = true;
+ bool rotationEnabled = true;
+ uint8_t rotationAlgo = 0;
+ uint8_t psOrder;
+ uint8_t numberOfPSU = 0;
+ uint32_t rotationPeriod = 7 * secondsInOneDay;
+
+ std::shared_ptr<sdbusplus::asio::connection>& systemBus;
+
+ std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+ boost::asio::deadline_timer timerRotation;
+ boost::asio::deadline_timer timerCheck;
+};
+
+constexpr const uint8_t pmbusCmdCRSupport = 0xd0;
+
+class PowerSupply
+{
+ public:
+ PowerSupply(
+ std::string name, uint8_t bus, uint8_t address,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
+ ~PowerSupply();
+ std::string name;
+ uint8_t order = 0;
+ uint8_t bus;
+ uint8_t address;
+ PSUState state = PSUState::normal;
+};
diff --git a/psu-manager/include/utility.hpp b/psu-manager/include/utility.hpp
new file mode 100644
index 0000000..0b4d834
--- /dev/null
+++ b/psu-manager/include/utility.hpp
@@ -0,0 +1,56 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#pragma once
+#include <boost/container/flat_map.hpp>
+#include <chrono>
+#include <cstdint>
+#include <iostream>
+#include <sdbusplus/asio/connection.hpp>
+
+const constexpr char* entityManagerName = "xyz.openbmc_project.EntityManager";
+static const constexpr std::array<const char*, 1> psuEventInterface = {
+ "xyz.openbmc_project.State.Decorator.OperationalStatus"};
+
+using BasicVariantType =
+ std::variant<std::vector<std::string>, std::string, int64_t, uint64_t,
+ double, int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>;
+
+// using PropertyMapType =
+// std::vector<std::pair<std::string, BasicVariantType>>;
+using PropertyMapType =
+ boost::container::flat_map<std::string, BasicVariantType>;
+
+using GetSubTreeType = std::vector<
+ std::pair<std::string,
+ std::vector<std::pair<std::string, std::vector<std::string>>>>>;
+
+constexpr std::chrono::microseconds dbusTimeout(5000);
+
+using Value = sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t,
+ int32_t, uint32_t, int64_t, uint64_t,
+ double, std::string>;
+
+enum class PSUState
+{
+ normal,
+ acLost
+};
+
+void getPSUEvent(
+ const std::array<const char*, 1>& type,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ const std::string& psuName, PSUState& state);
diff --git a/psu-manager/service_files/xyz.openbmc_project.coldredundancy.service b/psu-manager/service_files/xyz.openbmc_project.coldredundancy.service
new file mode 100644
index 0000000..f6adf16
--- /dev/null
+++ b/psu-manager/service_files/xyz.openbmc_project.coldredundancy.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Intel BMC PSU Cold Redundancy
+
+[Service]
+Restart=always
+RestartSec=5
+StartLimitBurst=10
+ExecStart=/usr/bin/env psuredundancy
+SyslogIdentifier=psuredundancy
+
+[Install]
+WantedBy=multi-user.target
diff --git a/psu-manager/src/coldRedundancy.cpp b/psu-manager/src/coldRedundancy.cpp
new file mode 100644
index 0000000..308d17a
--- /dev/null
+++ b/psu-manager/src/coldRedundancy.cpp
@@ -0,0 +1,204 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <array>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_set.hpp>
+#include <coldRedundancy.hpp>
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <phosphor-logging/elog-errors.hpp>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/asio/sd_event.hpp>
+#include <utility.hpp>
+
+static constexpr const bool debug = false;
+
+static constexpr const std::array<const char*, 1> psuInterfaceTypes = {
+ "xyz.openbmc_project.Configuration.pmbus"};
+static const constexpr char* inventoryPath = "/xyz/openbmc_project/inventory";
+static const constexpr char* eventPath = "/xyz/openbmc_project/State/Decorator";
+static const constexpr char* coldRedundancyPath =
+ "/xyz/openbmc_project/control/power_supply_redundancy";
+
+static std::vector<std::unique_ptr<PowerSupply>> powerSupplies;
+
+ColdRedundancy::ColdRedundancy(
+ boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& systemBus) :
+ sdbusplus::xyz::openbmc_project::Control::server::PowerSupplyRedundancy(
+ *systemBus, coldRedundancyPath),
+ timerRotation(io), timerCheck(io), systemBus(systemBus)
+{
+ io.post([this, &io, &objectServer, &systemBus]() {
+ createPSU(io, objectServer, systemBus);
+ });
+ std::function<void(sdbusplus::message::message&)> eventHandler =
+ [this, &io, &objectServer,
+ &systemBus](sdbusplus::message::message& message) {
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ boost::asio::deadline_timer filterTimer(io);
+ filterTimer.expires_from_now(boost::posix_time::seconds(1));
+ filterTimer.async_wait([this, &io, &objectServer, &systemBus](
+ const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+ else if (ec)
+ {
+ std::cerr << "timer error\n";
+ }
+ createPSU(io, objectServer, systemBus);
+ });
+ };
+ for (const char* type : psuInterfaceTypes)
+ {
+ auto match = std::make_unique<sdbusplus::bus::match::match>(
+ static_cast<sdbusplus::bus::bus&>(*systemBus),
+ "type='signal',member='PropertiesChanged',path_namespace='" +
+ std::string(inventoryPath) + "',arg0namespace='" + type + "'",
+ eventHandler);
+ matches.emplace_back(std::move(match));
+ }
+
+ io.run();
+}
+
+// Check PSU information from entity-manager D-Bus interface and use the bus
+// address to create PSU Class for cold redundancy.
+void ColdRedundancy::createPSU(
+ boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn)
+{
+ std::vector<PropertyMapType> sensorConfigs;
+ numberOfPSU = 0;
+ powerSupplies.clear();
+ sensorConfigs.clear();
+
+ // call mapper to get matched obj paths
+ conn->async_method_call(
+ [this, &conn, &sensorConfigs](const boost::system::error_code ec,
+ GetSubTreeType subtree) {
+ if (ec)
+ {
+ std::cerr << "Exception happened when communicating to "
+ "ObjectMapper\n";
+ return;
+ }
+ if (debug)
+ {
+ std::cerr << "get valid subtree\n";
+ }
+ for (const auto& object : subtree)
+ {
+ std::string pathName = object.first;
+ for (const auto& serviceIface : object.second)
+ {
+ std::string serviceName = serviceIface.first;
+ for (const auto& interface : serviceIface.second)
+ {
+ // only get property of matched interface
+ bool isIfaceMatched = false;
+ for (const auto& type : psuInterfaceTypes)
+ {
+ if (type == interface)
+ {
+ isIfaceMatched = true;
+ break;
+ }
+ }
+ if (!isIfaceMatched)
+ continue;
+
+ conn->async_method_call(
+ [this, &conn,
+ &sensorConfigs](const boost::system::error_code ec,
+ PropertyMapType propMap) {
+ if (ec)
+ {
+ std::cerr
+ << "Exception happened when get all "
+ "properties\n";
+ return;
+ }
+ if (debug)
+ {
+ std::cerr << "get valid propMap\n";
+ }
+ // sensorConfigs.emplace_back(propMap);
+ auto configBus =
+ std::get_if<uint64_t>(&propMap["Bus"]);
+ auto configAddress =
+ std::get_if<uint64_t>(&propMap["Address"]);
+ auto configName =
+ std::get_if<std::string>(&propMap["Name"]);
+
+ if (configBus == nullptr ||
+ configAddress == nullptr ||
+ configName == nullptr)
+ {
+ std::cerr << "error finding necessary "
+ "entry in configuration\n";
+ return;
+ }
+
+ powerSupplies.emplace_back(
+ std::make_unique<PowerSupply>(
+ *configName,
+ static_cast<uint8_t>(*configBus),
+ static_cast<uint8_t>(*configAddress),
+ conn));
+ numberOfPSU++;
+ },
+ serviceName.c_str(), pathName.c_str(),
+ "org.freedesktop.DBus.Properties", "GetAll",
+ interface);
+ }
+ }
+ }
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/inventory/system/powersupply", 2,
+ psuInterfaceTypes);
+}
+
+PowerSupply::PowerSupply(
+ std::string name, uint8_t bus, uint8_t address,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) :
+ name(name),
+ bus(bus), address(address)
+{
+ getPSUEvent(psuEventInterface, dbusConnection, name, state);
+ if (debug)
+ {
+ std::cerr << "psu state " << static_cast<int>(state) << "\n";
+ }
+}
+
+PowerSupply::~PowerSupply()
+{
+}
diff --git a/psu-manager/src/redundancyMain.cpp b/psu-manager/src/redundancyMain.cpp
new file mode 100644
index 0000000..fa147c5
--- /dev/null
+++ b/psu-manager/src/redundancyMain.cpp
@@ -0,0 +1,31 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <coldRedundancy.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+int main(int argc, char** argv)
+{
+ boost::asio::io_service io;
+ auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+
+ systemBus->request_name("xyz.openbmc_project.PSURedundancy");
+ sdbusplus::asio::object_server objectServer(systemBus);
+
+ ColdRedundancy coldRedundancy(io, objectServer, systemBus);
+
+ return 0;
+}
diff --git a/psu-manager/src/utility.cpp b/psu-manager/src/utility.cpp
new file mode 100644
index 0000000..0b9581e
--- /dev/null
+++ b/psu-manager/src/utility.cpp
@@ -0,0 +1,102 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include "utility.hpp"
+
+#include <boost/algorithm/string/predicate.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+
+extern "C" {
+#include <i2c/smbus.h>
+#include <linux/i2c-dev.h>
+}
+
+void getPSUEvent(const std::array<const char*, 1>& configTypes,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::string& psuName, PSUState& state)
+{
+
+ conn->async_method_call(
+ [&conn, &state, &psuName, &configTypes](
+ const boost::system::error_code ec, GetSubTreeType subtree) {
+ if (ec)
+ {
+ std::cerr << "Exception happened when communicating to "
+ "ObjectMapper\n";
+ return;
+ }
+ state = PSUState::normal;
+
+ for (const auto& object : subtree)
+ {
+ std::string pathStr = object.first;
+
+ // /State/Decorator/PSUx_OperationalStatus
+ auto slantingPos = pathStr.find_last_of("/\\") + 1;
+ std::string statePSUName = pathStr.substr(slantingPos);
+ auto hypenPos = statePSUName.find("_");
+
+ std::string name = statePSUName.substr(0, hypenPos);
+ if (name != psuName)
+ {
+ continue;
+ }
+ for (const auto& serviceIface : object.second)
+ {
+ std::string serviceName = serviceIface.first;
+ for (const auto& interface : serviceIface.second)
+ {
+ // only get property of matched interface
+ bool isIfaceMatched = false;
+ for (const auto& type : configTypes)
+ {
+ if (type == interface)
+ {
+ isIfaceMatched = true;
+ break;
+ }
+ }
+ if (!isIfaceMatched)
+ continue;
+
+ conn->async_method_call(
+ [&conn, &state](const boost::system::error_code ec,
+ const bool& result) {
+ if (ec)
+ {
+ std::cerr << "Exception happened when get "
+ "functional propert\n";
+ return;
+ }
+
+ if (!result)
+ {
+ state = PSUState::acLost;
+ }
+ return;
+ },
+ serviceName.c_str(), pathStr.c_str(),
+ "org.freedesktop.DBus.Properties", "Get",
+ interface.c_str(), "functional");
+ }
+ }
+ }
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/State/Decorator", 1, configTypes);
+}