Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <vector> |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 5 | #include "filedescriptor.hpp" |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace targeting |
| 10 | { |
| 11 | |
| 12 | constexpr auto fsiMasterDevPath = |
| 13 | "/sys/devices/platform/fsi-master/slave@00:00/raw"; |
| 14 | |
Matt Spinler | fabe92e | 2017-03-17 11:25:22 -0500 | [diff] [blame] | 15 | constexpr auto fsiSlaveBaseDir = "/sys/devices/platform/fsi-master/slave@00:00/hub@00/"; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Represents a specific P9 processor in the system. Used by |
| 19 | * the access APIs to specify the chip to operate on. |
| 20 | */ |
| 21 | class 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 Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 32 | pos(position), cfamPath(devPath) |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 33 | { |
| 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 Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 51 | * Returns the CFAM sysfs path |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 52 | */ |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 53 | inline auto getCFAMPath() const |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 54 | { |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 55 | return cfamPath; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 58 | /** |
| 59 | * Returns the file descriptor to use |
| 60 | * for read/writeCFAM operations. |
| 61 | */ |
| 62 | int getCFAMFD(); |
| 63 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 64 | private: |
| 65 | |
| 66 | /** |
| 67 | * The logical position of this target |
| 68 | */ |
| 69 | size_t pos; |
| 70 | |
| 71 | /** |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 72 | * The sysfs device path for the CFAM |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 73 | */ |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 74 | 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 Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Class that manages processor targeting for FSI operations. |
| 85 | */ |
| 86 | class 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 | |
Michael Tritz | be40716 | 2017-03-30 16:52:24 -0500 | [diff] [blame^] | 130 | /** |
| 131 | * Returns a target by position. |
| 132 | */ |
| 133 | std::unique_ptr<Target>& getTarget(size_t pos); |
| 134 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 135 | private: |
| 136 | |
| 137 | /** |
| 138 | * The path to the fsi-master sysfs device to access |
| 139 | */ |
| 140 | const std::string fsiMasterPath; |
| 141 | |
| 142 | /** |
| 143 | * The path to the fsi slave sysfs base directory |
| 144 | */ |
| 145 | const std::string fsiSlaveBasePath; |
| 146 | |
| 147 | /** |
| 148 | * A container of Targets in the system |
| 149 | */ |
| 150 | std::vector<std::unique_ptr<Target>> targets; |
| 151 | }; |
| 152 | |
| 153 | } |
| 154 | } |