blob: 5e8127e9096440c5a932776a405900af09168e48 [file] [log] [blame]
Alexander Hansen40fb5492025-10-28 17:56:12 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3
Matt Spinler32f13c92019-10-09 12:48:25 -05004#include "callouts.hpp"
5
Matt Spinlercc9adb72024-02-26 11:24:36 -06006#include <phosphor-logging/lg2.hpp>
Patrick Williams2544b412022-10-04 08:41:06 -05007
Matt Spinler2ea96f62022-02-23 16:31:01 -06008#include <algorithm>
Matt Spinlere0366f32020-03-13 13:02:19 -05009
Matt Spinler32f13c92019-10-09 12:48:25 -050010namespace openpower
11{
12namespace pels
13{
14namespace src
15{
16
17Callouts::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 Spinler724d0d82019-11-06 10:05:36 -060031void Callouts::flatten(Stream& pel) const
Matt Spinler32f13c92019-10-09 12:48:25 -050032{
33 pel << _subsectionID << _subsectionFlags << _subsectionWordLength;
34
35 for (auto& callout : _callouts)
36 {
37 callout->flatten(pel);
38 }
39}
40
Matt Spinlere0366f32020-03-13 13:02:19 -050041void Callouts::addCallout(std::unique_ptr<Callout> callout)
42{
Matt Spinler4efed0e2024-02-26 11:16:07 -060043 bool shouldAdd = true;
Matt Spinlere0366f32020-03-13 13:02:19 -050044
Matt Spinler4efed0e2024-02-26 11:16:07 -060045 // Check if there is already a callout for this FRU
Patrick Williams075c7922024-08-16 15:19:49 -040046 auto it = std::ranges::find_if(_callouts, [&callout](const auto& c) {
47 return *callout == *c;
48 });
Matt Spinler4efed0e2024-02-26 11:16:07 -060049
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 Spinlere0366f32020-03-13 13:02:19 -050054 {
Matt Spinler4efed0e2024-02-26 11:16:07 -060055 if (*callout > **it)
56 {
57 (*it)->setPriority(callout->priority());
58 }
59 shouldAdd = false;
Matt Spinlere0366f32020-03-13 13:02:19 -050060 }
Miguel Gomez53ef1552020-10-14 21:16:32 +000061
Matt Spinler4efed0e2024-02-26 11:16:07 -060062 if (shouldAdd)
63 {
64 if (_callouts.size() < maxNumberOfCallouts)
65 {
66 _callouts.push_back(std::move(callout));
Miguel Gomez53ef1552020-10-14 21:16:32 +000067
Matt Spinler4efed0e2024-02-26 11:16:07 -060068 _subsectionWordLength += _callouts.back()->flattenedSize() / 4;
69 }
70 else
71 {
Matt Spinlercc9adb72024-02-26 11:24:36 -060072 lg2::info("Dropping PEL callout because at max");
Matt Spinler4efed0e2024-02-26 11:16:07 -060073 }
74 }
Miguel Gomez53ef1552020-10-14 21:16:32 +000075
Matt Spinler4efed0e2024-02-26 11:16:07 -060076 std::ranges::sort(_callouts,
77 [](const auto& c1, const auto& c2) { return *c1 > *c2; });
Matt Spinlere0366f32020-03-13 13:02:19 -050078}
Miguel Gomez53ef1552020-10-14 21:16:32 +000079
Matt Spinler32f13c92019-10-09 12:48:25 -050080} // namespace src
81} // namespace pels
Matt Spinler2ea96f62022-02-23 16:31:01 -060082} // namespace openpower