Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 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 | */ |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 16 | #include "callouts.hpp" |
| 17 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/log.hpp> |
| 19 | |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame] | 20 | #include <algorithm> |
Matt Spinler | 7681e5e | 2022-03-11 15:14:57 -0600 | [diff] [blame] | 21 | #include <map> |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 22 | |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 23 | namespace openpower |
| 24 | { |
| 25 | namespace pels |
| 26 | { |
| 27 | namespace src |
| 28 | { |
| 29 | |
| 30 | Callouts::Callouts(Stream& pel) |
| 31 | { |
| 32 | pel >> _subsectionID >> _subsectionFlags >> _subsectionWordLength; |
| 33 | |
| 34 | size_t currentLength = sizeof(_subsectionID) + sizeof(_subsectionFlags) + |
| 35 | sizeof(_subsectionWordLength); |
| 36 | |
| 37 | while ((_subsectionWordLength * 4) > currentLength) |
| 38 | { |
| 39 | _callouts.emplace_back(new Callout(pel)); |
| 40 | currentLength += _callouts.back()->flattenedSize(); |
| 41 | } |
| 42 | } |
| 43 | |
Matt Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 44 | void Callouts::flatten(Stream& pel) const |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 45 | { |
| 46 | pel << _subsectionID << _subsectionFlags << _subsectionWordLength; |
| 47 | |
| 48 | for (auto& callout : _callouts) |
| 49 | { |
| 50 | callout->flatten(pel); |
| 51 | } |
| 52 | } |
| 53 | |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 54 | void Callouts::addCallout(std::unique_ptr<Callout> callout) |
| 55 | { |
| 56 | if (_callouts.size() < maxNumberOfCallouts) |
| 57 | { |
| 58 | _callouts.push_back(std::move(callout)); |
| 59 | |
| 60 | _subsectionWordLength += _callouts.back()->flattenedSize() / 4; |
| 61 | } |
| 62 | else |
| 63 | { |
Matt Spinler | 7f1b905 | 2022-03-22 09:18:58 -0500 | [diff] [blame] | 64 | using namespace phosphor::logging; |
| 65 | log<level::INFO>("Dropping PEL callout because at max"); |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 66 | } |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 67 | |
| 68 | // Mapping including the 3 Medium levels as A,B and C |
| 69 | const std::map<std::uint8_t, int> priorities = { |
| 70 | {'H', 10}, {'M', 9}, {'A', 8}, {'B', 7}, {'C', 6}, {'L', 5}}; |
| 71 | |
| 72 | auto sortPriority = [&priorities](const std::unique_ptr<Callout>& p1, |
| 73 | const std::unique_ptr<Callout>& p2) { |
| 74 | return priorities.at(p1->priority()) > priorities.at(p2->priority()); |
| 75 | }; |
| 76 | |
| 77 | std::sort(_callouts.begin(), _callouts.end(), sortPriority); |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 78 | } |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 79 | |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 80 | } // namespace src |
| 81 | } // namespace pels |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame] | 82 | } // namespace openpower |