blob: 68677986e9dc8d5a8b0d48c7963a43b4ae850a99 [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 Spinlercc9adb72024-02-26 11:24:36 -060018#include <phosphor-logging/lg2.hpp>
Patrick Williams2544b412022-10-04 08:41:06 -050019
Matt Spinler2ea96f62022-02-23 16:31:01 -060020#include <algorithm>
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{
Matt Spinler4efed0e2024-02-26 11:16:07 -060055 bool shouldAdd = true;
Matt Spinlere0366f32020-03-13 13:02:19 -050056
Matt Spinler4efed0e2024-02-26 11:16:07 -060057 // Check if there is already a callout for this FRU
58 auto it = std::ranges::find_if(
59 _callouts, [&callout](const auto& c) { return *callout == *c; });
60
61 // If the callout already exists, but the new one has a higher
62 // priority, change the existing callout's priority to this
63 // new value and don't add the new one.
64 if (it != _callouts.end())
Matt Spinlere0366f32020-03-13 13:02:19 -050065 {
Matt Spinler4efed0e2024-02-26 11:16:07 -060066 if (*callout > **it)
67 {
68 (*it)->setPriority(callout->priority());
69 }
70 shouldAdd = false;
Matt Spinlere0366f32020-03-13 13:02:19 -050071 }
Miguel Gomez53ef1552020-10-14 21:16:32 +000072
Matt Spinler4efed0e2024-02-26 11:16:07 -060073 if (shouldAdd)
74 {
75 if (_callouts.size() < maxNumberOfCallouts)
76 {
77 _callouts.push_back(std::move(callout));
Miguel Gomez53ef1552020-10-14 21:16:32 +000078
Matt Spinler4efed0e2024-02-26 11:16:07 -060079 _subsectionWordLength += _callouts.back()->flattenedSize() / 4;
80 }
81 else
82 {
Matt Spinlercc9adb72024-02-26 11:24:36 -060083 lg2::info("Dropping PEL callout because at max");
Matt Spinler4efed0e2024-02-26 11:16:07 -060084 }
85 }
Miguel Gomez53ef1552020-10-14 21:16:32 +000086
Matt Spinler4efed0e2024-02-26 11:16:07 -060087 std::ranges::sort(_callouts,
88 [](const auto& c1, const auto& c2) { return *c1 > *c2; });
Matt Spinlere0366f32020-03-13 13:02:19 -050089}
Miguel Gomez53ef1552020-10-14 21:16:32 +000090
Matt Spinler32f13c92019-10-09 12:48:25 -050091} // namespace src
92} // namespace pels
Matt Spinler2ea96f62022-02-23 16:31:01 -060093} // namespace openpower