blob: eedde91afb043a3734bf7f4b66daffc0df190665 [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 Shelley7bf1f6d2019-10-18 16:03:51 -050051 // This is needed to allow the flyweights to use the copy constructor, but
52 // not allow it to be used in general.
53 friend class Flyweight<IsolationNode>;
54
55 /**
56 * @brief Copy constructor.
57 *
58 * Needed by Flyweight class, but should not be allowed in general.
59 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050060 IsolationNode(const IsolationNode&) = default;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050061
62 /**
63 * @brief Explicitly disables assignment operator.
64 *
65 * This is redundant since the compilier will implicitly delete this because
66 * of the constant instance variables, but helps communicate it is not
67 * allowed.
68 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050069 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050070
71 private: // Instance variables
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050072 /**
73 * This is a reference to the HardwareRegister targeted for isolation by
74 * this instance of the class. The reference is required to maintain
75 * polymorphism.
76 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050077 const HardwareRegister& iv_hwReg;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050078
79 /**
80 * This register could report multiple types of attentions. We can use a
81 * register 'rule' (value) to find any active attentions for each attention
82 * type (key). A 'rule', like "register & ~mask", is a combination of
83 * HardwareRegister objects and virtual operator registers (all children
84 * of the Register class).
85 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050086 std::map<AttentionType_t, const Register*> iv_rules;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050087
88 /**
89 * Each bit (key) in this map indicates that an attention was driven from
90 * another register (value).
91 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050092 std::map<RegisterBit_t, const IsolationNode*> iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050093
94 public: // Member functions
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050095 /**
96 * @brief Finds all active attentions on this register. If an active bit is
97 * a leaf in the isolation tree, the bit's signature is added to the
98 * isolation data. Otherwise, this function is recursively called
99 * to analyze the child register that is driving the attention in
100 * this register.
101 * @param i_chip The target chip for isolation.
102 * @param i_attnType The target attention type to analyze on this register.
103 * Will assert a rule must exist for this attention type.
104 * @param io_isoData The isolation data returned back to the user
105 * application.
106 * @return True, if any active attentions found on this register.
107 * False, otherwise.
108 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500109 bool analyze(const Chip& i_chip, AttentionType_t i_attnType,
110 IsolationData& io_isoData) const;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500111
112 // TODO: The next two functions are only intended to be used during
113 // initialization of the isolator. Consider, making them private and
114 // make the Chip Data File code friends of this class. So that it has
115 // access to these init functions.
116
117 /**
118 * @brief Adds a register rule for the given attention type. See iv_rules
119 * for details.
120 *
121 * This is only intended to be used during initialization of the isolator.
122 * Will assert that nothing has already been defined for this rule.
123 *
124 * @param The target attention type.
125 * @param The rule for this attention type.
126 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500127 void addRule(AttentionType_t i_attnType, const Register* i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500128
129 /**
130 * @brief Adds a child register to analyze for the given bit in this
131 * register. See iv_children for details.
132 *
133 * This is only intended to be used during initialization of the isolator.
134 * Will assert that nothing has already been defined for this bit.
135 *
136 * @param The target bit on this register.
137 * @param The child register to analyze for the given bit.
138 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500139 void addChild(RegisterBit_t i_bit, const IsolationNode* i_child);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500140
141 public: // Operators
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500142 /** @brief Equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500143 bool operator==(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500144 {
145 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500146 return (iv_hwReg == i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500147 }
148
149 /** @brief Less than operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500150 bool operator<(const IsolationNode& i_r) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500151 {
152 // iv_hwReg should be unique per IsolationNode.
Zane Shelley83da2452019-10-25 15:45:34 -0500153 return (iv_hwReg < i_r.iv_hwReg);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500154 }
155
156 private: // Isolation stack and supporting functions.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500157 /** When analyze() is called at the tree root, all recursive calls to
158 * analyze() will target the same chip and attention type. So we only need
159 * to keep track of the nodes that have been analyzed to avoid cyclic
160 * isolation (an infinite loop). In fact, we only need to keep track of the
161 * nodes directly from this node to the root node. As long as this node
162 * does not already exist in the list, we can be sure there will not be a
163 * loop. So the list can be treated as a stack. When analyze() is called on
164 * a node, that node is pushed to the top of the stack (as long as it
165 * doesn't already exist in the stack). Then, just before analyze() exits,
166 * this node can be popped off the top of the stack. Once all the recursive
167 * calls have returned back to the root node the stack should be empty.
168 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500169 static std::vector<const IsolationNode*> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500170
171 /**
172 * @brief Pushes this node to the top of the stack. Will assert that this
173 * node does not already exist in cv_isolationStack.
174 */
175 void pushIsolationStack() const;
176
177 /** @brief Pops the top node off of cv_isolationStack. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500178 void popIsolationStack() const
179 {
180 cv_isolationStack.pop_back();
181 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500182};
183
Zane Shelleydd69c962020-05-05 22:19:11 -0500184/** Pointer management for isolation nodes. */
185using IsolationNodePtr = std::shared_ptr<IsolationNode>;
186
Zane Shelley508ce582020-05-05 13:47:19 -0500187/** Simple map to ensure only one root IsolationNode per attention type. */
Zane Shelleydd69c962020-05-05 22:19:11 -0500188using RootNodeMap = std::map<AttentionType_t, const IsolationNodePtr>;
Zane Shelley508ce582020-05-05 13:47:19 -0500189
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500190} // end namespace libhei