blob: 4fc5927ce47315318185fe1908f46fe1212b39d0 [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 Shelleyca9f6252019-10-25 21:17:30 -05005#include <register/hei_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{
42 public: // Constructors, destructor, assignment
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050043 /**
44 * @brief Constructor from components.
Zane Shelley6722b5b2020-05-12 22:09:04 -050045 * @param i_id Unique ID for all instances of this node.
46 * @param i_instance Instance of this node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050047 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050048 IsolationNode(NodeId_t i_id, Instance_t i_instance) :
49 iv_id(i_id), iv_instance(i_instance)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050050 {}
51
52 /** @brief Destructor. */
53 ~IsolationNode() = default;
54
55 private:
Zane Shelley981e56a2020-05-11 21:24:20 -050056 /** @brief Copy constructor. */
57 IsolationNode(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050058
Zane Shelley981e56a2020-05-11 21:24:20 -050059 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050060 IsolationNode& operator=(const IsolationNode&) = delete;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050061
62 private: // Instance variables
Zane Shelley6722b5b2020-05-12 22:09:04 -050063 /** The unique ID for all instances of this node. */
64 const NodeId_t iv_id;
65
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050066 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -050067 * A node may have multiple instances. All of which will have the same ID.
68 * This variable is used to distinguish between each instance of the node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050069 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050070 const Instance_t iv_instance;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050071
72 /**
73 * This register could report multiple types of attentions. We can use a
74 * register 'rule' (value) to find any active attentions for each attention
75 * type (key). A 'rule', like "register & ~mask", is a combination of
76 * HardwareRegister objects and virtual operator registers (all children
77 * of the Register class).
78 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050079 std::map<AttentionType_t, const RegisterPtr> iv_rules;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050080
81 /**
82 * Each bit (key) in this map indicates that an attention was driven from
83 * another register (value).
84 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050085 std::map<BitPosition_t, const std::shared_ptr<const IsolationNode>>
86 iv_children;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050087
88 public: // Member functions
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050089 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -050090 * @brief Finds all active attentions on this node. If an active bit is a
91 * leaf in the isolation tree, the bit's signature is added to the
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050092 * isolation data. Otherwise, this function is recursively called
Zane Shelley6722b5b2020-05-12 22:09:04 -050093 * to analyze the child node that is driving the attention in this
94 * node.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050095 * @param i_chip The target chip for isolation.
96 * @param i_attnType The target attention type to analyze on this register.
97 * Will assert a rule must exist for this attention type.
98 * @param io_isoData The isolation data returned back to the user
99 * application.
100 * @return True, if any active attentions found on this register.
101 * False, otherwise.
102 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500103 bool analyze(const Chip& i_chip, AttentionType_t i_attnType,
104 IsolationData& io_isoData) const;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500105
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500106 /**
107 * @brief Adds a register rule for the given attention type. See iv_rules
108 * for details.
109 *
110 * This is only intended to be used during initialization of the isolator.
Zane Shelley6722b5b2020-05-12 22:09:04 -0500111 * Will assert that a rule has not already been defined for this type.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500112 *
113 * @param The target attention type.
114 * @param The rule for this attention type.
115 */
Zane Shelley6722b5b2020-05-12 22:09:04 -0500116 void addRule(AttentionType_t i_attnType, RegisterPtr i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500117
118 /**
Zane Shelley6722b5b2020-05-12 22:09:04 -0500119 * @brief Adds a child node to analyze for the given bit position in this
120 * node. See iv_children for details.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500121 *
122 * This is only intended to be used during initialization of the isolator.
123 * Will assert that nothing has already been defined for this bit.
124 *
Zane Shelley6722b5b2020-05-12 22:09:04 -0500125 * @param The target bit on this node.
126 * @param The child node to analyze for the given bit.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500127 */
Zane Shelley6722b5b2020-05-12 22:09:04 -0500128 void addChild(BitPosition_t i_bit,
129 std::shared_ptr<const IsolationNode> i_child);
130
131 /** @return The node ID. */
132 NodeId_t getId() const
133 {
134 return iv_id;
135 }
136
137 /** @return The node instance. */
138 Instance_t getInstance() const
139 {
140 return iv_instance;
141 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500142
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500143 private: // Isolation stack and supporting functions.
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500144 /** When analyze() is called at the tree root, all recursive calls to
145 * analyze() will target the same chip and attention type. So we only need
146 * to keep track of the nodes that have been analyzed to avoid cyclic
147 * isolation (an infinite loop). In fact, we only need to keep track of the
148 * nodes directly from this node to the root node. As long as this node
149 * does not already exist in the list, we can be sure there will not be a
150 * loop. So the list can be treated as a stack. When analyze() is called on
151 * a node, that node is pushed to the top of the stack (as long as it
152 * doesn't already exist in the stack). Then, just before analyze() exits,
153 * this node can be popped off the top of the stack. Once all the recursive
154 * calls have returned back to the root node the stack should be empty.
155 */
Zane Shelley6722b5b2020-05-12 22:09:04 -0500156 static std::vector<std::shared_ptr<const IsolationNode>> cv_isolationStack;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500157
158 /**
159 * @brief Pushes this node to the top of the stack. Will assert that this
160 * node does not already exist in cv_isolationStack.
161 */
162 void pushIsolationStack() const;
163
164 /** @brief Pops the top node off of cv_isolationStack. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500165 void popIsolationStack() const
166 {
167 cv_isolationStack.pop_back();
168 }
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500169};
170
Zane Shelley6722b5b2020-05-12 22:09:04 -0500171/** Pointer management for IsolationNode objects. */
172using IsolationNodePtr = std::shared_ptr<const IsolationNode>;
Zane Shelley508ce582020-05-05 13:47:19 -0500173
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500174} // end namespace libhei