Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 1 | #include <isolator/hei_isolation_node.hpp> |
Zane Shelley | 995be6c | 2021-02-24 15:48:55 -0600 | [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 | |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 17 | // Capture all registers for this node. |
| 18 | for (const auto& hwReg : iv_capRegs) |
| 19 | { |
| 20 | // Read the register (adds BitString to register cache). |
| 21 | if (hwReg->read(i_chip)) |
| 22 | { |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 23 | // The register read failed. |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 24 | // TODO: Would be nice to add SCOM errors to the log just in case |
| 25 | // traces are not available. |
Zane Shelley | 734cfe9 | 2020-08-10 19:57:27 -0500 | [diff] [blame] | 26 | // TODO: This trace could be redundant with the user application, |
| 27 | // which will have more information on the actual chip that |
| 28 | // failed anyway. Leaving it commented out for now until the |
| 29 | // SCOM errors are added to the log. |
| 30 | // HEI_ERR("register read failed on chip type=0x%0" PRIx32 |
| 31 | // "address=0x%0" PRIx64, |
| 32 | // i_chip.getType(), hwReg->getAddress()); |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 33 | } |
Zane Shelley | dae1af6 | 2021-01-14 11:00:46 -0600 | [diff] [blame] | 34 | else |
| 35 | { |
| 36 | // Add to the FFDC. |
| 37 | io_isoData.addRegister(i_chip, hwReg->getId(), hwReg->getInstance(), |
| 38 | hwReg->getBitString(i_chip)); |
| 39 | } |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 42 | // A rule for i_attnType must exist. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 43 | auto rule_itr = iv_rules.find(i_attnType); |
| 44 | HEI_ASSERT(iv_rules.end() != rule_itr); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 45 | |
| 46 | // Get the returned BitString for this rule. |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 47 | const BitString* bs = rule_itr->second->getBitString(i_chip); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 48 | |
| 49 | // Ensure this BitString is not longer than the maximum bit field. |
Zane Shelley | 13b182b | 2020-05-07 20:23:45 -0500 | [diff] [blame] | 50 | HEI_ASSERT(bs->getBitLen() <= (1 << (sizeof(BitPosition_t) * 8))); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 51 | |
| 52 | // Find all active bits for this rule. |
Zane Shelley | 13b182b | 2020-05-07 20:23:45 -0500 | [diff] [blame] | 53 | for (BitPosition_t bit = 0; bit < bs->getBitLen(); bit++) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 54 | { |
| 55 | // Continue to the next bit if not active. |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 56 | if (!bs->isBitSet(bit)) |
| 57 | continue; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 58 | |
| 59 | // At least one active bit was found. |
| 60 | o_activeAttn = true; |
| 61 | |
| 62 | // Determine if this attention originated from another register or if it |
| 63 | // is a leaf in the isolation tree. |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 64 | auto child_itr = iv_children.find(bit); |
| 65 | if (iv_children.end() != child_itr) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 66 | { |
| 67 | // This bit was driven from an attention from another register. |
| 68 | // Continue down the isolation tree to look for more attentions. |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 69 | bool attnFound = |
| 70 | child_itr->second->analyze(i_chip, i_attnType, io_isoData); |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 71 | if (!attnFound) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 72 | { |
| 73 | // Something went wrong. There should have been an active |
| 74 | // attention. It's possible there is a bug in the Chip Data |
| 75 | // File. Or, it is also possible some other piece of code is |
| 76 | // clearing the attention before this code is able to analyze |
| 77 | // it. Another possibility is that the hardware it not behaving |
| 78 | // as expected. Since we really don't know what happened, we |
| 79 | // should not assert. Instead, add this bit's signature to |
| 80 | // io_isoData. If there are no other active attentions, the user |
| 81 | // application could use this signature to help determine, and |
| 82 | // circumvent, the isolation problem. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 83 | io_isoData.addSignature( |
| 84 | Signature{i_chip, iv_id, iv_instance, bit, i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | // We have reached a leaf in the isolation tree. Add this bit's |
| 90 | // signature to io_isoData. |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 91 | io_isoData.addSignature( |
| 92 | Signature{i_chip, iv_id, iv_instance, bit, i_attnType}); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | // Analysis is complete on this node. So remove it from cv_isolationStack. |
| 97 | popIsolationStack(); |
| 98 | |
| 99 | return o_activeAttn; |
| 100 | } |
| 101 | |
| 102 | //------------------------------------------------------------------------------ |
| 103 | |
Zane Shelley | e8dc72c | 2020-05-14 16:40:52 -0500 | [diff] [blame] | 104 | void IsolationNode::addCaptureRegister(HardwareRegister::ConstPtr i_hwReg) |
| 105 | { |
| 106 | HEI_ASSERT(i_hwReg); // should not be null |
| 107 | |
| 108 | // If the register already exists, ignore it. Otherwise, add it to the list. |
| 109 | auto itr = std::find(iv_capRegs.begin(), iv_capRegs.end(), i_hwReg); |
| 110 | if (iv_capRegs.end() == itr) |
| 111 | { |
| 112 | iv_capRegs.push_back(i_hwReg); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | //------------------------------------------------------------------------------ |
| 117 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 118 | void IsolationNode::addRule(AttentionType_t i_attnType, |
| 119 | Register::ConstPtr i_rule) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 120 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 121 | HEI_ASSERT(i_rule); // should not be null |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 122 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 123 | auto ret = iv_rules.emplace(i_attnType, i_rule); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 124 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 125 | // If an entry already existed, it must point to the same object. |
| 126 | HEI_ASSERT(ret.second || (ret.first->second == i_rule)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | //------------------------------------------------------------------------------ |
| 130 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 131 | void IsolationNode::addChild(uint8_t i_bit, ConstPtr i_child) |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 132 | { |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 133 | HEI_ASSERT(i_child); // should not be null |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 134 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 135 | auto ret = iv_children.emplace(i_bit, i_child); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 136 | |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 137 | // If an entry already existed, it must point to the same object. |
| 138 | HEI_ASSERT(ret.second || (ret.first->second == i_child)); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | //------------------------------------------------------------------------------ |
| 142 | |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 143 | std::vector<const IsolationNode*> IsolationNode::cv_isolationStack{}; |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 144 | |
| 145 | //------------------------------------------------------------------------------ |
| 146 | |
| 147 | void IsolationNode::pushIsolationStack() const |
| 148 | { |
| 149 | // Ensure this node does not already exist in cv_isolationStack. |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 150 | auto itr = |
| 151 | std::find(cv_isolationStack.begin(), cv_isolationStack.end(), this); |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 152 | HEI_ASSERT(cv_isolationStack.end() == itr); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 153 | |
| 154 | // Push to node to the stack. |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 155 | cv_isolationStack.push_back(this); |
Zane Shelley | 7bf1f6d | 2019-10-18 16:03:51 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | //------------------------------------------------------------------------------ |
| 159 | |
| 160 | } // end namespace libhei |