Functions to add nodes and regs to IsolationChip class
Change-Id: I3361f23f795b9015235add237bf5a78bd8afa861
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
diff --git a/src/isolator/hei_isolation_chip.cpp b/src/isolator/hei_isolation_chip.cpp
index ef40564..69bc643 100644
--- a/src/isolator/hei_isolation_chip.cpp
+++ b/src/isolator/hei_isolation_chip.cpp
@@ -27,4 +27,72 @@
//------------------------------------------------------------------------------
+void IsolationChip::addHardwareRegister(HardwareRegisterPtr i_hwReg)
+{
+ HEI_ASSERT(i_hwReg); // should not be null
+
+ RegisterKey_t key = {i_hwReg->getId(), i_hwReg->getInstance()};
+
+ auto ret = iv_regs.emplace(key, i_hwReg);
+
+ // If an entry already exists, it should point to the same object.
+ HEI_ASSERT(ret.second || (ret.first->second == i_hwReg));
+}
+
+//------------------------------------------------------------------------------
+
+void IsolationChip::addIsolationNode(IsolationNodePtr i_isoNode)
+{
+ HEI_ASSERT(i_isoNode); // should not be null
+
+ NodeKey_t key = {i_isoNode->getId(), i_isoNode->getInstance()};
+
+ auto ret = iv_nodes.emplace(key, i_isoNode);
+
+ // If an entry already exists, it should point to the same object.
+ HEI_ASSERT(ret.second || (ret.first->second == i_isoNode));
+}
+
+//------------------------------------------------------------------------------
+
+void IsolationChip::addRootNode(AttentionType_t i_attnType,
+ IsolationNodePtr i_rootNode)
+{
+ HEI_ASSERT(i_rootNode); // should not be null
+
+ auto ret = iv_rootNodes.emplace(i_attnType, i_rootNode);
+
+ // If an entry already exists, it should point to the same object.
+ HEI_ASSERT(ret.second || (ret.first->second == i_rootNode));
+}
+
+//------------------------------------------------------------------------------
+
+HardwareRegisterPtr
+ IsolationChip::getHardwareRegister(RegisterId_t i_regId,
+ Instance_t i_regInst) const
+{
+ RegisterKey_t key = {i_regId, i_regInst};
+
+ auto itr = iv_regs.find(key);
+ HEI_ASSERT(iv_regs.end() != itr); // The register should exist.
+
+ return itr->second;
+}
+
+//------------------------------------------------------------------------------
+
+IsolationNodePtr IsolationChip::getIsolationNode(NodeId_t i_nodeId,
+ Instance_t i_nodeInst) const
+{
+ NodeKey_t key = {i_nodeId, i_nodeInst};
+
+ auto itr = iv_nodes.find(key);
+ HEI_ASSERT(iv_nodes.end() != itr); // The node should exist.
+
+ return itr->second;
+}
+
+//------------------------------------------------------------------------------
+
} // end namespace libhei
diff --git a/src/isolator/hei_isolation_chip.hpp b/src/isolator/hei_isolation_chip.hpp
index 4fabea1..cb41353 100644
--- a/src/isolator/hei_isolation_chip.hpp
+++ b/src/isolator/hei_isolation_chip.hpp
@@ -2,6 +2,7 @@
#include <hei_isolation_data.hpp>
#include <isolator/hei_isolation_node.hpp>
+#include <register/hei_hardware_register.hpp>
namespace libhei
{
@@ -46,6 +47,14 @@
/** This chip's type. */
const ChipType_t iv_chipType;
+ /** All hardware registers for this chip type. */
+ using RegisterKey_t = std::pair<RegisterId_t, Instance_t>;
+ std::map<RegisterKey_t, const HardwareRegisterPtr> iv_regs;
+
+ /** All isolation nodes for this chip type. */
+ using NodeKey_t = std::pair<NodeId_t, Instance_t>;
+ std::map<NodeKey_t, const IsolationNodePtr> iv_nodes;
+
/** Root nodes for this chip type. */
std::map<AttentionType_t, const IsolationNodePtr> iv_rootNodes;
@@ -68,16 +77,46 @@
}
/**
+ * @brief Adds a hardware register to this chip.
+ * @param i_hwReg The target hardware register. Will assert that a different
+ * register with the same ID and instance does not exist.
+ */
+ void addHardwareRegister(HardwareRegisterPtr i_hwReg);
+
+ /**
+ * @brief Adds an isolation node to this chip.
+ * @param i_isoNode The target isolation node. Will assert that a different
+ * node with the same ID and instance does not exist.
+ */
+ void addIsolationNode(IsolationNodePtr i_isoNode);
+
+ /**
* @brief Adds a root node to this chip.
* @param i_attnType The target attention type. Will assert this type does
* not already exist in iv_rootNodes.
- * @param i_node The target isolation node for this attention type.
+ * @param i_rootNode The target isolation node for this attention type.
*/
- void addRootNode(AttentionType_t i_attnType, IsolationNodePtr i_node)
- {
- auto ret = iv_rootNodes.emplace(i_attnType, i_node);
- HEI_ASSERT(ret.second); // Should have not already existed.
- }
+ void addRootNode(AttentionType_t i_attnType, IsolationNodePtr i_rootNode);
+
+ /**
+ * @brief Retrieves a hardware register from this chip, if it exists.
+ * @param i_regId The register ID.
+ * @param i_regInst The register instance.
+ * @return The target hardware register. Will assert that the target
+ * register exists in iv_regs.
+ */
+ HardwareRegisterPtr getHardwareRegister(RegisterId_t i_regId,
+ Instance_t i_regInst) const;
+
+ /**
+ * @brief Retrieves an isolation node from this chip, if it exists.
+ * @param i_nodeId The node ID.
+ * @param i_nodeInst The node instance.
+ * @return The target isolation node. Will assert that the target node
+ * exists in iv_nodes.
+ */
+ IsolationNodePtr getIsolationNode(NodeId_t i_nodeId,
+ Instance_t i_nodeInst) const;
};
/** A simple map to ensure only one IsolationChip exists per chip type. */
diff --git a/src/register/hei_hardware_register.hpp b/src/register/hei_hardware_register.hpp
index 0f5ac61..f69e8a7 100644
--- a/src/register/hei_hardware_register.hpp
+++ b/src/register/hei_hardware_register.hpp
@@ -293,4 +293,7 @@
}
};
+/** Pointer management for hardware registers. */
+using HardwareRegisterPtr = std::shared_ptr<const HardwareRegister>;
+
} // end namespace libhei