1 #include <analyzer/plugins/plugin.hpp>
2 #include <analyzer/resolution.hpp>
3 #include <util/pdbg.hpp>
4 #include <util/trace.hpp>
5
6 namespace analyzer
7 {
8
9 //------------------------------------------------------------------------------
10
11 // Helper function to get the root cause chip target from the service data.
__getRootCauseChipTarget(const ServiceData & i_sd)12 pdbg_target* __getRootCauseChipTarget(const ServiceData& i_sd)
13 {
14 auto target = util::pdbg::getTrgt(i_sd.getRootCause().getChip());
15 assert(nullptr != target); // This would be a really bad bug.
16 return target;
17 }
18
19 //------------------------------------------------------------------------------
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.
__getUnitTarget(pdbg_target * i_chipTarget,const std::string & i_unitPath)24 pdbg_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())
32 {
33 auto path = std::string{util::pdbg::getPath(target)} + "/" + i_unitPath;
34
35 target = util::pdbg::getTrgt(path);
36 if (nullptr == target)
37 {
38 // Likely a bug the RAS data files.
39 throw std::logic_error("Unable to find target for " + path);
40 }
41 }
42
43 return target;
44 }
45
46 //------------------------------------------------------------------------------
47
resolve(ServiceData & io_sd) const48 void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
49 {
50 // Get the target for the hardware callout.
51 auto target = __getUnitTarget(__getRootCauseChipTarget(io_sd), iv_unitPath);
52
53 // Add the callout and the FFDC to the service data.
54 io_sd.calloutTarget(target, iv_priority, iv_guard);
55 }
56
57 //------------------------------------------------------------------------------
58
resolve(ServiceData & io_sd) const59 void ConnectedCalloutResolution::resolve(ServiceData& io_sd) const
60 {
61 // Get the chip target from the root cause signature.
62 auto chipTarget = __getRootCauseChipTarget(io_sd);
63
64 // Get the endpoint target for the receiving side of the bus.
65 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
66
67 // Add the callout and the FFDC to the service data.
68 io_sd.calloutConnected(rxTarget, iv_busType, iv_priority, iv_guard);
69 }
70
71 //------------------------------------------------------------------------------
72
resolve(ServiceData & io_sd) const73 void BusCalloutResolution::resolve(ServiceData& io_sd) const
74 {
75 // Get the chip target from the root cause signature.
76 auto chipTarget = __getRootCauseChipTarget(io_sd);
77
78 // Get the endpoint target for the receiving side of the bus.
79 auto rxTarget = __getUnitTarget(chipTarget, iv_unitPath);
80
81 // Add the callout and the FFDC to the service data.
82 io_sd.calloutBus(rxTarget, iv_busType, iv_priority, iv_guard);
83 }
84
85 //------------------------------------------------------------------------------
86
resolve(ServiceData & io_sd) const87 void ClockCalloutResolution::resolve(ServiceData& io_sd) const
88 {
89 // Add the callout and the FFDC to the service data.
90 io_sd.calloutClock(iv_clockType, iv_priority, iv_guard);
91 }
92
93 //------------------------------------------------------------------------------
94
resolve(ServiceData & io_sd) const95 void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
96 {
97 // Add the callout and the FFDC to the service data.
98 io_sd.calloutProcedure(iv_procedure, iv_priority);
99 }
100
101 //------------------------------------------------------------------------------
102
resolve(ServiceData & io_sd) const103 void PartCalloutResolution::resolve(ServiceData& io_sd) const
104 {
105 // Add the callout and the FFDC to the service data.
106 io_sd.calloutPart(iv_part, iv_priority);
107 }
108
109 //------------------------------------------------------------------------------
110
resolve(ServiceData & io_sd) const111 void PluginResolution::resolve(ServiceData& io_sd) const
112 {
113 // Get the plugin function and call it.
114
115 auto chip = io_sd.getRootCause().getChip();
116
117 auto func = PluginMap::getSingleton().get(chip.getType(), iv_name);
118
119 func(iv_instance, chip, io_sd);
120 }
121
122 //------------------------------------------------------------------------------
123
124 } // namespace analyzer
125