blob: 7482aca2baafe0ef3c9b404e5e262a201e2afc08 [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 Spinler32f13c92019-10-09 12:48:25 -050016#include "callouts.hpp"
17
Matt Spinler2ea96f62022-02-23 16:31:01 -060018#include <algorithm>
Matt Spinler7681e5e2022-03-11 15:14:57 -060019#include <map>
Matt Spinler7f1b9052022-03-22 09:18:58 -050020#include <phosphor-logging/log.hpp>
Matt Spinlere0366f32020-03-13 13:02:19 -050021
Matt Spinler32f13c92019-10-09 12:48:25 -050022namespace openpower
23{
24namespace pels
25{
26namespace src
27{
28
29Callouts::Callouts(Stream& pel)
30{
31 pel >> _subsectionID >> _subsectionFlags >> _subsectionWordLength;
32
33 size_t currentLength = sizeof(_subsectionID) + sizeof(_subsectionFlags) +
34 sizeof(_subsectionWordLength);
35
36 while ((_subsectionWordLength * 4) > currentLength)
37 {
38 _callouts.emplace_back(new Callout(pel));
39 currentLength += _callouts.back()->flattenedSize();
40 }
41}
42
Matt Spinler724d0d82019-11-06 10:05:36 -060043void Callouts::flatten(Stream& pel) const
Matt Spinler32f13c92019-10-09 12:48:25 -050044{
45 pel << _subsectionID << _subsectionFlags << _subsectionWordLength;
46
47 for (auto& callout : _callouts)
48 {
49 callout->flatten(pel);
50 }
51}
52
Matt Spinlere0366f32020-03-13 13:02:19 -050053void Callouts::addCallout(std::unique_ptr<Callout> callout)
54{
55 if (_callouts.size() < maxNumberOfCallouts)
56 {
57 _callouts.push_back(std::move(callout));
58
59 _subsectionWordLength += _callouts.back()->flattenedSize() / 4;
60 }
61 else
62 {
Matt Spinler7f1b9052022-03-22 09:18:58 -050063 using namespace phosphor::logging;
64 log<level::INFO>("Dropping PEL callout because at max");
Matt Spinlere0366f32020-03-13 13:02:19 -050065 }
Miguel Gomez53ef1552020-10-14 21:16:32 +000066
67 // Mapping including the 3 Medium levels as A,B and C
68 const std::map<std::uint8_t, int> priorities = {
69 {'H', 10}, {'M', 9}, {'A', 8}, {'B', 7}, {'C', 6}, {'L', 5}};
70
71 auto sortPriority = [&priorities](const std::unique_ptr<Callout>& p1,
72 const std::unique_ptr<Callout>& p2) {
73 return priorities.at(p1->priority()) > priorities.at(p2->priority());
74 };
75
76 std::sort(_callouts.begin(), _callouts.end(), sortPriority);
Matt Spinlere0366f32020-03-13 13:02:19 -050077}
Miguel Gomez53ef1552020-10-14 21:16:32 +000078
Matt Spinler32f13c92019-10-09 12:48:25 -050079} // namespace src
80} // namespace pels
Matt Spinler2ea96f62022-02-23 16:31:01 -060081} // namespace openpower