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 = |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 13 | "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/raw"; |
| 14 | constexpr auto fsiMasterDevPathOld = |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 15 | "/sys/devices/platform/fsi-master/slave@00:00/raw"; |
| 16 | |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 17 | constexpr auto fsiSlaveBaseDir = |
Edward A. James | 23763b1 | 2017-07-06 14:23:32 -0500 | [diff] [blame] | 18 | "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/00:00:00:0a/fsi1/"; |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 19 | constexpr auto fsiSlaveBaseDirOld = |
| 20 | "/sys/devices/platform/fsi-master/slave@00:00/hub@00/"; |
| 21 | |
| 22 | typedef uint32_t (*swap_endian_t)(uint32_t); |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Represents a specific P9 processor in the system. Used by |
| 26 | * the access APIs to specify the chip to operate on. |
| 27 | */ |
| 28 | class Target |
| 29 | { |
| 30 | public: |
| 31 | |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @param[in] - The logical position of the target |
| 36 | * @param[in] - The sysfs device path |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 37 | * @param[in] - The function pointer for swapping endianness |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 38 | */ |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 39 | Target(size_t position, const std::string& devPath, |
| 40 | const swap_endian_t swapper) : |
| 41 | pos(position), cfamPath(devPath), doSwapEndian(swapper) |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
| 45 | Target() = delete; |
| 46 | ~Target() = default; |
| 47 | Target(const Target&) = default; |
| 48 | Target(Target&&) = default; |
| 49 | Target& operator=(Target&&) = default; |
| 50 | |
| 51 | /** |
| 52 | * Returns the position |
| 53 | */ |
| 54 | inline auto getPos() const |
| 55 | { |
| 56 | return pos; |
| 57 | } |
| 58 | |
| 59 | /** |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 60 | * Returns the CFAM sysfs path |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 61 | */ |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 62 | inline auto getCFAMPath() const |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 63 | { |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 64 | return cfamPath; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 65 | } |
| 66 | |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 67 | /** |
| 68 | * Returns the file descriptor to use |
| 69 | * for read/writeCFAM operations. |
| 70 | */ |
| 71 | int getCFAMFD(); |
| 72 | |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 73 | /** |
| 74 | * Returns correct byte-order data. (May or may not swap it depending |
| 75 | * on the function received during construction from Targeting and the |
| 76 | * host endianness). |
| 77 | */ |
| 78 | inline uint32_t swapEndian(uint32_t data) const |
| 79 | { |
| 80 | return doSwapEndian(data); |
| 81 | } |
| 82 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 83 | private: |
| 84 | |
| 85 | /** |
| 86 | * The logical position of this target |
| 87 | */ |
| 88 | size_t pos; |
| 89 | |
| 90 | /** |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 91 | * The sysfs device path for the CFAM |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 92 | */ |
Matt Spinler | c3bffed | 2017-03-10 09:05:30 -0600 | [diff] [blame] | 93 | const std::string cfamPath; |
| 94 | |
| 95 | /** |
| 96 | * The file descriptor to use for read/writeCFAMReg |
| 97 | */ |
| 98 | std::unique_ptr<openpower::util::FileDescriptor> cfamFD; |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * The function pointer for swapping endianness |
| 102 | */ |
| 103 | const swap_endian_t doSwapEndian; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | |
| 107 | /** |
| 108 | * Class that manages processor targeting for FSI operations. |
| 109 | */ |
| 110 | class Targeting |
| 111 | { |
| 112 | public: |
| 113 | |
| 114 | /** |
| 115 | * Scans sysfs to find all processors and creates Target objects |
| 116 | * for them. |
| 117 | * @param[in] fsiMasterDev - the sysfs device for the master |
| 118 | * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves |
| 119 | */ |
| 120 | Targeting(const std::string& fsiMasterDev, |
| 121 | const std::string& fsiSlaveDir); |
| 122 | |
| 123 | Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) {} |
| 124 | |
| 125 | ~Targeting() = default; |
| 126 | Targeting(const Targeting&) = default; |
| 127 | Targeting(Targeting&&) = default; |
| 128 | Targeting& operator=(Targeting&&) = default; |
| 129 | |
| 130 | /** |
| 131 | * Returns a const iterator to the first target |
| 132 | */ |
| 133 | inline auto begin() |
| 134 | { |
| 135 | return targets.cbegin(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns a const iterator to the last (highest position) target. |
| 140 | */ |
| 141 | inline auto end() |
| 142 | { |
| 143 | return targets.cend(); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns the number of targets |
| 148 | */ |
| 149 | inline auto size() |
| 150 | { |
| 151 | return targets.size(); |
| 152 | } |
| 153 | |
Michael Tritz | be40716 | 2017-03-30 16:52:24 -0500 | [diff] [blame] | 154 | /** |
| 155 | * Returns a target by position. |
| 156 | */ |
| 157 | std::unique_ptr<Target>& getTarget(size_t pos); |
| 158 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 159 | private: |
| 160 | |
| 161 | /** |
| 162 | * The path to the fsi-master sysfs device to access |
| 163 | */ |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 164 | std::string fsiMasterPath; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * The path to the fsi slave sysfs base directory |
| 168 | */ |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 169 | std::string fsiSlaveBasePath; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * A container of Targets in the system |
| 173 | */ |
| 174 | std::vector<std::unique_ptr<Target>> targets; |
| 175 | }; |
| 176 | |
| 177 | } |
| 178 | } |