blob: 2c30e0c0b0741e77309cedf81bae355144f2fa5f [file] [log] [blame]
Zane Shelleya61f4c52019-08-01 13:58:49 -05001#pragma once
2
Zane Shelley3a02e242020-05-08 16:25:36 -05003#include <hei_signature.hpp>
Zane Shelley995be6c2021-02-24 15:48:55 -06004#include <util/hei_bit_string.hpp>
Zane Shelley3a02e242020-05-08 16:25:36 -05005
Zane Shelley47ca5c22021-06-22 11:44:02 -05006#include <algorithm>
Zane Shelleydae1af62021-01-14 11:00:46 -06007#include <map>
8#include <memory>
Zane Shelley3a02e242020-05-08 16:25:36 -05009#include <vector>
Zane Shelleya61f4c52019-08-01 13:58:49 -050010
11namespace libhei
12{
13
14/**
Zane Shelleyb406de42019-09-09 16:10:38 -050015 * @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 Shelleya61f4c52019-08-01 13:58:49 -050019 */
20class IsolationData
21{
Zane Shelley93b61ad2019-10-16 20:41:03 -050022 public: // Constructors, destructor, assignment, etc.
Zane Shelleyb406de42019-09-09 16:10:38 -050023 /** @brief Default constructor. */
24 IsolationData() = default;
Zane Shelley5a266612019-08-15 16:23:53 -050025
26 /** @brief Destructor. */
27 ~IsolationData() = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050028
29 /** @brief Copy constructor. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050030 IsolationData(const IsolationData&) = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050031
32 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050033 IsolationData& operator=(const IsolationData&) = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050034
Zane Shelleydae1af62021-01-14 11:00:46 -060035 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) :
Patrick Williams8db65db2024-08-16 15:22:30 -040041 regId(i_regId), regInst(i_regInst), data(i_data)
Zane Shelleydae1af62021-01-14 11:00:46 -060042 {}
43
44 RegisterId_t regId; ///< 3-byte register ID
45 Instance_t regInst; ///< 1-byte register instance
46 std::shared_ptr<BitStringBuffer> data; ///< register data
Zane Shelley47ca5c22021-06-22 11:44:02 -050047
48 bool operator==(const RegDumpEntry& r) const
49 {
50 return regId == r.regId && regInst == r.regInst && *data == *r.data;
51 }
Zane Shelleydae1af62021-01-14 11:00:46 -060052 };
53
Zane Shelley93b61ad2019-10-16 20:41:03 -050054 private: // Instance variables
Zane Shelley93b61ad2019-10-16 20:41:03 -050055 /** A list of all signatures found during isolation. */
Zane Shelley91f1d3d2021-08-09 10:21:30 -050056 std::vector<Signature> iv_sigList;
Zane Shelleya61f4c52019-08-01 13:58:49 -050057
Zane Shelleydae1af62021-01-14 11:00:46 -060058 /**
59 * This intended to be a snapshot of the register values read from hardware
60 * as the isolator iterates the isolation tree. Therefore, it cannot share
61 * the values stored in the hardware register cache. Instead, it must be a
62 * copy of the data.
63 */
64 std::map<Chip, std::vector<RegDumpEntry>> iv_regDump;
Zane Shelley93b61ad2019-10-16 20:41:03 -050065
66 public: // Member functions
Zane Shelley93b61ad2019-10-16 20:41:03 -050067 /**
68 * @brief Adds a signature to the signature list.
69 * @param i_signature The target signature.
70 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050071 void addSignature(const Signature& i_signature)
Zane Shelley93b61ad2019-10-16 20:41:03 -050072 {
Zane Shelley91f1d3d2021-08-09 10:21:30 -050073 iv_sigList.push_back(i_signature);
Zane Shelley93b61ad2019-10-16 20:41:03 -050074 }
75
Zane Shelleydae1af62021-01-14 11:00:46 -060076 /**
77 * @brief Adds the contents of a register to the register dump.
78 * @param i_chip The chip associated with this register.
79 * @param i_regId The register ID.
80 * @param i_regInst The register instance.
81 * @param i_data A BitString containing the contents of the register.
82 * Note that this function will make a copy of the data,
83 * which will be stored separately from the hardware
84 * register cache.
85 */
86 void addRegister(const Chip& i_chip, RegisterId_t i_regId,
87 Instance_t i_regInst, const BitString* i_data)
88 {
89 if (!i_data->isZero()) // Only add non-zero values to save space.
90 {
91 // Make a copy of the register value.
92 auto data = std::make_shared<BitStringBuffer>(*i_data);
93
Zane Shelley47ca5c22021-06-22 11:44:02 -050094 // We'll want to avoid adding duplicate data if possible.
95 if (iv_regDump.end() == iv_regDump.find(i_chip))
96 {
97 // The chip doesn't exist in the map. Therefore, the data
98 // doesn't currently exist. So, add it.
99 iv_regDump[i_chip].emplace_back(i_regId, i_regInst, data);
100 }
101 else
102 {
103 // Search this chip for the data.
104 RegDumpEntry entry{i_regId, i_regInst, data};
105 auto itr = std::find(iv_regDump[i_chip].begin(),
106 iv_regDump[i_chip].end(), entry);
107
108 if (iv_regDump[i_chip].end() == itr)
109 {
110 // The data doesn't currently exist. So, add it.
111 iv_regDump[i_chip].push_back(entry);
112 }
113 }
Zane Shelleydae1af62021-01-14 11:00:46 -0600114 }
115 }
116
Zane Shelley93b61ad2019-10-16 20:41:03 -0500117 /** @brief Allows access to the signature list. */
Zane Shelley2e38ae52020-11-05 22:21:30 -0600118 const std::vector<Signature>& getSignatureList() const
Zane Shelley93b61ad2019-10-16 20:41:03 -0500119 {
Zane Shelley91f1d3d2021-08-09 10:21:30 -0500120 return iv_sigList;
Zane Shelley93b61ad2019-10-16 20:41:03 -0500121 }
122
Zane Shelleydae1af62021-01-14 11:00:46 -0600123 /** @brief Allows access to the register dump. */
124 const std::map<Chip, std::vector<RegDumpEntry>>& getRegisterDump() const
125 {
126 return iv_regDump;
127 }
128
Zane Shelley93b61ad2019-10-16 20:41:03 -0500129 /** @brief Flushes the data to ensure a clean slate for isolation. */
130 void flush()
131 {
Zane Shelley91f1d3d2021-08-09 10:21:30 -0500132 iv_sigList.clear();
Zane Shelleydae1af62021-01-14 11:00:46 -0600133 iv_regDump.clear();
Zane Shelley93b61ad2019-10-16 20:41:03 -0500134 }
Zane Shelley5a266612019-08-15 16:23:53 -0500135
Zane Shelleya61f4c52019-08-01 13:58:49 -0500136}; // end class IsolationData
137
138} // end namespace libhei