Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 1 | #include <chip_data/hei_chip_data.hpp> |
| 2 | #include <chip_data/hei_chip_data_stream.hpp> |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 3 | #include <register/hei_operator_register.hpp> |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 4 | #include <register/hei_scom_register.hpp> |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 5 | |
| 6 | namespace libhei |
| 7 | { |
| 8 | |
| 9 | //------------------------------------------------------------------------------ |
| 10 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 11 | using SectionKeyword_t = uint32_t; |
| 12 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 13 | constexpr SectionKeyword_t KW_REGS = 0x52454753; // "REGS" ASCII |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 14 | constexpr SectionKeyword_t KW_NODE = 0x4e4f4445; // "NODE" ASCII |
| 15 | constexpr SectionKeyword_t KW_ROOT = 0x524f4f54; // "ROOT" ASCII |
| 16 | |
| 17 | using Version_t = uint8_t; |
| 18 | |
| 19 | constexpr Version_t VERSION_1 = 0x01; |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 20 | constexpr Version_t VERSION_2 = 0x02; |
Caleb Palmer | f2a2932 | 2024-07-25 13:14:26 -0500 | [diff] [blame] | 21 | constexpr Version_t VERSION_3 = 0x03; |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 22 | |
| 23 | //------------------------------------------------------------------------------ |
| 24 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 25 | void __readRegister(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 26 | { |
| 27 | // Read the register metadata. |
| 28 | RegisterId_t id; |
| 29 | RegisterType_t type; |
| 30 | RegisterAttributeFlags_t attr; |
| 31 | Instance_t numInsts; |
| 32 | io_stream >> id >> type >> attr >> numInsts; |
| 33 | |
| 34 | // Must have at least one instance. |
| 35 | HEI_ASSERT(0 != numInsts); |
| 36 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 37 | for (unsigned int i = 0; i < numInsts; i++) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 38 | { |
| 39 | // Read the register instance metadata. |
| 40 | Instance_t inst; |
| 41 | io_stream >> inst; |
| 42 | |
| 43 | // The address size is dependent on the register type. |
| 44 | if (REG_TYPE_SCOM == type) |
| 45 | { |
| 46 | uint32_t addr; // 4-byte address. |
| 47 | io_stream >> addr; |
| 48 | |
| 49 | // Get this register from the flyweight factory. |
| 50 | auto& factory = Flyweight<const ScomRegister>::getSingleton(); |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 51 | auto hwReg = factory.get(id, inst, attr, addr); |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 52 | |
| 53 | // Add this register to the isolation chip. |
| 54 | io_isoChip->addHardwareRegister(hwReg); |
| 55 | } |
| 56 | else if (REG_TYPE_ID_SCOM == type) |
| 57 | { |
| 58 | uint64_t addr; // 8-byte address. |
| 59 | io_stream >> addr; |
| 60 | |
| 61 | // Get this register from the flyweight factory. |
| 62 | auto& factory = Flyweight<const IdScomRegister>::getSingleton(); |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 63 | auto hwReg = factory.get(id, inst, attr, addr); |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 64 | |
| 65 | // Add this register to the isolation chip. |
| 66 | io_isoChip->addHardwareRegister(hwReg); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | HEI_ASSERT(false); // Register type unsupported. |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | //------------------------------------------------------------------------------ |
| 76 | |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 77 | Register::ConstPtr __readExpr(ChipDataStream& io_stream, |
| 78 | const IsolationChip::Ptr& i_isoChip, |
| 79 | IsolationNode::Ptr& io_isoNode) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 80 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 81 | Register::ConstPtr expr{}; |
| 82 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 83 | uint8_t exprType; |
| 84 | io_stream >> exprType; |
| 85 | switch (exprType) |
| 86 | { |
| 87 | case 0x01: // register reference |
| 88 | { |
| 89 | RegisterId_t regId; |
| 90 | Instance_t regInst; |
| 91 | io_stream >> regId >> regInst; |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 92 | |
| 93 | // Find the hardware register that is stored in this isolation chip |
| 94 | // and add it to the list of capture registers. This ensures all |
| 95 | // registers referenced in the rules are are captured by default. |
| 96 | // Note that this will assert that the target register must exist in |
| 97 | // the isolation chip. |
| 98 | auto hwReg = i_isoChip->getHardwareRegister({regId, regInst}); |
| 99 | |
| 100 | // Add the register to the isolation node. |
| 101 | io_isoNode->addCaptureRegister(hwReg); |
| 102 | |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 103 | // Simply return this register. |
| 104 | expr = hwReg; |
| 105 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 106 | break; |
| 107 | } |
| 108 | case 0x02: // integer constant |
| 109 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 110 | auto& factory = Flyweight<const ConstantRegister>::getSingleton(); |
| 111 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 112 | if (REG_TYPE_SCOM == io_isoNode->getRegisterType() || |
| 113 | REG_TYPE_ID_SCOM == io_isoNode->getRegisterType()) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 114 | { |
| 115 | uint64_t constant; // 8-byte value |
| 116 | io_stream >> constant; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 117 | |
| 118 | // Create the constant register and put it in the flyweights. |
| 119 | expr = factory.get(constant); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 120 | } |
| 121 | else |
| 122 | { |
| 123 | HEI_ASSERT(false); // register type unsupported |
| 124 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 125 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 126 | break; |
| 127 | } |
| 128 | case 0x10: // AND operation |
| 129 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 130 | auto& factory = Flyweight<const AndRegister>::getSingleton(); |
| 131 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 132 | uint8_t numSubExpr; |
| 133 | io_stream >> numSubExpr; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 134 | |
| 135 | HEI_ASSERT(2 <= numSubExpr); // must be at least two |
| 136 | |
| 137 | // Read the first two sub-expressions. |
| 138 | auto e1 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 139 | auto e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 140 | HEI_ASSERT(e1 && e2); // Cannot be null |
| 141 | |
| 142 | // Create the AND register and put it in the flyweights. |
| 143 | expr = factory.get(e1, e2); |
| 144 | |
| 145 | // Iterate any remaining expressions. |
| 146 | for (uint8_t i = 2; i < numSubExpr; i++) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 147 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 148 | // Read the next sub-expressions. |
| 149 | e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 150 | HEI_ASSERT(e2); // Cannot be null |
| 151 | |
| 152 | // Create the AND register and put it in the flyweights. |
| 153 | expr = factory.get(expr, e2); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 154 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 155 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 156 | break; |
| 157 | } |
| 158 | case 0x11: // OR operation |
| 159 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 160 | auto& factory = Flyweight<const OrRegister>::getSingleton(); |
| 161 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 162 | uint8_t numSubExpr; |
| 163 | io_stream >> numSubExpr; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 164 | |
| 165 | HEI_ASSERT(2 <= numSubExpr); // must be at least two |
| 166 | |
| 167 | // Read the first two sub-expressions. |
| 168 | auto e1 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 169 | auto e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 170 | HEI_ASSERT(e1 && e2); // Cannot be null |
| 171 | |
| 172 | // Create the OR register and put it in the flyweights. |
| 173 | expr = factory.get(e1, e2); |
| 174 | |
| 175 | // Iterate any remaining expressions. |
| 176 | for (uint8_t i = 2; i < numSubExpr; i++) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 177 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 178 | // Read the next sub-expressions. |
| 179 | e2 = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 180 | HEI_ASSERT(e2); // Cannot be null |
| 181 | |
| 182 | // Create the OR register and put it in the flyweights. |
| 183 | expr = factory.get(expr, e2); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 184 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 185 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 186 | break; |
| 187 | } |
| 188 | case 0x12: // NOT operation |
| 189 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 190 | auto& factory = Flyweight<const NotRegister>::getSingleton(); |
| 191 | |
| 192 | // Read the sub-expression |
| 193 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 194 | HEI_ASSERT(e); // Cannot be null |
| 195 | |
| 196 | // Create the NOT register and put it in the flyweights. |
| 197 | expr = factory.get(e); |
| 198 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | case 0x13: // left shift operation |
| 202 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 203 | auto& factory = Flyweight<const LeftShiftRegister>::getSingleton(); |
| 204 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 205 | uint8_t shiftValue; |
| 206 | io_stream >> shiftValue; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 207 | |
| 208 | // Read the sub-expression |
| 209 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 210 | HEI_ASSERT(e); // Cannot be null |
| 211 | |
| 212 | // Create the left shift register and put it in the flyweights. |
| 213 | expr = factory.get(e, shiftValue); |
| 214 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | case 0x14: // right shift operation |
| 218 | { |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 219 | auto& factory = Flyweight<const RightShiftRegister>::getSingleton(); |
| 220 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 221 | uint8_t shiftValue; |
| 222 | io_stream >> shiftValue; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 223 | |
| 224 | // Read the sub-expression |
| 225 | auto e = __readExpr(io_stream, i_isoChip, io_isoNode); |
| 226 | HEI_ASSERT(e); // Cannot be null |
| 227 | |
| 228 | // Create the right shift register and put it in the flyweights. |
| 229 | expr = factory.get(e, shiftValue); |
| 230 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | default: |
| 234 | HEI_ASSERT(false); // unsupported expression type |
| 235 | } |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 236 | |
| 237 | return expr; |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | //------------------------------------------------------------------------------ |
| 241 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 242 | using TmpChildNodeMap = std::map<BitPosition_t, IsolationNode::Key>; |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 243 | using TmpNodeData = std::pair<IsolationNode::Ptr, TmpChildNodeMap>; |
| 244 | using TmpNodeMap = std::map<IsolationNode::Key, TmpNodeData>; |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 245 | |
| 246 | void __readNode(ChipDataStream& io_stream, const IsolationChip::Ptr& i_isoChip, |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 247 | TmpNodeMap& io_tmpNodeMap, Version_t i_version) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 248 | { |
| 249 | // Read the node metadata. |
| 250 | NodeId_t nodeId; |
| 251 | RegisterType_t regType; |
| 252 | Instance_t numInsts; |
| 253 | io_stream >> nodeId >> regType >> numInsts; |
| 254 | |
Caleb Palmer | f2a2932 | 2024-07-25 13:14:26 -0500 | [diff] [blame] | 255 | // Version 3 and above: Read any write operations that exist. |
| 256 | std::map<OpRuleName_t, std::pair<OpRuleType_t, RegisterId_t>> opRules; |
| 257 | if (VERSION_3 <= i_version) |
| 258 | { |
| 259 | uint8_t numOpRules; |
| 260 | io_stream >> numOpRules; |
| 261 | for (unsigned int i = 0; i < numOpRules; i++) |
| 262 | { |
| 263 | OpRuleName_t opName; |
| 264 | OpRuleType_t opType; |
| 265 | RegisterId_t regId; |
| 266 | io_stream >> opName >> opType >> regId; |
| 267 | |
| 268 | std::pair<OpRuleType_t, RegisterId_t> tmpPair = {opType, regId}; |
| 269 | auto ret = opRules.emplace(opName, tmpPair); |
| 270 | HEI_ASSERT(ret.second || ret.first->second == tmpPair); |
| 271 | } |
| 272 | } |
| 273 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 274 | for (unsigned int i = 0; i < numInsts; i++) |
| 275 | { |
| 276 | // Read the node instance metadata. |
| 277 | Instance_t nodeInst; |
| 278 | uint8_t numCapRegs, numIsoRules, numChildNodes; |
| 279 | io_stream >> nodeInst >> numCapRegs >> numIsoRules >> numChildNodes; |
| 280 | |
Zane Shelley | bcb4395 | 2021-07-08 22:13:57 -0500 | [diff] [blame] | 281 | // It is possible to have rules defined and no child nodes, However, if |
| 282 | // there are no rules defined (FFDC-only node), there should not be |
| 283 | // any child nodes defined. |
| 284 | HEI_ASSERT(0 != numIsoRules || 0 == numChildNodes); |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 285 | |
| 286 | // Allocate memory for this isolation node. |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 287 | auto isoNode = std::make_shared<IsolationNode>(nodeId, nodeInst, |
| 288 | regType); |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 289 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 290 | // Add capture registers. |
| 291 | for (unsigned int j = 0; j < numCapRegs; j++) |
| 292 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 293 | // Read the capture register metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 294 | RegisterId_t regId; |
| 295 | Instance_t regInst; |
| 296 | io_stream >> regId >> regInst; |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 297 | |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 298 | BitPosition_t bit = MAX_BIT_POSITION; // default all bits |
| 299 | if (VERSION_2 <= i_version) |
| 300 | { |
| 301 | io_stream >> bit; |
| 302 | } |
| 303 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 304 | // Find the hardware register that is stored in this isolation chip |
| 305 | // and add it to the list of capture registers. Note that this will |
| 306 | // assert that the target register must exist in the isolation chip. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 307 | auto hwReg = i_isoChip->getHardwareRegister({regId, regInst}); |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 308 | |
| 309 | // Add the register to the isolation node. |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 310 | isoNode->addCaptureRegister(hwReg, bit); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // Add isolation rules. |
| 314 | for (unsigned int j = 0; j < numIsoRules; j++) |
| 315 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 316 | // Read the rule metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 317 | AttentionType_t attnType; |
| 318 | io_stream >> attnType; |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 319 | |
| 320 | // Read out the rule for this attention type. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 321 | auto rule = __readExpr(io_stream, i_isoChip, isoNode); |
Zane Shelley | f8c92f9 | 2020-05-16 10:17:16 -0500 | [diff] [blame] | 322 | HEI_ASSERT(rule); // Cannot be null |
| 323 | |
| 324 | // Add the rule to the isolation node. |
| 325 | isoNode->addRule(attnType, rule); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 328 | // At this point, we will need to read out the child node metadata. |
| 329 | // However, we can't look up the child nodes and add them to this |
| 330 | // isolation node yet because we are still in the process of parsing |
| 331 | // them out of the Chip Data File. Therefore, we'll save a temporary map |
| 332 | // containing the child node information which will be used to look up |
| 333 | // the actual node objects later. |
| 334 | TmpChildNodeMap cMap{}; |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 335 | for (unsigned int j = 0; j < numChildNodes; j++) |
| 336 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 337 | // Read the child node metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 338 | BitPosition_t bit; |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame] | 339 | NodeId_t childId; |
| 340 | Instance_t childInst; |
| 341 | io_stream >> bit >> childId >> childInst; |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 342 | |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 343 | auto ret = cMap.emplace(bit, |
| 344 | IsolationNode::Key{childId, childInst}); |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 345 | HEI_ASSERT(ret.second); // Should not have duplicate entries |
| 346 | } |
| 347 | |
Caleb Palmer | f2a2932 | 2024-07-25 13:14:26 -0500 | [diff] [blame] | 348 | // Version 3 and above: Add any write operations to the isoNode. |
| 349 | if (VERSION_3 <= i_version) |
| 350 | { |
| 351 | for (const auto& rule : opRules) |
| 352 | { |
| 353 | isoNode->addOpRule(rule.first, rule.second.first, |
| 354 | rule.second.second); |
| 355 | } |
| 356 | } |
| 357 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 358 | // Add this isolation node with the temporary child node map to the |
| 359 | // returned map of nodes. |
| 360 | auto ret = io_tmpNodeMap.emplace(IsolationNode::Key{nodeId, nodeInst}, |
| 361 | TmpNodeData{isoNode, cMap}); |
| 362 | HEI_ASSERT(ret.second); // Should not have duplicate entries |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | //------------------------------------------------------------------------------ |
| 367 | |
| 368 | void __insertNodes(IsolationChip::Ptr& io_isoChip, |
| 369 | const TmpNodeMap& i_tmpNodeMap) |
| 370 | { |
| 371 | for (const auto& n : i_tmpNodeMap) |
| 372 | { |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 373 | const IsolationNode::Ptr& node = n.second.first; |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 374 | const TmpChildNodeMap& childMap = n.second.second; |
| 375 | |
| 376 | // Link the child nodes, if they exist. |
| 377 | for (const auto& c : childMap) |
| 378 | { |
Patrick Williams | 2f7537d | 2023-05-10 07:51:39 -0500 | [diff] [blame] | 379 | const BitPosition_t& bit = c.first; |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 380 | const IsolationNode::Key& childKey = c.second; |
| 381 | |
| 382 | // Find the child node in the temporary map. |
| 383 | auto itr = i_tmpNodeMap.find(childKey); |
| 384 | HEI_ASSERT(i_tmpNodeMap.end() != itr); // Child node must exist. |
| 385 | |
| 386 | const IsolationNode::Ptr& child = itr->second.first; |
| 387 | |
| 388 | node->addChild(bit, child); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 389 | } |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 390 | |
| 391 | // Add this node to the isolation chip. |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 392 | io_isoChip->addIsolationNode(node); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
| 396 | //------------------------------------------------------------------------------ |
| 397 | |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 398 | void __readRoot(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip) |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 399 | { |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 400 | // Read the root node metadata. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 401 | AttentionType_t attnType; |
| 402 | NodeId_t id; |
| 403 | Instance_t inst; |
| 404 | io_stream >> attnType >> id >> inst; |
Zane Shelley | 2467db8 | 2020-05-18 19:56:30 -0500 | [diff] [blame] | 405 | |
| 406 | // Add the root node. |
| 407 | io_isoChip->addRootNode(attnType, io_isoChip->getIsolationNode({id, inst})); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | //------------------------------------------------------------------------------ |
| 411 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 412 | void parseChipDataFile(void* i_buffer, size_t i_bufferSize, |
Zane Shelley | 4de8ff8 | 2020-05-14 15:39:01 -0500 | [diff] [blame] | 413 | IsolationChip::Map& io_isoChips) |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 414 | { |
| 415 | ChipDataStream stream{i_buffer, i_bufferSize}; |
| 416 | |
| 417 | // Read the file metadata. |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 418 | FileKeyword_t fileKeyword; |
| 419 | ChipType_t chipType; |
| 420 | Version_t version; |
| 421 | stream >> fileKeyword >> chipType >> version; |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 422 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 423 | // Check the file keyword. |
| 424 | HEI_ASSERT(KW_CHIPDATA == fileKeyword); |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 425 | |
| 426 | // This chip type should not already exist. |
| 427 | HEI_ASSERT(io_isoChips.end() == io_isoChips.find(chipType)); |
| 428 | |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 429 | // Check supported versions. |
Caleb Palmer | f2a2932 | 2024-07-25 13:14:26 -0500 | [diff] [blame] | 430 | HEI_ASSERT(VERSION_1 <= version && version <= VERSION_3); |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 431 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 432 | // Allocate memory for the new isolation chip. |
Zane Shelley | d5d2363 | 2022-12-13 09:34:31 -0600 | [diff] [blame] | 433 | auto isoChip = std::make_shared<IsolationChip>(chipType); |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 434 | |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 435 | // Read the register list metadata. |
| 436 | SectionKeyword_t regsKeyword; |
| 437 | RegisterId_t numRegs; |
| 438 | stream >> regsKeyword >> numRegs; |
| 439 | |
| 440 | // Check the register keyword. |
| 441 | HEI_ASSERT(KW_REGS == regsKeyword); |
| 442 | |
| 443 | // There must be at least one register defined. |
| 444 | HEI_ASSERT(0 != numRegs); |
| 445 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 446 | for (unsigned int i = 0; i < numRegs; i++) |
Zane Shelley | b9a8e76 | 2020-05-11 21:41:32 -0500 | [diff] [blame] | 447 | { |
| 448 | __readRegister(stream, isoChip); |
| 449 | } |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 450 | |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 451 | // Read the node list metadata. |
| 452 | SectionKeyword_t nodeKeyword; |
| 453 | NodeId_t numNodes; |
| 454 | stream >> nodeKeyword >> numNodes; |
| 455 | |
| 456 | // Check the node keyword. |
| 457 | HEI_ASSERT(KW_NODE == nodeKeyword); |
| 458 | |
| 459 | // There must be at least one node defined. |
| 460 | HEI_ASSERT(0 != numNodes); |
| 461 | |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 462 | TmpNodeMap tmpNodeMap; // Stores all nodes with child node map. |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 463 | for (unsigned int i = 0; i < numNodes; i++) |
| 464 | { |
Zane Shelley | 6b1fe16 | 2022-11-18 13:37:42 -0600 | [diff] [blame] | 465 | __readNode(stream, isoChip, tmpNodeMap, version); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 466 | } |
Zane Shelley | f229d5f | 2020-05-17 21:13:41 -0500 | [diff] [blame] | 467 | // Link all nodes with their child nodes. Then add them to isoChip. |
| 468 | __insertNodes(isoChip, tmpNodeMap); |
Zane Shelley | 0165edc | 2020-05-11 22:28:29 -0500 | [diff] [blame] | 469 | |
| 470 | // Read the root node list metadata. |
| 471 | SectionKeyword_t rootKeyword; |
| 472 | AttentionType_t numRoots; |
| 473 | stream >> rootKeyword >> numRoots; |
| 474 | |
| 475 | // Check the root node keyword. |
| 476 | HEI_ASSERT(KW_ROOT == rootKeyword); |
| 477 | |
| 478 | // There must be at least one register defined. |
| 479 | HEI_ASSERT(0 != numRoots); |
| 480 | |
| 481 | for (unsigned int i = 0; i < numRoots; i++) |
| 482 | { |
| 483 | __readRoot(stream, isoChip); |
| 484 | } |
| 485 | |
| 486 | // At this point, the stream is done and it should be at the end of the |
| 487 | // file. |
| 488 | HEI_ASSERT(stream.eof()); |
| 489 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 490 | // Add this isolation chip to the collective list of isolation chips. |
Zane Shelley | d5d2363 | 2022-12-13 09:34:31 -0600 | [diff] [blame] | 491 | auto ret = io_isoChips.emplace(chipType, isoChip); |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 492 | HEI_ASSERT(ret.second); // Just in case. |
| 493 | } |
| 494 | |
| 495 | //------------------------------------------------------------------------------ |
| 496 | |
| 497 | } // namespace libhei |