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