1 /** 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 */ 16 #include "mru.hpp" 17 18 #include <phosphor-logging/log.hpp> 19 20 namespace openpower 21 { 22 namespace pels 23 { 24 namespace src 25 { 26 27 using namespace phosphor::logging; 28 29 MRU::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 56 void MRU::flatten(Stream& pel) const 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 69