Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <hei_includes.hpp> |
| 4 | #include <hei_isolation_data.hpp> |
Zane Shelley | ca9f625 | 2019-10-25 21:17:30 -0500 | [diff] [blame] | 5 | #include <register/hei_register.hpp> |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 6 | |
| 7 | namespace libhei |
| 8 | { |
| 9 | |
| 10 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 11 | * @brief This class contains the isolation rules and bit definition for a node |
| 12 | * in a chip's error reporting structure. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 13 | * |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 14 | * 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 Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 17 | * |
| 18 | * The primary function of this class is analyze(), which will do a depth-first |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 19 | * search of the tree to find all active attentions and add their signatures to |
| 20 | * the returned isolation data. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 21 | * |
| 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 Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 27 | * 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 Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 33 | */ |
| 34 | class IsolationNode |
| 35 | { |
| 36 | public: // Constructors, destructor, assignment |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 37 | /** |
| 38 | * @brief Constructor from components. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 39 | * @param i_id Unique ID for all instances of this node. |
| 40 | * @param i_instance Instance of this node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 41 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 42 | IsolationNode(NodeId_t i_id, Instance_t i_instance) : |
| 43 | iv_id(i_id), iv_instance(i_instance) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 44 | {} |
| 45 | |
| 46 | /** @brief Destructor. */ |
| 47 | ~IsolationNode() = default; |
| 48 | |
| 49 | private: |
Zane Shelley | 981e56a | 2020-05-11 21:24:20 -0500 | [diff] [blame] | 50 | /** @brief Copy constructor. */ |
| 51 | IsolationNode(const IsolationNode&) = delete; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 52 | |
Zane Shelley | 981e56a | 2020-05-11 21:24:20 -0500 | [diff] [blame] | 53 | /** @brief Assignment operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 54 | IsolationNode& operator=(const IsolationNode&) = delete; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 55 | |
| 56 | private: // Instance variables |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 57 | /** The unique ID for all instances of this node. */ |
| 58 | const NodeId_t iv_id; |
| 59 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 60 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 61 | * A node may have multiple instances. All of which will have the same ID. |
| 62 | * This variable is used to distinguish between each instance of the node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 63 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 64 | const Instance_t iv_instance; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * This register could report multiple types of attentions. We can use a |
| 68 | * register 'rule' (value) to find any active attentions for each attention |
| 69 | * type (key). A 'rule', like "register & ~mask", is a combination of |
| 70 | * HardwareRegister objects and virtual operator registers (all children |
| 71 | * of the Register class). |
| 72 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 73 | std::map<AttentionType_t, const RegisterPtr> iv_rules; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Each bit (key) in this map indicates that an attention was driven from |
| 77 | * another register (value). |
| 78 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 79 | std::map<BitPosition_t, const std::shared_ptr<const IsolationNode>> |
| 80 | iv_children; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 81 | |
| 82 | public: // Member functions |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 83 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 84 | * @brief Finds all active attentions on this node. If an active bit is a |
| 85 | * leaf in the isolation tree, the bit's signature is added to the |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 86 | * isolation data. Otherwise, this function is recursively called |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 87 | * to analyze the child node that is driving the attention in this |
| 88 | * node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 89 | * @param i_chip The target chip for isolation. |
| 90 | * @param i_attnType The target attention type to analyze on this register. |
| 91 | * Will assert a rule must exist for this attention type. |
| 92 | * @param io_isoData The isolation data returned back to the user |
| 93 | * application. |
| 94 | * @return True, if any active attentions found on this register. |
| 95 | * False, otherwise. |
| 96 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 97 | bool analyze(const Chip& i_chip, AttentionType_t i_attnType, |
| 98 | IsolationData& io_isoData) const; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 99 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 100 | /** |
| 101 | * @brief Adds a register rule for the given attention type. See iv_rules |
| 102 | * for details. |
| 103 | * |
| 104 | * This is only intended to be used during initialization of the isolator. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 105 | * Will assert that a rule has not already been defined for this type. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 106 | * |
| 107 | * @param The target attention type. |
| 108 | * @param The rule for this attention type. |
| 109 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 110 | void addRule(AttentionType_t i_attnType, RegisterPtr i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 111 | |
| 112 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 113 | * @brief Adds a child node to analyze for the given bit position in this |
| 114 | * node. See iv_children for details. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 115 | * |
| 116 | * This is only intended to be used during initialization of the isolator. |
| 117 | * Will assert that nothing has already been defined for this bit. |
| 118 | * |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 119 | * @param The target bit on this node. |
| 120 | * @param The child node to analyze for the given bit. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 121 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 122 | void addChild(BitPosition_t i_bit, |
| 123 | std::shared_ptr<const IsolationNode> i_child); |
| 124 | |
| 125 | /** @return The node ID. */ |
| 126 | NodeId_t getId() const |
| 127 | { |
| 128 | return iv_id; |
| 129 | } |
| 130 | |
| 131 | /** @return The node instance. */ |
| 132 | Instance_t getInstance() const |
| 133 | { |
| 134 | return iv_instance; |
| 135 | } |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 136 | |
| 137 | public: // Operators |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 138 | /** @brief Equals operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 139 | bool operator==(const IsolationNode& i_r) const |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 140 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 141 | return (iv_id == i_r.iv_id) && (iv_instance == i_r.iv_instance); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** @brief Less than operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 145 | bool operator<(const IsolationNode& i_r) const |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 146 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 147 | if (iv_id < i_r.iv_id) |
| 148 | { |
| 149 | return true; |
| 150 | } |
| 151 | else if (iv_id == i_r.iv_id) |
| 152 | { |
| 153 | return (iv_instance < i_r.iv_instance); |
| 154 | } |
| 155 | |
| 156 | return false; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private: // Isolation stack and supporting functions. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 160 | /** When analyze() is called at the tree root, all recursive calls to |
| 161 | * analyze() will target the same chip and attention type. So we only need |
| 162 | * to keep track of the nodes that have been analyzed to avoid cyclic |
| 163 | * isolation (an infinite loop). In fact, we only need to keep track of the |
| 164 | * nodes directly from this node to the root node. As long as this node |
| 165 | * does not already exist in the list, we can be sure there will not be a |
| 166 | * loop. So the list can be treated as a stack. When analyze() is called on |
| 167 | * a node, that node is pushed to the top of the stack (as long as it |
| 168 | * doesn't already exist in the stack). Then, just before analyze() exits, |
| 169 | * this node can be popped off the top of the stack. Once all the recursive |
| 170 | * calls have returned back to the root node the stack should be empty. |
| 171 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 172 | static std::vector<std::shared_ptr<const IsolationNode>> cv_isolationStack; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * @brief Pushes this node to the top of the stack. Will assert that this |
| 176 | * node does not already exist in cv_isolationStack. |
| 177 | */ |
| 178 | void pushIsolationStack() const; |
| 179 | |
| 180 | /** @brief Pops the top node off of cv_isolationStack. */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 181 | void popIsolationStack() const |
| 182 | { |
| 183 | cv_isolationStack.pop_back(); |
| 184 | } |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 185 | }; |
| 186 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 187 | /** Pointer management for IsolationNode objects. */ |
| 188 | using IsolationNodePtr = std::shared_ptr<const IsolationNode>; |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 189 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 190 | } // end namespace libhei |