Matt Spinler | 6c9662c | 2019-10-09 11:27:20 -0500 | [diff] [blame] | 1 | #include "callout.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | |
| 5 | namespace openpower |
| 6 | { |
| 7 | namespace pels |
| 8 | { |
| 9 | namespace src |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::logging; |
| 13 | |
| 14 | Callout::Callout(Stream& pel) |
| 15 | { |
| 16 | pel >> _size >> _flags >> _priority >> _locationCodeSize; |
| 17 | |
| 18 | if (_locationCodeSize) |
| 19 | { |
| 20 | _locationCode.resize(_locationCodeSize); |
| 21 | pel >> _locationCode; |
| 22 | } |
| 23 | |
| 24 | size_t currentSize = 4 + _locationCodeSize; |
| 25 | |
| 26 | // Read in the substructures until the end of this structure. |
| 27 | // Any stream overflows will throw an exception up to the SRC constructor |
| 28 | while (_size > currentSize) |
| 29 | { |
| 30 | // Peek the type |
| 31 | uint16_t type = 0; |
| 32 | pel >> type; |
| 33 | pel.offset(pel.offset() - 2); |
| 34 | |
| 35 | switch (type) |
| 36 | { |
| 37 | case FRUIdentity::substructureType: |
| 38 | { |
| 39 | _fruIdentity = std::make_unique<FRUIdentity>(pel); |
| 40 | currentSize += _fruIdentity->flattenedSize(); |
| 41 | break; |
| 42 | } |
| 43 | case PCEIdentity::substructureType: |
| 44 | { |
| 45 | _pceIdentity = std::make_unique<PCEIdentity>(pel); |
| 46 | currentSize += _pceIdentity->flattenedSize(); |
| 47 | break; |
| 48 | } |
| 49 | case MRU::substructureType: |
| 50 | { |
| 51 | _mru = std::make_unique<MRU>(pel); |
| 52 | currentSize += _mru->flattenedSize(); |
| 53 | break; |
| 54 | } |
| 55 | default: |
| 56 | log<level::ERR>("Invalid Callout subsection type", |
| 57 | entry("CALLOUT_TYPE=0x%X", type)); |
| 58 | throw std::runtime_error("Invalid Callout subsection type"); |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | size_t Callout::flattenedSize() |
| 65 | { |
| 66 | size_t size = sizeof(_size) + sizeof(_flags) + sizeof(_priority) + |
| 67 | sizeof(_locationCodeSize) + _locationCodeSize; |
| 68 | |
| 69 | size += _fruIdentity ? _fruIdentity->flattenedSize() : 0; |
| 70 | size += _pceIdentity ? _pceIdentity->flattenedSize() : 0; |
| 71 | size += _mru ? _mru->flattenedSize() : 0; |
| 72 | |
| 73 | return size; |
| 74 | } |
| 75 | |
| 76 | void Callout::flatten(Stream& pel) |
| 77 | { |
| 78 | pel << _size << _flags << _priority << _locationCodeSize; |
| 79 | |
| 80 | if (_locationCodeSize) |
| 81 | { |
| 82 | pel << _locationCode; |
| 83 | } |
| 84 | |
| 85 | if (_fruIdentity) |
| 86 | { |
| 87 | _fruIdentity->flatten(pel); |
| 88 | } |
| 89 | |
| 90 | if (_pceIdentity) |
| 91 | { |
| 92 | _pceIdentity->flatten(pel); |
| 93 | } |
| 94 | if (_mru) |
| 95 | { |
| 96 | _mru->flatten(pel); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | } // namespace src |
| 101 | } // namespace pels |
| 102 | } // namespace openpower |