blob: 69bc643c02d2b240e9339fe16a02ddd5984569f7 [file] [log] [blame]
Zane Shelley508ce582020-05-05 13:47:19 -05001#include <isolator/hei_isolation_chip.hpp>
2
3namespace libhei
4{
5
6//------------------------------------------------------------------------------
7
8bool IsolationChip::analyze(const Chip& i_chip, IsolationData& io_isoData) const
9{
10 bool o_activeAttn = false; // Initially, assume no active attentions.
11
12 // The given chip must be the same type as iv_chipType.
13 HEI_ASSERT(iv_chipType == i_chip.getType());
14
15 // Iterate each root node.
16 for (const auto& node : iv_rootNodes)
17 {
18 if (node.second->analyze(i_chip, node.first, io_isoData))
19 {
20 // At least one attention type had an active attention.
21 o_activeAttn = true;
22 }
23 }
24
25 return o_activeAttn;
26}
27
28//------------------------------------------------------------------------------
29
Zane Shelley4caa0432020-05-12 22:29:02 -050030void IsolationChip::addHardwareRegister(HardwareRegisterPtr i_hwReg)
31{
32 HEI_ASSERT(i_hwReg); // should not be null
33
34 RegisterKey_t key = {i_hwReg->getId(), i_hwReg->getInstance()};
35
36 auto ret = iv_regs.emplace(key, i_hwReg);
37
38 // If an entry already exists, it should point to the same object.
39 HEI_ASSERT(ret.second || (ret.first->second == i_hwReg));
40}
41
42//------------------------------------------------------------------------------
43
44void IsolationChip::addIsolationNode(IsolationNodePtr i_isoNode)
45{
46 HEI_ASSERT(i_isoNode); // should not be null
47
48 NodeKey_t key = {i_isoNode->getId(), i_isoNode->getInstance()};
49
50 auto ret = iv_nodes.emplace(key, i_isoNode);
51
52 // If an entry already exists, it should point to the same object.
53 HEI_ASSERT(ret.second || (ret.first->second == i_isoNode));
54}
55
56//------------------------------------------------------------------------------
57
58void IsolationChip::addRootNode(AttentionType_t i_attnType,
59 IsolationNodePtr i_rootNode)
60{
61 HEI_ASSERT(i_rootNode); // should not be null
62
63 auto ret = iv_rootNodes.emplace(i_attnType, i_rootNode);
64
65 // If an entry already exists, it should point to the same object.
66 HEI_ASSERT(ret.second || (ret.first->second == i_rootNode));
67}
68
69//------------------------------------------------------------------------------
70
71HardwareRegisterPtr
72 IsolationChip::getHardwareRegister(RegisterId_t i_regId,
73 Instance_t i_regInst) const
74{
75 RegisterKey_t key = {i_regId, i_regInst};
76
77 auto itr = iv_regs.find(key);
78 HEI_ASSERT(iv_regs.end() != itr); // The register should exist.
79
80 return itr->second;
81}
82
83//------------------------------------------------------------------------------
84
85IsolationNodePtr IsolationChip::getIsolationNode(NodeId_t i_nodeId,
86 Instance_t i_nodeInst) const
87{
88 NodeKey_t key = {i_nodeId, i_nodeInst};
89
90 auto itr = iv_nodes.find(key);
91 HEI_ASSERT(iv_nodes.end() != itr); // The node should exist.
92
93 return itr->second;
94}
95
96//------------------------------------------------------------------------------
97
Zane Shelley508ce582020-05-05 13:47:19 -050098} // end namespace libhei