Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 3 | #include <hei_isolation_data.hpp> |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 4 | #include <register/hei_hardware_register.hpp> |
Zane Shelley | d507351 | 2021-01-14 12:51:18 -0600 | [diff] [blame] | 5 | #include <util/hei_includes.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 | d39aa57 | 2020-05-14 10:35:57 -0500 | [diff] [blame] | 33 | * |
| 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 Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 39 | */ |
| 40 | class IsolationNode |
| 41 | { |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 42 | 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 Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 48 | public: // Constructors, destructor, assignment |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 49 | /** |
| 50 | * @brief Constructor from components. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 51 | * @param i_id Unique ID for all instances of this node. |
| 52 | * @param i_instance Instance of this node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 53 | */ |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 54 | IsolationNode(NodeId_t i_id, Instance_t i_instance, |
| 55 | RegisterType_t i_regType) : |
| 56 | iv_id(i_id), |
| 57 | iv_instance(i_instance), iv_regType(i_regType) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 58 | {} |
| 59 | |
| 60 | /** @brief Destructor. */ |
| 61 | ~IsolationNode() = default; |
| 62 | |
Zane Shelley | 981e56a | 2020-05-11 21:24:20 -0500 | [diff] [blame] | 63 | /** @brief Copy constructor. */ |
| 64 | IsolationNode(const IsolationNode&) = delete; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 65 | |
Zane Shelley | 981e56a | 2020-05-11 21:24:20 -0500 | [diff] [blame] | 66 | /** @brief Assignment operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 67 | IsolationNode& operator=(const IsolationNode&) = delete; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 68 | |
| 69 | private: // Instance variables |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 70 | /** The unique ID for all instances of this node. */ |
| 71 | const NodeId_t iv_id; |
| 72 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 73 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 74 | * A node may have multiple instances. All of which will have the same ID. |
| 75 | * This variable is used to distinguish between each instance of the node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 76 | */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 77 | const Instance_t iv_instance; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 78 | |
| 79 | /** |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 80 | * A registers referenced by this node's rules must be of this type. No |
| 81 | * mixing of register types is allowed because comparing different sized |
| 82 | * registers is undefined behavior. Note that it is possible to have capture |
| 83 | * registers of mixed types. |
| 84 | */ |
| 85 | const RegisterType_t iv_regType; |
| 86 | |
| 87 | /** |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 88 | * The lists of register to capture and add to the log for additional |
| 89 | * debugging. The lists are indexed in a map where the key is a bit |
| 90 | * position. All registers that should be captured by default when |
| 91 | * isolating to this node will have a bit position of `MAX_BIT_POSITION`. |
| 92 | * Otherwise, any other list targeted for a specific bit will only be |
| 93 | * captured if there is an active attention on that bit. |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 94 | */ |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 95 | std::map<BitPosition_t, std::vector<HardwareRegister::ConstPtr>> iv_capRegs; |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 96 | |
| 97 | /** |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 98 | * This register could report multiple types of attentions. We can use a |
| 99 | * register 'rule' (value) to find any active attentions for each attention |
| 100 | * type (key). A 'rule', like "register & ~mask", is a combination of |
| 101 | * HardwareRegister objects and virtual operator registers (all children |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 102 | * of the Register class). Note that all registers referenced by these rules |
| 103 | * must be the same type as iv_regType. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 104 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 105 | std::map<AttentionType_t, const Register::ConstPtr> iv_rules; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Each bit (key) in this map indicates that an attention was driven from |
| 109 | * another register (value). |
| 110 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 111 | std::map<BitPosition_t, const ConstPtr> iv_children; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 112 | |
| 113 | public: // Member functions |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 114 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 115 | * @brief Finds all active attentions on this node. If an active bit is a |
| 116 | * 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] | 117 | * isolation data. Otherwise, this function is recursively called |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 118 | * to analyze the child node that is driving the attention in this |
| 119 | * node. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 120 | * @param i_chip The target chip for isolation. |
| 121 | * @param i_attnType The target attention type to analyze on this register. |
| 122 | * Will assert a rule must exist for this attention type. |
| 123 | * @param io_isoData The isolation data returned back to the user |
| 124 | * application. |
| 125 | * @return True, if any active attentions found on this register. |
| 126 | * False, otherwise. |
| 127 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 128 | bool analyze(const Chip& i_chip, AttentionType_t i_attnType, |
| 129 | IsolationData& io_isoData) const; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 130 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 131 | /** |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 132 | * @brief Adds a hardware register to the list of registers that will be |
| 133 | * captured for additional debugging. See iv_capRegs for details. |
| 134 | * |
| 135 | * This is only intended to be used during initialization of the isolator. |
| 136 | * Duplicate registers will be ignored. |
| 137 | * |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 138 | * @param i_hwReg The target hardware register. |
| 139 | * @param i_bit If specified, the given register should only be captured |
| 140 | * when there is an active attention on the given bit. If |
| 141 | * omitted, the given register will be captured any time |
| 142 | * this isolation node is analyzed. |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 143 | */ |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 144 | void addCaptureRegister(HardwareRegister::ConstPtr i_hwReg, |
| 145 | BitPosition_t i_bit = MAX_BIT_POSITION); |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 146 | |
| 147 | /** |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 148 | * @brief Adds a register rule for the given attention type. See iv_rules |
| 149 | * for details. |
| 150 | * |
| 151 | * This is only intended to be used during initialization of the isolator. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 152 | * 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] | 153 | * |
| 154 | * @param The target attention type. |
| 155 | * @param The rule for this attention type. |
| 156 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 157 | void addRule(AttentionType_t i_attnType, Register::ConstPtr i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 158 | |
| 159 | /** |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 160 | * @brief Adds a child node to analyze for the given bit position in this |
| 161 | * node. See iv_children for details. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 162 | * |
| 163 | * This is only intended to be used during initialization of the isolator. |
| 164 | * Will assert that nothing has already been defined for this bit. |
| 165 | * |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 166 | * @param The target bit on this node. |
| 167 | * @param The child node to analyze for the given bit. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 168 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 169 | void addChild(BitPosition_t i_bit, ConstPtr i_child); |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 170 | |
| 171 | /** @return The node ID. */ |
| 172 | NodeId_t getId() const |
| 173 | { |
| 174 | return iv_id; |
| 175 | } |
| 176 | |
| 177 | /** @return The node instance. */ |
| 178 | Instance_t getInstance() const |
| 179 | { |
| 180 | return iv_instance; |
| 181 | } |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 182 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 183 | /** @return The node/instance key. */ |
| 184 | Key getKey() const |
| 185 | { |
| 186 | return {iv_id, iv_instance}; |
| 187 | } |
| 188 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 189 | /** @return This node's register type.. */ |
| 190 | RegisterType_t getRegisterType() const |
| 191 | { |
| 192 | return iv_regType; |
| 193 | } |
| 194 | |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 195 | private: // Member functions |
| 196 | /** |
| 197 | * @param i_chip The target chip for isolation. |
| 198 | * @param io_isoData The isolation data returned back to the user |
| 199 | * application. |
| 200 | * @param i_bit If specified, only the registers specifically |
| 201 | * targeted for the given bit are captured. If omitted, |
| 202 | * the default list of registers for this isolation node |
| 203 | * will be captured. |
| 204 | */ |
| 205 | void captureRegisters(const Chip& i_chip, IsolationData& io_isoData, |
| 206 | BitPosition_t i_bit = MAX_BIT_POSITION) const; |
| 207 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 208 | private: // Isolation stack and supporting functions. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 209 | /** When analyze() is called at the tree root, all recursive calls to |
| 210 | * analyze() will target the same chip and attention type. So we only need |
| 211 | * to keep track of the nodes that have been analyzed to avoid cyclic |
| 212 | * isolation (an infinite loop). In fact, we only need to keep track of the |
| 213 | * nodes directly from this node to the root node. As long as this node |
| 214 | * does not already exist in the list, we can be sure there will not be a |
| 215 | * loop. So the list can be treated as a stack. When analyze() is called on |
| 216 | * a node, that node is pushed to the top of the stack (as long as it |
| 217 | * doesn't already exist in the stack). Then, just before analyze() exits, |
| 218 | * this node can be popped off the top of the stack. Once all the recursive |
| 219 | * calls have returned back to the root node the stack should be empty. |
| 220 | */ |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 221 | static std::vector<const IsolationNode*> cv_isolationStack; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * @brief Pushes this node to the top of the stack. Will assert that this |
| 225 | * node does not already exist in cv_isolationStack. |
| 226 | */ |
| 227 | void pushIsolationStack() const; |
| 228 | |
| 229 | /** @brief Pops the top node off of cv_isolationStack. */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 230 | void popIsolationStack() const |
| 231 | { |
| 232 | cv_isolationStack.pop_back(); |
| 233 | } |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | } // end namespace libhei |