blob: 65cf37b1324f780bd4248f093fcdf588e101b753 [file] [log] [blame]
Zane Shelleya61f4c52019-08-01 13:58:49 -05001#pragma once
2
Zane Shelleydae1af62021-01-14 11:00:46 -06003#include <hei_bit_string.hpp>
Zane Shelley3a02e242020-05-08 16:25:36 -05004#include <hei_signature.hpp>
5
Zane Shelleydae1af62021-01-14 11:00:46 -06006#include <map>
7#include <memory>
Zane Shelley3a02e242020-05-08 16:25:36 -05008#include <vector>
Zane Shelleya61f4c52019-08-01 13:58:49 -05009
10namespace libhei
11{
12
13/**
Zane Shelleyb406de42019-09-09 16:10:38 -050014 * @brief The main isolate() API is given a list of chips to analyze. This class
15 * will contain a list of all active hardware errors found on those
16 * chips, the contents of any registers associated with the active
17 * errors, and any other data that can be useful for debug.
Zane Shelleya61f4c52019-08-01 13:58:49 -050018 */
19class IsolationData
20{
Zane Shelley93b61ad2019-10-16 20:41:03 -050021 public: // Constructors, destructor, assignment, etc.
Zane Shelleyb406de42019-09-09 16:10:38 -050022 /** @brief Default constructor. */
23 IsolationData() = default;
Zane Shelley5a266612019-08-15 16:23:53 -050024
25 /** @brief Destructor. */
26 ~IsolationData() = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050027
28 /** @brief Copy constructor. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050029 IsolationData(const IsolationData&) = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050030
31 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050032 IsolationData& operator=(const IsolationData&) = default;
Zane Shelleya61f4c52019-08-01 13:58:49 -050033
Zane Shelleydae1af62021-01-14 11:00:46 -060034 public:
35 /** The data stored in each entry of the register dump. */
36 struct RegDumpEntry
37 {
38 RegDumpEntry(RegisterId_t i_regId, Instance_t i_regInst,
39 std::shared_ptr<BitStringBuffer> i_data) :
40 regId(i_regId),
41 regInst(i_regInst), data(i_data)
42 {}
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
47 };
48
Zane Shelley93b61ad2019-10-16 20:41:03 -050049 private: // Instance variables
Zane Shelley93b61ad2019-10-16 20:41:03 -050050 /** A list of all signatures found during isolation. */
51 std::vector<Signature> iv_sigLists;
Zane Shelleya61f4c52019-08-01 13:58:49 -050052
Zane Shelleydae1af62021-01-14 11:00:46 -060053 /**
54 * This intended to be a snapshot of the register values read from hardware
55 * as the isolator iterates the isolation tree. Therefore, it cannot share
56 * the values stored in the hardware register cache. Instead, it must be a
57 * copy of the data.
58 */
59 std::map<Chip, std::vector<RegDumpEntry>> iv_regDump;
Zane Shelley93b61ad2019-10-16 20:41:03 -050060
61 public: // Member functions
Zane Shelley93b61ad2019-10-16 20:41:03 -050062 /**
63 * @brief Adds a signature to the signature list.
64 * @param i_signature The target signature.
65 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050066 void addSignature(const Signature& i_signature)
Zane Shelley93b61ad2019-10-16 20:41:03 -050067 {
Zane Shelley83da2452019-10-25 15:45:34 -050068 iv_sigLists.push_back(i_signature);
Zane Shelley93b61ad2019-10-16 20:41:03 -050069 }
70
Zane Shelleydae1af62021-01-14 11:00:46 -060071 /**
72 * @brief Adds the contents of a register to the register dump.
73 * @param i_chip The chip associated with this register.
74 * @param i_regId The register ID.
75 * @param i_regInst The register instance.
76 * @param i_data A BitString containing the contents of the register.
77 * Note that this function will make a copy of the data,
78 * which will be stored separately from the hardware
79 * register cache.
80 */
81 void addRegister(const Chip& i_chip, RegisterId_t i_regId,
82 Instance_t i_regInst, const BitString* i_data)
83 {
84 if (!i_data->isZero()) // Only add non-zero values to save space.
85 {
86 // Make a copy of the register value.
87 auto data = std::make_shared<BitStringBuffer>(*i_data);
88
89 // Add to the list.
90 iv_regDump[i_chip].emplace_back(i_regId, i_regInst, data);
91 }
92 }
93
Zane Shelley93b61ad2019-10-16 20:41:03 -050094 /** @brief Allows access to the signature list. */
Zane Shelley2e38ae52020-11-05 22:21:30 -060095 const std::vector<Signature>& getSignatureList() const
Zane Shelley93b61ad2019-10-16 20:41:03 -050096 {
97 return iv_sigLists;
98 }
99
Zane Shelleydae1af62021-01-14 11:00:46 -0600100 /** @brief Allows access to the register dump. */
101 const std::map<Chip, std::vector<RegDumpEntry>>& getRegisterDump() const
102 {
103 return iv_regDump;
104 }
105
Zane Shelley93b61ad2019-10-16 20:41:03 -0500106 /** @brief Flushes the data to ensure a clean slate for isolation. */
107 void flush()
108 {
109 iv_sigLists.clear();
Zane Shelleydae1af62021-01-14 11:00:46 -0600110 iv_regDump.clear();
Zane Shelley93b61ad2019-10-16 20:41:03 -0500111 }
Zane Shelley5a266612019-08-15 16:23:53 -0500112
Zane Shelleya61f4c52019-08-01 13:58:49 -0500113}; // end class IsolationData
114
115} // end namespace libhei