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 | |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/log.hpp> |
| 19 | |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 20 | namespace openpower |
| 21 | { |
| 22 | namespace pels |
| 23 | { |
| 24 | namespace src |
| 25 | { |
| 26 | |
| 27 | Callouts::Callouts(Stream& pel) |
| 28 | { |
| 29 | pel >> _subsectionID >> _subsectionFlags >> _subsectionWordLength; |
| 30 | |
| 31 | size_t currentLength = sizeof(_subsectionID) + sizeof(_subsectionFlags) + |
| 32 | sizeof(_subsectionWordLength); |
| 33 | |
| 34 | while ((_subsectionWordLength * 4) > currentLength) |
| 35 | { |
| 36 | _callouts.emplace_back(new Callout(pel)); |
| 37 | currentLength += _callouts.back()->flattenedSize(); |
| 38 | } |
| 39 | } |
| 40 | |
Matt Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 41 | void Callouts::flatten(Stream& pel) const |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 42 | { |
| 43 | pel << _subsectionID << _subsectionFlags << _subsectionWordLength; |
| 44 | |
| 45 | for (auto& callout : _callouts) |
| 46 | { |
| 47 | callout->flatten(pel); |
| 48 | } |
| 49 | } |
| 50 | |
Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 51 | void Callouts::addCallout(std::unique_ptr<Callout> callout) |
| 52 | { |
| 53 | if (_callouts.size() < maxNumberOfCallouts) |
| 54 | { |
| 55 | _callouts.push_back(std::move(callout)); |
| 56 | |
| 57 | _subsectionWordLength += _callouts.back()->flattenedSize() / 4; |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | using namespace phosphor::logging; |
| 62 | log<level::INFO>("Dropping PEL callout because at max"); |
| 63 | } |
| 64 | } |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 65 | } // namespace src |
| 66 | } // namespace pels |
| 67 | } // namespace openpower |