| 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 | cc9adb7 | 2024-02-26 11:24:36 -0600 | [diff] [blame] | 18 | #include <phosphor-logging/lg2.hpp> | 
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 19 |  | 
| Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame] | 20 | #include <algorithm> | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 21 |  | 
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 22 | namespace openpower | 
 | 23 | { | 
 | 24 | namespace pels | 
 | 25 | { | 
 | 26 | namespace src | 
 | 27 | { | 
 | 28 |  | 
 | 29 | Callouts::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 Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 43 | void Callouts::flatten(Stream& pel) const | 
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 44 | { | 
 | 45 |     pel << _subsectionID << _subsectionFlags << _subsectionWordLength; | 
 | 46 |  | 
 | 47 |     for (auto& callout : _callouts) | 
 | 48 |     { | 
 | 49 |         callout->flatten(pel); | 
 | 50 |     } | 
 | 51 | } | 
 | 52 |  | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 53 | void Callouts::addCallout(std::unique_ptr<Callout> callout) | 
 | 54 | { | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 55 |     bool shouldAdd = true; | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 56 |  | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 57 |     // Check if there is already a callout for this FRU | 
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 58 |     auto it = std::ranges::find_if(_callouts, [&callout](const auto& c) { | 
 | 59 |         return *callout == *c; | 
 | 60 |     }); | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 61 |  | 
 | 62 |     // If the callout already exists, but the new one has a higher | 
 | 63 |     // priority, change the existing callout's priority to this | 
 | 64 |     // new value and don't add the new one. | 
 | 65 |     if (it != _callouts.end()) | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 66 |     { | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 67 |         if (*callout > **it) | 
 | 68 |         { | 
 | 69 |             (*it)->setPriority(callout->priority()); | 
 | 70 |         } | 
 | 71 |         shouldAdd = false; | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 72 |     } | 
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 73 |  | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 74 |     if (shouldAdd) | 
 | 75 |     { | 
 | 76 |         if (_callouts.size() < maxNumberOfCallouts) | 
 | 77 |         { | 
 | 78 |             _callouts.push_back(std::move(callout)); | 
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 79 |  | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 80 |             _subsectionWordLength += _callouts.back()->flattenedSize() / 4; | 
 | 81 |         } | 
 | 82 |         else | 
 | 83 |         { | 
| Matt Spinler | cc9adb7 | 2024-02-26 11:24:36 -0600 | [diff] [blame] | 84 |             lg2::info("Dropping PEL callout because at max"); | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 85 |         } | 
 | 86 |     } | 
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 87 |  | 
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 88 |     std::ranges::sort(_callouts, | 
 | 89 |                       [](const auto& c1, const auto& c2) { return *c1 > *c2; }); | 
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 90 | } | 
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 91 |  | 
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 92 | } // namespace src | 
 | 93 | } // namespace pels | 
| Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame] | 94 | } // namespace openpower |