blob: 68e23893e8918fbae22698315a2258876b1a2491 [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
39
40 /**
41 * @brief Constructor from components.
42 * @param i_hwReg A reference to the HardwareRegister targeted for
43 * isolation.
44 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050045 explicit IsolationNode(const HardwareRegister& i_hwReg) :
Zane Shelley83da2452019-10-25 15:45:34 -050046 iv_hwReg(i_hwReg)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050047 {}
48
49 /** @brief Destructor. */
50 ~IsolationNode() = default;
51
52 private:
53
54 // This is needed to allow the flyweights to use the copy constructor, but
55 // not allow it to be used in general.
56 friend class Flyweight<IsolationNode>;
57
58 /**
59 * @brief Copy constructor.
60 *
61 * Needed by Flyweight class, but should not be allowed in general.
62 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050063 IsolationNode(const IsolationNode&) = default;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050064
65 /**
66 * @brief Explicitly disables assignment operator.
67 *
68 * This is redundant since the compilier will implicitly delete this because
69 * of the constant instance variables, but helps communicate it is not
70 * allowed.
71 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050072 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050073
74 private: // Instance variables
75
76 /**
77 * This is a reference to the HardwareRegister targeted for isolation by
78 * this instance of the class. The reference is required to maintain
79 * polymorphism.
80 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050081 const HardwareRegister& iv_hwReg;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050082
83 /**
84 * This register could report multiple types of attentions. We can use a
85 * register 'rule' (value) to find any active attentions for each attention
86 * type (key). A 'rule', like "register & ~mask", is a combination of
87 * HardwareRegister objects and virtual operator registers (all children
88 * of the Register class).
89 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050090 std::map<AttentionType_t, const Register*> iv_rules;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050091
92 /**
93 * Each bit (key) in this map indicates that an attention was driven from
94 * another register (value).
95 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050096 std::map<RegisterBit_t, const IsolationNode*> iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050097
98 public: // Member functions
99
100 /**
101 * @brief Finds all active attentions on this register. If an active bit is
102 * a leaf in the isolation tree, the bit's signature is added to the
103 * isolation data. Otherwise, this function is recursively called
104 * to analyze the child register that is driving the attention in
105 * this register.
106 * @param i_chip The target chip for isolation.
107 * @param i_attnType The target attention type to analyze on this register.
108 * Will assert a rule must exist for this attention type.
109 * @param io_isoData The isolation data returned back to the user
110 * application.
111 * @return True, if any active attentions found on this register.
112 * False, otherwise.
113 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500114 bool analyze(const Chip& i_chip, AttentionType_t i_attnType,
115 IsolationData& io_isoData) const;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500116
117 // TODO: The next two functions are only intended to be used during
118 // initialization of the isolator. Consider, making them private and
119 // make the Chip Data File code friends of this class. So that it has
120 // access to these init functions.
121
122 /**
123 * @brief Adds a register rule for the given attention type. See iv_rules
124 * for details.
125 *
126 * This is only intended to be used during initialization of the isolator.
127 * Will assert that nothing has already been defined for this rule.
128 *
129 * @param The target attention type.
130 * @param The rule for this attention type.
131 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500132 void addRule(AttentionType_t i_attnType, const Register* i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500133
134 /**
135 * @brief Adds a child register to analyze for the given bit in this
136 * register. See iv_children for details.
137 *
138 * This is only intended to be used during initialization of the isolator.
139 * Will assert that nothing has already been defined for this bit.
140 *
141 * @param The target bit on this register.
142 * @param The child register to analyze for the given bit.
143 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500144 void addChild(RegisterBit_t i_bit, const IsolationNode* i_child);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500145
146 public: // Operators
147
148 /** @brief Equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500149 bool operator==(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500150 {
151 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500152 return (iv_hwReg == i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500153 }
154
155 /** @brief Less than operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500156 bool operator<(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500157 {
158 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500159 return (iv_hwReg < i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500160 }
161
162 private: // Isolation stack and supporting functions.
163
164 /** When analyze() is called at the tree root, all recursive calls to
165 * analyze() will target the same chip and attention type. So we only need
166 * to keep track of the nodes that have been analyzed to avoid cyclic
167 * isolation (an infinite loop). In fact, we only need to keep track of the
168 * nodes directly from this node to the root node. As long as this node
169 * does not already exist in the list, we can be sure there will not be a
170 * loop. So the list can be treated as a stack. When analyze() is called on
171 * a node, that node is pushed to the top of the stack (as long as it
172 * doesn't already exist in the stack). Then, just before analyze() exits,
173 * this node can be popped off the top of the stack. Once all the recursive
174 * calls have returned back to the root node the stack should be empty.
175 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500176 static std::vector<const IsolationNode*> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500177
178 /**
179 * @brief Pushes this node to the top of the stack. Will assert that this
180 * node does not already exist in cv_isolationStack.
181 */
182 void pushIsolationStack() const;
183
184 /** @brief Pops the top node off of cv_isolationStack. */
185 void popIsolationStack() const { cv_isolationStack.pop_back(); }
186
187};
188
189} // end namespace libhei