blob: 78ce6b46dd93321461055b4e030ee12bae7500ab [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler90b4a0a2019-10-09 10:08:43 -050016#include "mru.hpp"
17
18#include <phosphor-logging/log.hpp>
19
20namespace openpower
21{
22namespace pels
23{
24namespace src
25{
26
27using namespace phosphor::logging;
28
29MRU::MRU(Stream& pel)
30{
31 pel >> _type >> _size >> _flags >> _reserved4B;
32
33 size_t numMRUs = _flags & 0xF;
34
35 for (size_t i = 0; i < numMRUs; i++)
36 {
37 MRUCallout mru;
38 pel >> mru.priority;
39 pel >> mru.id;
40 _mrus.push_back(std::move(mru));
41 }
42
43 size_t actualSize = sizeof(_type) + sizeof(_size) + sizeof(_flags) +
44 sizeof(_reserved4B) +
45 (sizeof(MRUCallout) * _mrus.size());
46 if (_size != actualSize)
47 {
48 log<level::WARNING>("MRU callout section in PEL has listed size that "
49 "doesn't match actual size",
50 entry("SUBSTRUCTURE_SIZE=%lu", _size),
51 entry("NUM_MRUS=%lu", _mrus.size()),
52 entry("ACTUAL_SIZE=%lu", actualSize));
53 }
54}
55
56void MRU::flatten(Stream& pel)
57{
58 pel << _type << _size << _flags << _reserved4B;
59
60 for (auto& mru : _mrus)
61 {
62 pel << mru.priority;
63 pel << mru.id;
64 }
65}
66} // namespace src
67} // namespace pels
68} // namespace openpower