Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 1 | #include <isolator/hei_isolation_node.hpp> |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 2 | #include <util/hei_bit_string.hpp> |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 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 | 13b182b | 2020-05-07 20:23:45 -0500 | [diff] [blame] | 25 | HEI_ASSERT(bs->getBitLen() <= (1 << (sizeof(BitPosition_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 | 13b182b | 2020-05-07 20:23:45 -0500 | [diff] [blame] | 28 | for (BitPosition_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 | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 58 | io_isoData.addSignature( |
| 59 | Signature{i_chip, iv_id, iv_instance, bit, i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | // We have reached a leaf in the isolation tree. Add this bit's |
| 65 | // signature to io_isoData. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 66 | io_isoData.addSignature( |
| 67 | Signature{i_chip, iv_id, iv_instance, bit, i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | // Analysis is complete on this node. So remove it from cv_isolationStack. |
| 72 | popIsolationStack(); |
| 73 | |
| 74 | return o_activeAttn; |
| 75 | } |
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 79 | void IsolationNode::addRule(AttentionType_t i_attnType, RegisterPtr i_rule) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 80 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 81 | HEI_ASSERT(i_rule); // should not be null |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 82 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 83 | auto ret = iv_rules.emplace(i_attnType, i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 84 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 85 | // If an entry already existed, it must point to the same object. |
| 86 | HEI_ASSERT(ret.second || (ret.first->second == i_rule)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | //------------------------------------------------------------------------------ |
| 90 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 91 | void IsolationNode::addChild(uint8_t i_bit, IsolationNodePtr i_child) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 92 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 93 | HEI_ASSERT(i_child); // should not be null |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 94 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 95 | auto ret = iv_children.emplace(i_bit, i_child); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 96 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 97 | // If an entry already existed, it must point to the same object. |
| 98 | HEI_ASSERT(ret.second || (ret.first->second == i_child)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | //------------------------------------------------------------------------------ |
| 102 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 103 | std::vector<IsolationNodePtr> IsolationNode::cv_isolationStack{}; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 104 | |
| 105 | //------------------------------------------------------------------------------ |
| 106 | |
| 107 | void IsolationNode::pushIsolationStack() const |
| 108 | { |
| 109 | // Ensure this node does not already exist in cv_isolationStack. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 110 | auto itr = std::find(cv_isolationStack.begin(), cv_isolationStack.end(), |
| 111 | IsolationNodePtr(this)); |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 112 | HEI_ASSERT(cv_isolationStack.end() == itr); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 113 | |
| 114 | // Push to node to the stack. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame^] | 115 | cv_isolationStack.push_back(IsolationNodePtr(this)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | //------------------------------------------------------------------------------ |
| 119 | |
| 120 | } // end namespace libhei |