blob: ac5410e67eeb6052da3a9c0b86d98933ae80d885 [file] [log] [blame]
Zane Shelley15527a42021-12-16 21:43:13 -06001#include <analyzer/plugins/plugin.hpp>
Zane Shelley0b8368c2021-03-18 17:33:41 -05002#include <analyzer/resolution.hpp>
Zane Shelley236bb732021-03-24 17:07:46 -05003#include <util/pdbg.hpp>
4#include <util/trace.hpp>
Zane Shelley0b8368c2021-03-18 17:33:41 -05005
6namespace analyzer
7{
8
Zane Shelley2d114322021-08-25 17:06:12 -05009//------------------------------------------------------------------------------
10
Zane Shelley96d54862021-09-17 11:16:12 -050011// Helper function to get the root cause chip target from the service data.
12pdbg_target* __getRootCauseChipTarget(const ServiceData& i_sd)
Zane Shelley0b8368c2021-03-18 17:33:41 -050013{
Zane Shelley96d54862021-09-17 11:16:12 -050014 auto target = util::pdbg::getTrgt(i_sd.getRootCause().getChip());
15 assert(nullptr != target); // This would be a really bad bug.
16 return target;
17}
Zane Shelley236bb732021-03-24 17:07:46 -050018
Zane Shelley96d54862021-09-17 11:16:12 -050019//------------------------------------------------------------------------------
20
21// Helper function to get a unit target from the given unit path, which is a
22// devtree path relative the the containing chip. An empty string indicates the
23// chip target should be returned.
24pdbg_target* __getUnitTarget(pdbg_target* i_chipTarget,
25 const std::string& i_unitPath)
26{
27 assert(nullptr != i_chipTarget);
28
29 auto target = i_chipTarget; // default, if i_unitPath is empty
30
31 if (!i_unitPath.empty())
Zane Shelley236bb732021-03-24 17:07:46 -050032 {
Zane Shelley96d54862021-09-17 11:16:12 -050033 auto path = std::string{util::pdbg::getPath(target)} + "/" + i_unitPath;
34
35 target = util::pdbg::getTrgt(path);
36 if (nullptr == target)
Zane Shelley236bb732021-03-24 17:07:46 -050037 {
Zane Shelley96d54862021-09-17 11:16:12 -050038 // Likely a bug the RAS data files.
39 throw std::logic_error("Unable to find target for " + path);
Zane Shelley236bb732021-03-24 17:07:46 -050040 }
41 }
42
Zane Shelley96d54862021-09-17 11:16:12 -050043 return target;
44}
45
46//------------------------------------------------------------------------------
47
Zane Shelley9a738f72021-11-03 20:45:30 -050048void __calloutTarget(ServiceData& io_sd, pdbg_target* i_target,
49 const callout::Priority& i_priority, bool i_guard)
50{
51 nlohmann::json callout;
52 callout["LocationCode"] = util::pdbg::getLocationCode(i_target);
53 callout["Priority"] = i_priority.getUserDataString();
54 callout["Deconfigured"] = false;
Zane Shelleybf3326f2021-11-12 13:41:39 -060055 callout["Guarded"] = false; // default
56
57 // Check if guard info should be added.
58 if (i_guard)
59 {
60 auto guardType = io_sd.queryGuardPolicy();
61
62 if (!(callout::GuardType::NONE == guardType))
63 {
64 callout["Guarded"] = true;
65 callout["EntityPath"] = util::pdbg::getPhysBinPath(i_target);
66 callout["GuardType"] = guardType.getString();
67 }
68 }
69
Zane Shelley9a738f72021-11-03 20:45:30 -050070 io_sd.addCallout(callout);
71}
72
73//------------------------------------------------------------------------------
74
Zane Shelley1eff9452021-11-03 13:59:54 -050075void __calloutBackplane(ServiceData& io_sd, const callout::Priority& i_priority)
76{
77 // TODO: There isn't a device tree object for this. So will need to hardcode
78 // the location code for now. In the future, we will need a mechanism
79 // to make this data driven.
80
81 nlohmann::json callout;
82 callout["LocationCode"] = "P0";
83 callout["Priority"] = i_priority.getUserDataString();
84 callout["Deconfigured"] = false;
85 callout["Guarded"] = false;
86 io_sd.addCallout(callout);
87}
88
89//------------------------------------------------------------------------------
90
Zane Shelley96d54862021-09-17 11:16:12 -050091void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
92{
93 // Get the target for the hardware callout.
94 auto target = __getUnitTarget(__getRootCauseChipTarget(io_sd), iv_unitPath);
95
Zane Shelleyc85716c2021-08-17 10:54:06 -050096 // Add the actual callout to the service data.
Zane Shelley9a738f72021-11-03 20:45:30 -050097 __calloutTarget(io_sd, target, iv_priority, iv_guard);
Zane Shelley236bb732021-03-24 17:07:46 -050098
Zane Shelley2d114322021-08-25 17:06:12 -050099 // Add the callout FFDC to the service data.
100 nlohmann::json ffdc;
101 ffdc["Callout Type"] = "Hardware Callout";
Zane Shelleya00426f2021-11-04 10:50:50 -0500102 ffdc["Target"] = util::pdbg::getPhysDevPath(target);
Zane Shelley2d114322021-08-25 17:06:12 -0500103 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500104 ffdc["Guard"] = iv_guard;
Zane Shelley2d114322021-08-25 17:06:12 -0500105 io_sd.addCalloutFFDC(ffdc);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500106}
107
Zane Shelleyc85716c2021-08-17 10:54:06 -0500108//------------------------------------------------------------------------------
109
Zane Shelley5d63cef2021-09-17 18:10:17 -0500110void ConnectedCalloutResolution::resolve(ServiceData& io_sd) const
111{
112 // Get the chip target from the root cause signature.
113 auto chipTarget = __getRootCauseChipTarget(io_sd);
114
115 // Get the endpoint target for the receiving side of the bus.
116 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
117
118 // Get the endpoint target for the transfer side of the bus.
Zane Shelley38501e12022-01-10 15:42:28 -0600119 auto txTarget = util::pdbg::getConnectedTarget(rxTarget, iv_busType);
Zane Shelley5d63cef2021-09-17 18:10:17 -0500120
121 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500122 __calloutTarget(io_sd, txTarget, iv_priority, iv_guard);
Zane Shelley5d63cef2021-09-17 18:10:17 -0500123
Zane Shelley5d63cef2021-09-17 18:10:17 -0500124 // Add the callout FFDC to the service data.
125 nlohmann::json ffdc;
126 ffdc["Callout Type"] = "Connected Callout";
127 ffdc["Bus Type"] = iv_busType.getString();
128 ffdc["Target"] = util::pdbg::getPhysDevPath(txTarget);
129 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500130 ffdc["Guard"] = iv_guard;
Zane Shelley5d63cef2021-09-17 18:10:17 -0500131 io_sd.addCalloutFFDC(ffdc);
132}
133
134//------------------------------------------------------------------------------
135
Zane Shelley4757a7b2021-09-20 22:23:38 -0500136void BusCalloutResolution::resolve(ServiceData& io_sd) const
137{
138 // Get the chip target from the root cause signature.
139 auto chipTarget = __getRootCauseChipTarget(io_sd);
140
141 // Get the endpoint target for the receiving side of the bus.
142 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
143
144 // Get the endpoint target for the transfer side of the bus.
Zane Shelley38501e12022-01-10 15:42:28 -0600145 auto txTarget = util::pdbg::getConnectedTarget(rxTarget, iv_busType);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500146
147 // Callout the RX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500148 __calloutTarget(io_sd, rxTarget, iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500149
150 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500151 __calloutTarget(io_sd, txTarget, iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500152
153 // Callout everything else in between.
154 // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
Zane Shelley1eff9452021-11-03 13:59:54 -0500155 __calloutBackplane(io_sd, iv_priority);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500156
Zane Shelley4757a7b2021-09-20 22:23:38 -0500157 // Add the callout FFDC to the service data.
158 nlohmann::json ffdc;
159 ffdc["Callout Type"] = "Bus Callout";
160 ffdc["Bus Type"] = iv_busType.getString();
161 ffdc["RX Target"] = util::pdbg::getPhysDevPath(rxTarget);
162 ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
163 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500164 ffdc["Guard"] = iv_guard;
Zane Shelley4757a7b2021-09-20 22:23:38 -0500165 io_sd.addCalloutFFDC(ffdc);
166}
167
168//------------------------------------------------------------------------------
169
Zane Shelley84721d92021-09-08 13:30:27 -0500170void ClockCalloutResolution::resolve(ServiceData& io_sd) const
171{
Zane Shelley1eff9452021-11-03 13:59:54 -0500172 // Callout the clock target.
173 // TODO: For P10, the callout is simply the backplane. Also, there are no
174 // clock targets in the device tree. So at the moment there is no
175 // guard support for clock targets.
176 __calloutBackplane(io_sd, iv_priority);
Zane Shelley84721d92021-09-08 13:30:27 -0500177
178 // Add the callout FFDC to the service data.
Zane Shelley1eff9452021-11-03 13:59:54 -0500179 // TODO: Add the target and guard type if guard is ever supported.
Zane Shelley84721d92021-09-08 13:30:27 -0500180 nlohmann::json ffdc;
181 ffdc["Callout Type"] = "Clock Callout";
182 ffdc["Clock Type"] = iv_clockType.getString();
Zane Shelley84721d92021-09-08 13:30:27 -0500183 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelley84721d92021-09-08 13:30:27 -0500184 io_sd.addCalloutFFDC(ffdc);
185}
186
187//------------------------------------------------------------------------------
188
Zane Shelleyc85716c2021-08-17 10:54:06 -0500189void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
190{
191 // Add the actual callout to the service data.
192 nlohmann::json callout;
193 callout["Procedure"] = iv_procedure.getString();
194 callout["Priority"] = iv_priority.getUserDataString();
195 io_sd.addCallout(callout);
Zane Shelley2d114322021-08-25 17:06:12 -0500196
197 // Add the callout FFDC to the service data.
198 nlohmann::json ffdc;
199 ffdc["Callout Type"] = "Procedure Callout";
200 ffdc["Procedure"] = iv_procedure.getString();
201 ffdc["Priority"] = iv_priority.getRegistryString();
202 io_sd.addCalloutFFDC(ffdc);
Zane Shelleyc85716c2021-08-17 10:54:06 -0500203}
204
205//------------------------------------------------------------------------------
206
Zane Shelley15527a42021-12-16 21:43:13 -0600207void PluginResolution::resolve(ServiceData& io_sd) const
Zane Shelleye13a9f92021-12-16 21:19:11 -0600208{
Zane Shelley15527a42021-12-16 21:43:13 -0600209 // Get the plugin function and call it.
210
211 auto chip = io_sd.getRootCause().getChip();
212
213 auto func = PluginMap::getSingleton().get(chip.getType(), iv_name);
214
215 func(iv_instance, chip, io_sd);
Zane Shelleye13a9f92021-12-16 21:19:11 -0600216}
217
218//------------------------------------------------------------------------------
219
Zane Shelley0b8368c2021-03-18 17:33:41 -0500220} // namespace analyzer