targeting.cpp (8316b77b67aac9dea3e7281e2455ad80f509a5b3) targeting.cpp (18b0786a93964c2f30ada2e5405b103d4d3b82e5)
1/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0

--- 4 unchanged lines hidden (view full) ---

13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <endian.h>
18#include <experimental/filesystem>
19#include <phosphor-logging/log.hpp>
20#include <regex>
1/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0

--- 4 unchanged lines hidden (view full) ---

13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <endian.h>
18#include <experimental/filesystem>
19#include <phosphor-logging/log.hpp>
20#include <regex>
21#include <phosphor-logging/elog.hpp>
22#include "elog-errors.hpp"
21#include "targeting.hpp"
22
23#include "targeting.hpp"
24
25
23namespace openpower
24{
25namespace targeting
26{
27
28using namespace phosphor::logging;
29namespace fs = std::experimental::filesystem;
30

--- 55 unchanged lines hidden (view full) ---

86 fsiSlaveBasePath = fsiSlaveBaseDirOld;
87
88 //And don't swap the endianness of CFAM data
89 swapper = noEndianSwap;
90 }
91
92 //Always create P0, the FSI master.
93 targets.push_back(std::make_unique<Target>(0, fsiMasterPath, swapper));
26namespace openpower
27{
28namespace targeting
29{
30
31using namespace phosphor::logging;
32namespace fs = std::experimental::filesystem;
33

--- 55 unchanged lines hidden (view full) ---

89 fsiSlaveBasePath = fsiSlaveBaseDirOld;
90
91 //And don't swap the endianness of CFAM data
92 swapper = noEndianSwap;
93 }
94
95 //Always create P0, the FSI master.
96 targets.push_back(std::make_unique<Target>(0, fsiMasterPath, swapper));
94
95 //Find the the remaining P9s dynamically based on which files show up
96 for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
97 try
97 {
98 {
98 std::smatch match;
99 std::string path = file.path();
100 if (std::regex_search(path, match, exp))
99 //Find the the remaining P9s dynamically based on which files show up
100 for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
101 {
101 {
102 auto pos = atoi(match[1].str().c_str());
103 if (pos == 0)
102 std::smatch match;
103 std::string path = file.path();
104 if (std::regex_search(path, match, exp))
104 {
105 {
105 log<level::ERR>("Unexpected FSI slave device name found",
106 entry("DEVICE_NAME=%s", path.c_str()));
107 continue;
108 }
106 auto pos = atoi(match[1].str().c_str());
107 if (pos == 0)
108 {
109 log<level::ERR>("Unexpected FSI slave device name found",
110 entry("DEVICE_NAME=%s", path.c_str()));
111 continue;
112 }
109
113
110 path += "/raw";
114 path += "/raw";
111
115
112 targets.push_back(std::make_unique<Target>(pos, path, swapper));
116 targets.push_back(std::make_unique<Target>(pos, path, swapper));
117 }
113 }
114 }
118 }
119 }
120 catch (fs::filesystem_error& e)
121 {
122 elog<org::open_power::Proc::CFAM::OpenFailure>(
123 org::open_power::Proc::CFAM::OpenFailure::ERRNO(e.code().value()),
124 org::open_power::Proc::CFAM::OpenFailure::PATH(e.path1().c_str()));
125 }
115
116 auto sortTargets = [](const std::unique_ptr<Target>& left,
117 const std::unique_ptr<Target>& right)
118 {
119 return left->getPos() < right->getPos();
120 };
121 std::sort(targets.begin(), targets.end(), sortTargets);
122}
123
124}
125}
126
127 auto sortTargets = [](const std::unique_ptr<Target>& left,
128 const std::unique_ptr<Target>& right)
129 {
130 return left->getPos() < right->getPos();
131 };
132 std::sort(targets.begin(), targets.end(), sortTargets);
133}
134
135}
136}