blob: 42bc99ee8334c602d04f34ea0787e0da17daf519 [file] [log] [blame]
Ben Tyner792f32f2020-06-02 08:50:47 -05001#include <libpdbg.h>
2
Ben Tyner0205f3b2020-02-24 10:24:47 -06003#include <analyzer/analyzer_main.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05004#include <attn/attention.hpp>
5#include <attn/attn_config.hpp>
6#include <attn/attn_handler.hpp>
7#include <attn/attn_logging.hpp>
8#include <attn/bp_handler.hpp>
9#include <attn/ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -060010
Ben Tynerb481d902020-03-05 10:24:23 -060011#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -060012#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050013#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060014#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060015#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060016
17namespace attn
18{
19
20/**
21 * @brief Handle SBE vital attention
22 *
Ben Tynerb481d902020-03-05 10:24:23 -060023 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050024 * @return 0 indicates that the vital attention was successfully handled
25 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060026 */
Ben Tynerb481d902020-03-05 10:24:23 -060027int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060028
29/**
30 * @brief Handle checkstop attention
31 *
Ben Tynerb481d902020-03-05 10:24:23 -060032 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050033 * @return 0 indicates that the checkstop attention was successfully handled
34 * 1 indicates that the checkstop attention was NOT successfully
35 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060036 */
Ben Tynerb481d902020-03-05 10:24:23 -060037int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060038
39/**
40 * @brief Handle special attention
41 *
Ben Tynerb481d902020-03-05 10:24:23 -060042 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050043 * @return 0 indicates that the special attention was successfully handled
44 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060045 */
Ben Tynerb481d902020-03-05 10:24:23 -060046int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060047
Ben Tynerfb190542020-11-06 09:27:56 -060048/** @brief Determine if attention is active and not masked */
Ben Tyner1965e502020-11-20 10:32:24 -060049bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn);
Ben Tynerfb190542020-11-06 09:27:56 -060050
Ben Tyneref320152020-01-09 10:31:23 -060051/**
Ben Tyneref320152020-01-09 10:31:23 -060052 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060053 *
54 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060055 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050056void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060057{
Ben Tynerb481d902020-03-05 10:24:23 -060058 // Vector of active attentions to be handled
59 std::vector<Attention> active_attentions;
60
Ben Tyneref320152020-01-09 10:31:23 -060061 uint32_t isr_val, isr_mask;
62 uint32_t proc;
63
Ben Tyner1965e502020-11-20 10:32:24 -060064 std::stringstream ss; // for trace messages
65
Ben Tyneref320152020-01-09 10:31:23 -060066 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050067 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050068
Ben Tyneref320152020-01-09 10:31:23 -060069 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050070 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060071 {
72 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
73 {
74 proc = pdbg_target_index(target); // get processor number
75
Ben Tyner5e622d82020-09-11 10:10:24 -050076 // The processor FSI target is required for CFAM read
77 char path[16];
Ben Tynerfb190542020-11-06 09:27:56 -060078 sprintf(path, "/proc%d/fsi", proc);
Ben Tyner5e622d82020-09-11 10:10:24 -050079 pdbg_target* attnTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050080
Ben Tyner5e622d82020-09-11 10:10:24 -050081 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnTarget))
Ben Tyneref320152020-01-09 10:31:23 -060082 {
Ben Tyner1965e502020-11-20 10:32:24 -060083 // trace fsi path
84 ss.str(std::string()); // clear stream
85 ss << "target - " << path;
86 trace<level::INFO>(ss.str().c_str());
87
Ben Tyner5e622d82020-09-11 10:10:24 -050088 // get active attentions on processor
89 if (RC_SUCCESS != fsi_read(attnTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060090 {
Ben Tynerfb190542020-11-06 09:27:56 -060091 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -050092 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -060093 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -060094 }
95 else
96 {
Ben Tyner1965e502020-11-20 10:32:24 -060097 // trace isr
98 ss.str(std::string()); // clear stream
99 ss << std::hex << std::showbase; // trace as hex vals
100 ss << "cfam 0x1007 = " << std::setw(8) << std::setfill('0')
101 << isr_val;
102 trace<level::INFO>(ss.str().c_str());
103
Ben Tyner5e622d82020-09-11 10:10:24 -0500104 // get interrupt enabled special attentions mask
105 if (RC_SUCCESS != fsi_read(attnTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600106 {
Ben Tynerfb190542020-11-06 09:27:56 -0600107 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -0500108 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -0600109 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600110 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500111 else
112 {
Ben Tyner1965e502020-11-20 10:32:24 -0600113 // trace true-mask
114 ss.str(std::string()); // clear stream
115 ss << std::hex << std::showbase; // trace as hex vals
116 ss << "cfam 0x100d = " << std::setw(8)
117 << std::setfill('0') << isr_mask;
118 trace<level::INFO>(ss.str().c_str());
119
Ben Tynerfb190542020-11-06 09:27:56 -0600120 // SBE vital attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600121 if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500122 {
123 active_attentions.emplace_back(Attention::Vital,
124 handleVital, target,
125 i_config);
126 }
127
Ben Tynerfb190542020-11-06 09:27:56 -0600128 // Checkstop attention active and not masked?
129 if (true ==
Ben Tyner1965e502020-11-20 10:32:24 -0600130 activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500131 {
132 active_attentions.emplace_back(Attention::Checkstop,
133 handleCheckstop,
134 target, i_config);
135 }
136
Ben Tynerfb190542020-11-06 09:27:56 -0600137 // Special attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600138 if (true == activeAttn(isr_val, isr_mask, SPECIAL_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500139 {
140 active_attentions.emplace_back(Attention::Special,
141 handleSpecial,
142 target, i_config);
143 }
144 } // cfam 0x100d valid
145 } // cfam 0x1007 valid
146 } // proc target enabled
147 } // fsi target enabled
148 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600149
Ben Tynerb481d902020-03-05 10:24:23 -0600150 // convert to heap, highest priority is at front
151 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
152 {
153 std::make_heap(active_attentions.begin(), active_attentions.end());
154 }
155
156 // call the attention handler until one is handled or all were attempted
157 while (false == active_attentions.empty())
158 {
159 // handle highest priority attention, done if successful
160 if (RC_SUCCESS == active_attentions.front().handle())
161 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500162 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600163 break;
164 }
165
166 // move attention to back of vector
167 std::pop_heap(active_attentions.begin(), active_attentions.end());
168
169 // remove attention from vector
170 active_attentions.pop_back();
171 }
Ben Tyneref320152020-01-09 10:31:23 -0600172}
173
174/**
175 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500176 *
177 * @param i_attention Attention object
178 * @return 0 indicates that the vital attention was successfully handled
179 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600180 */
Ben Tynerb481d902020-03-05 10:24:23 -0600181int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600182{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500183 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600184
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500185 trace<level::INFO>("vital handler started");
186
Ben Tyner3fb52e52020-03-31 10:10:07 -0500187 // if vital handling enabled, handle vital attention
188 if (false == (i_attention->getConfig()->getFlag(enVital)))
189 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500190 trace<level::INFO>("vital handling disabled");
Ben Tyner792f32f2020-06-02 08:50:47 -0500191 rc = RC_NOT_HANDLED;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500192 }
193 else
Ben Tyneref320152020-01-09 10:31:23 -0600194 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500195 eventVital();
Ben Tyneref320152020-01-09 10:31:23 -0600196 }
197
198 return rc;
199}
200
201/**
202 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500203 *
204 * @param i_attention Attention object
205 * @return 0 indicates that the checkstop attention was successfully handled
206 * 1 indicates that the checkstop attention was NOT successfully
207 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600208 */
Ben Tynerb481d902020-03-05 10:24:23 -0600209int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600210{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500211 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600212
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500213 trace<level::INFO>("checkstop handler started");
214
Ben Tyner3fb52e52020-03-31 10:10:07 -0500215 // if checkstop handling enabled, handle checkstop attention
216 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
217 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500218 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500219 }
220 else
221 {
Zane Shelley9fb73932020-09-15 13:34:57 -0500222 // Look for any attentions found in hardware. This will generate and
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600223 // commit a PEL if any errors are found.
Zane Shelley9fb73932020-09-15 13:34:57 -0500224 if (true != analyzer::analyzeHardware())
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500225 {
226 rc = RC_ANALYZER_ERROR;
227 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500228 }
Ben Tyneref320152020-01-09 10:31:23 -0600229
Ben Tyneref320152020-01-09 10:31:23 -0600230 return rc;
231}
232
233/**
234 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500235 *
236 * @param i_attention Attention object
237 * @return 0 indicates that the special attention was successfully handled
238 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600239 */
Ben Tynerb481d902020-03-05 10:24:23 -0600240int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600241{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500242 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600243
Ben Tynerfb190542020-11-06 09:27:56 -0600244 // The TI info chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500245 uint8_t* tiInfo = nullptr; // ptr to TI info data
246 uint32_t tiInfoLen = 0; // length of TI info data
247 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500248
Ben Tyner98430b32020-08-19 19:14:02 -0500249 if (attnProc != nullptr)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500250 {
Ben Tyner98430b32020-08-19 19:14:02 -0500251 // The processor PIB target is required for get TI info chipop
252 char path[16];
253 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
254 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
255
256 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500257 {
Ben Tyner98430b32020-08-19 19:14:02 -0500258 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
259 {
Ben Tyner98430b32020-08-19 19:14:02 -0500260 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
261 if (tiInfo == nullptr)
262 {
263 trace<level::INFO>("TI info data ptr is null after call");
264 }
265 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500266 }
267 }
Ben Tyneref320152020-01-09 10:31:23 -0600268
Ben Tyner792f32f2020-06-02 08:50:47 -0500269 // If TI area exists and is marked valid we can assume TI occurred
270 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600271 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500272 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
Ben Tyner7e6611f2020-02-13 16:42:56 -0600273
Ben Tyner792f32f2020-06-02 08:50:47 -0500274 // trace a few known TI data area values
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500275 std::stringstream ss;
276 ss << std::hex << std::showbase;
Ben Tyner40717722020-09-23 09:43:20 -0500277
278 ss << "TI data command = " << (int)tiDataArea->command;
Ben Tyner792f32f2020-06-02 08:50:47 -0500279 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500280 ss.str(std::string());
281
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500282 ss << "TI data hb_terminate_type = "
283 << (int)tiDataArea->hbTerminateType;
284 trace<level::INFO>(ss.str().c_str());
285 ss.str(std::string());
286
Ben Tyner40717722020-09-23 09:43:20 -0500287 ss << "TI data SRC format = " << (int)tiDataArea->srcFormat;
Ben Tyner792f32f2020-06-02 08:50:47 -0500288 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500289 ss.str(std::string());
290
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500291 ss << "TI data source = " << (int)tiDataArea->source;
Ben Tyner792f32f2020-06-02 08:50:47 -0500292 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500293 ss.str(std::string());
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500294
Ben Tyner792f32f2020-06-02 08:50:47 -0500295 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
296 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500297 // Call TI special attention handler
298 rc = tiHandler(tiDataArea);
299 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500300 }
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500301 // TI area not valid or not available
Ben Tyner3fb52e52020-03-31 10:10:07 -0500302 else
303 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500304 trace<level::INFO>("TI info NOT available");
Ben Tyner98430b32020-08-19 19:14:02 -0500305
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500306 // if configured to handle breakpoint as default special attention
307 if (i_attention->getConfig()->getFlag(dfltBreakpoint))
Ben Tyner3fb52e52020-03-31 10:10:07 -0500308 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500309 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
310 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500311 // Call the breakpoint special attention handler
312 bpHandler();
313 }
314 }
315 // if configured to handle TI as default special attention
316 else
317 {
318 trace<level::INFO>("assuming TI");
319
320 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
321 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500322 // Call TI special attention handler
323 rc = tiHandler(nullptr);
324 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500325 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600326 }
Ben Tyneref320152020-01-09 10:31:23 -0600327
Ben Tyner792f32f2020-06-02 08:50:47 -0500328 // release TI data buffer
329 if (nullptr != tiInfo)
330 {
331 free(tiInfo);
332 }
333
Ben Tyner3fb52e52020-03-31 10:10:07 -0500334 if (RC_SUCCESS != rc)
335 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500336 trace<level::INFO>("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500337 }
Ben Tyneref320152020-01-09 10:31:23 -0600338
339 return rc;
340}
341
Ben Tynerfb190542020-11-06 09:27:56 -0600342/**
343 * @brief Determine if attention is active and not masked
344 *
345 * Determine whether an attention needs to be handled and trace details of
346 * attention type and whether it is masked or not.
347 *
348 * @param i_val attention status register
349 * @param i_mask attention true mask register
350 * @param i_attn attention type
351 * @param i_proc processor associated with registers
352 *
353 * @return true if attention is active and not masked, otherwise false
354 */
Ben Tyner1965e502020-11-20 10:32:24 -0600355bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn)
Ben Tynerfb190542020-11-06 09:27:56 -0600356{
357 bool rc = false; // assume attn masked and/or inactive
358 bool validAttn = true; // known attention type
359
360 // if attention active
361 if (0 != (i_val & i_attn))
362 {
Ben Tynerfb190542020-11-06 09:27:56 -0600363 std::stringstream ss;
Ben Tynerfb190542020-11-06 09:27:56 -0600364
365 switch (i_attn)
366 {
367 case SBE_ATTN:
368 ss << "SBE attn";
369 break;
370 case CHECKSTOP_ATTN:
371 ss << "Checkstop attn";
372 break;
373 case SPECIAL_ATTN:
374 ss << "Special attn";
375 break;
376 default:
377 ss << "Unknown attn";
378 validAttn = false;
379 }
380
381 // see if attention is masked
382 if (true == validAttn)
383 {
384 if (0 != (i_mask & i_attn))
385 {
386 rc = true; // attention active and not masked
387 }
388 else
389 {
390 ss << " masked";
391 }
392 }
393
394 trace<level::INFO>(ss.str().c_str()); // commit trace stream
395 }
396
397 return rc;
398}
399
Ben Tyneref320152020-01-09 10:31:23 -0600400} // namespace attn