blob: 89b653b88665e4c71d91997f06b1096c224b0497 [file] [log] [blame]
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05001#include <isolator/hei_isolation_node.hpp>
Zane Shelley6722b5b2020-05-12 22:09:04 -05002#include <util/hei_bit_string.hpp>
Zane Shelley7bf1f6d2019-10-18 16:03:51 -05003
4namespace libhei
5{
6
7//------------------------------------------------------------------------------
8
Zane Shelleyfe27b652019-10-28 11:33:07 -05009bool IsolationNode::analyze(const Chip& i_chip, AttentionType_t i_attnType,
10 IsolationData& io_isoData) const
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050011{
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 Shelleye8dc72c2020-05-14 16:40:52 -050017 // 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 {
23 // TODO: Would be nice to add SCOM errors to the log just in case
24 // traces are not available.
25 HEI_ERR("register read failed on chip type=0x%0" PRIx32
26 "address=0x%0" PRIx64,
27 i_chip.getType(), hwReg->getAddress());
28 }
29
30 // TODO: Add this register to io_isoData.
31 // TODO: getBitString() does read hardware if read() has not been called
32 // and there is nothing in the register cache. However, it does
33 // not does not indicate if the read was successful. Not sure if
34 // this is intentional. Will need to investigate.
35 // auto bs = hwReg->getBitString();
36 }
37
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050038 // A rule for i_attnType must exist.
Zane Shelley83da2452019-10-25 15:45:34 -050039 auto rule_itr = iv_rules.find(i_attnType);
40 HEI_ASSERT(iv_rules.end() != rule_itr);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050041
42 // Get the returned BitString for this rule.
Zane Shelleyfe27b652019-10-28 11:33:07 -050043 const BitString* bs = rule_itr->second->getBitString(i_chip);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050044
45 // Ensure this BitString is not longer than the maximum bit field.
Zane Shelley13b182b2020-05-07 20:23:45 -050046 HEI_ASSERT(bs->getBitLen() <= (1 << (sizeof(BitPosition_t) * 8)));
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050047
48 // Find all active bits for this rule.
Zane Shelley13b182b2020-05-07 20:23:45 -050049 for (BitPosition_t bit = 0; bit < bs->getBitLen(); bit++)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050050 {
51 // Continue to the next bit if not active.
Zane Shelley7f7a42d2019-10-28 13:28:31 -050052 if (!bs->isBitSet(bit))
53 continue;
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050054
55 // At least one active bit was found.
56 o_activeAttn = true;
57
58 // Determine if this attention originated from another register or if it
59 // is a leaf in the isolation tree.
Zane Shelley83da2452019-10-25 15:45:34 -050060 auto child_itr = iv_children.find(bit);
61 if (iv_children.end() != child_itr)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050062 {
63 // This bit was driven from an attention from another register.
64 // Continue down the isolation tree to look for more attentions.
Zane Shelley7f7a42d2019-10-28 13:28:31 -050065 bool attnFound =
66 child_itr->second->analyze(i_chip, i_attnType, io_isoData);
Zane Shelley83da2452019-10-25 15:45:34 -050067 if (!attnFound)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050068 {
69 // Something went wrong. There should have been an active
70 // attention. It's possible there is a bug in the Chip Data
71 // File. Or, it is also possible some other piece of code is
72 // clearing the attention before this code is able to analyze
73 // it. Another possibility is that the hardware it not behaving
74 // as expected. Since we really don't know what happened, we
75 // should not assert. Instead, add this bit's signature to
76 // io_isoData. If there are no other active attentions, the user
77 // application could use this signature to help determine, and
78 // circumvent, the isolation problem.
Zane Shelley6722b5b2020-05-12 22:09:04 -050079 io_isoData.addSignature(
80 Signature{i_chip, iv_id, iv_instance, bit, i_attnType});
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050081 }
82 }
83 else
84 {
85 // We have reached a leaf in the isolation tree. Add this bit's
86 // signature to io_isoData.
Zane Shelley6722b5b2020-05-12 22:09:04 -050087 io_isoData.addSignature(
88 Signature{i_chip, iv_id, iv_instance, bit, i_attnType});
Zane Shelley7bf1f6d2019-10-18 16:03:51 -050089 }
90 }
91
92 // Analysis is complete on this node. So remove it from cv_isolationStack.
93 popIsolationStack();
94
95 return o_activeAttn;
96}
97
98//------------------------------------------------------------------------------
99
Zane Shelleye8dc72c2020-05-14 16:40:52 -0500100void IsolationNode::addCaptureRegister(HardwareRegister::ConstPtr i_hwReg)
101{
102 HEI_ASSERT(i_hwReg); // should not be null
103
104 // If the register already exists, ignore it. Otherwise, add it to the list.
105 auto itr = std::find(iv_capRegs.begin(), iv_capRegs.end(), i_hwReg);
106 if (iv_capRegs.end() == itr)
107 {
108 iv_capRegs.push_back(i_hwReg);
109 }
110}
111
112//------------------------------------------------------------------------------
113
Zane Shelley4de8ff82020-05-14 15:39:01 -0500114void IsolationNode::addRule(AttentionType_t i_attnType,
115 Register::ConstPtr i_rule)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500116{
Zane Shelley6722b5b2020-05-12 22:09:04 -0500117 HEI_ASSERT(i_rule); // should not be null
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500118
Zane Shelley6722b5b2020-05-12 22:09:04 -0500119 auto ret = iv_rules.emplace(i_attnType, i_rule);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500120
Zane Shelley6722b5b2020-05-12 22:09:04 -0500121 // If an entry already existed, it must point to the same object.
122 HEI_ASSERT(ret.second || (ret.first->second == i_rule));
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500123}
124
125//------------------------------------------------------------------------------
126
Zane Shelley4de8ff82020-05-14 15:39:01 -0500127void IsolationNode::addChild(uint8_t i_bit, ConstPtr i_child)
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500128{
Zane Shelley6722b5b2020-05-12 22:09:04 -0500129 HEI_ASSERT(i_child); // should not be null
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500130
Zane Shelley6722b5b2020-05-12 22:09:04 -0500131 auto ret = iv_children.emplace(i_bit, i_child);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500132
Zane Shelley6722b5b2020-05-12 22:09:04 -0500133 // If an entry already existed, it must point to the same object.
134 HEI_ASSERT(ret.second || (ret.first->second == i_child));
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500135}
136
137//------------------------------------------------------------------------------
138
Zane Shelley2467db82020-05-18 19:56:30 -0500139std::vector<const IsolationNode*> IsolationNode::cv_isolationStack{};
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500140
141//------------------------------------------------------------------------------
142
143void IsolationNode::pushIsolationStack() const
144{
145 // Ensure this node does not already exist in cv_isolationStack.
Zane Shelley2467db82020-05-18 19:56:30 -0500146 auto itr =
147 std::find(cv_isolationStack.begin(), cv_isolationStack.end(), this);
Zane Shelley83da2452019-10-25 15:45:34 -0500148 HEI_ASSERT(cv_isolationStack.end() == itr);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500149
150 // Push to node to the stack.
Zane Shelley2467db82020-05-18 19:56:30 -0500151 cv_isolationStack.push_back(this);
Zane Shelley7bf1f6d2019-10-18 16:03:51 -0500152}
153
154//------------------------------------------------------------------------------
155
156} // end namespace libhei