1711d51d8SMatt Spinler /** 2711d51d8SMatt Spinler * Copyright © 2019 IBM Corporation 3711d51d8SMatt Spinler * 4711d51d8SMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License"); 5711d51d8SMatt Spinler * you may not use this file except in compliance with the License. 6711d51d8SMatt Spinler * You may obtain a copy of the License at 7711d51d8SMatt Spinler * 8711d51d8SMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0 9711d51d8SMatt Spinler * 10711d51d8SMatt Spinler * Unless required by applicable law or agreed to in writing, software 11711d51d8SMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS, 12711d51d8SMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13711d51d8SMatt Spinler * See the License for the specific language governing permissions and 14711d51d8SMatt Spinler * limitations under the License. 15711d51d8SMatt Spinler */ 1632f13c91SMatt Spinler #include "callouts.hpp" 1732f13c91SMatt Spinler 18*2ea96f6cSMatt Spinler #include "trace.hpp" 19*2ea96f6cSMatt Spinler 20*2ea96f6cSMatt Spinler #include <algorithm> 21e0366f31SMatt Spinler 2232f13c91SMatt Spinler namespace openpower 2332f13c91SMatt Spinler { 2432f13c91SMatt Spinler namespace pels 2532f13c91SMatt Spinler { 2632f13c91SMatt Spinler namespace src 2732f13c91SMatt Spinler { 2832f13c91SMatt Spinler 2932f13c91SMatt Spinler Callouts::Callouts(Stream& pel) 3032f13c91SMatt Spinler { 3132f13c91SMatt Spinler pel >> _subsectionID >> _subsectionFlags >> _subsectionWordLength; 3232f13c91SMatt Spinler 3332f13c91SMatt Spinler size_t currentLength = sizeof(_subsectionID) + sizeof(_subsectionFlags) + 3432f13c91SMatt Spinler sizeof(_subsectionWordLength); 3532f13c91SMatt Spinler 3632f13c91SMatt Spinler while ((_subsectionWordLength * 4) > currentLength) 3732f13c91SMatt Spinler { 3832f13c91SMatt Spinler _callouts.emplace_back(new Callout(pel)); 3932f13c91SMatt Spinler currentLength += _callouts.back()->flattenedSize(); 4032f13c91SMatt Spinler } 4132f13c91SMatt Spinler } 4232f13c91SMatt Spinler 43724d0d8cSMatt Spinler void Callouts::flatten(Stream& pel) const 4432f13c91SMatt Spinler { 4532f13c91SMatt Spinler pel << _subsectionID << _subsectionFlags << _subsectionWordLength; 4632f13c91SMatt Spinler 4732f13c91SMatt Spinler for (auto& callout : _callouts) 4832f13c91SMatt Spinler { 4932f13c91SMatt Spinler callout->flatten(pel); 5032f13c91SMatt Spinler } 5132f13c91SMatt Spinler } 5232f13c91SMatt Spinler 53e0366f31SMatt Spinler void Callouts::addCallout(std::unique_ptr<Callout> callout) 54e0366f31SMatt Spinler { 55e0366f31SMatt Spinler if (_callouts.size() < maxNumberOfCallouts) 56e0366f31SMatt Spinler { 57e0366f31SMatt Spinler _callouts.push_back(std::move(callout)); 58e0366f31SMatt Spinler 59e0366f31SMatt Spinler _subsectionWordLength += _callouts.back()->flattenedSize() / 4; 60e0366f31SMatt Spinler } 61e0366f31SMatt Spinler else 62e0366f31SMatt Spinler { 63*2ea96f6cSMatt Spinler trace::info("Dropping PEL callout because at max"); 64e0366f31SMatt Spinler } 6553ef1552SMiguel Gomez 6653ef1552SMiguel Gomez // Mapping including the 3 Medium levels as A,B and C 6753ef1552SMiguel Gomez const std::map<std::uint8_t, int> priorities = { 6853ef1552SMiguel Gomez {'H', 10}, {'M', 9}, {'A', 8}, {'B', 7}, {'C', 6}, {'L', 5}}; 6953ef1552SMiguel Gomez 7053ef1552SMiguel Gomez auto sortPriority = [&priorities](const std::unique_ptr<Callout>& p1, 7153ef1552SMiguel Gomez const std::unique_ptr<Callout>& p2) { 7253ef1552SMiguel Gomez return priorities.at(p1->priority()) > priorities.at(p2->priority()); 7353ef1552SMiguel Gomez }; 7453ef1552SMiguel Gomez 7553ef1552SMiguel Gomez std::sort(_callouts.begin(), _callouts.end(), sortPriority); 76e0366f31SMatt Spinler } 7753ef1552SMiguel Gomez 7832f13c91SMatt Spinler } // namespace src 7932f13c91SMatt Spinler } // namespace pels 8032f13c91SMatt Spinler } // namespace openpower 81