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"; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 15 | |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 16 | constexpr auto fsiSlaveBaseDir = |
Edward A. James | 23763b1 | 2017-07-06 14:23:32 -0500 | [diff] [blame] | 17 | "/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] | 18 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 19 | /** |
| 20 | * Represents a specific P9 processor in the system. Used by |
| 21 | * the access APIs to specify the chip to operate on. |
| 22 | */ |
| 23 | class Target |
| 24 | { |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 25 | public: |
| 26 | /** |
| 27 | * Constructor |
| 28 | * |
| 29 | * @param[in] - The logical position of the target |
| 30 | * @param[in] - The sysfs device path |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 31 | */ |
Joel Stanley | afa1d22 | 2019-09-27 15:35:04 +0930 | [diff] [blame] | 32 | Target(size_t position, const std::string& devPath) : |
| 33 | pos(position), cfamPath(devPath) |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 34 | { |
| 35 | } |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 36 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 37 | Target() = delete; |
| 38 | ~Target() = default; |
| 39 | Target(const Target&) = default; |
| 40 | Target(Target&&) = default; |
| 41 | Target& operator=(Target&&) = default; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 42 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Returns the position |
| 45 | */ |
| 46 | inline auto getPos() const |
| 47 | { |
| 48 | return pos; |
| 49 | } |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 50 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Returns the CFAM sysfs path |
| 53 | */ |
| 54 | inline auto getCFAMPath() const |
| 55 | { |
| 56 | return cfamPath; |
| 57 | } |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 58 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Returns the file descriptor to use |
| 61 | * for read/writeCFAM operations. |
| 62 | */ |
| 63 | int getCFAMFD(); |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 64 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 65 | private: |
| 66 | /** |
| 67 | * The logical position of this target |
| 68 | */ |
| 69 | size_t pos; |
Edward A. James | 8316b77 | 2017-04-24 14:20:48 -0500 | [diff] [blame] | 70 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 71 | /** |
| 72 | * The sysfs device path for the CFAM |
| 73 | */ |
| 74 | const std::string cfamPath; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 75 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 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 | |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 82 | /** |
| 83 | * Class that manages processor targeting for FSI operations. |
| 84 | */ |
| 85 | class Targeting |
| 86 | { |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 87 | public: |
| 88 | /** |
| 89 | * Scans sysfs to find all processors and creates Target objects |
| 90 | * for them. |
| 91 | * @param[in] fsiMasterDev - the sysfs device for the master |
| 92 | * @param[in] fsiSlaveDirectory - the base sysfs dir for slaves |
| 93 | */ |
| 94 | Targeting(const std::string& fsiMasterDev, const std::string& fsiSlaveDir); |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 95 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 96 | Targeting() : Targeting(fsiMasterDevPath, fsiSlaveBaseDir) |
| 97 | { |
| 98 | } |
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 | ~Targeting() = default; |
| 101 | Targeting(const Targeting&) = default; |
| 102 | Targeting(Targeting&&) = default; |
| 103 | Targeting& operator=(Targeting&&) = default; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 104 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Returns a const iterator to the first target |
| 107 | */ |
| 108 | inline auto begin() |
| 109 | { |
| 110 | return targets.cbegin(); |
| 111 | } |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 112 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Returns a const iterator to the last (highest position) target. |
| 115 | */ |
| 116 | inline auto end() |
| 117 | { |
| 118 | return targets.cend(); |
| 119 | } |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 120 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Returns the number of targets |
| 123 | */ |
| 124 | inline auto size() |
| 125 | { |
| 126 | return targets.size(); |
| 127 | } |
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 target by position. |
| 131 | */ |
| 132 | std::unique_ptr<Target>& getTarget(size_t pos); |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 133 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 134 | private: |
| 135 | /** |
| 136 | * The path to the fsi-master sysfs device to access |
| 137 | */ |
| 138 | std::string fsiMasterPath; |
Michael Tritz | be40716 | 2017-03-30 16:52:24 -0500 | [diff] [blame] | 139 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 140 | /** |
| 141 | * The path to the fsi slave sysfs base directory |
| 142 | */ |
| 143 | std::string fsiSlaveBasePath; |
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 | * A container of Targets in the system |
| 147 | */ |
| 148 | std::vector<std::unique_ptr<Target>> targets; |
Matt Spinler | 2c05aa7 | 2017-02-28 09:48:13 -0600 | [diff] [blame] | 149 | }; |
| 150 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 151 | } // namespace targeting |
| 152 | } // namespace openpower |