diff options
| author | Patrick Venture <venture@google.com> | 2018-11-01 15:39:53 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-11-02 07:44:49 -0700 |
| commit | f78d90420967100233cc9c2a5e0834e9789e2637 (patch) | |
| tree | a2acee81dcaa830217753a84acf5af7c92a9c3f5 | |
| parent | e84b4ddb671d97cb4725ee2de18979c69e42b971 (diff) | |
| download | openpower-proc-control-f78d90420967100233cc9c2a5e0834e9789e2637.tar.gz openpower-proc-control-f78d90420967100233cc9c2a5e0834e9789e2637.zip | |
add .clang-format
Add .clang-format for automatic style.
Change-Id: I6d240009370179b5b8f1f646b0476a059ec6aa85
Signed-off-by: Patrick Venture <venture@google.com>
| -rw-r--r-- | .clang-format | 99 | ||||
| -rw-r--r-- | cfam_access.cpp | 59 | ||||
| -rw-r--r-- | cfam_access.hpp | 23 | ||||
| -rw-r--r-- | ext_interface.cpp | 30 | ||||
| -rw-r--r-- | filedescriptor.cpp | 18 | ||||
| -rw-r--r-- | filedescriptor.hpp | 73 | ||||
| -rw-r--r-- | p9_cfam.hpp | 36 | ||||
| -rw-r--r-- | proc_control.cpp | 21 | ||||
| -rw-r--r-- | procedures/openfsi/scan.cpp | 53 | ||||
| -rw-r--r-- | procedures/p9/cfam_overrides.cpp | 23 | ||||
| -rw-r--r-- | procedures/p9/cleanup_pcie.cpp | 7 | ||||
| -rw-r--r-- | procedures/p9/collect_sbe_hb_data.cpp | 54 | ||||
| -rw-r--r-- | procedures/p9/set_sync_fsi_clock_mode.cpp | 9 | ||||
| -rw-r--r-- | procedures/p9/start_host.cpp | 37 | ||||
| -rw-r--r-- | procedures/p9/vcs_workaround.cpp | 25 | ||||
| -rw-r--r-- | registration.cpp | 1 | ||||
| -rw-r--r-- | registration.hpp | 67 | ||||
| -rw-r--r-- | targeting.cpp | 37 | ||||
| -rw-r--r-- | targeting.hpp | 280 | ||||
| -rw-r--r-- | test/utest.cpp | 60 |
20 files changed, 532 insertions, 480 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ea71ad6 --- /dev/null +++ b/.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/cfam_access.cpp b/cfam_access.cpp index 78d95da..2538eb0 100644 --- a/cfam_access.cpp +++ b/cfam_access.cpp @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <phosphor-logging/elog.hpp> +#include "cfam_access.hpp" + +#include "targeting.hpp" + +#include <unistd.h> + #include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> #include <xyz/openbmc_project/Common/Device/error.hpp> #include <xyz/openbmc_project/Common/File/error.hpp> -#include <unistd.h> -#include "cfam_access.hpp" -#include "targeting.hpp" namespace openpower { @@ -32,10 +35,8 @@ constexpr auto cfamRegSize = 4; using namespace openpower::targeting; using namespace openpower::util; -namespace file_error = sdbusplus::xyz::openbmc_project:: - Common::File::Error; -namespace device_error = sdbusplus::xyz::openbmc_project:: - Common::Device::Error; +namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error; +namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error; /** * Converts the CFAM register address used by the calling @@ -47,9 +48,7 @@ static inline cfam_address_t makeOffset(cfam_address_t address) return (address & 0xFC00) | ((address & 0x03FF) << 2); } - -void writeReg(const std::unique_ptr<Target>& target, - cfam_address_t address, +void writeReg(const std::unique_ptr<Target>& target, cfam_address_t address, cfam_data_t data) { using namespace phosphor::logging; @@ -57,15 +56,14 @@ void writeReg(const std::unique_ptr<Target>& target, if (rc < 0) { log<level::ERR>("Failed seeking on a processor CFAM", - entry("CFAM_ADDRESS=0x%X", address)); + entry("CFAM_ADDRESS=0x%X", address)); using metadata = xyz::openbmc_project::Common::File::Seek; - elog<file_error::Seek>( - metadata::OFFSET(makeOffset(address)), - metadata::WHENCE(SEEK_SET), - metadata::ERRNO(errno), - metadata::PATH(target->getCFAMPath().c_str())); + elog<file_error::Seek>(metadata::OFFSET(makeOffset(address)), + metadata::WHENCE(SEEK_SET), + metadata::ERRNO(errno), + metadata::PATH(target->getCFAMPath().c_str())); } data = target->swapEndian(data); @@ -76,13 +74,11 @@ void writeReg(const std::unique_ptr<Target>& target, using metadata = xyz::openbmc_project::Common::Device::WriteFailure; elog<device_error::WriteFailure>( - metadata::CALLOUT_ERRNO(errno), - metadata::CALLOUT_DEVICE_PATH( - target->getCFAMPath().c_str())); + metadata::CALLOUT_ERRNO(errno), + metadata::CALLOUT_DEVICE_PATH(target->getCFAMPath().c_str())); } } - cfam_data_t readReg(const std::unique_ptr<Target>& target, cfam_address_t address) { @@ -94,15 +90,14 @@ cfam_data_t readReg(const std::unique_ptr<Target>& target, if (rc < 0) { log<level::ERR>("Failed seeking on a processor CFAM", - entry("CFAM_ADDRESS=0x%X", address)); + entry("CFAM_ADDRESS=0x%X", address)); using metadata = xyz::openbmc_project::Common::File::Seek; - elog<file_error::Seek>( - metadata::OFFSET(makeOffset(address)), - metadata::WHENCE(SEEK_SET), - metadata::ERRNO(errno), - metadata::PATH(target->getCFAMPath().c_str())); + elog<file_error::Seek>(metadata::OFFSET(makeOffset(address)), + metadata::WHENCE(SEEK_SET), + metadata::ERRNO(errno), + metadata::PATH(target->getCFAMPath().c_str())); } rc = read(target->getCFAMFD(), &data, cfamRegSize); @@ -118,10 +113,8 @@ cfam_data_t readReg(const std::unique_ptr<Target>& target, return target->swapEndian(data); } - void writeRegWithMask(const std::unique_ptr<Target>& target, - cfam_address_t address, - cfam_data_t data, + cfam_address_t address, cfam_data_t data, cfam_mask_t mask) { cfam_data_t readData = readReg(target, address); @@ -132,6 +125,6 @@ void writeRegWithMask(const std::unique_ptr<Target>& target, writeReg(target, address, readData); } -} -} -} +} // namespace access +} // namespace cfam +} // namespace openpower diff --git a/cfam_access.hpp b/cfam_access.hpp index 88dcc77..131376c 100644 --- a/cfam_access.hpp +++ b/cfam_access.hpp @@ -1,8 +1,9 @@ #pragma once -#include <memory> #include "targeting.hpp" +#include <memory> + namespace openpower { namespace cfam @@ -24,9 +25,7 @@ using cfam_mask_t = uint32_t; * @param[in] data - The data to write */ void writeReg(const std::unique_ptr<openpower::targeting::Target>& target, - cfam_address_t address, - cfam_data_t data); - + cfam_address_t address, cfam_data_t data); /** * @brief Reads a CFAM (Common FRU Access Macro) register in a P9. @@ -37,10 +36,8 @@ void writeReg(const std::unique_ptr<openpower::targeting::Target>& target, * @param[in] address - The register address to read * @return - The register data */ -cfam_data_t readReg( - const std::unique_ptr<openpower::targeting::Target>& target, - cfam_address_t address); - +cfam_data_t readReg(const std::unique_ptr<openpower::targeting::Target>& target, + cfam_address_t address); /** * @brief Writes a CFAM (Common FRU Access Macro) register in a P9 @@ -57,9 +54,7 @@ cfam_data_t readReg( */ void writeRegWithMask( const std::unique_ptr<openpower::targeting::Target>& target, - cfam_address_t address, - cfam_data_t data, - cfam_mask_t mask); -} -} -} + cfam_address_t address, cfam_data_t data, cfam_mask_t mask); +} // namespace access +} // namespace cfam +} // namespace openpower diff --git a/ext_interface.cpp b/ext_interface.cpp index b1902d4..554da80 100644 --- a/ext_interface.cpp +++ b/ext_interface.cpp @@ -1,7 +1,7 @@ -#include <string> -#include <sdbusplus/server.hpp> -#include <phosphor-logging/log.hpp> #include <ext_interface.hpp> +#include <phosphor-logging/log.hpp> +#include <sdbusplus/server.hpp> +#include <string> // Mapper constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; @@ -10,7 +10,8 @@ constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; // Reboot count constexpr auto REBOOTCOUNTER_PATH("/xyz/openbmc_project/state/host0"); -constexpr auto REBOOTCOUNTER_INTERFACE("xyz.openbmc_project.Control.Boot.RebootAttempts"); +constexpr auto + REBOOTCOUNTER_INTERFACE("xyz.openbmc_project.Control.Boot.RebootAttempts"); using namespace phosphor::logging; @@ -26,15 +27,12 @@ using namespace phosphor::logging; * * @return distinct dbus name for input interface/path **/ -std::string getService(sdbusplus::bus::bus& bus, - const std::string& intf, +std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, const std::string& path) { - auto mapper = bus.new_method_call(MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject"); + auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, + MAPPER_INTERFACE, "GetObject"); mapper.append(path); mapper.append(std::vector<std::string>({intf})); @@ -59,19 +57,15 @@ std::string getService(sdbusplus::bus::bus& bus, return mapperResponse.begin()->first; } - uint32_t getBootCount() { auto bus = sdbusplus::bus::new_default(); - auto rebootSvc = getService(bus, - REBOOTCOUNTER_INTERFACE, - REBOOTCOUNTER_PATH); + auto rebootSvc = + getService(bus, REBOOTCOUNTER_INTERFACE, REBOOTCOUNTER_PATH); - auto method = bus.new_method_call(rebootSvc.c_str(), - REBOOTCOUNTER_PATH, - "org.freedesktop.DBus.Properties", - "Get"); + auto method = bus.new_method_call(rebootSvc.c_str(), REBOOTCOUNTER_PATH, + "org.freedesktop.DBus.Properties", "Get"); method.append(REBOOTCOUNTER_INTERFACE, "AttemptsLeft"); auto reply = bus.call(method); diff --git a/filedescriptor.cpp b/filedescriptor.cpp index 89f77e2..c96249e 100644 --- a/filedescriptor.cpp +++ b/filedescriptor.cpp @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <stdexcept> +#include "filedescriptor.hpp" + #include <unistd.h> -#include <phosphor-logging/elog.hpp> + #include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> +#include <stdexcept> #include <xyz/openbmc_project/Common/File/error.hpp> -#include "filedescriptor.hpp" namespace openpower { @@ -37,13 +39,11 @@ FileDescriptor::FileDescriptor(const std::string& path) { using metadata = xyz::openbmc_project::Common::File::Open; - elog<file_error::Open>( - metadata::ERRNO(errno), - metadata::PATH(path.c_str())); + elog<file_error::Open>(metadata::ERRNO(errno), + metadata::PATH(path.c_str())); } } - FileDescriptor::~FileDescriptor() { if (fd >= 0) @@ -52,5 +52,5 @@ FileDescriptor::~FileDescriptor() } } -} -} +} // namespace util +} // namespace openpower diff --git a/filedescriptor.hpp b/filedescriptor.hpp index 2a4c6d0..7179398 100644 --- a/filedescriptor.hpp +++ b/filedescriptor.hpp @@ -1,6 +1,7 @@ #pragma once #include <fcntl.h> + #include <string> namespace openpower @@ -16,42 +17,40 @@ namespace util */ class FileDescriptor { - public: - - FileDescriptor() = delete; - FileDescriptor(const FileDescriptor&) = delete; - FileDescriptor(FileDescriptor&&) = default; - FileDescriptor& operator=(const FileDescriptor) = delete; - FileDescriptor& operator=(FileDescriptor&&) = default; - - /** - * Creates a file descriptor by opening the device - * path passed in. - * - * @param path[in] - the device path that will be open - */ - FileDescriptor(const std::string& path); - - /** - * Closes the file. - */ - ~FileDescriptor(); - - /** - * The method to access the file descriptor value - */ - inline auto get() const - { - return fd; - } - - private: - - /** - * The actual file descriptor - */ - int fd; + public: + FileDescriptor() = delete; + FileDescriptor(const FileDescriptor&) = delete; + FileDescriptor(FileDescriptor&&) = default; + FileDescriptor& operator=(const FileDescriptor) = delete; + FileDescriptor& operator=(FileDescriptor&&) = default; + + /** + * Creates a file descriptor by opening the device + * path passed in. + * + * @param path[in] - the device path that will be open + */ + FileDescriptor(const std::string& path); + + /** + * Closes the file. + */ + ~FileDescriptor(); + + /** + * The method to access the file descriptor value + */ + inline auto get() const + { + return fd; + } + + private: + /** + * The actual file descriptor + */ + int fd; }; -} -} +} // namespace util +} // namespace openpower diff --git a/p9_cfam.hpp b/p9_cfam.hpp index 19b6e33..4ffdc6d 100644 --- a/p9_cfam.hpp +++ b/p9_cfam.hpp @@ -7,22 +7,22 @@ namespace cfam namespace p9 { -static constexpr uint32_t P9_DD10_CHIPID = 0x120D1049; +static constexpr uint32_t P9_DD10_CHIPID = 0x120D1049; -static constexpr uint16_t P9_FSI_A_SI1S = 0x081C; -static constexpr uint16_t P9_LL_MODE_REG = 0x0840; -static constexpr uint16_t P9_FSI2PIB_CHIPID = 0x100A; -static constexpr uint16_t P9_FSI2PIB_INTERRUPT = 0x100B; -static constexpr uint16_t P9_FSI2PIB_TRUE_MASK = 0x100D; -static constexpr uint16_t P9_CBS_CS = 0x2801; -static constexpr uint16_t P9_SBE_CTRL_STATUS = 0x2808; -static constexpr uint16_t P9_SBE_MSG_REGISTER = 0x2809; -static constexpr uint16_t P9_ROOT_CTRL0 = 0x2810; -static constexpr uint16_t P9_PERV_CTRL0 = 0x281A; -static constexpr uint16_t P9_HB_MBX5_REG = 0x283C; -static constexpr uint16_t P9_SCRATCH_REGISTER_8 = 0x283F; -static constexpr uint16_t P9_ROOT_CTRL8 = 0x2918; -static constexpr uint16_t P9_ROOT_CTRL1_CLEAR = 0x2931; -} -} -} +static constexpr uint16_t P9_FSI_A_SI1S = 0x081C; +static constexpr uint16_t P9_LL_MODE_REG = 0x0840; +static constexpr uint16_t P9_FSI2PIB_CHIPID = 0x100A; +static constexpr uint16_t P9_FSI2PIB_INTERRUPT = 0x100B; +static constexpr uint16_t P9_FSI2PIB_TRUE_MASK = 0x100D; +static constexpr uint16_t P9_CBS_CS = 0x2801; +static constexpr uint16_t P9_SBE_CTRL_STATUS = 0x2808; +static constexpr uint16_t P9_SBE_MSG_REGISTER = 0x2809; +static constexpr uint16_t P9_ROOT_CTRL0 = 0x2810; +static constexpr uint16_t P9_PERV_CTRL0 = 0x281A; +static constexpr uint16_t P9_HB_MBX5_REG = 0x283C; +static constexpr uint16_t P9_SCRATCH_REGISTER_8 = 0x283F; +static constexpr uint16_t P9_ROOT_CTRL8 = 0x2918; +static constexpr uint16_t P9_ROOT_CTRL1_CLEAR = 0x2931; +} // namespace p9 +} // namespace cfam +} // namespace openpower diff --git a/proc_control.cpp b/proc_control.cpp index 5668c00..b295c13 100644 --- a/proc_control.cpp +++ b/proc_control.cpp @@ -13,25 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "registration.hpp" + #include <algorithm> #include <functional> #include <iostream> -#include <phosphor-logging/log.hpp> -#include <phosphor-logging/elog.hpp> -#include <phosphor-logging/elog-errors.hpp> #include <org/open_power/Proc/FSI/error.hpp> -#include <xyz/openbmc_project/Common/error.hpp> +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> +#include <phosphor-logging/log.hpp> #include <xyz/openbmc_project/Common/Device/error.hpp> #include <xyz/openbmc_project/Common/File/error.hpp> -#include "registration.hpp" +#include <xyz/openbmc_project/Common/error.hpp> using namespace openpower::util; -namespace common_error = sdbusplus::xyz::openbmc_project:: - Common::Error; -namespace device_error = sdbusplus::xyz::openbmc_project:: - Common::Device::Error; -namespace file_error = sdbusplus::xyz::openbmc_project:: - Common::File::Error; +namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error; +namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error; +namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error; namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error; void usage(char** argv, const ProcedureMap& procedures) @@ -106,6 +104,5 @@ int main(int argc, char** argv) return -1; } - return 0; } diff --git a/procedures/openfsi/scan.cpp b/procedures/openfsi/scan.cpp index e616e7f..a9693fb 100644 --- a/procedures/openfsi/scan.cpp +++ b/procedures/openfsi/scan.cpp @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "registration.hpp" + #include <experimental/filesystem> #include <fstream> #include <org/open_power/Proc/FSI/error.hpp> #include <phosphor-logging/log.hpp> -#include "registration.hpp" namespace openpower { @@ -29,16 +30,14 @@ namespace fs = std::experimental::filesystem; namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error; constexpr auto masterScanPath = - "/sys/bus/platform/devices/gpio-fsi/fsi0/rescan"; + "/sys/bus/platform/devices/gpio-fsi/fsi0/rescan"; -constexpr auto hubScanPath = - "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/" - "00:00:00:0a/fsi1/rescan"; +constexpr auto hubScanPath = "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/" + "00:00:00:0a/fsi1/rescan"; constexpr auto masterCalloutPath = "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/raw"; - /** * Writes a 1 to the sysfs file passed in to trigger * the device driver to do an FSI scan. @@ -49,9 +48,9 @@ static void doScan(const std::string& path) { std::ofstream file; - file.exceptions(std::ofstream::failbit | //logic error on operation - std::ofstream::badbit | //read/write error on operation - std::ofstream::eofbit); //end of file reached + file.exceptions(std::ofstream::failbit | // logic error on operation + std::ofstream::badbit | // read/write error on operation + std::ofstream::eofbit); // end of file reached try { file.open(path); @@ -72,12 +71,12 @@ static void doScan(const std::string& path) */ void scan() { - //Note: Currently the FSI device driver will always return success on both - //the master and hub scans. The only way we can detect something - //went wrong is if the master scan didn't create the hub scan file, so - //we will check for that. - //It is possible the driver will be updated in the future to actually - //return a failure so the code will still check for them. + // Note: Currently the FSI device driver will always return success on both + // the master and hub scans. The only way we can detect something + // went wrong is if the master scan didn't create the hub scan file, so + // we will check for that. + // It is possible the driver will be updated in the future to actually + // return a failure so the code will still check for them. try { @@ -90,8 +89,8 @@ void scan() using metadata = org::open_power::Proc::FSI::MasterDetectionFailure; elog<fsi_error::MasterDetectionFailure>( - metadata::CALLOUT_ERRNO(e.code().value()), - metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); + metadata::CALLOUT_ERRNO(e.code().value()), + metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); } if (!fs::exists(hubScanPath)) @@ -101,8 +100,8 @@ void scan() using metadata = org::open_power::Proc::FSI::MasterDetectionFailure; elog<fsi_error::MasterDetectionFailure>( - metadata::CALLOUT_ERRNO(0), - metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); + metadata::CALLOUT_ERRNO(0), + metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); } try @@ -111,22 +110,22 @@ void scan() } catch (std::system_error& e) { - //If the device driver is ever updated in the future to fail the sysfs - //write call on a scan failure then it should also provide some hints - //about which hardware failed so we can do an appropriate callout - //here. At this point in time, the driver shouldn't ever fail so - //we won't worry about guessing at the callout. + // If the device driver is ever updated in the future to fail the sysfs + // write call on a scan failure then it should also provide some hints + // about which hardware failed so we can do an appropriate callout + // here. At this point in time, the driver shouldn't ever fail so + // we won't worry about guessing at the callout. log<level::ERR>("Failed to run the FSI hub scan"); using metadata = org::open_power::Proc::FSI::SlaveDetectionFailure; elog<fsi_error::SlaveDetectionFailure>( - metadata::ERRNO(e.code().value())); + metadata::ERRNO(e.code().value())); } } REGISTER_PROCEDURE("scanFSI", scan); -} -} +} // namespace openfsi +} // namespace openpower diff --git a/procedures/p9/cfam_overrides.cpp b/procedures/p9/cfam_overrides.cpp index a594e0c..13f7659 100644 --- a/procedures/p9/cfam_overrides.cpp +++ b/procedures/p9/cfam_overrides.cpp @@ -1,12 +1,13 @@ -#include <fstream> -#include <sstream> -#include <iostream> #include "cfam_access.hpp" #include "p9_cfam.hpp" #include "registration.hpp" #include "targeting.hpp" -#include <phosphor-logging/elog.hpp> + +#include <fstream> +#include <iostream> #include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> +#include <sstream> #include <xyz/openbmc_project/Common/error.hpp> /* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters @@ -24,7 +25,8 @@ using namespace openpower::cfam::access; using namespace openpower::targeting; using namespace openpower::util; -void CFAMOverride() { +void CFAMOverride() +{ int pos = 0; cfam_address_t address = 0; cfam_data_t data = 0; @@ -38,7 +40,7 @@ void CFAMOverride() { if (overrides.is_open()) { - while (std::getline(overrides,line)) + while (std::getline(overrides, line)) { if (!line.empty()) { @@ -47,7 +49,7 @@ void CFAMOverride() { { mask = 0xFFFFFFFF; if (sscanf(line.c_str(), "%x %hx %x %x", &pos, &address, - &data, &mask) >= 3) + &data, &mask) >= 3) { const auto& target = targets.getTarget(pos); writeRegWithMask(target, address, data, mask); @@ -60,7 +62,8 @@ void CFAMOverride() { phosphor::logging::xyz::openbmc_project::Common; phosphor::logging::elog<error::InvalidArgument>( metadata::InvalidArgument::ARGUMENT_NAME("line"), - metadata::InvalidArgument::ARGUMENT_VALUE(line.c_str())); + metadata::InvalidArgument::ARGUMENT_VALUE( + line.c_str())); } } } @@ -73,5 +76,5 @@ void CFAMOverride() { REGISTER_PROCEDURE("CFAMOverride", CFAMOverride); -} -} +} // namespace p9 +} // namespace openpower diff --git a/procedures/p9/cleanup_pcie.cpp b/procedures/p9/cleanup_pcie.cpp index bfeb472..a0be3f5 100644 --- a/procedures/p9/cleanup_pcie.cpp +++ b/procedures/p9/cleanup_pcie.cpp @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <phosphor-logging/log.hpp>
#include "cfam_access.hpp"
#include "p9_cfam.hpp"
#include "registration.hpp"
#include "targeting.hpp"
+#include <phosphor-logging/log.hpp>
+
namespace openpower
{
namespace p9
@@ -46,5 +47,5 @@ void cleanupPcie() REGISTER_PROCEDURE("cleanupPcie", cleanupPcie);
-}
-}
+} // namespace p9
+} // namespace openpower
diff --git a/procedures/p9/collect_sbe_hb_data.cpp b/procedures/p9/collect_sbe_hb_data.cpp index 436a379..b29d194 100644 --- a/procedures/p9/collect_sbe_hb_data.cpp +++ b/procedures/p9/collect_sbe_hb_data.cpp @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <phosphor-logging/log.hpp> #include "cfam_access.hpp" #include "p9_cfam.hpp" #include "registration.hpp" #include "targeting.hpp" +#include <phosphor-logging/log.hpp> + namespace openpower { namespace p9 @@ -61,21 +62,21 @@ union MboxScratch5_HB_t struct { #if __BYTE_ORDER == __LITTLE_ENDIAN - uint32_t minorStep :8; //24:31 - uint32_t majorStep :8; //16:23 - uint32_t internalStep :4; //12:15 - uint32_t reserved :2; //10:11 - uint32_t stepFinish :1; //9 - uint32_t stepStart :1; //8 - uint32_t magic :8; //0:7 + uint32_t minorStep : 8; // 24:31 + uint32_t majorStep : 8; // 16:23 + uint32_t internalStep : 4; // 12:15 + uint32_t reserved : 2; // 10:11 + uint32_t stepFinish : 1; // 9 + uint32_t stepStart : 1; // 8 + uint32_t magic : 8; // 0:7 #else - uint32_t magic :8; //0:7 - uint32_t stepStart :1; //8 - uint32_t stepFinish :1; //9 - uint32_t reserved :2; //10:11 - uint32_t internalStep :4; //12:15 - uint32_t majorStep :8; //16:23 - uint32_t minorStep :8; //24:31 + uint32_t magic : 8; // 0:7 + uint32_t stepStart : 1; // 8 + uint32_t stepFinish : 1; // 9 + uint32_t reserved : 2; // 10:11 + uint32_t internalStep : 4; // 12:15 + uint32_t majorStep : 8; // 16:23 + uint32_t minorStep : 8; // 24:31 #endif } PACKED; }; @@ -95,7 +96,7 @@ void collectSBEHBData() Targeting targets; - for (const auto& proc: targets) + for (const auto& proc : targets) { // Read and parse SBE messaging register try @@ -103,14 +104,10 @@ void collectSBEHBData() auto readData = readReg(proc, P9_SBE_MSG_REGISTER); auto msg = reinterpret_cast<const sbeMsgReg_t*>(&readData); log<level::INFO>("SBE status register", - entry("PROC=%d", - proc->getPos()), - entry("SBE_MAJOR_ISTEP=%d", - msg->PACKED.majorStep), - entry("SBE_MINOR_ISTEP=%d", - msg->PACKED.minorStep), - entry("REG_VAL=0x%08X", - msg->data32)); + entry("PROC=%d", proc->getPos()), + entry("SBE_MAJOR_ISTEP=%d", msg->PACKED.majorStep), + entry("SBE_MINOR_ISTEP=%d", msg->PACKED.minorStep), + entry("REG_VAL=0x%08X", msg->data32)); } catch (const std::exception& e) { @@ -128,12 +125,9 @@ void collectSBEHBData() if (HB_MBX5_VALID_FLAG == msg->PACKED.magic) { log<level::INFO>("HB MBOX 5 register", - entry("HB_MAJOR_ISTEP=%d", - msg->PACKED.majorStep), - entry("HB_MINOR_ISTEP=%d", - msg->PACKED.minorStep), - entry("REG_VAL=0x%08X", - msg->data32)); + entry("HB_MAJOR_ISTEP=%d", msg->PACKED.majorStep), + entry("HB_MINOR_ISTEP=%d", msg->PACKED.minorStep), + entry("REG_VAL=0x%08X", msg->data32)); } } catch (const std::exception& e) diff --git a/procedures/p9/set_sync_fsi_clock_mode.cpp b/procedures/p9/set_sync_fsi_clock_mode.cpp index b17aec5..4ffff9f 100644 --- a/procedures/p9/set_sync_fsi_clock_mode.cpp +++ b/procedures/p9/set_sync_fsi_clock_mode.cpp @@ -27,7 +27,6 @@ using namespace openpower::cfam::access; using namespace openpower::cfam::p9; using namespace openpower::targeting; - /** * @Brief Sets the P9 FSI clock to synchronous mode. */ @@ -36,13 +35,11 @@ void setSynchronousFSIClock() Targeting targets; const auto& master = *(targets.begin()); - //Set bit 31 to 0 + // Set bit 31 to 0 writeRegWithMask(master, P9_LL_MODE_REG, 0x00000000, 0x00000001); } - REGISTER_PROCEDURE("setSyncFSIClock", setSynchronousFSIClock); -} -} - +} // namespace p9 +} // namespace openpower diff --git a/procedures/p9/start_host.cpp b/procedures/p9/start_host.cpp index 07020df..f959ce7 100644 --- a/procedures/p9/start_host.cpp +++ b/procedures/p9/start_host.cpp @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <phosphor-logging/log.hpp> #include "cfam_access.hpp" +#include "ext_interface.hpp" #include "p9_cfam.hpp" #include "registration.hpp" #include "targeting.hpp" -#include "ext_interface.hpp" + +#include <phosphor-logging/log.hpp> namespace openpower { @@ -30,7 +31,6 @@ using namespace openpower::cfam::access; using namespace openpower::cfam::p9; using namespace openpower::targeting; - /** * @brief Starts the self boot engine on P9 position 0 to kick off a boot. * @return void @@ -43,55 +43,54 @@ void startHost() log<level::INFO>("Running P9 procedure startHost", entry("NUM_PROCS=%d", targets.size())); - //Ensure asynchronous clock mode is set + // Ensure asynchronous clock mode is set writeReg(master, P9_LL_MODE_REG, 0x00000001); - //Clock mux select override + // Clock mux select override for (const auto& t : targets) { - writeRegWithMask(t, P9_ROOT_CTRL8, - 0x0000000C, 0x0000000C); + writeRegWithMask(t, P9_ROOT_CTRL8, 0x0000000C, 0x0000000C); } - //Enable P9 checkstop to be reported to the BMC + // Enable P9 checkstop to be reported to the BMC - //Setup FSI2PIB to report checkstop + // Setup FSI2PIB to report checkstop writeReg(master, P9_FSI_A_SI1S, 0x20000000); - //Enable Xstop/ATTN interrupt + // Enable Xstop/ATTN interrupt writeReg(master, P9_FSI2PIB_TRUE_MASK, 0x60000000); - //Arm it + // Arm it writeReg(master, P9_FSI2PIB_INTERRUPT, 0xFFFFFFFF); - //Kick off the SBE to start the boot + // Kick off the SBE to start the boot // Choose seeprom side to boot from cfam_data_t sbeSide = 0; - if(getBootCount() > 0) + if (getBootCount() > 0) { sbeSide = 0; log<level::INFO>("Setting SBE seeprom side to 0", - entry("SBE_SIDE_SELECT=%d", 0)); + entry("SBE_SIDE_SELECT=%d", 0)); } else { sbeSide = 0x00004000; log<level::INFO>("Setting SBE seeprom side to 1", - entry("SBE_SIDE_SELECT=%d", 1)); + entry("SBE_SIDE_SELECT=%d", 1)); } // Bit 17 of the ctrl status reg indicates sbe seeprom boot side // 0 -> Side 0, 1 -> Side 1 writeRegWithMask(master, P9_SBE_CTRL_STATUS, sbeSide, 0x00004000); - //Ensure ISTEP stepping isn't enabled + // Ensure ISTEP stepping isn't enabled writeRegWithMask(master, P9_SCRATCH_REGISTER_8, 0x20000000, 0x20000000); - //Start the SBE + // Start the SBE writeRegWithMask(master, P9_CBS_CS, 0x80000000, 0x80000000); } REGISTER_PROCEDURE("startHost", startHost); -} -} +} // namespace p9 +} // namespace openpower diff --git a/procedures/p9/vcs_workaround.cpp b/procedures/p9/vcs_workaround.cpp index e418971..fe3da3c 100644 --- a/procedures/p9/vcs_workaround.cpp +++ b/procedures/p9/vcs_workaround.cpp @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <phosphor-logging/log.hpp> #include "cfam_access.hpp" #include "p9_cfam.hpp" #include "registration.hpp" #include "targeting.hpp" +#include <phosphor-logging/log.hpp> + namespace openpower { namespace p9 @@ -29,7 +30,6 @@ using namespace openpower::cfam::access; using namespace openpower::cfam::p9; using namespace openpower::targeting; - /** * @brief Performs the 'VCS Workaround' on all P9s in the system. * @return void @@ -54,26 +54,23 @@ void vcsWorkaround() log<level::INFO>("Running P9 procedure vcsWorkaround", entry("NUM_PROCS=%d", targets.size())); - //Set asynchronous clock mode + // Set asynchronous clock mode writeReg(master, P9_LL_MODE_REG, 0x00000001); for (const auto& t : targets) { - //Unfence PLL controls - writeRegWithMask(t, P9_ROOT_CTRL0, - 0x00000000, 0x00010000); + // Unfence PLL controls + writeRegWithMask(t, P9_ROOT_CTRL0, 0x00000000, 0x00010000); - //Assert Perv chiplet endpoint reset - writeRegWithMask(t, P9_PERV_CTRL0, - 0x40000000, 0x40000000); + // Assert Perv chiplet endpoint reset + writeRegWithMask(t, P9_PERV_CTRL0, 0x40000000, 0x40000000); - //Enable Nest PLL - writeRegWithMask(t, P9_PERV_CTRL0, - 0x00000001, 0x00000001); + // Enable Nest PLL + writeRegWithMask(t, P9_PERV_CTRL0, 0x00000001, 0x00000001); } } REGISTER_PROCEDURE("vcsWorkaround", vcsWorkaround); -} -} +} // namespace p9 +} // namespace openpower diff --git a/registration.cpp b/registration.cpp index 9442c11..787d6cd 100644 --- a/registration.cpp +++ b/registration.cpp @@ -17,4 +17,3 @@ using namespace openpower::util; ProcedureMap Registration::procedures{}; - diff --git a/registration.hpp b/registration.hpp index d0dde00..0f093ff 100644 --- a/registration.hpp +++ b/registration.hpp @@ -1,9 +1,9 @@ #pragma once #include <functional> +#include <iostream> #include <map> #include <string> -#include <iostream> namespace openpower { @@ -18,13 +18,11 @@ using ProcedureMap = std::map<ProcedureName, ProcedureFunction>; * This macro can be used in each procedure cpp file to make it * available to the openpower-proc-control executable. */ -#define REGISTER_PROCEDURE(name, func) \ - namespace func##_ns \ - { \ - openpower::util::Registration r{ \ - std::move(name), std::move(func)}; \ - } - +#define REGISTER_PROCEDURE(name, func) \ + namespace func##_ns \ + { \ + openpower::util::Registration r{std::move(name), std::move(func)}; \ + } /** * Used to register procedures. Each procedure function can then @@ -32,33 +30,30 @@ using ProcedureMap = std::map<ProcedureName, ProcedureFunction>; */ class Registration { - public: - - /** - * Adds the procedure name and function to the internal - * procedure map. - * - * @param[in] name - the procedure name - * @param[in] function - the function to run - */ - Registration(ProcedureName&& name, - ProcedureFunction&& function) - { - procedures.emplace(std::move(name), std::move(function)); - } - - /** - * Returns the map of procedures - */ - static const ProcedureMap& getProcedures() - { - return procedures; - } - - private: - - static ProcedureMap procedures; + public: + /** + * Adds the procedure name and function to the internal + * procedure map. + * + * @param[in] name - the procedure name + * @param[in] function - the function to run + */ + Registration(ProcedureName&& name, ProcedureFunction&& function) + { + procedures.emplace(std::move(name), std::move(function)); + } + + /** + * Returns the map of procedures + */ + static const ProcedureMap& getProcedures() + { + return procedures; + } + + private: + static ProcedureMap procedures; }; -} -} +} // namespace util +} // namespace openpower diff --git a/targeting.cpp b/targeting.cpp index 5d55ac9..7dd68ef 100644 --- a/targeting.cpp +++ b/targeting.cpp @@ -14,15 +14,16 @@ * limitations under the License. */ +#include "targeting.hpp" + #include <endian.h> + #include <experimental/filesystem> -#include <phosphor-logging/elog.hpp> #include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> #include <phosphor-logging/log.hpp> #include <regex> #include <xyz/openbmc_project/Common/File/error.hpp> -#include "targeting.hpp" - namespace openpower { @@ -37,8 +38,8 @@ int Target::getCFAMFD() { if (cfamFD.get() == nullptr) { - cfamFD = std::make_unique< - openpower::util::FileDescriptor>(getCFAMPath()); + cfamFD = + std::make_unique<openpower::util::FileDescriptor>(getCFAMPath()); } return cfamFD->get(); @@ -46,10 +47,7 @@ int Target::getCFAMFD() std::unique_ptr<Target>& Targeting::getTarget(size_t pos) { - auto search = [pos](const auto& t) - { - return t->getPos() == pos; - }; + auto search = [pos](const auto& t) { return t->getPos() == pos; }; auto target = find_if(targets.begin(), targets.end(), search); if (target == targets.end()) @@ -62,7 +60,6 @@ std::unique_ptr<Target>& Targeting::getTarget(size_t pos) } } - static uint32_t noEndianSwap(uint32_t data) { return data; @@ -85,20 +82,20 @@ Targeting::Targeting(const std::string& fsiMasterDev, { std::regex expOld{"hub@00/slave@([0-9]{2}):00", std::regex::extended}; - //Fall back to old (4.7) path + // Fall back to old (4.7) path exp = expOld; fsiMasterPath = fsiMasterDevPathOld; fsiSlaveBasePath = fsiSlaveBaseDirOld; - //And don't swap the endianness of CFAM data + // And don't swap the endianness of CFAM data swapper = noEndianSwap; } - //Always create P0, the FSI master. + // Always create P0, the FSI master. targets.push_back(std::make_unique<Target>(0, fsiMasterPath, swapper)); try { - //Find the the remaining P9s dynamically based on which files show up + // Find the the remaining P9s dynamically based on which files show up for (auto& file : fs::directory_iterator(fsiSlaveBasePath)) { std::smatch match; @@ -123,18 +120,16 @@ Targeting::Targeting(const std::string& fsiMasterDev, { using metadata = xyz::openbmc_project::Common::File::Open; - elog<file_error::Open>( - metadata::ERRNO(e.code().value()), - metadata::PATH(e.path1().c_str())); + elog<file_error::Open>(metadata::ERRNO(e.code().value()), + metadata::PATH(e.path1().c_str())); } auto sortTargets = [](const std::unique_ptr<Target>& left, - const std::unique_ptr<Target>& right) - { + const std::unique_ptr<Target>& right) { return left->getPos() < right->getPos(); }; std::sort(targets.begin(), targets.end(), sortTargets); } -} -} +} // namespace targeting +} // namespace openpower diff --git a/targeting.hpp b/targeting.hpp index 0a946f6..6d86b50 100644 --- a/targeting.hpp +++ b/targeting.hpp @@ -1,8 +1,9 @@ #pragma once +#include "filedescriptor.hpp" + #include <memory> #include <vector> -#include "filedescriptor.hpp" namespace openpower { @@ -27,152 +28,149 @@ typedef uint32_t (*swap_endian_t)(uint32_t); */ class Target { - public: - - /** - * Constructor - * - * @param[in] - The logical position of the target - * @param[in] - The sysfs device path - * @param[in] - The function pointer for swapping endianness - */ - Target(size_t position, const std::string& devPath, - const swap_endian_t swapper) : - pos(position), cfamPath(devPath), doSwapEndian(swapper) - { - } - - Target() = delete; - ~Target() = default; - Target(const Target&) = default; - Target(Target&&) = default; - Target& operator=(Target&&) = default; - - /** - * Returns the position - */ - inline auto getPos() const - { - return pos; - } - - /** - * Returns the CFAM sysfs path - */ - inline auto getCFAMPath() const - { - return cfamPath; - } - - /** - * Returns the file descriptor to use - * for read/writeCFAM operations. - */ - int getCFAMFD(); - - /** - * Returns correct byte-order data. (May or may not swap it depending - * on the function received during construction from Targeting and the - * host endianness). - */ - inline uint32_t swapEndian(uint32_t data) const - { - return doSwapEndian(data); - } - - private: - - /** - * The logical position of this target - */ - size_t pos; - - /** - * The sysfs device path for the CFAM - */ - const std::string cfamPath; - - /** - * The file descriptor to use for read/writeCFAMReg - */ - std::unique_ptr<openpower::util::FileDescriptor> cfamFD; - - /** - * The function pointer for swapping endianness - */ - const swap_endian_t doSwapEndian; + public: + /** + * Constructor + * + * @param[in] - The logical position of the target + * @param[in] - The sysfs device path + * @param[in] - The function pointer for swapping endianness + */ + Target(size_t position, const std::string& devPath, + const swap_endian_t swapper) : + pos(position), + cfamPath(devPath), doSwapEndian(swapper) + { + } + + Target() = delete; + ~Target() = default; + Target(const Target&) = default; + Target(Target&&) = default; + Target& operator=(Target&&) = default; + + /** + * Returns the position + */ + inline auto getPos() const + { + return pos; + } + + /** + * Returns the CFAM sysfs path + */ + inline auto getCFAMPath() const + { + return cfamPath; + } + + /** + * Returns the file descriptor to use + * for read/writeCFAM operations. + */ + int getCFAMFD(); + + /** + * Returns correct byte-order data. (May or may not swap it depending + * on the function received during construction from Targeting and the + * host endianness). + */ + inline uint32_t swapEndian(uint32_t data) const + { + return doSwapEndian(data); + } + + private: + /** + * The logical position of this target + */ + size_t pos; + + /** + * The sysfs device path for the CFAM + */ + const std::string cfamPath; + + /** + * The file descriptor to use for read/writeCFAMReg + */ + std::unique_ptr<openpower::util::FileDescriptor> cfamFD; + + /** + * The function pointer for swapping endianness + */ + const swap_endian_t doSwapEndian; }; - /** * Class that manages processor targeting for FSI operations. */ class Targeting { - public: - - /** - * Scans sysfs to find all processors and creates Target objects - * for them. - * @param[in] fsiMasterDev - the sysfs device for the master - * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves - */ - Targeting(const std::string& fsiMasterDev, - const std::string& fsiSlaveDir); - - Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {} - - ~Targeting() = default; - Targeting(const Targeting&) = default; - Targeting(Targeting&&) = default; - Targeting& operator=(Targeting&&) = default; - - /** - * Returns a const iterator to the first target - */ - inline auto begin() - { - return targets.cbegin(); - } - - /** - * Returns a const iterator to the last (highest position) target. - */ - inline auto end() - { - return targets.cend(); - } - - /** - * Returns the number of targets - */ - inline auto size() - { - return targets.size(); - } - - /** - * Returns a target by position. - */ - std::unique_ptr<Target>& getTarget(size_t pos); - - private: - - /** - * The path to the fsi-master sysfs device to access - */ - std::string fsiMasterPath; - - /** - * The path to the fsi slave sysfs base directory - */ - std::string fsiSlaveBasePath; - - /** - * A container of Targets in the system - */ - std::vector<std::unique_ptr<Target>> targets; + public: + /** + * Scans sysfs to find all processors and creates Target objects + * for them. + * @param[in] fsiMasterDev - the sysfs device for the master + * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves + */ + Targeting(const std::string& fsiMasterDev, const std::string& fsiSlaveDir); + + Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) + { + } + + ~Targeting() = default; + Targeting(const Targeting&) = default; + Targeting(Targeting&&) = default; + Targeting& operator=(Targeting&&) = default; + + /** + * Returns a const iterator to the first target + */ + inline auto begin() + { + return targets.cbegin(); + } + + /** + * Returns a const iterator to the last (highest position) target. + */ + inline auto end() + { + return targets.cend(); + } + + /** + * Returns the number of targets + */ + inline auto size() + { + return targets.size(); + } + + /** + * Returns a target by position. + */ + std::unique_ptr<Target>& getTarget(size_t pos); + + private: + /** + * The path to the fsi-master sysfs device to access + */ + std::string fsiMasterPath; + + /** + * The path to the fsi slave sysfs base directory + */ + std::string fsiSlaveBasePath; + + /** + * A container of Targets in the system + */ + std::vector<std::unique_ptr<Target>> targets; }; -} -} +} // namespace targeting +} // namespace openpower diff --git a/test/utest.cpp b/test/utest.cpp index 85ee6e4..1d1f431 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <gtest/gtest.h> -#include <experimental/filesystem> -#include <fstream> -#include <stdlib.h> #include "registration.hpp" #include "targeting.hpp" +#include <stdlib.h> + +#include <experimental/filesystem> +#include <fstream> + +#include <gtest/gtest.h> + using namespace openpower::util; using namespace openpower::targeting; namespace fs = std::experimental::filesystem; @@ -30,38 +33,36 @@ constexpr auto masterDir = "/tmp"; class TargetingTest : public ::testing::Test { - protected: - - virtual void SetUp() - { - char dir[50]; - strcpy(dir, masterDir); - strcat(dir, "/targetingXXXXXX"); + protected: + virtual void SetUp() + { + char dir[50]; + strcpy(dir, masterDir); + strcat(dir, "/targetingXXXXXX"); - auto path = mkdtemp(dir); - assert(path != nullptr); + auto path = mkdtemp(dir); + assert(path != nullptr); - _slaveBaseDir = path; + _slaveBaseDir = path; - _slaveDir = _slaveBaseDir / "fsi1"; - fs::create_directory(_slaveDir); - } + _slaveDir = _slaveBaseDir / "fsi1"; + fs::create_directory(_slaveDir); + } - virtual void TearDown() - { - fs::remove_all(_slaveDir); - fs::remove_all(_slaveBaseDir); - } + virtual void TearDown() + { + fs::remove_all(_slaveDir); + fs::remove_all(_slaveBaseDir); + } - fs::path _slaveBaseDir; - fs::path _slaveDir; + fs::path _slaveBaseDir; + fs::path _slaveDir; }; - TEST_F(TargetingTest, CreateTargets) { - //Test that we always create the first Target + // Test that we always create the first Target { Targeting targets{masterDir, _slaveDir}; ASSERT_EQ(targets.size(), 1); @@ -72,10 +73,9 @@ TEST_F(TargetingTest, CreateTargets) ASSERT_EQ((*t)->getCFAMPath(), masterDir); } - - //Test that we can create multiple Targets + // Test that we can create multiple Targets { - //make some fake slave entries + // make some fake slave entries std::ofstream(_slaveDir / "slave@01:00"); std::ofstream(_slaveDir / "slave@02:00"); std::ofstream(_slaveDir / "slave@03:00"); @@ -112,7 +112,6 @@ TEST_F(TargetingTest, CreateTargets) } } - void func1() { std::cout << "Hello\n"; @@ -126,7 +125,6 @@ void func2() REGISTER_PROCEDURE("hello", func1); REGISTER_PROCEDURE("world", func2); - TEST(RegistrationTest, TestReg) { int count = 0; |

