blob: a4abf7477fbd02d09d698377341fbf2704172700 [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>
Ben Tynerbcf65a82020-12-01 08:46:36 -06005#include <attn/attn_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05006#include <attn/attn_config.hpp>
7#include <attn/attn_handler.hpp>
8#include <attn/attn_logging.hpp>
9#include <attn/bp_handler.hpp>
10#include <attn/ti_handler.hpp>
Ben Tynerbcf65a82020-12-01 08:46:36 -060011#include <attn/vital_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -060012
Ben Tynerb481d902020-03-05 10:24:23 -060013#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -060014#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050015#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060016#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060017#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060018
19namespace attn
20{
21
22/**
Ben Tyneref320152020-01-09 10:31:23 -060023 * @brief Handle checkstop attention
24 *
Ben Tynerb481d902020-03-05 10:24:23 -060025 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050026 * @return 0 indicates that the checkstop attention was successfully handled
27 * 1 indicates that the checkstop attention was NOT successfully
28 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060029 */
Ben Tynerb481d902020-03-05 10:24:23 -060030int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060031
32/**
33 * @brief Handle special attention
34 *
Ben Tynerb481d902020-03-05 10:24:23 -060035 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050036 * @return 0 indicates that the special attention was successfully handled
37 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060038 */
Ben Tynerb481d902020-03-05 10:24:23 -060039int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060040
Ben Tynerfb190542020-11-06 09:27:56 -060041/** @brief Determine if attention is active and not masked */
Ben Tyner1965e502020-11-20 10:32:24 -060042bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn);
Ben Tynerfb190542020-11-06 09:27:56 -060043
Ben Tyneref320152020-01-09 10:31:23 -060044/**
Ben Tyneref320152020-01-09 10:31:23 -060045 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060046 *
47 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060048 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050049void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060050{
Ben Tynerb481d902020-03-05 10:24:23 -060051 // Vector of active attentions to be handled
52 std::vector<Attention> active_attentions;
53
Ben Tyneref320152020-01-09 10:31:23 -060054 uint32_t isr_val, isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -060055
Ben Tyner1965e502020-11-20 10:32:24 -060056 std::stringstream ss; // for trace messages
57
Ben Tyneref320152020-01-09 10:31:23 -060058 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050059 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050060
Ben Tyneref320152020-01-09 10:31:23 -060061 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050062 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060063 {
64 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
65 {
Zane Shelleya79f6c82021-01-12 16:38:49 -060066 auto proc = pdbg_target_index(target); // get processor number
Ben Tyneref320152020-01-09 10:31:23 -060067
Ben Tynerb83c8522020-11-20 10:45:26 -060068 // Use PIB target to determine if a processor is enabled
Ben Tyner5e622d82020-09-11 10:10:24 -050069 char path[16];
Ben Tynerb83c8522020-11-20 10:45:26 -060070 sprintf(path, "/proc%d/pib", proc);
Ben Tyner5e622d82020-09-11 10:10:24 -050071 pdbg_target* attnTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050072
Ben Tynerb83c8522020-11-20 10:45:26 -060073 // sanity check
74 if (nullptr == attnTarget)
75 {
76 trace<level::INFO>("pib path or target not found");
77 continue;
78 }
79
Ben Tyner5e622d82020-09-11 10:10:24 -050080 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnTarget))
Ben Tyneref320152020-01-09 10:31:23 -060081 {
Ben Tynerb83c8522020-11-20 10:45:26 -060082 // The processor FSI target is required for CFAM read
83 sprintf(path, "/proc%d/fsi", proc);
84 attnTarget = pdbg_target_from_path(nullptr, path);
85
86 // sanity check
87 if (nullptr == attnTarget)
88 {
89 trace<level::INFO>("fsi path or target not found");
90 continue;
91 }
92
Ben Tyner1965e502020-11-20 10:32:24 -060093 // trace fsi path
94 ss.str(std::string()); // clear stream
95 ss << "target - " << path;
96 trace<level::INFO>(ss.str().c_str());
97
Ben Tyner5adc96e2020-11-20 10:54:12 -060098 isr_val = 0xffffffff; // invalid isr value
99
Ben Tyner5e622d82020-09-11 10:10:24 -0500100 // get active attentions on processor
101 if (RC_SUCCESS != fsi_read(attnTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -0600102 {
Ben Tynerfb190542020-11-06 09:27:56 -0600103 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -0500104 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -0600105 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600106 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600107 else if (0xffffffff == isr_val)
108 {
109 trace<level::INFO>("Error! cfam read 0x1007 INVALID");
110 continue;
111 }
Ben Tyneref320152020-01-09 10:31:23 -0600112 else
113 {
Ben Tyner1965e502020-11-20 10:32:24 -0600114 // trace isr
115 ss.str(std::string()); // clear stream
116 ss << std::hex << std::showbase; // trace as hex vals
117 ss << "cfam 0x1007 = " << std::setw(8) << std::setfill('0')
118 << isr_val;
119 trace<level::INFO>(ss.str().c_str());
120
Ben Tyner5adc96e2020-11-20 10:54:12 -0600121 isr_mask = 0xffffffff; // invalid isr mask
122
Ben Tyner5e622d82020-09-11 10:10:24 -0500123 // get interrupt enabled special attentions mask
124 if (RC_SUCCESS != fsi_read(attnTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600125 {
Ben Tynerfb190542020-11-06 09:27:56 -0600126 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -0500127 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -0600128 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600129 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600130 else if (0xffffffff == isr_mask)
131 {
132 trace<level::INFO>("Error! cfam read 0x100d INVALID");
133 continue;
134 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500135 else
136 {
Ben Tyner1965e502020-11-20 10:32:24 -0600137 // trace true-mask
138 ss.str(std::string()); // clear stream
139 ss << std::hex << std::showbase; // trace as hex vals
140 ss << "cfam 0x100d = " << std::setw(8)
141 << std::setfill('0') << isr_mask;
142 trace<level::INFO>(ss.str().c_str());
143
Ben Tynerfb190542020-11-06 09:27:56 -0600144 // SBE vital attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600145 if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500146 {
147 active_attentions.emplace_back(Attention::Vital,
148 handleVital, target,
149 i_config);
150 }
151
Ben Tynerfb190542020-11-06 09:27:56 -0600152 // Checkstop attention active and not masked?
153 if (true ==
Ben Tyner1965e502020-11-20 10:32:24 -0600154 activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500155 {
156 active_attentions.emplace_back(Attention::Checkstop,
157 handleCheckstop,
158 target, i_config);
159 }
160
Ben Tynerfb190542020-11-06 09:27:56 -0600161 // Special attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600162 if (true == activeAttn(isr_val, isr_mask, SPECIAL_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500163 {
164 active_attentions.emplace_back(Attention::Special,
165 handleSpecial,
166 target, i_config);
167 }
168 } // cfam 0x100d valid
169 } // cfam 0x1007 valid
170 } // proc target enabled
171 } // fsi target enabled
172 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600173
Ben Tynerb481d902020-03-05 10:24:23 -0600174 // convert to heap, highest priority is at front
175 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
176 {
177 std::make_heap(active_attentions.begin(), active_attentions.end());
178 }
179
180 // call the attention handler until one is handled or all were attempted
181 while (false == active_attentions.empty())
182 {
183 // handle highest priority attention, done if successful
184 if (RC_SUCCESS == active_attentions.front().handle())
185 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500186 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600187 break;
188 }
189
190 // move attention to back of vector
191 std::pop_heap(active_attentions.begin(), active_attentions.end());
192
193 // remove attention from vector
194 active_attentions.pop_back();
195 }
Ben Tyneref320152020-01-09 10:31:23 -0600196}
197
198/**
Ben Tyneref320152020-01-09 10:31:23 -0600199 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500200 *
201 * @param i_attention Attention object
202 * @return 0 indicates that the checkstop attention was successfully handled
203 * 1 indicates that the checkstop attention was NOT successfully
204 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600205 */
Ben Tynerb481d902020-03-05 10:24:23 -0600206int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600207{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500208 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600209
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500210 trace<level::INFO>("checkstop handler started");
211
Ben Tyner3fb52e52020-03-31 10:10:07 -0500212 // if checkstop handling enabled, handle checkstop attention
213 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
214 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500215 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500216 }
217 else
218 {
Zane Shelley9fb73932020-09-15 13:34:57 -0500219 // Look for any attentions found in hardware. This will generate and
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600220 // commit a PEL if any errors are found.
Zane Shelley9fb73932020-09-15 13:34:57 -0500221 if (true != analyzer::analyzeHardware())
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500222 {
223 rc = RC_ANALYZER_ERROR;
224 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500225 }
Ben Tyneref320152020-01-09 10:31:23 -0600226
Ben Tyneref320152020-01-09 10:31:23 -0600227 return rc;
228}
229
230/**
231 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500232 *
233 * @param i_attention Attention object
234 * @return 0 indicates that the special attention was successfully handled
235 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600236 */
Ben Tynerb481d902020-03-05 10:24:23 -0600237int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600238{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500239 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600240
Ben Tynerfb190542020-11-06 09:27:56 -0600241 // The TI info chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500242 uint8_t* tiInfo = nullptr; // ptr to TI info data
243 uint32_t tiInfoLen = 0; // length of TI info data
244 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500245
Ben Tyner98430b32020-08-19 19:14:02 -0500246 if (attnProc != nullptr)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500247 {
Ben Tyner98430b32020-08-19 19:14:02 -0500248 // The processor PIB target is required for get TI info chipop
249 char path[16];
250 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
251 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
252
253 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500254 {
Ben Tyner98430b32020-08-19 19:14:02 -0500255 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
256 {
Ben Tyner98430b32020-08-19 19:14:02 -0500257 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
258 if (tiInfo == nullptr)
259 {
260 trace<level::INFO>("TI info data ptr is null after call");
261 }
262 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500263 }
264 }
Ben Tyneref320152020-01-09 10:31:23 -0600265
Ben Tyner0fe5df42020-12-03 08:57:17 -0600266 bool tiInfoValid = false; // TI area data not valid or not available
267
Ben Tyner792f32f2020-06-02 08:50:47 -0500268 // If TI area exists and is marked valid we can assume TI occurred
269 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600270 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500271 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
Ben Tyner7e6611f2020-02-13 16:42:56 -0600272
Ben Tyner792f32f2020-06-02 08:50:47 -0500273 // trace a few known TI data area values
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500274 std::stringstream ss;
275 ss << std::hex << std::showbase;
Ben Tyner40717722020-09-23 09:43:20 -0500276
277 ss << "TI data command = " << (int)tiDataArea->command;
Ben Tyner792f32f2020-06-02 08:50:47 -0500278 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500279 ss.str(std::string());
280
Ben Tyner0fe5df42020-12-03 08:57:17 -0600281 // Another check for valid TI Info since it has been seen that
282 // tiInfo[0] != 0 but TI info is not valid
283 if (0xa1 == tiDataArea->command)
Ben Tyner792f32f2020-06-02 08:50:47 -0500284 {
Ben Tyner0fe5df42020-12-03 08:57:17 -0600285 tiInfoValid = true;
286
287 // trace some more data since TI info appears valid
288 ss << "TI data hb_terminate_type = "
289 << (int)tiDataArea->hbTerminateType;
290 trace<level::INFO>(ss.str().c_str());
291 ss.str(std::string());
292
293 ss << "TI data SRC format = " << (int)tiDataArea->srcFormat;
294 trace<level::INFO>(ss.str().c_str());
295 ss.str(std::string());
296
297 ss << "TI data source = " << (int)tiDataArea->source;
298 trace<level::INFO>(ss.str().c_str());
299 ss.str(std::string());
300
301 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
302 {
303 // Call TI special attention handler
304 rc = tiHandler(tiDataArea);
305 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500306 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500307 }
Ben Tyner0fe5df42020-12-03 08:57:17 -0600308
309 // If TI area not valid or not available
310 if (false == tiInfoValid)
Ben Tyner3fb52e52020-03-31 10:10:07 -0500311 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500312 trace<level::INFO>("TI info NOT available");
Ben Tyner98430b32020-08-19 19:14:02 -0500313
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500314 // if configured to handle breakpoint as default special attention
315 if (i_attention->getConfig()->getFlag(dfltBreakpoint))
Ben Tyner3fb52e52020-03-31 10:10:07 -0500316 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500317 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
318 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500319 // Call the breakpoint special attention handler
320 bpHandler();
321 }
322 }
323 // if configured to handle TI as default special attention
324 else
325 {
326 trace<level::INFO>("assuming TI");
327
328 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
329 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500330 // Call TI special attention handler
331 rc = tiHandler(nullptr);
332 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500333 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600334 }
Ben Tyneref320152020-01-09 10:31:23 -0600335
Ben Tyner792f32f2020-06-02 08:50:47 -0500336 // release TI data buffer
337 if (nullptr != tiInfo)
338 {
339 free(tiInfo);
340 }
341
Ben Tyner3fb52e52020-03-31 10:10:07 -0500342 if (RC_SUCCESS != rc)
343 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500344 trace<level::INFO>("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500345 }
Ben Tyneref320152020-01-09 10:31:23 -0600346
347 return rc;
348}
349
Ben Tynerfb190542020-11-06 09:27:56 -0600350/**
351 * @brief Determine if attention is active and not masked
352 *
353 * Determine whether an attention needs to be handled and trace details of
354 * attention type and whether it is masked or not.
355 *
356 * @param i_val attention status register
357 * @param i_mask attention true mask register
358 * @param i_attn attention type
359 * @param i_proc processor associated with registers
360 *
361 * @return true if attention is active and not masked, otherwise false
362 */
Ben Tyner1965e502020-11-20 10:32:24 -0600363bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn)
Ben Tynerfb190542020-11-06 09:27:56 -0600364{
Zane Shelley9fb657f2021-01-12 15:30:58 -0600365 bool rc = false; // assume attn masked and/or inactive
Ben Tynerfb190542020-11-06 09:27:56 -0600366
367 // if attention active
368 if (0 != (i_val & i_attn))
369 {
Ben Tynerfb190542020-11-06 09:27:56 -0600370 std::stringstream ss;
Ben Tynerfb190542020-11-06 09:27:56 -0600371
Zane Shelley9fb657f2021-01-12 15:30:58 -0600372 bool validAttn = true; // known attention type
373
Ben Tynerfb190542020-11-06 09:27:56 -0600374 switch (i_attn)
375 {
376 case SBE_ATTN:
377 ss << "SBE attn";
378 break;
379 case CHECKSTOP_ATTN:
380 ss << "Checkstop attn";
381 break;
382 case SPECIAL_ATTN:
383 ss << "Special attn";
384 break;
385 default:
386 ss << "Unknown attn";
387 validAttn = false;
388 }
389
390 // see if attention is masked
391 if (true == validAttn)
392 {
393 if (0 != (i_mask & i_attn))
394 {
395 rc = true; // attention active and not masked
396 }
397 else
398 {
399 ss << " masked";
400 }
401 }
402
403 trace<level::INFO>(ss.str().c_str()); // commit trace stream
404 }
405
406 return rc;
407}
408
Ben Tyneref320152020-01-09 10:31:23 -0600409} // namespace attn