blob: 9c63f6c719b25246c02c42b8e704dc9984e8a5c5 [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)
Patrick Venturef78d9042018-11-01 15:39:53 -070032 {
33 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060034
Patrick Venturef78d9042018-11-01 15:39:53 -070035 Target() = delete;
36 ~Target() = default;
37 Target(const Target&) = default;
38 Target(Target&&) = default;
39 Target& operator=(Target&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -060040
Patrick Venturef78d9042018-11-01 15:39:53 -070041 /**
42 * Returns the position
43 */
44 inline auto getPos() const
45 {
46 return pos;
47 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060048
Patrick Venturef78d9042018-11-01 15:39:53 -070049 /**
50 * Returns the CFAM sysfs path
51 */
52 inline auto getCFAMPath() const
53 {
54 return cfamPath;
55 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060056
Patrick Venturef78d9042018-11-01 15:39:53 -070057 /**
58 * Returns the file descriptor to use
59 * for read/writeCFAM operations.
60 */
61 int getCFAMFD();
Matt Spinler2c05aa72017-02-28 09:48:13 -060062
Patrick Venturef78d9042018-11-01 15:39:53 -070063 private:
64 /**
65 * The logical position of this target
66 */
67 size_t pos;
Edward A. James8316b772017-04-24 14:20:48 -050068
Patrick Venturef78d9042018-11-01 15:39:53 -070069 /**
70 * The sysfs device path for the CFAM
71 */
72 const std::string cfamPath;
Matt Spinler2c05aa72017-02-28 09:48:13 -060073
Patrick Venturef78d9042018-11-01 15:39:53 -070074 /**
75 * The file descriptor to use for read/writeCFAMReg
76 */
77 std::unique_ptr<openpower::util::FileDescriptor> cfamFD;
Matt Spinler2c05aa72017-02-28 09:48:13 -060078};
79
Matt Spinler2c05aa72017-02-28 09:48:13 -060080/**
81 * Class that manages processor targeting for FSI operations.
82 */
83class Targeting
84{
Patrick Venturef78d9042018-11-01 15:39:53 -070085 public:
86 /**
87 * Scans sysfs to find all processors and creates Target objects
88 * for them.
89 * @param[in] fsiMasterDev - the sysfs device for the master
90 * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves
91 */
92 Targeting(const std::string& fsiMasterDev, const std::string& fsiSlaveDir);
Matt Spinler2c05aa72017-02-28 09:48:13 -060093
Patrick Venturef78d9042018-11-01 15:39:53 -070094 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir)
95 {
96 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060097
Patrick Venturef78d9042018-11-01 15:39:53 -070098 ~Targeting() = default;
99 Targeting(const Targeting&) = default;
100 Targeting(Targeting&&) = default;
101 Targeting& operator=(Targeting&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600102
Patrick Venturef78d9042018-11-01 15:39:53 -0700103 /**
104 * Returns a const iterator to the first target
105 */
106 inline auto begin()
107 {
108 return targets.cbegin();
109 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600110
Patrick Venturef78d9042018-11-01 15:39:53 -0700111 /**
112 * Returns a const iterator to the last (highest position) target.
113 */
114 inline auto end()
115 {
116 return targets.cend();
117 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600118
Patrick Venturef78d9042018-11-01 15:39:53 -0700119 /**
120 * Returns the number of targets
121 */
122 inline auto size()
123 {
124 return targets.size();
125 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600126
Patrick Venturef78d9042018-11-01 15:39:53 -0700127 /**
128 * Returns a target by position.
129 */
130 std::unique_ptr<Target>& getTarget(size_t pos);
Matt Spinler2c05aa72017-02-28 09:48:13 -0600131
Patrick Venturef78d9042018-11-01 15:39:53 -0700132 private:
133 /**
134 * The path to the fsi-master sysfs device to access
135 */
136 std::string fsiMasterPath;
Michael Tritzbe407162017-03-30 16:52:24 -0500137
Patrick Venturef78d9042018-11-01 15:39:53 -0700138 /**
139 * The path to the fsi slave sysfs base directory
140 */
141 std::string fsiSlaveBasePath;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600142
Patrick Venturef78d9042018-11-01 15:39:53 -0700143 /**
144 * A container of Targets in the system
145 */
146 std::vector<std::unique_ptr<Target>> targets;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600147};
148
Patrick Venturef78d9042018-11-01 15:39:53 -0700149} // namespace targeting
150} // namespace openpower