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 | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 5 | #include <register/hei_hardware_register.hpp> |
Zane Shelley | ca9f625 | 2019-10-25 21:17:30 -0500 | [diff] [blame] | 6 | #include <register/hei_register.hpp> |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 7 | #include <util/hei_bit_string.hpp> |
| 8 | #include <util/hei_flyweight.hpp> |
| 9 | |
| 10 | namespace libhei |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | * @brief This class contains the isolation rules and bit definition of a |
| 15 | * HardwareRegister used for error isolation. |
| 16 | * |
| 17 | * These objects are linked together as a tree. Any active bits in the |
| 18 | * associated register will either be a true active attention (leaf node) or |
| 19 | * indicate one or more active attentions occurred in a child node. |
| 20 | * |
| 21 | * The primary function of this class is analyze(), which will do a depth-first |
| 22 | * search of the tree to find all leaves and add their signatures to the |
| 23 | * returned isolation data. |
| 24 | * |
| 25 | * The tree structure is built from information in the Chip Data Files. It is |
| 26 | * possible that the tree could be built with loop in the isolation. This would |
| 27 | * be bug in the Chip Data Files. This class will keep track of all nodes that |
| 28 | * have been analyzed to prevent cyclic isolation (an infinite loop). |
| 29 | * |
| 30 | * Each isolation register will have a rule for each supported attention type. |
| 31 | * These rules are a combination of HardwareRegisters and operator registers to |
| 32 | * define rules like "REG & ~MASK & CNFG", which reads "return all bits in REG |
| 33 | * that are not in MASK and set in CNFG". See the definition of the Register |
| 34 | * class for details on how this works. |
| 35 | */ |
| 36 | class IsolationNode |
| 37 | { |
| 38 | public: // Constructors, destructor, assignment |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 39 | /** |
| 40 | * @brief Constructor from components. |
| 41 | * @param i_hwReg A reference to the HardwareRegister targeted for |
| 42 | * isolation. |
| 43 | */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 44 | explicit IsolationNode(const HardwareRegister& i_hwReg) : iv_hwReg(i_hwReg) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 45 | {} |
| 46 | |
| 47 | /** @brief Destructor. */ |
| 48 | ~IsolationNode() = default; |
| 49 | |
| 50 | private: |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 51 | // This is needed to allow the flyweights to use the copy constructor, but |
| 52 | // not allow it to be used in general. |
| 53 | friend class Flyweight<IsolationNode>; |
| 54 | |
| 55 | /** |
| 56 | * @brief Copy constructor. |
| 57 | * |
| 58 | * Needed by Flyweight class, but should not be allowed in general. |
| 59 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 60 | IsolationNode(const IsolationNode&) = default; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * @brief Explicitly disables assignment operator. |
| 64 | * |
| 65 | * This is redundant since the compilier will implicitly delete this because |
| 66 | * of the constant instance variables, but helps communicate it is not |
| 67 | * allowed. |
| 68 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 69 | IsolationNode& operator=(const IsolationNode&) = delete; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 70 | |
| 71 | private: // Instance variables |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 72 | /** |
| 73 | * This is a reference to the HardwareRegister targeted for isolation by |
| 74 | * this instance of the class. The reference is required to maintain |
| 75 | * polymorphism. |
| 76 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 77 | const HardwareRegister& iv_hwReg; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * This register could report multiple types of attentions. We can use a |
| 81 | * register 'rule' (value) to find any active attentions for each attention |
| 82 | * type (key). A 'rule', like "register & ~mask", is a combination of |
| 83 | * HardwareRegister objects and virtual operator registers (all children |
| 84 | * of the Register class). |
| 85 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 86 | std::map<AttentionType_t, const Register*> iv_rules; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Each bit (key) in this map indicates that an attention was driven from |
| 90 | * another register (value). |
| 91 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 92 | std::map<RegisterBit_t, const IsolationNode*> iv_children; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 93 | |
| 94 | public: // Member functions |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 95 | /** |
| 96 | * @brief Finds all active attentions on this register. If an active bit is |
| 97 | * a leaf in the isolation tree, the bit's signature is added to the |
| 98 | * isolation data. Otherwise, this function is recursively called |
| 99 | * to analyze the child register that is driving the attention in |
| 100 | * this register. |
| 101 | * @param i_chip The target chip for isolation. |
| 102 | * @param i_attnType The target attention type to analyze on this register. |
| 103 | * Will assert a rule must exist for this attention type. |
| 104 | * @param io_isoData The isolation data returned back to the user |
| 105 | * application. |
| 106 | * @return True, if any active attentions found on this register. |
| 107 | * False, otherwise. |
| 108 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 109 | bool analyze(const Chip& i_chip, AttentionType_t i_attnType, |
| 110 | IsolationData& io_isoData) const; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 111 | |
| 112 | // TODO: The next two functions are only intended to be used during |
| 113 | // initialization of the isolator. Consider, making them private and |
| 114 | // make the Chip Data File code friends of this class. So that it has |
| 115 | // access to these init functions. |
| 116 | |
| 117 | /** |
| 118 | * @brief Adds a register rule for the given attention type. See iv_rules |
| 119 | * for details. |
| 120 | * |
| 121 | * This is only intended to be used during initialization of the isolator. |
| 122 | * Will assert that nothing has already been defined for this rule. |
| 123 | * |
| 124 | * @param The target attention type. |
| 125 | * @param The rule for this attention type. |
| 126 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 127 | void addRule(AttentionType_t i_attnType, const Register* i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * @brief Adds a child register to analyze for the given bit in this |
| 131 | * register. See iv_children for details. |
| 132 | * |
| 133 | * This is only intended to be used during initialization of the isolator. |
| 134 | * Will assert that nothing has already been defined for this bit. |
| 135 | * |
| 136 | * @param The target bit on this register. |
| 137 | * @param The child register to analyze for the given bit. |
| 138 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 139 | void addChild(RegisterBit_t i_bit, const IsolationNode* i_child); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 140 | |
| 141 | public: // Operators |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 142 | /** @brief Equals operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 143 | bool operator==(const IsolationNode& i_r) const |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 144 | { |
| 145 | // iv_hwReg should be unique per IsolationNode. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 146 | return (iv_hwReg == i_r.iv_hwReg); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** @brief Less than operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 150 | bool operator<(const IsolationNode& i_r) const |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 151 | { |
| 152 | // iv_hwReg should be unique per IsolationNode. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 153 | return (iv_hwReg < i_r.iv_hwReg); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | private: // Isolation stack and supporting functions. |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 157 | /** When analyze() is called at the tree root, all recursive calls to |
| 158 | * analyze() will target the same chip and attention type. So we only need |
| 159 | * to keep track of the nodes that have been analyzed to avoid cyclic |
| 160 | * isolation (an infinite loop). In fact, we only need to keep track of the |
| 161 | * nodes directly from this node to the root node. As long as this node |
| 162 | * does not already exist in the list, we can be sure there will not be a |
| 163 | * loop. So the list can be treated as a stack. When analyze() is called on |
| 164 | * a node, that node is pushed to the top of the stack (as long as it |
| 165 | * doesn't already exist in the stack). Then, just before analyze() exits, |
| 166 | * this node can be popped off the top of the stack. Once all the recursive |
| 167 | * calls have returned back to the root node the stack should be empty. |
| 168 | */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 169 | static std::vector<const IsolationNode*> cv_isolationStack; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * @brief Pushes this node to the top of the stack. Will assert that this |
| 173 | * node does not already exist in cv_isolationStack. |
| 174 | */ |
| 175 | void pushIsolationStack() const; |
| 176 | |
| 177 | /** @brief Pops the top node off of cv_isolationStack. */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 178 | void popIsolationStack() const |
| 179 | { |
| 180 | cv_isolationStack.pop_back(); |
| 181 | } |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 184 | /** Simple map to ensure only one root IsolationNode per attention type. */ |
| 185 | using RootNodeMap = std::map<AttentionType_t, const IsolationNode*>; |
| 186 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 187 | } // end namespace libhei |