blob: 2546a93cd68b9813ab9391a6348121aa0f1c910a [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 Shelleye8dc72c2020-05-14 16:40:52 -05005#include <register/hei_hardware_register.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
43 using Ptr = std::shared_ptr<IsolationNode>;
44 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 Shelley6722b5b2020-05-12 22:09:04 -050054 IsolationNode(NodeId_t i_id, Instance_t i_instance) :
55 iv_id(i_id), iv_instance(i_instance)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050056 {}
57
58 /** @brief Destructor. */
59 ~IsolationNode() = default;
60
Zane Shelley981e56a2020-05-11 21:24:20 -050061 /** @brief Copy constructor. */
62 IsolationNode(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050063
Zane Shelley981e56a2020-05-11 21:24:20 -050064 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050065 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050066
67 private: // Instance variables
Zane Shelley6722b5b2020-05-12 22:09:04 -050068 /** The unique ID for all instances of this node. */
69 const NodeId_t iv_id;
70
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050071 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -050072 * A node may have multiple instances. All of which will have the same ID.
73 * This variable is used to distinguish between each instance of the node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050074 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050075 const Instance_t iv_instance;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050076
77 /**
Zane Shelleye8dc72c2020-05-14 16:40:52 -050078 * The list of register to capture and add to the log for additional
79 * debugging.
80 */
81 std::vector<HardwareRegister::ConstPtr> iv_capRegs;
82
83 /**
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050084 * 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 Shelley4de8ff82020-05-14 15:39:01 -050090 std::map<AttentionType_t, const Register::ConstPtr> 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 Shelley4de8ff82020-05-14 15:39:01 -050096 std::map<BitPosition_t, const ConstPtr> iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050097
98 public: // Member functions
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050099 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -0500100 * @brief Finds all active attentions on this node. If an active bit is a
101 * leaf in the isolation tree, the bit's signature is added to the
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500102 * isolation data. Otherwise, this function is recursively called
Zane Shelley6722b5b2020-05-12 22:09:04 -0500103 * to analyze the child node that is driving the attention in this
104 * node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500105 * @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
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500116 /**
Zane Shelleye8dc72c2020-05-14 16:40:52 -0500117 * @brief Adds a hardware register to the list of registers that will be
118 * captured for additional debugging. See iv_capRegs for details.
119 *
120 * This is only intended to be used during initialization of the isolator.
121 * Duplicate registers will be ignored.
122 *
123 * @param The target hardware register.
124 */
125 void addCaptureRegister(HardwareRegister::ConstPtr i_hwReg);
126
127 /**
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500128 * @brief Adds a register rule for the given attention type. See iv_rules
129 * for details.
130 *
131 * This is only intended to be used during initialization of the isolator.
Zane Shelley6722b5b2020-05-12 22:09:04 -0500132 * Will assert that a rule has not already been defined for this type.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500133 *
134 * @param The target attention type.
135 * @param The rule for this attention type.
136 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500137 void addRule(AttentionType_t i_attnType, Register::ConstPtr i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500138
139 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -0500140 * @brief Adds a child node to analyze for the given bit position in this
141 * node. See iv_children for details.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500142 *
143 * This is only intended to be used during initialization of the isolator.
144 * Will assert that nothing has already been defined for this bit.
145 *
Zane Shelley6722b5b2020-05-12 22:09:04 -0500146 * @param The target bit on this node.
147 * @param The child node to analyze for the given bit.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500148 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500149 void addChild(BitPosition_t i_bit, ConstPtr i_child);
Zane Shelley6722b5b2020-05-12 22:09:04 -0500150
151 /** @return The node ID. */
152 NodeId_t getId() const
153 {
154 return iv_id;
155 }
156
157 /** @return The node instance. */
158 Instance_t getInstance() const
159 {
160 return iv_instance;
161 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500162
Zane Shelley4de8ff82020-05-14 15:39:01 -0500163 /** @return The node/instance key. */
164 Key getKey() const
165 {
166 return {iv_id, iv_instance};
167 }
168
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500169 private: // Isolation stack and supporting functions.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500170 /** When analyze() is called at the tree root, all recursive calls to
171 * analyze() will target the same chip and attention type. So we only need
172 * to keep track of the nodes that have been analyzed to avoid cyclic
173 * isolation (an infinite loop). In fact, we only need to keep track of the
174 * nodes directly from this node to the root node. As long as this node
175 * does not already exist in the list, we can be sure there will not be a
176 * loop. So the list can be treated as a stack. When analyze() is called on
177 * a node, that node is pushed to the top of the stack (as long as it
178 * doesn't already exist in the stack). Then, just before analyze() exits,
179 * this node can be popped off the top of the stack. Once all the recursive
180 * calls have returned back to the root node the stack should be empty.
181 */
Zane Shelley4de8ff82020-05-14 15:39:01 -0500182 static std::vector<ConstPtr> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500183
184 /**
185 * @brief Pushes this node to the top of the stack. Will assert that this
186 * node does not already exist in cv_isolationStack.
187 */
188 void pushIsolationStack() const;
189
190 /** @brief Pops the top node off of cv_isolationStack. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500191 void popIsolationStack() const
192 {
193 cv_isolationStack.pop_back();
194 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500195};
196
197} // end namespace libhei