blob: 4cf44ddbfee3384c16652ec561600b039f984fae [file] [log] [blame]
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05001#pragma once
2
3#include <hei_includes.hpp>
4#include <hei_isolation_data.hpp>
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05005#include <register/hei_hardware_register.hpp>
Zane Shelleyca9f6252019-10-25 21:17:30 -05006#include <register/hei_register.hpp>
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05007#include <util/hei_bit_string.hpp>
8#include <util/hei_flyweight.hpp>
9
10namespace libhei
11{
12
13/**
14 * @brief This class contains the isolation rules and bit definition of a
15 * HardwareRegister used for error isolation.
16 *
17 * These objects are linked together as a tree. Any active bits in the
18 * associated register will either be a true active attention (leaf node) or
19 * indicate one or more active attentions occurred in a child node.
20 *
21 * The primary function of this class is analyze(), which will do a depth-first
22 * search of the tree to find all leaves and add their signatures to the
23 * returned isolation data.
24 *
25 * The tree structure is built from information in the Chip Data Files. It is
26 * possible that the tree could be built with loop in the isolation. This would
27 * be bug in the Chip Data Files. This class will keep track of all nodes that
28 * have been analyzed to prevent cyclic isolation (an infinite loop).
29 *
30 * Each isolation register will have a rule for each supported attention type.
31 * These rules are a combination of HardwareRegisters and operator registers to
32 * define rules like "REG & ~MASK & CNFG", which reads "return all bits in REG
33 * that are not in MASK and set in CNFG". See the definition of the Register
34 * class for details on how this works.
35 */
36class IsolationNode
37{
38 public: // Constructors, destructor, assignment
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050039 /**
40 * @brief Constructor from components.
41 * @param i_hwReg A reference to the HardwareRegister targeted for
42 * isolation.
43 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050044 explicit IsolationNode(const HardwareRegister& i_hwReg) : iv_hwReg(i_hwReg)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050045 {}
46
47 /** @brief Destructor. */
48 ~IsolationNode() = default;
49
50 private:
Zane Shelley981e56a2020-05-11 21:24:20 -050051 /** @brief Copy constructor. */
52 IsolationNode(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050053
Zane Shelley981e56a2020-05-11 21:24:20 -050054 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050055 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050056
57 private: // Instance variables
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050058 /**
59 * This is a reference to the HardwareRegister targeted for isolation by
60 * this instance of the class. The reference is required to maintain
61 * polymorphism.
62 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050063 const HardwareRegister& iv_hwReg;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050064
65 /**
66 * This register could report multiple types of attentions. We can use a
67 * register 'rule' (value) to find any active attentions for each attention
68 * type (key). A 'rule', like "register & ~mask", is a combination of
69 * HardwareRegister objects and virtual operator registers (all children
70 * of the Register class).
71 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050072 std::map<AttentionType_t, const Register*> iv_rules;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050073
74 /**
75 * Each bit (key) in this map indicates that an attention was driven from
76 * another register (value).
77 */
Zane Shelley13b182b2020-05-07 20:23:45 -050078 std::map<BitPosition_t, const IsolationNode*> iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050079
80 public: // Member functions
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050081 /**
82 * @brief Finds all active attentions on this register. If an active bit is
83 * a leaf in the isolation tree, the bit's signature is added to the
84 * isolation data. Otherwise, this function is recursively called
85 * to analyze the child register that is driving the attention in
86 * this register.
87 * @param i_chip The target chip for isolation.
88 * @param i_attnType The target attention type to analyze on this register.
89 * Will assert a rule must exist for this attention type.
90 * @param io_isoData The isolation data returned back to the user
91 * application.
92 * @return True, if any active attentions found on this register.
93 * False, otherwise.
94 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050095 bool analyze(const Chip& i_chip, AttentionType_t i_attnType,
96 IsolationData& io_isoData) const;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050097
98 // TODO: The next two functions are only intended to be used during
99 // initialization of the isolator. Consider, making them private and
100 // make the Chip Data File code friends of this class. So that it has
101 // access to these init functions.
102
103 /**
104 * @brief Adds a register rule for the given attention type. See iv_rules
105 * for details.
106 *
107 * This is only intended to be used during initialization of the isolator.
108 * Will assert that nothing has already been defined for this rule.
109 *
110 * @param The target attention type.
111 * @param The rule for this attention type.
112 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500113 void addRule(AttentionType_t i_attnType, const Register* i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500114
115 /**
116 * @brief Adds a child register to analyze for the given bit in this
117 * register. See iv_children for details.
118 *
119 * This is only intended to be used during initialization of the isolator.
120 * Will assert that nothing has already been defined for this bit.
121 *
122 * @param The target bit on this register.
123 * @param The child register to analyze for the given bit.
124 */
Zane Shelley13b182b2020-05-07 20:23:45 -0500125 void addChild(BitPosition_t i_bit, const IsolationNode* i_child);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500126
127 public: // Operators
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500128 /** @brief Equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500129 bool operator==(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500130 {
131 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500132 return (iv_hwReg == i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500133 }
134
135 /** @brief Less than operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500136 bool operator<(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500137 {
138 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500139 return (iv_hwReg < i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500140 }
141
142 private: // Isolation stack and supporting functions.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500143 /** When analyze() is called at the tree root, all recursive calls to
144 * analyze() will target the same chip and attention type. So we only need
145 * to keep track of the nodes that have been analyzed to avoid cyclic
146 * isolation (an infinite loop). In fact, we only need to keep track of the
147 * nodes directly from this node to the root node. As long as this node
148 * does not already exist in the list, we can be sure there will not be a
149 * loop. So the list can be treated as a stack. When analyze() is called on
150 * a node, that node is pushed to the top of the stack (as long as it
151 * doesn't already exist in the stack). Then, just before analyze() exits,
152 * this node can be popped off the top of the stack. Once all the recursive
153 * calls have returned back to the root node the stack should be empty.
154 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500155 static std::vector<const IsolationNode*> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500156
157 /**
158 * @brief Pushes this node to the top of the stack. Will assert that this
159 * node does not already exist in cv_isolationStack.
160 */
161 void pushIsolationStack() const;
162
163 /** @brief Pops the top node off of cv_isolationStack. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500164 void popIsolationStack() const
165 {
166 cv_isolationStack.pop_back();
167 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500168};
169
Zane Shelleydd69c962020-05-05 22:19:11 -0500170/** Pointer management for isolation nodes. */
171using IsolationNodePtr = std::shared_ptr<IsolationNode>;
172
Zane Shelley508ce582020-05-05 13:47:19 -0500173/** Simple map to ensure only one root IsolationNode per attention type. */
Zane Shelleydd69c962020-05-05 22:19:11 -0500174using RootNodeMap = std::map<AttentionType_t, const IsolationNodePtr>;
Zane Shelley508ce582020-05-05 13:47:19 -0500175
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500176} // end namespace libhei