Ben Tyner | 032bf9e | 2020-05-06 21:27:54 -0500 | [diff] [blame] | 1 | #include <hei_macros.hpp> |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 2 | #include <isolator/hei_isolation_node.hpp> |
| 3 | |
| 4 | namespace libhei |
| 5 | { |
| 6 | |
| 7 | //------------------------------------------------------------------------------ |
| 8 | |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 9 | bool IsolationNode::analyze(const Chip& i_chip, AttentionType_t i_attnType, |
| 10 | IsolationData& io_isoData) const |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 11 | { |
| 12 | bool o_activeAttn = false; // Initially, assume no active attentions. |
| 13 | |
| 14 | // Keep track of nodes that have been analyzed to avoid cyclic isolation. |
| 15 | pushIsolationStack(); |
| 16 | |
| 17 | // A rule for i_attnType must exist. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 18 | auto rule_itr = iv_rules.find(i_attnType); |
| 19 | HEI_ASSERT(iv_rules.end() != rule_itr); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 20 | |
| 21 | // Get the returned BitString for this rule. |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 22 | const BitString* bs = rule_itr->second->getBitString(i_chip); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 23 | |
| 24 | // Ensure this BitString is not longer than the maximum bit field. |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 25 | HEI_ASSERT(bs->getBitLen() <= (1 << (sizeof(RegisterBit_t) * 8))); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 26 | |
| 27 | // Find all active bits for this rule. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 28 | for (RegisterBit_t bit = 0; bit < bs->getBitLen(); bit++) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 29 | { |
| 30 | // Continue to the next bit if not active. |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 31 | if (!bs->isBitSet(bit)) |
| 32 | continue; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 33 | |
| 34 | // At least one active bit was found. |
| 35 | o_activeAttn = true; |
| 36 | |
| 37 | // Determine if this attention originated from another register or if it |
| 38 | // is a leaf in the isolation tree. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 39 | auto child_itr = iv_children.find(bit); |
| 40 | if (iv_children.end() != child_itr) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 41 | { |
| 42 | // This bit was driven from an attention from another register. |
| 43 | // Continue down the isolation tree to look for more attentions. |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 44 | bool attnFound = |
| 45 | child_itr->second->analyze(i_chip, i_attnType, io_isoData); |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 46 | if (!attnFound) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 47 | { |
| 48 | // Something went wrong. There should have been an active |
| 49 | // attention. It's possible there is a bug in the Chip Data |
| 50 | // File. Or, it is also possible some other piece of code is |
| 51 | // clearing the attention before this code is able to analyze |
| 52 | // it. Another possibility is that the hardware it not behaving |
| 53 | // as expected. Since we really don't know what happened, we |
| 54 | // should not assert. Instead, add this bit's signature to |
| 55 | // io_isoData. If there are no other active attentions, the user |
| 56 | // application could use this signature to help determine, and |
| 57 | // circumvent, the isolation problem. |
Zane Shelley | c477199 | 2019-10-28 22:01:49 -0500 | [diff] [blame] | 58 | io_isoData.addSignature(Signature{i_chip, iv_hwReg.getId(), |
| 59 | iv_hwReg.getInstance(), bit, |
| 60 | i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | // We have reached a leaf in the isolation tree. Add this bit's |
| 66 | // signature to io_isoData. |
Zane Shelley | c477199 | 2019-10-28 22:01:49 -0500 | [diff] [blame] | 67 | io_isoData.addSignature(Signature{i_chip, iv_hwReg.getId(), |
| 68 | iv_hwReg.getInstance(), bit, |
| 69 | i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | // Analysis is complete on this node. So remove it from cv_isolationStack. |
| 74 | popIsolationStack(); |
| 75 | |
| 76 | return o_activeAttn; |
| 77 | } |
| 78 | |
| 79 | //------------------------------------------------------------------------------ |
| 80 | |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 81 | void IsolationNode::addRule(AttentionType_t i_attnType, const Register* i_rule) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 82 | { |
| 83 | // A rule for this attention type should not already exist. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 84 | HEI_ASSERT(iv_rules.end() == iv_rules.find(i_attnType)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 85 | |
| 86 | // The rule should not be null. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 87 | HEI_ASSERT(nullptr != i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 88 | |
| 89 | // Add the new rule. |
| 90 | iv_rules[i_attnType] = i_rule; |
| 91 | } |
| 92 | |
| 93 | //------------------------------------------------------------------------------ |
| 94 | |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 95 | void IsolationNode::addChild(uint8_t i_bit, const IsolationNode* i_child) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 96 | { |
| 97 | // An entry for this bit should not already exist. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 98 | HEI_ASSERT(iv_children.end() == iv_children.find(i_bit)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 99 | |
| 100 | // The child register should not be null. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 101 | HEI_ASSERT(nullptr != i_child); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 102 | |
| 103 | // Add the new rule. |
| 104 | iv_children[i_bit] = i_child; |
| 105 | } |
| 106 | |
| 107 | //------------------------------------------------------------------------------ |
| 108 | |
Zane Shelley | c477199 | 2019-10-28 22:01:49 -0500 | [diff] [blame] | 109 | std::vector<const IsolationNode*> IsolationNode::cv_isolationStack{}; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 110 | |
| 111 | //------------------------------------------------------------------------------ |
| 112 | |
| 113 | void IsolationNode::pushIsolationStack() const |
| 114 | { |
| 115 | // Ensure this node does not already exist in cv_isolationStack. |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 116 | auto itr = |
| 117 | std::find(cv_isolationStack.begin(), cv_isolationStack.end(), this); |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 118 | HEI_ASSERT(cv_isolationStack.end() == itr); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 119 | |
| 120 | // Push to node to the stack. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 121 | cv_isolationStack.push_back(this); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | //------------------------------------------------------------------------------ |
| 125 | |
| 126 | } // end namespace libhei |