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