blob: cb4135314bd7cc6e6a3234ab084faabbbafeace0 [file] [log] [blame]
Zane Shelley508ce582020-05-05 13:47:19 -05001#pragma once
2
3#include <hei_isolation_data.hpp>
4#include <isolator/hei_isolation_node.hpp>
Zane Shelley4caa0432020-05-12 22:29:02 -05005#include <register/hei_hardware_register.hpp>
Zane Shelley508ce582020-05-05 13:47:19 -05006
7namespace libhei
8{
9
10/**
11 * @brief This class contains all information required to isolate attentions on
12 * a specific chip type.
13 *
14 * The primary function of this class is analyze(), which will do a depth-first
15 * search of the hardware attention reporting tree structure (characterized by
16 * IsolationNode objects) to find all active attentions on a chip.
17 *
18 * The data for each chip type is built from information in the Chip Data Files.
19 *
20 * IMPORTANT:
21 * Most of the objects created and referenced by this class are stored in the
22 * flyweight factories, which are used as a space saving mechanism by
23 * preventing duplicate object creation. For example, a large set of the
24 * registers for a specific chip model will likely be common between each of
25 * chip level of that model. It is not necessary to create new objects for
26 * each level when the attributes are all the same. Because the flyweights are
27 * used, it is not possible to remove all of the data for a specific chip
28 * model/level be deleting an IsolationChip object. Instead, you must call the
29 * main uninitialize() function and clear all data for all objects.
30 */
31class IsolationChip
32{
33 public: // Constructors, destructor, assignment
Zane Shelleydd69c962020-05-05 22:19:11 -050034 /** @brief Constructor. */
35 explicit IsolationChip(ChipType_t i_chipType) : iv_chipType(i_chipType) {}
Zane Shelley508ce582020-05-05 13:47:19 -050036
37 /** @brief Destructor. */
38 ~IsolationChip() = default;
39
40 /** @brief Copy constructor. */
41 IsolationChip(const IsolationChip&) = delete;
42
43 /** @brief Assignment operator. */
44 IsolationChip& operator=(const IsolationChip&) = delete;
45
46 private: // Instance variables
47 /** This chip's type. */
48 const ChipType_t iv_chipType;
49
Zane Shelley4caa0432020-05-12 22:29:02 -050050 /** All hardware registers for this chip type. */
51 using RegisterKey_t = std::pair<RegisterId_t, Instance_t>;
52 std::map<RegisterKey_t, const HardwareRegisterPtr> iv_regs;
53
54 /** All isolation nodes for this chip type. */
55 using NodeKey_t = std::pair<NodeId_t, Instance_t>;
56 std::map<NodeKey_t, const IsolationNodePtr> iv_nodes;
57
Zane Shelley508ce582020-05-05 13:47:19 -050058 /** Root nodes for this chip type. */
Zane Shelley6722b5b2020-05-12 22:09:04 -050059 std::map<AttentionType_t, const IsolationNodePtr> iv_rootNodes;
Zane Shelley508ce582020-05-05 13:47:19 -050060
61 public: // Member functions
62 /**
63 * @brief Finds all active attentions on this chip.
64 * @param i_chip The target chip for isolation. Will assert the given
65 * chip type matches iv_chipType.
66 * @param io_isoData The isolation data returned back to the user
67 * application.
68 * @return True, if any active attentions found on this chip.
69 * False, otherwise.
70 */
71 bool analyze(const Chip& i_chip, IsolationData& io_isoData) const;
72
73 /** @brief Chip type accessor. */
74 ChipType_t getChipType() const
75 {
76 return iv_chipType;
77 }
Zane Shelleydd69c962020-05-05 22:19:11 -050078
79 /**
Zane Shelley4caa0432020-05-12 22:29:02 -050080 * @brief Adds a hardware register to this chip.
81 * @param i_hwReg The target hardware register. Will assert that a different
82 * register with the same ID and instance does not exist.
83 */
84 void addHardwareRegister(HardwareRegisterPtr i_hwReg);
85
86 /**
87 * @brief Adds an isolation node to this chip.
88 * @param i_isoNode The target isolation node. Will assert that a different
89 * node with the same ID and instance does not exist.
90 */
91 void addIsolationNode(IsolationNodePtr i_isoNode);
92
93 /**
Zane Shelleydd69c962020-05-05 22:19:11 -050094 * @brief Adds a root node to this chip.
95 * @param i_attnType The target attention type. Will assert this type does
96 * not already exist in iv_rootNodes.
Zane Shelley4caa0432020-05-12 22:29:02 -050097 * @param i_rootNode The target isolation node for this attention type.
Zane Shelleydd69c962020-05-05 22:19:11 -050098 */
Zane Shelley4caa0432020-05-12 22:29:02 -050099 void addRootNode(AttentionType_t i_attnType, IsolationNodePtr i_rootNode);
100
101 /**
102 * @brief Retrieves a hardware register from this chip, if it exists.
103 * @param i_regId The register ID.
104 * @param i_regInst The register instance.
105 * @return The target hardware register. Will assert that the target
106 * register exists in iv_regs.
107 */
108 HardwareRegisterPtr getHardwareRegister(RegisterId_t i_regId,
109 Instance_t i_regInst) const;
110
111 /**
112 * @brief Retrieves an isolation node from this chip, if it exists.
113 * @param i_nodeId The node ID.
114 * @param i_nodeInst The node instance.
115 * @return The target isolation node. Will assert that the target node
116 * exists in iv_nodes.
117 */
118 IsolationNodePtr getIsolationNode(NodeId_t i_nodeId,
119 Instance_t i_nodeInst) const;
Zane Shelley508ce582020-05-05 13:47:19 -0500120};
121
Zane Shelleydd69c962020-05-05 22:19:11 -0500122/** A simple map to ensure only one IsolationChip exists per chip type. */
123using IsolationChipMap =
124 std::map<ChipType_t, const std::unique_ptr<const IsolationChip>>;
125
Zane Shelley508ce582020-05-05 13:47:19 -0500126} // end namespace libhei