blob: 53fe85d643ba32966b9942aa45e71caf982e40d9 [file] [log] [blame]
Matt Spinler6c9662c2019-10-09 11:27:20 -05001#include "callout.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace openpower
6{
7namespace pels
8{
9namespace src
10{
11
12using namespace phosphor::logging;
13
14Callout::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
64size_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
76void 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