blob: 2f025ecab11c4628125b886e8626bcaee08fc6c9 [file] [log] [blame]
Matt Spinler2c05aa72017-02-28 09:48:13 -06001#pragma once
2
Patrick Venturef78d9042018-11-01 15:39:53 -07003#include "filedescriptor.hpp"
4
Matt Spinler2c05aa72017-02-28 09:48:13 -06005#include <memory>
6#include <vector>
7
8namespace openpower
9{
10namespace targeting
11{
12
Joel Stanley60db8b12019-09-27 15:23:39 +093013constexpr auto fsiMasterDevPath = "/sys/class/fsi-master/fsi0/slave@00:00/raw";
Matt Spinler2c05aa72017-02-28 09:48:13 -060014
Joel Stanley60db8b12019-09-27 15:23:39 +093015constexpr auto fsiSlaveBaseDir = "/sys/class/fsi-master/fsi1/";
Edward A. James8316b772017-04-24 14:20:48 -050016
Matt Spinler2c05aa72017-02-28 09:48:13 -060017/**
18 * Represents a specific P9 processor in the system. Used by
19 * the access APIs to specify the chip to operate on.
20 */
21class Target
22{
Patrick Venturef78d9042018-11-01 15:39:53 -070023 public:
24 /**
25 * Constructor
26 *
27 * @param[in] - The logical position of the target
28 * @param[in] - The sysfs device path
Patrick Venturef78d9042018-11-01 15:39:53 -070029 */
Joel Stanleyafa1d222019-09-27 15:35:04 +093030 Target(size_t position, const std::string& devPath) :
31 pos(position), cfamPath(devPath)
Brad Bishop5e5d4452020-10-27 19:46:13 -040032 {}
Matt Spinler2c05aa72017-02-28 09:48:13 -060033
Patrick Venturef78d9042018-11-01 15:39:53 -070034 Target() = delete;
35 ~Target() = default;
36 Target(const Target&) = default;
37 Target(Target&&) = default;
38 Target& operator=(Target&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -060039
Patrick Venturef78d9042018-11-01 15:39:53 -070040 /**
41 * Returns the position
42 */
43 inline auto getPos() const
44 {
45 return pos;
46 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060047
Patrick Venturef78d9042018-11-01 15:39:53 -070048 /**
49 * Returns the CFAM sysfs path
50 */
51 inline auto getCFAMPath() const
52 {
53 return cfamPath;
54 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060055
Patrick Venturef78d9042018-11-01 15:39:53 -070056 /**
57 * Returns the file descriptor to use
58 * for read/writeCFAM operations.
59 */
60 int getCFAMFD();
Matt Spinler2c05aa72017-02-28 09:48:13 -060061
Patrick Venturef78d9042018-11-01 15:39:53 -070062 private:
63 /**
64 * The logical position of this target
65 */
66 size_t pos;
Edward A. James8316b772017-04-24 14:20:48 -050067
Patrick Venturef78d9042018-11-01 15:39:53 -070068 /**
69 * The sysfs device path for the CFAM
70 */
71 const std::string cfamPath;
Matt Spinler2c05aa72017-02-28 09:48:13 -060072
Patrick Venturef78d9042018-11-01 15:39:53 -070073 /**
74 * The file descriptor to use for read/writeCFAMReg
75 */
76 std::unique_ptr<openpower::util::FileDescriptor> cfamFD;
Matt Spinler2c05aa72017-02-28 09:48:13 -060077};
78
Matt Spinler2c05aa72017-02-28 09:48:13 -060079/**
80 * Class that manages processor targeting for FSI operations.
81 */
82class Targeting
83{
Patrick Venturef78d9042018-11-01 15:39:53 -070084 public:
85 /**
86 * Scans sysfs to find all processors and creates Target objects
87 * for them.
88 * @param[in] fsiMasterDev - the sysfs device for the master
89 * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves
90 */
91 Targeting(const std::string& fsiMasterDev, const std::string& fsiSlaveDir);
Matt Spinler2c05aa72017-02-28 09:48:13 -060092
Patrick Williams00dd33e2023-05-10 07:50:37 -050093 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {}
Matt Spinler2c05aa72017-02-28 09:48:13 -060094
Patrick Venturef78d9042018-11-01 15:39:53 -070095 ~Targeting() = default;
96 Targeting(const Targeting&) = default;
97 Targeting(Targeting&&) = default;
98 Targeting& operator=(Targeting&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -060099
Patrick Venturef78d9042018-11-01 15:39:53 -0700100 /**
101 * Returns a const iterator to the first target
102 */
103 inline auto begin()
104 {
105 return targets.cbegin();
106 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600107
Patrick Venturef78d9042018-11-01 15:39:53 -0700108 /**
109 * Returns a const iterator to the last (highest position) target.
110 */
111 inline auto end()
112 {
113 return targets.cend();
114 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600115
Patrick Venturef78d9042018-11-01 15:39:53 -0700116 /**
117 * Returns the number of targets
118 */
119 inline auto size()
120 {
121 return targets.size();
122 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600123
Patrick Venturef78d9042018-11-01 15:39:53 -0700124 /**
125 * Returns a target by position.
126 */
127 std::unique_ptr<Target>& getTarget(size_t pos);
Matt Spinler2c05aa72017-02-28 09:48:13 -0600128
Patrick Venturef78d9042018-11-01 15:39:53 -0700129 private:
130 /**
131 * The path to the fsi-master sysfs device to access
132 */
133 std::string fsiMasterPath;
Michael Tritzbe407162017-03-30 16:52:24 -0500134
Patrick Venturef78d9042018-11-01 15:39:53 -0700135 /**
136 * The path to the fsi slave sysfs base directory
137 */
138 std::string fsiSlaveBasePath;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600139
Patrick Venturef78d9042018-11-01 15:39:53 -0700140 /**
141 * A container of Targets in the system
142 */
143 std::vector<std::unique_ptr<Target>> targets;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600144};
145
Patrick Venturef78d9042018-11-01 15:39:53 -0700146} // namespace targeting
147} // namespace openpower