Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 3 | #include <hei_signature.hpp> |
Zane Shelley | 995be6c | 2021-02-24 15:48:55 -0600 | [diff] [blame] | 4 | #include <util/hei_bit_string.hpp> |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 5 | |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 6 | #include <algorithm> |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <memory> |
Zane Shelley | 3a02e24 | 2020-05-08 16:25:36 -0500 | [diff] [blame] | 9 | #include <vector> |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 10 | |
| 11 | namespace libhei |
| 12 | { |
| 13 | |
| 14 | /** |
Zane Shelley | b406de4 | 2019-09-09 16:10:38 -0500 | [diff] [blame] | 15 | * @brief The main isolate() API is given a list of chips to analyze. This class |
| 16 | * will contain a list of all active hardware errors found on those |
| 17 | * chips, the contents of any registers associated with the active |
| 18 | * errors, and any other data that can be useful for debug. |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 19 | */ |
| 20 | class IsolationData |
| 21 | { |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 22 | public: // Constructors, destructor, assignment, etc. |
Zane Shelley | b406de4 | 2019-09-09 16:10:38 -0500 | [diff] [blame] | 23 | /** @brief Default constructor. */ |
| 24 | IsolationData() = default; |
Zane Shelley | 5a26661 | 2019-08-15 16:23:53 -0500 | [diff] [blame] | 25 | |
| 26 | /** @brief Destructor. */ |
| 27 | ~IsolationData() = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 28 | |
| 29 | /** @brief Copy constructor. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 30 | IsolationData(const IsolationData&) = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 31 | |
| 32 | /** @brief Assignment operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 33 | IsolationData& operator=(const IsolationData&) = default; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 34 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 35 | public: |
| 36 | /** The data stored in each entry of the register dump. */ |
| 37 | struct RegDumpEntry |
| 38 | { |
| 39 | RegDumpEntry(RegisterId_t i_regId, Instance_t i_regInst, |
| 40 | std::shared_ptr<BitStringBuffer> i_data) : |
| 41 | regId(i_regId), |
| 42 | regInst(i_regInst), data(i_data) |
| 43 | {} |
| 44 | |
| 45 | RegisterId_t regId; ///< 3-byte register ID |
| 46 | Instance_t regInst; ///< 1-byte register instance |
| 47 | std::shared_ptr<BitStringBuffer> data; ///< register data |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 48 | |
| 49 | bool operator==(const RegDumpEntry& r) const |
| 50 | { |
| 51 | return regId == r.regId && regInst == r.regInst && *data == *r.data; |
| 52 | } |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 55 | private: // Instance variables |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 56 | /** A list of all signatures found during isolation. */ |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 57 | std::vector<Signature> iv_sigList; |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 58 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 59 | /** |
| 60 | * This intended to be a snapshot of the register values read from hardware |
| 61 | * as the isolator iterates the isolation tree. Therefore, it cannot share |
| 62 | * the values stored in the hardware register cache. Instead, it must be a |
| 63 | * copy of the data. |
| 64 | */ |
| 65 | std::map<Chip, std::vector<RegDumpEntry>> iv_regDump; |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 66 | |
| 67 | public: // Member functions |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 68 | /** |
| 69 | * @brief Adds a signature to the signature list. |
| 70 | * @param i_signature The target signature. |
| 71 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 72 | void addSignature(const Signature& i_signature) |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 73 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 74 | iv_sigList.push_back(i_signature); |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 77 | /** |
| 78 | * @brief Adds the contents of a register to the register dump. |
| 79 | * @param i_chip The chip associated with this register. |
| 80 | * @param i_regId The register ID. |
| 81 | * @param i_regInst The register instance. |
| 82 | * @param i_data A BitString containing the contents of the register. |
| 83 | * Note that this function will make a copy of the data, |
| 84 | * which will be stored separately from the hardware |
| 85 | * register cache. |
| 86 | */ |
| 87 | void addRegister(const Chip& i_chip, RegisterId_t i_regId, |
| 88 | Instance_t i_regInst, const BitString* i_data) |
| 89 | { |
| 90 | if (!i_data->isZero()) // Only add non-zero values to save space. |
| 91 | { |
| 92 | // Make a copy of the register value. |
| 93 | auto data = std::make_shared<BitStringBuffer>(*i_data); |
| 94 | |
Zane Shelley | 47ca5c2 | 2021-06-22 11:44:02 -0500 | [diff] [blame] | 95 | // We'll want to avoid adding duplicate data if possible. |
| 96 | if (iv_regDump.end() == iv_regDump.find(i_chip)) |
| 97 | { |
| 98 | // The chip doesn't exist in the map. Therefore, the data |
| 99 | // doesn't currently exist. So, add it. |
| 100 | iv_regDump[i_chip].emplace_back(i_regId, i_regInst, data); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | // Search this chip for the data. |
| 105 | RegDumpEntry entry{i_regId, i_regInst, data}; |
| 106 | auto itr = std::find(iv_regDump[i_chip].begin(), |
| 107 | iv_regDump[i_chip].end(), entry); |
| 108 | |
| 109 | if (iv_regDump[i_chip].end() == itr) |
| 110 | { |
| 111 | // The data doesn't currently exist. So, add it. |
| 112 | iv_regDump[i_chip].push_back(entry); |
| 113 | } |
| 114 | } |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 118 | /** @brief Allows access to the signature list. */ |
Zane Shelley | 2e38ae5 | 2020-11-05 22:21:30 -0600 | [diff] [blame] | 119 | const std::vector<Signature>& getSignatureList() const |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 120 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 121 | return iv_sigList; |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 124 | /** @brief Allows access to the register dump. */ |
| 125 | const std::map<Chip, std::vector<RegDumpEntry>>& getRegisterDump() const |
| 126 | { |
| 127 | return iv_regDump; |
| 128 | } |
| 129 | |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 130 | /** @brief Flushes the data to ensure a clean slate for isolation. */ |
| 131 | void flush() |
| 132 | { |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 133 | iv_sigList.clear(); |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 134 | iv_regDump.clear(); |
Zane Shelley | 93b61ad | 2019-10-16 20:41:03 -0500 | [diff] [blame] | 135 | } |
Zane Shelley | 5a26661 | 2019-08-15 16:23:53 -0500 | [diff] [blame] | 136 | |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 137 | /** @brief Queries the signature list for any checkstop attentions. */ |
| 138 | bool queryCheckstop() const |
| 139 | { |
| 140 | auto itr = std::find_if( |
Zane Shelley | b7005ca | 2023-03-24 15:23:59 -0500 | [diff] [blame^] | 141 | iv_sigList.begin(), iv_sigList.end(), |
| 142 | [](const auto& s) { return ATTN_TYPE_CHIP_CS == s.getAttnType(); }); |
Zane Shelley | 91f1d3d | 2021-08-09 10:21:30 -0500 | [diff] [blame] | 143 | |
| 144 | return iv_sigList.end() != itr; |
| 145 | } |
| 146 | |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 147 | }; // end class IsolationData |
| 148 | |
| 149 | } // end namespace libhei |