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 | { |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 33 | public: // Aliases |
| 34 | using Ptr = std::unique_ptr<IsolationChip>; |
| 35 | using ConstPtr = std::unique_ptr<const IsolationChip>; |
| 36 | |
| 37 | using Map = std::map<ChipType_t, const ConstPtr>; |
| 38 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 39 | public: // Constructors, destructor, assignment |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 40 | /** @brief Constructor. */ |
| 41 | explicit IsolationChip(ChipType_t i_chipType) : iv_chipType(i_chipType) {} |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 42 | |
| 43 | /** @brief Destructor. */ |
| 44 | ~IsolationChip() = default; |
| 45 | |
| 46 | /** @brief Copy constructor. */ |
| 47 | IsolationChip(const IsolationChip&) = delete; |
| 48 | |
| 49 | /** @brief Assignment operator. */ |
| 50 | IsolationChip& operator=(const IsolationChip&) = delete; |
| 51 | |
| 52 | private: // Instance variables |
| 53 | /** This chip's type. */ |
| 54 | const ChipType_t iv_chipType; |
| 55 | |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 56 | /** All hardware registers for this chip type. */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 57 | std::map<HardwareRegister::Key, const HardwareRegister::ConstPtr> iv_regs; |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 58 | |
| 59 | /** All isolation nodes for this chip type. */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 60 | std::map<IsolationNode::Key, const IsolationNode::ConstPtr> iv_nodes; |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 61 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 62 | /** Root nodes for this chip type. */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 63 | std::map<AttentionType_t, const IsolationNode::ConstPtr> iv_rootNodes; |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 64 | |
| 65 | public: // Member functions |
| 66 | /** |
| 67 | * @brief Finds all active attentions on this chip. |
| 68 | * @param i_chip The target chip for isolation. Will assert the given |
| 69 | * chip type matches iv_chipType. |
| 70 | * @param io_isoData The isolation data returned back to the user |
| 71 | * application. |
| 72 | * @return True, if any active attentions found on this chip. |
| 73 | * False, otherwise. |
| 74 | */ |
| 75 | bool analyze(const Chip& i_chip, IsolationData& io_isoData) const; |
| 76 | |
| 77 | /** @brief Chip type accessor. */ |
| 78 | ChipType_t getChipType() const |
| 79 | { |
| 80 | return iv_chipType; |
| 81 | } |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 82 | |
| 83 | /** |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 84 | * @brief Adds a hardware register to this chip. |
| 85 | * @param i_hwReg The target hardware register. Will assert that a different |
| 86 | * register with the same ID and instance does not exist. |
| 87 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 88 | void addHardwareRegister(HardwareRegister::ConstPtr i_hwReg); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * @brief Adds an isolation node to this chip. |
| 92 | * @param i_isoNode The target isolation node. Will assert that a different |
| 93 | * node with the same ID and instance does not exist. |
| 94 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 95 | void addIsolationNode(IsolationNode::ConstPtr i_isoNode); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 96 | |
| 97 | /** |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 98 | * @brief Adds a root node to this chip. |
| 99 | * @param i_attnType The target attention type. Will assert this type does |
| 100 | * not already exist in iv_rootNodes. |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 101 | * @param i_rootNode The target isolation node for this attention type. |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 102 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 103 | void addRootNode(AttentionType_t i_attnType, |
| 104 | IsolationNode::ConstPtr i_rootNode); |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * @brief Retrieves a hardware register from this chip, if it exists. |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 108 | * @param i_key The register key. |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 109 | * @return The target hardware register. Will assert that the target |
| 110 | * register exists in iv_regs. |
| 111 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 112 | HardwareRegister::ConstPtr |
| 113 | getHardwareRegister(HardwareRegister::Key i_key) const; |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * @brief Retrieves an isolation node from this chip, if it exists. |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 117 | * @param i_key The node key. |
Zane Shelley | 4caa043 | 2020-05-12 22:29:02 -0500 | [diff] [blame] | 118 | * @return The target isolation node. Will assert that the target node |
| 119 | * exists in iv_nodes. |
| 120 | */ |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 121 | IsolationNode::ConstPtr getIsolationNode(IsolationNode::Key i_key) const; |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 124 | } // end namespace libhei |