blob: 9719a65f34e564fd2032821597f7dab700089944 [file] [log] [blame]
Matt Spinler2c05aa72017-02-28 09:48:13 -06001#pragma once
2
3#include <memory>
4#include <vector>
Matt Spinlerc3bffed2017-03-10 09:05:30 -06005#include "filedescriptor.hpp"
Matt Spinler2c05aa72017-02-28 09:48:13 -06006
7namespace openpower
8{
9namespace targeting
10{
11
12constexpr auto fsiMasterDevPath =
13 "/sys/devices/platform/fsi-master/slave@00:00/raw";
14
Matt Spinlerfabe92e2017-03-17 11:25:22 -050015constexpr auto fsiSlaveBaseDir = "/sys/devices/platform/fsi-master/slave@00:00/hub@00/";
Matt Spinler2c05aa72017-02-28 09:48:13 -060016
17/**
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{
23 public:
24
25 /**
26 * Constructor
27 *
28 * @param[in] - The logical position of the target
29 * @param[in] - The sysfs device path
30 */
31 Target(size_t position, const std::string& devPath) :
Matt Spinlerc3bffed2017-03-10 09:05:30 -060032 pos(position), cfamPath(devPath)
Matt Spinler2c05aa72017-02-28 09:48:13 -060033 {
34 }
35
36 Target() = delete;
37 ~Target() = default;
38 Target(const Target&) = default;
39 Target(Target&&) = default;
40 Target& operator=(Target&&) = default;
41
42 /**
43 * Returns the position
44 */
45 inline auto getPos() const
46 {
47 return pos;
48 }
49
50 /**
Matt Spinlerc3bffed2017-03-10 09:05:30 -060051 * Returns the CFAM sysfs path
Matt Spinler2c05aa72017-02-28 09:48:13 -060052 */
Matt Spinlerc3bffed2017-03-10 09:05:30 -060053 inline auto getCFAMPath() const
Matt Spinler2c05aa72017-02-28 09:48:13 -060054 {
Matt Spinlerc3bffed2017-03-10 09:05:30 -060055 return cfamPath;
Matt Spinler2c05aa72017-02-28 09:48:13 -060056 }
57
Matt Spinlerc3bffed2017-03-10 09:05:30 -060058 /**
59 * Returns the file descriptor to use
60 * for read/writeCFAM operations.
61 */
62 int getCFAMFD();
63
Matt Spinler2c05aa72017-02-28 09:48:13 -060064 private:
65
66 /**
67 * The logical position of this target
68 */
69 size_t pos;
70
71 /**
Matt Spinlerc3bffed2017-03-10 09:05:30 -060072 * The sysfs device path for the CFAM
Matt Spinler2c05aa72017-02-28 09:48:13 -060073 */
Matt Spinlerc3bffed2017-03-10 09:05:30 -060074 const std::string cfamPath;
75
76 /**
77 * The file descriptor to use for read/writeCFAMReg
78 */
79 std::unique_ptr<openpower::util::FileDescriptor> cfamFD;
Matt Spinler2c05aa72017-02-28 09:48:13 -060080};
81
82
83/**
84 * Class that manages processor targeting for FSI operations.
85 */
86class Targeting
87{
88 public:
89
90 /**
91 * Scans sysfs to find all processors and creates Target objects
92 * for them.
93 * @param[in] fsiMasterDev - the sysfs device for the master
94 * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves
95 */
96 Targeting(const std::string& fsiMasterDev,
97 const std::string& fsiSlaveDir);
98
99 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {}
100
101 ~Targeting() = default;
102 Targeting(const Targeting&) = default;
103 Targeting(Targeting&&) = default;
104 Targeting& operator=(Targeting&&) = default;
105
106 /**
107 * Returns a const iterator to the first target
108 */
109 inline auto begin()
110 {
111 return targets.cbegin();
112 }
113
114 /**
115 * Returns a const iterator to the last (highest position) target.
116 */
117 inline auto end()
118 {
119 return targets.cend();
120 }
121
122 /**
123 * Returns the number of targets
124 */
125 inline auto size()
126 {
127 return targets.size();
128 }
129
130 private:
131
132 /**
133 * The path to the fsi-master sysfs device to access
134 */
135 const std::string fsiMasterPath;
136
137 /**
138 * The path to the fsi slave sysfs base directory
139 */
140 const std::string fsiSlaveBasePath;
141
142 /**
143 * A container of Targets in the system
144 */
145 std::vector<std::unique_ptr<Target>> targets;
146};
147
148}
149}