1 #pragma once 2 3 #include "filedescriptor.hpp" 4 5 #include <memory> 6 #include <vector> 7 8 namespace openpower 9 { 10 namespace targeting 11 { 12 13 constexpr auto fsiMasterDevPath = "/sys/class/fsi-master/fsi0/slave@00:00/raw"; 14 15 constexpr auto fsiSlaveBaseDir = "/sys/class/fsi-master/fsi1/"; 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 * 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), cfamPath(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 CFAM sysfs path 51 */ 52 inline auto getCFAMPath() const 53 { 54 return cfamPath; 55 } 56 57 /** 58 * Returns the file descriptor to use 59 * for read/writeCFAM operations. 60 */ 61 int getCFAMFD(); 62 63 private: 64 /** 65 * The logical position of this target 66 */ 67 size_t pos; 68 69 /** 70 * The sysfs device path for the CFAM 71 */ 72 const std::string cfamPath; 73 74 /** 75 * The file descriptor to use for read/writeCFAMReg 76 */ 77 std::unique_ptr<openpower::util::FileDescriptor> cfamFD; 78 }; 79 80 /** 81 * Class that manages processor targeting for FSI operations. 82 */ 83 class Targeting 84 { 85 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); 93 94 Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) 95 { 96 } 97 98 ~Targeting() = default; 99 Targeting(const Targeting&) = default; 100 Targeting(Targeting&&) = default; 101 Targeting& operator=(Targeting&&) = default; 102 103 /** 104 * Returns a const iterator to the first target 105 */ 106 inline auto begin() 107 { 108 return targets.cbegin(); 109 } 110 111 /** 112 * Returns a const iterator to the last (highest position) target. 113 */ 114 inline auto end() 115 { 116 return targets.cend(); 117 } 118 119 /** 120 * Returns the number of targets 121 */ 122 inline auto size() 123 { 124 return targets.size(); 125 } 126 127 /** 128 * Returns a target by position. 129 */ 130 std::unique_ptr<Target>& getTarget(size_t pos); 131 132 private: 133 /** 134 * The path to the fsi-master sysfs device to access 135 */ 136 std::string fsiMasterPath; 137 138 /** 139 * The path to the fsi slave sysfs base directory 140 */ 141 std::string fsiSlaveBasePath; 142 143 /** 144 * A container of Targets in the system 145 */ 146 std::vector<std::unique_ptr<Target>> targets; 147 }; 148 149 } // namespace targeting 150 } // namespace openpower 151