Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <vector> |
| 5 | |
| 6 | namespace openpower |
| 7 | { |
| 8 | namespace targeting |
| 9 | { |
| 10 | |
| 11 | constexpr auto fsiMasterDevPath = |
| 12 | "/sys/devices/platform/fsi-master/slave@00:00/raw"; |
| 13 | |
| 14 | constexpr auto fsiSlaveBaseDir = "/sys/devices/hub@00/"; |
| 15 | |
| 16 | /** |
| 17 | * Represents a specific P9 processor in the system. Used by |
| 18 | * the access APIs to specify the chip to operate on. |
| 19 | */ |
| 20 | class Target |
| 21 | { |
| 22 | public: |
| 23 | |
| 24 | /** |
| 25 | * Constructor |
| 26 | * |
| 27 | * @param[in] - The logical position of the target |
| 28 | * @param[in] - The sysfs device path |
| 29 | */ |
| 30 | Target(size_t position, const std::string& devPath) : |
| 31 | pos(position), path(devPath) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | Target() = delete; |
| 36 | ~Target() = default; |
| 37 | Target(const Target&) = default; |
| 38 | Target(Target&&) = default; |
| 39 | Target& operator=(Target&&) = default; |
| 40 | |
| 41 | /** |
| 42 | * Returns the position |
| 43 | */ |
| 44 | inline auto getPos() const |
| 45 | { |
| 46 | return pos; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the path |
| 51 | */ |
| 52 | inline auto getPath() const |
| 53 | { |
| 54 | return path; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | |
| 59 | /** |
| 60 | * The logical position of this target |
| 61 | */ |
| 62 | size_t pos; |
| 63 | |
| 64 | /** |
| 65 | * The sysfs device path |
| 66 | */ |
| 67 | const std::string path; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Class that manages processor targeting for FSI operations. |
| 73 | */ |
| 74 | class Targeting |
| 75 | { |
| 76 | public: |
| 77 | |
| 78 | /** |
| 79 | * Scans sysfs to find all processors and creates Target objects |
| 80 | * for them. |
| 81 | * @param[in] fsiMasterDev - the sysfs device for the master |
| 82 | * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves |
| 83 | */ |
| 84 | Targeting(const std::string& fsiMasterDev, |
| 85 | const std::string& fsiSlaveDir); |
| 86 | |
| 87 | Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {} |
| 88 | |
| 89 | ~Targeting() = default; |
| 90 | Targeting(const Targeting&) = default; |
| 91 | Targeting(Targeting&&) = default; |
| 92 | Targeting& operator=(Targeting&&) = default; |
| 93 | |
| 94 | /** |
| 95 | * Returns a const iterator to the first target |
| 96 | */ |
| 97 | inline auto begin() |
| 98 | { |
| 99 | return targets.cbegin(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns a const iterator to the last (highest position) target. |
| 104 | */ |
| 105 | inline auto end() |
| 106 | { |
| 107 | return targets.cend(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the number of targets |
| 112 | */ |
| 113 | inline auto size() |
| 114 | { |
| 115 | return targets.size(); |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | |
| 120 | /** |
| 121 | * The path to the fsi-master sysfs device to access |
| 122 | */ |
| 123 | const std::string fsiMasterPath; |
| 124 | |
| 125 | /** |
| 126 | * The path to the fsi slave sysfs base directory |
| 127 | */ |
| 128 | const std::string fsiSlaveBasePath; |
| 129 | |
| 130 | /** |
| 131 | * A container of Targets in the system |
| 132 | */ |
| 133 | std::vector<std::unique_ptr<Target>> targets; |
| 134 | }; |
| 135 | |
| 136 | } |
| 137 | } |