blob: 945156d51a49923dd2b36a24a3fd1d3de34dd27d [file] [log] [blame]
Ben Tyner0205f3b2020-02-24 10:24:47 -06001#include <analyzer/analyzer_main.hpp>
Ben Tynerb481d902020-03-05 10:24:23 -06002#include <attention.hpp>
Ben Tyner3fb52e52020-03-31 10:10:07 -05003#include <attn_config.hpp>
Ben Tynerdbeaf792020-05-14 08:27:18 -05004#include <attn_handler.hpp>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05005#include <attn_logging.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06006#include <bp_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06007#include <ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06008
Ben Tynerb481d902020-03-05 10:24:23 -06009#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -060010#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050011#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060012#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060013#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060014
15namespace attn
16{
17
18/**
19 * @brief Handle SBE vital attention
20 *
Ben Tynerb481d902020-03-05 10:24:23 -060021 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050022 * @return 0 indicates that the vital attention was successfully handled
23 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060024 */
Ben Tynerb481d902020-03-05 10:24:23 -060025int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060026
27/**
28 * @brief Handle checkstop attention
29 *
Ben Tynerb481d902020-03-05 10:24:23 -060030 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050031 * @return 0 indicates that the checkstop attention was successfully handled
32 * 1 indicates that the checkstop attention was NOT successfully
33 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060034 */
Ben Tynerb481d902020-03-05 10:24:23 -060035int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060036
37/**
38 * @brief Handle special attention
39 *
Ben Tynerb481d902020-03-05 10:24:23 -060040 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050041 * @return 0 indicates that the special attention was successfully handled
42 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060043 */
Ben Tynerb481d902020-03-05 10:24:23 -060044int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060045
46/**
Ben Tyneref320152020-01-09 10:31:23 -060047 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060048 *
49 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060050 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050051void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060052{
Ben Tynerb481d902020-03-05 10:24:23 -060053 // Vector of active attentions to be handled
54 std::vector<Attention> active_attentions;
55
Ben Tyneref320152020-01-09 10:31:23 -060056 uint32_t isr_val, isr_mask;
57 uint32_t proc;
58
59 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050060 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050061
Ben Tyneref320152020-01-09 10:31:23 -060062 pdbg_target* target;
63 pdbg_for_each_class_target("fsi", target)
64 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050065 trace<level::INFO>("iterating targets");
Ben Tyneref320152020-01-09 10:31:23 -060066 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
67 {
68 proc = pdbg_target_index(target); // get processor number
69
70 std::stringstream ss; // log message stream
Ben Tyner9dbab8b2020-03-31 08:55:23 -050071 ss << "checking processor " << proc;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050072 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060073
74 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060075 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060076 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050077 // event
78 eventAttentionFail(RC_CFAM_ERROR);
79
80 // trace
81 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060082 }
83 else
84 {
85 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060086 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060087 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050088 ss << isr_val;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050089 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060090
91 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060092 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060093 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050094 // event
95 eventAttentionFail(RC_CFAM_ERROR);
96
97 // trace
98 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060099 }
100 else
101 {
102 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600103 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -0600104 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500105 ss << isr_mask;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500106 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -0600107
108 // bit 0 on "left": bit 30 = SBE vital attention
109 if (isr_val & isr_mask & 0x00000002)
110 {
Ben Tyner3fb52e52020-03-31 10:10:07 -0500111 active_attentions.emplace_back(
112 Attention::Vital, handleVital, target, i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600113 }
114
115 // bit 0 on "left": bit 1 = checkstop
116 if (isr_val & isr_mask & 0x40000000)
117 {
Ben Tynerb481d902020-03-05 10:24:23 -0600118 active_attentions.emplace_back(Attention::Checkstop,
119 handleCheckstop, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500120 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600121 }
122
123 // bit 0 on "left": bit 2 = special attention
124 if (isr_val & isr_mask & 0x20000000)
125 {
Ben Tynerb481d902020-03-05 10:24:23 -0600126 active_attentions.emplace_back(Attention::Special,
127 handleSpecial, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500128 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600129 }
130 } // cfam 0x100d valid
131 } // cfam 0x1007 valid
132 } // fsi target enabled
133 } // next processor
134
Ben Tynerb481d902020-03-05 10:24:23 -0600135 // convert to heap, highest priority is at front
136 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
137 {
138 std::make_heap(active_attentions.begin(), active_attentions.end());
139 }
140
141 // call the attention handler until one is handled or all were attempted
142 while (false == active_attentions.empty())
143 {
144 // handle highest priority attention, done if successful
145 if (RC_SUCCESS == active_attentions.front().handle())
146 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500147 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600148 break;
149 }
150
151 // move attention to back of vector
152 std::pop_heap(active_attentions.begin(), active_attentions.end());
153
154 // remove attention from vector
155 active_attentions.pop_back();
156 }
Ben Tyneref320152020-01-09 10:31:23 -0600157}
158
159/**
160 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500161 *
162 * @param i_attention Attention object
163 * @return 0 indicates that the vital attention was successfully handled
164 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600165 */
Ben Tynerb481d902020-03-05 10:24:23 -0600166int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600167{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500168 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600169
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500170 trace<level::INFO>("vital handler started");
171
Ben Tyner3fb52e52020-03-31 10:10:07 -0500172 // if vital handling enabled, handle vital attention
173 if (false == (i_attention->getConfig()->getFlag(enVital)))
174 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500175 trace<level::INFO>("vital handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500176 }
177 else
Ben Tyneref320152020-01-09 10:31:23 -0600178 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500179 // TODO need vital attention handling
180
181 // FIXME TEMP CODE - begin
182 if (0)
183 {
184 eventVital();
185 }
186 else
187 {
188 trace<level::INFO>("vital NOT handled"); // enabled but not handled
189 rc = RC_NOT_HANDLED;
190 }
191 // FIXME TEMP CODE -end
Ben Tyneref320152020-01-09 10:31:23 -0600192 }
193
194 return rc;
195}
196
197/**
198 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500199 *
200 * @param i_attention Attention object
201 * @return 0 indicates that the checkstop attention was successfully handled
202 * 1 indicates that the checkstop attention was NOT successfully
203 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600204 */
Ben Tynerb481d902020-03-05 10:24:23 -0600205int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600206{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500207 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600208
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500209 trace<level::INFO>("checkstop handler started");
210
Ben Tyner3fb52e52020-03-31 10:10:07 -0500211 // if checkstop handling enabled, handle checkstop attention
212 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
213 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500214 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500215 }
216 else
217 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500218 // errors that were isolated
219 std::map<std::string, std::string> errors;
220
Ben Tynerdbeaf792020-05-14 08:27:18 -0500221 // analyze errors
222 if (true != analyzer::analyzeHardware(errors))
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500223 {
224 rc = RC_ANALYZER_ERROR;
225 }
226 else
227 {
228 std::stringstream ss;
229 ss << "Analyzer isolated " << errors.size() << " error(s)";
230 trace<level::INFO>(ss.str().c_str());
231
232 // add checkstop event to log
233 eventCheckstop(errors);
234 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500235 }
Ben Tyneref320152020-01-09 10:31:23 -0600236
Ben Tyneref320152020-01-09 10:31:23 -0600237 return rc;
238}
239
240/**
241 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500242 *
243 * @param i_attention Attention object
244 * @return 0 indicates that the special attention was successfully handled
245 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600246 */
Ben Tynerb481d902020-03-05 10:24:23 -0600247int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600248{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500249 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600250
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500251 trace<level::INFO>("special attention handler started");
252
253 // TODO
Ben Tyner3fb52e52020-03-31 10:10:07 -0500254 // Until the special attention chipop is availabe we will treat the special
255 // attention as a TI. If TI handling is disabled we will treat the special
256 // attention as a breakpopint.
Ben Tyneref320152020-01-09 10:31:23 -0600257
Ben Tyner3fb52e52020-03-31 10:10:07 -0500258 // TI attention gets priority over breakpoints, if enabled then handle
259 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600260 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500261 trace<level::INFO>("TI (terminate immediately)");
Ben Tyner7e6611f2020-02-13 16:42:56 -0600262
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600263 // Call TI special attention handler
264 tiHandler();
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500265
266 // generate log event
267 eventTerminate();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500268 }
269 else
270 {
271 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
272 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500273 trace<level::INFO>("breakpoint");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500274
275 // Call the breakpoint special attention handler
276 bpHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500277 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600278 }
Ben Tyneref320152020-01-09 10:31:23 -0600279
Ben Tyner3fb52e52020-03-31 10:10:07 -0500280 if (RC_SUCCESS != rc)
281 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500282 trace<level::INFO>("Special attn handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500283 }
Ben Tyneref320152020-01-09 10:31:23 -0600284
285 return rc;
286}
287
Ben Tyneref320152020-01-09 10:31:23 -0600288} // namespace attn