blob: 466cb7e93f90988b7aabf8262d922a0bd13f197d [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 Venturef78d9042018-11-01 15:39:53 -070093 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir)
Brad Bishop5e5d4452020-10-27 19:46:13 -040094 {}
Matt Spinler2c05aa72017-02-28 09:48:13 -060095
Patrick Venturef78d9042018-11-01 15:39:53 -070096 ~Targeting() = default;
97 Targeting(const Targeting&) = default;
98 Targeting(Targeting&&) = default;
99 Targeting& operator=(Targeting&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600100
Patrick Venturef78d9042018-11-01 15:39:53 -0700101 /**
102 * Returns a const iterator to the first target
103 */
104 inline auto begin()
105 {
106 return targets.cbegin();
107 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600108
Patrick Venturef78d9042018-11-01 15:39:53 -0700109 /**
110 * Returns a const iterator to the last (highest position) target.
111 */
112 inline auto end()
113 {
114 return targets.cend();
115 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600116
Patrick Venturef78d9042018-11-01 15:39:53 -0700117 /**
118 * Returns the number of targets
119 */
120 inline auto size()
121 {
122 return targets.size();
123 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600124
Patrick Venturef78d9042018-11-01 15:39:53 -0700125 /**
126 * Returns a target by position.
127 */
128 std::unique_ptr<Target>& getTarget(size_t pos);
Matt Spinler2c05aa72017-02-28 09:48:13 -0600129
Patrick Venturef78d9042018-11-01 15:39:53 -0700130 private:
131 /**
132 * The path to the fsi-master sysfs device to access
133 */
134 std::string fsiMasterPath;
Michael Tritzbe407162017-03-30 16:52:24 -0500135
Patrick Venturef78d9042018-11-01 15:39:53 -0700136 /**
137 * The path to the fsi slave sysfs base directory
138 */
139 std::string fsiSlaveBasePath;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600140
Patrick Venturef78d9042018-11-01 15:39:53 -0700141 /**
142 * A container of Targets in the system
143 */
144 std::vector<std::unique_ptr<Target>> targets;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600145};
146
Patrick Venturef78d9042018-11-01 15:39:53 -0700147} // namespace targeting
148} // namespace openpower