Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <hei_isolation_data.hpp> |
| 4 | #include <isolator/hei_isolation_node.hpp> |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 5 | #include <register/hei_hardware_register.hpp> |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 6 | |
| 7 | namespace 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 | */ |
| 31 | class IsolationChip |
| 32 | { |
| 33 | public: // Constructors, destructor, assignment |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 34 | /** @brief Constructor. */ |
| 35 | explicit IsolationChip(ChipType_t i_chipType) : iv_chipType(i_chipType) {} |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 36 | |
| 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 Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 50 | /** 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 Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 58 | /** Root nodes for this chip type. */ |
Zane Shelley | 6722b5b | 2020-05-12 22:09:04 -0500 | [diff] [blame] | 59 | std::map<AttentionType_t, const IsolationNodePtr> iv_rootNodes; |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 60 | |
| 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 Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 78 | |
| 79 | /** |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 80 | * @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 Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 94 | * @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 Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 97 | * @param i_rootNode The target isolation node for this attention type. |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 98 | */ |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 99 | 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 Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 120 | }; |
| 121 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 122 | /** Pointer management for isolation chips. */ |
| 123 | using IsolationChipPtr = std::unique_ptr<IsolationChip>; |
| 124 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 125 | /** A simple map to ensure only one IsolationChip exists per chip type. */ |
| 126 | using IsolationChipMap = |
| 127 | std::map<ChipType_t, const std::unique_ptr<const IsolationChip>>; |
| 128 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 129 | } // end namespace libhei |