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