blob: 14620930716539f389bb5289ddb04f48e31ea682 [file] [log] [blame]
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05001#pragma once
2
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05003#include <hei_isolation_data.hpp>
Zane Shelleye8dc72c2020-05-14 16:40:52 -05004#include <register/hei_hardware_register.hpp>
Zane Shelleyd5073512021-01-14 12:51:18 -06005#include <util/hei_includes.hpp>
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05006
7namespace libhei
8{
9
10/**
Zane Shelley6722b5b2020-05-12 22:09:04 -050011 * @brief This class contains the isolation rules and bit definition for a node
12 * in a chip's error reporting structure.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050013 *
Zane Shelley6722b5b2020-05-12 22:09:04 -050014 * These objects are linked together to form a tree with a single root node. Any
15 * active bits found in a node will either indicate an active attention or that
16 * the attention originated in a child node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050017 *
18 * The primary function of this class is analyze(), which will do a depth-first
Zane Shelley6722b5b2020-05-12 22:09:04 -050019 * search of the tree to find all active attentions and add their signatures to
20 * the returned isolation data.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050021 *
22 * The tree structure is built from information in the Chip Data Files. It is
23 * possible that the tree could be built with loop in the isolation. This would
24 * be bug in the Chip Data Files. This class will keep track of all nodes that
25 * have been analyzed to prevent cyclic isolation (an infinite loop).
26 *
Zane Shelley6722b5b2020-05-12 22:09:04 -050027 * Each node instance will represent a register, or set of registers, that can
28 * be configured to represent one or more attention types. These configuration
29 * rules are a combination of hardware register objects and operator registers
30 * objects to define rules like "REG & ~MASK & CNFG", which reads "return all
31 * bits in REG that are not in MASK and set in CNFG". See the definition of the
32 * Register class for details on how this works.
Zane Shelleyd39aa572020-05-14 10:35:57 -050033 *
34 * This class cannot be added to the flyweights. There is no way to easily
35 * distinguish differences between nodes on different chips without comparing
36 * all of the capture registers, rules, and child nodes. Instead, the shared
37 * pointers will be stored in the isolation chip, which will ensure there isn't
38 * an attempt to add two nodes with the same ID and instance.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050039 */
40class IsolationNode
41{
Zane Shelley4de8ff82020-05-14 15:39:01 -050042 public: // Aliases
Patrick Williams2f7537d2023-05-10 07:51:39 -050043 using Ptr = std::shared_ptr<IsolationNode>;
Zane Shelley4de8ff82020-05-14 15:39:01 -050044 using ConstPtr = std::shared_ptr<const IsolationNode>;
45
46 using Key = std::pair<NodeId_t, Instance_t>;
47
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050048 public: // Constructors, destructor, assignment
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050049 /**
50 * @brief Constructor from components.
Zane Shelley6722b5b2020-05-12 22:09:04 -050051 * @param i_id Unique ID for all instances of this node.
52 * @param i_instance Instance of this node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050053 */
Zane Shelley6eb61902020-05-15 22:25:58 -050054 IsolationNode(NodeId_t i_id, Instance_t i_instance,
55 RegisterType_t i_regType) :
Patrick Williams8db65db2024-08-16 15:22:30 -040056 iv_id(i_id), iv_instance(i_instance), iv_regType(i_regType)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050057 {}
58
59 /** @brief Destructor. */
60 ~IsolationNode() = default;
61
Zane Shelley981e56a2020-05-11 21:24:20 -050062 /** @brief Copy constructor. */
63 IsolationNode(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050064
Zane Shelley981e56a2020-05-11 21:24:20 -050065 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050066 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050067
68 private: // Instance variables
Zane Shelley6722b5b2020-05-12 22:09:04 -050069 /** The unique ID for all instances of this node. */
70 const NodeId_t iv_id;
71
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050072 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -050073 * A node may have multiple instances. All of which will have the same ID.
74 * This variable is used to distinguish between each instance of the node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050075 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050076 const Instance_t iv_instance;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050077
78 /**
Zane Shelley6eb61902020-05-15 22:25:58 -050079 * A registers referenced by this node's rules must be of this type. No
80 * mixing of register types is allowed because comparing different sized
81 * registers is undefined behavior. Note that it is possible to have capture
82 * registers of mixed types.
83 */
84 const RegisterType_t iv_regType;
85
86 /**
Zane Shelley6b1fe162022-11-18 13:37:42 -060087 * The lists of register to capture and add to the log for additional
88 * debugging. The lists are indexed in a map where the key is a bit
89 * position. All registers that should be captured by default when
90 * isolating to this node will have a bit position of `MAX_BIT_POSITION`.
91 * Otherwise, any other list targeted for a specific bit will only be
92 * captured if there is an active attention on that bit.
Zane Shelleye8dc72c2020-05-14 16:40:52 -050093 */
Zane Shelley6b1fe162022-11-18 13:37:42 -060094 std::map<BitPosition_t, std::vector<HardwareRegister::ConstPtr>> iv_capRegs;
Zane Shelleye8dc72c2020-05-14 16:40:52 -050095
96 /**
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050097 * This register could report multiple types of attentions. We can use a
98 * register 'rule' (value) to find any active attentions for each attention
99 * type (key). A 'rule', like "register & ~mask", is a combination of
100 * HardwareRegister objects and virtual operator registers (all children
Zane Shelley6eb61902020-05-15 22:25:58 -0500101 * of the Register class). Note that all registers referenced by these rules
102 * must be the same type as iv_regType.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500103 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500104 std::map<AttentionType_t, const Register::ConstPtr> iv_rules;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500105
106 /**
107 * Each bit (key) in this map indicates that an attention was driven from
108 * another register (value).
109 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500110 std::map<BitPosition_t, const ConstPtr> iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500111
Caleb Palmerf2a29322024-07-25 13:14:26 -0500112 /**
113 * This map is used to store the write operation rules for the isolation
114 * node as defined in the Chip Data Files.
115 */
116 std::map<OpRuleName_t, std::pair<OpRuleType_t, RegisterId_t>> iv_op_rules;
117
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500118 public: // Member functions
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500119 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -0500120 * @brief Finds all active attentions on this node. If an active bit is a
121 * leaf in the isolation tree, the bit's signature is added to the
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500122 * isolation data. Otherwise, this function is recursively called
Zane Shelley6722b5b2020-05-12 22:09:04 -0500123 * to analyze the child node that is driving the attention in this
124 * node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500125 * @param i_chip The target chip for isolation.
126 * @param i_attnType The target attention type to analyze on this register.
127 * Will assert a rule must exist for this attention type.
128 * @param io_isoData The isolation data returned back to the user
129 * application.
130 * @return True, if any active attentions found on this register.
131 * False, otherwise.
132 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500133 bool analyze(const Chip& i_chip, AttentionType_t i_attnType,
134 IsolationData& io_isoData) const;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500135
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500136 /**
Zane Shelleye8dc72c2020-05-14 16:40:52 -0500137 * @brief Adds a hardware register to the list of registers that will be
138 * captured for additional debugging. See iv_capRegs for details.
139 *
140 * This is only intended to be used during initialization of the isolator.
141 * Duplicate registers will be ignored.
142 *
Zane Shelley6b1fe162022-11-18 13:37:42 -0600143 * @param i_hwReg The target hardware register.
144 * @param i_bit If specified, the given register should only be captured
145 * when there is an active attention on the given bit. If
146 * omitted, the given register will be captured any time
147 * this isolation node is analyzed.
Zane Shelleye8dc72c2020-05-14 16:40:52 -0500148 */
Zane Shelley6b1fe162022-11-18 13:37:42 -0600149 void addCaptureRegister(HardwareRegister::ConstPtr i_hwReg,
150 BitPosition_t i_bit = MAX_BIT_POSITION);
Zane Shelleye8dc72c2020-05-14 16:40:52 -0500151
152 /**
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500153 * @brief Adds a register rule for the given attention type. See iv_rules
154 * for details.
155 *
156 * This is only intended to be used during initialization of the isolator.
Zane Shelley6722b5b2020-05-12 22:09:04 -0500157 * Will assert that a rule has not already been defined for this type.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500158 *
Caleb Palmerf2a29322024-07-25 13:14:26 -0500159 * @param i_attnType The target attention type.
160 * @param i_rule The rule for this attention type.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500161 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500162 void addRule(AttentionType_t i_attnType, Register::ConstPtr i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500163
164 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -0500165 * @brief Adds a child node to analyze for the given bit position in this
166 * node. See iv_children for details.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500167 *
168 * This is only intended to be used during initialization of the isolator.
169 * Will assert that nothing has already been defined for this bit.
170 *
Caleb Palmerf2a29322024-07-25 13:14:26 -0500171 * @param i_bit The target bit on this node.
172 * @param i_child The child node to analyze for the given bit.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500173 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500174 void addChild(BitPosition_t i_bit, ConstPtr i_child);
Zane Shelley6722b5b2020-05-12 22:09:04 -0500175
Caleb Palmerf2a29322024-07-25 13:14:26 -0500176 /**
177 * @brief Adds a new write operation for the isolation node.
178 *
179 * This is only intended to be used during initialization of the isolator.
180 * Will assert that nothing has already been defined for this type.
181 *
182 * @param i_opName The name of the operation.
183 * @param i_opType The type of the operation.
184 * @param i_regId The ID of the register to be written.
185 */
186 void addOpRule(OpRuleName_t i_opName, OpRuleType_t i_opType,
187 RegisterId_t i_regId);
188
Caleb Palmere4ad4e32024-08-07 09:48:14 -0500189 /**
190 * @brief Returns a write operation for the isolation node based on the
191 * input operation name.
192 *
193 * @param i_name The name of the operation.
194 * @return The operation type and reg ID of the operation rule in a pair.
195 */
196 std::pair<OpRuleType_t, RegisterId_t> getOpRule(OpRuleName_t i_name) const;
197
198 /**
199 * @brief Returns whether the write operation rule exists for the node
200 *
201 * @param i_name The name of the operation.
202 * @return True if the operation exists, else false.
203 */
204 bool doesOpExist(OpRuleName_t i_name) const;
205
Zane Shelley6722b5b2020-05-12 22:09:04 -0500206 /** @return The node ID. */
207 NodeId_t getId() const
208 {
209 return iv_id;
210 }
211
212 /** @return The node instance. */
213 Instance_t getInstance() const
214 {
215 return iv_instance;
216 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500217
Zane Shelley4de8ff82020-05-14 15:39:01 -0500218 /** @return The node/instance key. */
219 Key getKey() const
220 {
221 return {iv_id, iv_instance};
222 }
223
Zane Shelley6eb61902020-05-15 22:25:58 -0500224 /** @return This node's register type.. */
225 RegisterType_t getRegisterType() const
226 {
227 return iv_regType;
228 }
229
Zane Shelley6b1fe162022-11-18 13:37:42 -0600230 private: // Member functions
231 /**
232 * @param i_chip The target chip for isolation.
233 * @param io_isoData The isolation data returned back to the user
234 * application.
235 * @param i_bit If specified, only the registers specifically
236 * targeted for the given bit are captured. If omitted,
237 * the default list of registers for this isolation node
238 * will be captured.
239 */
240 void captureRegisters(const Chip& i_chip, IsolationData& io_isoData,
241 BitPosition_t i_bit = MAX_BIT_POSITION) const;
242
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500243 private: // Isolation stack and supporting functions.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500244 /** When analyze() is called at the tree root, all recursive calls to
245 * analyze() will target the same chip and attention type. So we only need
246 * to keep track of the nodes that have been analyzed to avoid cyclic
247 * isolation (an infinite loop). In fact, we only need to keep track of the
248 * nodes directly from this node to the root node. As long as this node
249 * does not already exist in the list, we can be sure there will not be a
250 * loop. So the list can be treated as a stack. When analyze() is called on
251 * a node, that node is pushed to the top of the stack (as long as it
252 * doesn't already exist in the stack). Then, just before analyze() exits,
253 * this node can be popped off the top of the stack. Once all the recursive
254 * calls have returned back to the root node the stack should be empty.
255 */
Zane Shelley2467db82020-05-18 19:56:30 -0500256 static std::vector<const IsolationNode*> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500257
258 /**
259 * @brief Pushes this node to the top of the stack. Will assert that this
260 * node does not already exist in cv_isolationStack.
261 */
262 void pushIsolationStack() const;
263
264 /** @brief Pops the top node off of cv_isolationStack. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500265 void popIsolationStack() const
266 {
267 cv_isolationStack.pop_back();
268 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500269};
270
271} // end namespace libhei