blob: 341fe2b6d31acdc4c7bb5c75698cf71a2d6bdd7f [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 Tynerb1ebfcb2020-05-08 18:52:48 -05004#include <attn_logging.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06005#include <bp_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06006#include <ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06007
Ben Tynerb481d902020-03-05 10:24:23 -06008#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -06009#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050010#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060011#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060012#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060013
14namespace attn
15{
16
Ben Tynerb481d902020-03-05 10:24:23 -060017/** @brief Return codes */
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050018enum ReturnCodes
19{
20 RC_SUCCESS = 0,
21 RC_NOT_HANDLED,
22 RC_ANALYZER_ERROR,
23 RC_CFAM_ERROR
24};
Ben Tynerb481d902020-03-05 10:24:23 -060025
Ben Tyneref320152020-01-09 10:31:23 -060026/**
27 * @brief Handle SBE vital attention
28 *
Ben Tynerb481d902020-03-05 10:24:23 -060029 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050030 * @return 0 indicates that the vital attention was successfully handled
31 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060032 */
Ben Tynerb481d902020-03-05 10:24:23 -060033int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060034
35/**
36 * @brief Handle checkstop attention
37 *
Ben Tynerb481d902020-03-05 10:24:23 -060038 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050039 * @return 0 indicates that the checkstop attention was successfully handled
40 * 1 indicates that the checkstop attention was NOT successfully
41 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060042 */
Ben Tynerb481d902020-03-05 10:24:23 -060043int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060044
45/**
46 * @brief Handle special attention
47 *
Ben Tynerb481d902020-03-05 10:24:23 -060048 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050049 * @return 0 indicates that the special attention was successfully handled
50 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060051 */
Ben Tynerb481d902020-03-05 10:24:23 -060052int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060053
54/**
Ben Tyneref320152020-01-09 10:31:23 -060055 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060056 *
57 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060058 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050059void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060060{
Ben Tynerb481d902020-03-05 10:24:23 -060061 // Vector of active attentions to be handled
62 std::vector<Attention> active_attentions;
63
Ben Tyneref320152020-01-09 10:31:23 -060064 uint32_t isr_val, isr_mask;
65 uint32_t proc;
66
67 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050068 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050069
Ben Tyneref320152020-01-09 10:31:23 -060070 pdbg_target* target;
71 pdbg_for_each_class_target("fsi", target)
72 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050073 trace<level::INFO>("iterating targets");
Ben Tyneref320152020-01-09 10:31:23 -060074 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
75 {
76 proc = pdbg_target_index(target); // get processor number
77
78 std::stringstream ss; // log message stream
Ben Tyner9dbab8b2020-03-31 08:55:23 -050079 ss << "checking processor " << proc;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050080 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060081
82 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060083 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060084 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050085 // event
86 eventAttentionFail(RC_CFAM_ERROR);
87
88 // trace
89 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060090 }
91 else
92 {
93 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060094 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060095 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050096 ss << isr_val;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050097 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060098
99 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -0600100 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600101 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500102 // event
103 eventAttentionFail(RC_CFAM_ERROR);
104
105 // trace
106 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -0600107 }
108 else
109 {
110 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600111 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -0600112 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500113 ss << isr_mask;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500114 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -0600115
116 // bit 0 on "left": bit 30 = SBE vital attention
117 if (isr_val & isr_mask & 0x00000002)
118 {
Ben Tyner3fb52e52020-03-31 10:10:07 -0500119 active_attentions.emplace_back(
120 Attention::Vital, handleVital, target, i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600121 }
122
123 // bit 0 on "left": bit 1 = checkstop
124 if (isr_val & isr_mask & 0x40000000)
125 {
Ben Tynerb481d902020-03-05 10:24:23 -0600126 active_attentions.emplace_back(Attention::Checkstop,
127 handleCheckstop, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500128 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600129 }
130
131 // bit 0 on "left": bit 2 = special attention
132 if (isr_val & isr_mask & 0x20000000)
133 {
Ben Tynerb481d902020-03-05 10:24:23 -0600134 active_attentions.emplace_back(Attention::Special,
135 handleSpecial, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500136 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600137 }
138 } // cfam 0x100d valid
139 } // cfam 0x1007 valid
140 } // fsi target enabled
141 } // next processor
142
Ben Tynerb481d902020-03-05 10:24:23 -0600143 // convert to heap, highest priority is at front
144 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
145 {
146 std::make_heap(active_attentions.begin(), active_attentions.end());
147 }
148
149 // call the attention handler until one is handled or all were attempted
150 while (false == active_attentions.empty())
151 {
152 // handle highest priority attention, done if successful
153 if (RC_SUCCESS == active_attentions.front().handle())
154 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500155 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600156 break;
157 }
158
159 // move attention to back of vector
160 std::pop_heap(active_attentions.begin(), active_attentions.end());
161
162 // remove attention from vector
163 active_attentions.pop_back();
164 }
Ben Tyneref320152020-01-09 10:31:23 -0600165}
166
167/**
168 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500169 *
170 * @param i_attention Attention object
171 * @return 0 indicates that the vital attention was successfully handled
172 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600173 */
Ben Tynerb481d902020-03-05 10:24:23 -0600174int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600175{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500176 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600177
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500178 trace<level::INFO>("vital handler started");
179
Ben Tyner3fb52e52020-03-31 10:10:07 -0500180 // if vital handling enabled, handle vital attention
181 if (false == (i_attention->getConfig()->getFlag(enVital)))
182 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500183 trace<level::INFO>("vital handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500184 }
185 else
Ben Tyneref320152020-01-09 10:31:23 -0600186 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500187 // TODO need vital attention handling
188
189 // FIXME TEMP CODE - begin
190 if (0)
191 {
192 eventVital();
193 }
194 else
195 {
196 trace<level::INFO>("vital NOT handled"); // enabled but not handled
197 rc = RC_NOT_HANDLED;
198 }
199 // FIXME TEMP CODE -end
Ben Tyneref320152020-01-09 10:31:23 -0600200 }
201
202 return rc;
203}
204
205/**
206 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500207 *
208 * @param i_attention Attention object
209 * @return 0 indicates that the checkstop attention was successfully handled
210 * 1 indicates that the checkstop attention was NOT successfully
211 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600212 */
Ben Tynerb481d902020-03-05 10:24:23 -0600213int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600214{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500215 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600216
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500217 trace<level::INFO>("checkstop handler started");
218
Ben Tyner3fb52e52020-03-31 10:10:07 -0500219 // if checkstop handling enabled, handle checkstop attention
220 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
221 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500222 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500223 }
224 else
225 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500226 // errors that were isolated
227 std::map<std::string, std::string> errors;
228
229 rc = analyzer::analyzeHardware(errors); // analyze hardware
230
231 if (RC_SUCCESS != rc)
232 {
233 rc = RC_ANALYZER_ERROR;
234 }
235 else
236 {
237 std::stringstream ss;
238 ss << "Analyzer isolated " << errors.size() << " error(s)";
239 trace<level::INFO>(ss.str().c_str());
240
241 // add checkstop event to log
242 eventCheckstop(errors);
243 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500244 }
Ben Tyneref320152020-01-09 10:31:23 -0600245
Ben Tyneref320152020-01-09 10:31:23 -0600246 return rc;
247}
248
249/**
250 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500251 *
252 * @param i_attention Attention object
253 * @return 0 indicates that the special attention was successfully handled
254 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600255 */
Ben Tynerb481d902020-03-05 10:24:23 -0600256int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600257{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500258 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600259
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500260 trace<level::INFO>("special attention handler started");
261
262 // TODO
Ben Tyner3fb52e52020-03-31 10:10:07 -0500263 // Until the special attention chipop is availabe we will treat the special
264 // attention as a TI. If TI handling is disabled we will treat the special
265 // attention as a breakpopint.
Ben Tyneref320152020-01-09 10:31:23 -0600266
Ben Tyner3fb52e52020-03-31 10:10:07 -0500267 // TI attention gets priority over breakpoints, if enabled then handle
268 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600269 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500270 trace<level::INFO>("TI (terminate immediately)");
Ben Tyner7e6611f2020-02-13 16:42:56 -0600271
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600272 // Call TI special attention handler
273 tiHandler();
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500274
275 // generate log event
276 eventTerminate();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500277 }
278 else
279 {
280 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
281 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500282 trace<level::INFO>("breakpoint");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500283
284 // Call the breakpoint special attention handler
285 bpHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500286 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600287 }
Ben Tyneref320152020-01-09 10:31:23 -0600288
Ben Tyner3fb52e52020-03-31 10:10:07 -0500289 if (RC_SUCCESS != rc)
290 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500291 trace<level::INFO>("Special attn handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500292 }
Ben Tyneref320152020-01-09 10:31:23 -0600293
294 return rc;
295}
296
Ben Tyneref320152020-01-09 10:31:23 -0600297} // namespace attn