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