blob: 204b901048d1f5db86e94415395321b1381b19d5 [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
13constexpr auto fsiMasterDevPath =
Edward A. James8316b772017-04-24 14:20:48 -050014 "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/raw";
Matt Spinler2c05aa72017-02-28 09:48:13 -060015
Edward A. James8316b772017-04-24 14:20:48 -050016constexpr auto fsiSlaveBaseDir =
Edward A. James23763b12017-07-06 14:23:32 -050017 "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/00:00:00:0a/fsi1/";
Edward A. James8316b772017-04-24 14:20:48 -050018
Matt Spinler2c05aa72017-02-28 09:48:13 -060019/**
20 * Represents a specific P9 processor in the system. Used by
21 * the access APIs to specify the chip to operate on.
22 */
23class Target
24{
Patrick Venturef78d9042018-11-01 15:39:53 -070025 public:
26 /**
27 * Constructor
28 *
29 * @param[in] - The logical position of the target
30 * @param[in] - The sysfs device path
Patrick Venturef78d9042018-11-01 15:39:53 -070031 */
Joel Stanleyafa1d222019-09-27 15:35:04 +093032 Target(size_t position, const std::string& devPath) :
33 pos(position), cfamPath(devPath)
Patrick Venturef78d9042018-11-01 15:39:53 -070034 {
35 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060036
Patrick Venturef78d9042018-11-01 15:39:53 -070037 Target() = delete;
38 ~Target() = default;
39 Target(const Target&) = default;
40 Target(Target&&) = default;
41 Target& operator=(Target&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -060042
Patrick Venturef78d9042018-11-01 15:39:53 -070043 /**
44 * Returns the position
45 */
46 inline auto getPos() const
47 {
48 return pos;
49 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060050
Patrick Venturef78d9042018-11-01 15:39:53 -070051 /**
52 * Returns the CFAM sysfs path
53 */
54 inline auto getCFAMPath() const
55 {
56 return cfamPath;
57 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060058
Patrick Venturef78d9042018-11-01 15:39:53 -070059 /**
60 * Returns the file descriptor to use
61 * for read/writeCFAM operations.
62 */
63 int getCFAMFD();
Matt Spinler2c05aa72017-02-28 09:48:13 -060064
Patrick Venturef78d9042018-11-01 15:39:53 -070065 private:
66 /**
67 * The logical position of this target
68 */
69 size_t pos;
Edward A. James8316b772017-04-24 14:20:48 -050070
Patrick Venturef78d9042018-11-01 15:39:53 -070071 /**
72 * The sysfs device path for the CFAM
73 */
74 const std::string cfamPath;
Matt Spinler2c05aa72017-02-28 09:48:13 -060075
Patrick Venturef78d9042018-11-01 15:39:53 -070076 /**
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
Matt Spinler2c05aa72017-02-28 09:48:13 -060082/**
83 * Class that manages processor targeting for FSI operations.
84 */
85class Targeting
86{
Patrick Venturef78d9042018-11-01 15:39:53 -070087 public:
88 /**
89 * Scans sysfs to find all processors and creates Target objects
90 * for them.
91 * @param[in] fsiMasterDev - the sysfs device for the master
92 * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves
93 */
94 Targeting(const std::string& fsiMasterDev, const std::string& fsiSlaveDir);
Matt Spinler2c05aa72017-02-28 09:48:13 -060095
Patrick Venturef78d9042018-11-01 15:39:53 -070096 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir)
97 {
98 }
Matt Spinler2c05aa72017-02-28 09:48:13 -060099
Patrick Venturef78d9042018-11-01 15:39:53 -0700100 ~Targeting() = default;
101 Targeting(const Targeting&) = default;
102 Targeting(Targeting&&) = default;
103 Targeting& operator=(Targeting&&) = default;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600104
Patrick Venturef78d9042018-11-01 15:39:53 -0700105 /**
106 * Returns a const iterator to the first target
107 */
108 inline auto begin()
109 {
110 return targets.cbegin();
111 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600112
Patrick Venturef78d9042018-11-01 15:39:53 -0700113 /**
114 * Returns a const iterator to the last (highest position) target.
115 */
116 inline auto end()
117 {
118 return targets.cend();
119 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600120
Patrick Venturef78d9042018-11-01 15:39:53 -0700121 /**
122 * Returns the number of targets
123 */
124 inline auto size()
125 {
126 return targets.size();
127 }
Matt Spinler2c05aa72017-02-28 09:48:13 -0600128
Patrick Venturef78d9042018-11-01 15:39:53 -0700129 /**
130 * Returns a target by position.
131 */
132 std::unique_ptr<Target>& getTarget(size_t pos);
Matt Spinler2c05aa72017-02-28 09:48:13 -0600133
Patrick Venturef78d9042018-11-01 15:39:53 -0700134 private:
135 /**
136 * The path to the fsi-master sysfs device to access
137 */
138 std::string fsiMasterPath;
Michael Tritzbe407162017-03-30 16:52:24 -0500139
Patrick Venturef78d9042018-11-01 15:39:53 -0700140 /**
141 * The path to the fsi slave sysfs base directory
142 */
143 std::string fsiSlaveBasePath;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600144
Patrick Venturef78d9042018-11-01 15:39:53 -0700145 /**
146 * A container of Targets in the system
147 */
148 std::vector<std::unique_ptr<Target>> targets;
Matt Spinler2c05aa72017-02-28 09:48:13 -0600149};
150
Patrick Venturef78d9042018-11-01 15:39:53 -0700151} // namespace targeting
152} // namespace openpower