| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 4 | #include "callouts.hpp" |
| 5 | |
| Matt Spinler | cc9adb7 | 2024-02-26 11:24:36 -0600 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 7 | |
| Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame] | 8 | #include <algorithm> |
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 9 | |
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 10 | namespace openpower |
| 11 | { |
| 12 | namespace pels |
| 13 | { |
| 14 | namespace src |
| 15 | { |
| 16 | |
| 17 | Callouts::Callouts(Stream& pel) |
| 18 | { |
| 19 | pel >> _subsectionID >> _subsectionFlags >> _subsectionWordLength; |
| 20 | |
| 21 | size_t currentLength = sizeof(_subsectionID) + sizeof(_subsectionFlags) + |
| 22 | sizeof(_subsectionWordLength); |
| 23 | |
| 24 | while ((_subsectionWordLength * 4) > currentLength) |
| 25 | { |
| 26 | _callouts.emplace_back(new Callout(pel)); |
| 27 | currentLength += _callouts.back()->flattenedSize(); |
| 28 | } |
| 29 | } |
| 30 | |
| Matt Spinler | 724d0d8 | 2019-11-06 10:05:36 -0600 | [diff] [blame] | 31 | void Callouts::flatten(Stream& pel) const |
| Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 32 | { |
| 33 | pel << _subsectionID << _subsectionFlags << _subsectionWordLength; |
| 34 | |
| 35 | for (auto& callout : _callouts) |
| 36 | { |
| 37 | callout->flatten(pel); |
| 38 | } |
| 39 | } |
| 40 | |
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 41 | void Callouts::addCallout(std::unique_ptr<Callout> callout) |
| 42 | { |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 43 | bool shouldAdd = true; |
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 44 | |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 45 | // Check if there is already a callout for this FRU |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 46 | auto it = std::ranges::find_if(_callouts, [&callout](const auto& c) { |
| 47 | return *callout == *c; |
| 48 | }); |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 49 | |
| 50 | // If the callout already exists, but the new one has a higher |
| 51 | // priority, change the existing callout's priority to this |
| 52 | // new value and don't add the new one. |
| 53 | if (it != _callouts.end()) |
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 54 | { |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 55 | if (*callout > **it) |
| 56 | { |
| 57 | (*it)->setPriority(callout->priority()); |
| 58 | } |
| 59 | shouldAdd = false; |
| Matt Spinler | e0366f3 | 2020-03-13 13:02:19 -0500 | [diff] [blame] | 60 | } |
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 61 | |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 62 | if (shouldAdd) |
| 63 | { |
| 64 | if (_callouts.size() < maxNumberOfCallouts) |
| 65 | { |
| 66 | _callouts.push_back(std::move(callout)); |
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 67 | |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 68 | _subsectionWordLength += _callouts.back()->flattenedSize() / 4; |
| 69 | } |
| 70 | else |
| 71 | { |
| Matt Spinler | cc9adb7 | 2024-02-26 11:24:36 -0600 | [diff] [blame] | 72 | lg2::info("Dropping PEL callout because at max"); |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 73 | } |
| 74 | } |
| Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 75 | |
| Matt Spinler | 4efed0e | 2024-02-26 11:16:07 -0600 | [diff] [blame] | 76 | std::ranges::sort(_callouts, |
| 77 | [](const auto& c1, const auto& c2) { return *c1 > *c2; }); |
| 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 |