blob: e8684c6d767bcce2054b1916f4b20895df259a53 [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
48/**
Ben Tyneref320152020-01-09 10:31:23 -060049 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060050 *
51 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060052 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050053void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060054{
Ben Tynerb481d902020-03-05 10:24:23 -060055 // Vector of active attentions to be handled
56 std::vector<Attention> active_attentions;
57
Ben Tyneref320152020-01-09 10:31:23 -060058 uint32_t isr_val, isr_mask;
59 uint32_t proc;
60
61 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050062 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050063
Ben Tyneref320152020-01-09 10:31:23 -060064 pdbg_target* target;
65 pdbg_for_each_class_target("fsi", target)
66 {
67 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
68 {
69 proc = pdbg_target_index(target); // get processor number
70
71 std::stringstream ss; // log message stream
Ben Tyner9dbab8b2020-03-31 08:55:23 -050072 ss << "checking processor " << proc;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050073 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060074
75 // get active attentions on processor
Ben Tynerb481d902020-03-05 10:24:23 -060076 if (RC_SUCCESS != fsi_read(target, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060077 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050078 // event
79 eventAttentionFail(RC_CFAM_ERROR);
80
81 // trace
82 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060083 }
84 else
85 {
86 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -060087 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060088 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -050089 ss << isr_val;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050090 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060091
92 // get interrupt enabled special attentions mask
Ben Tynerb481d902020-03-05 10:24:23 -060093 if (RC_SUCCESS != fsi_read(target, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -060094 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050095 // event
96 eventAttentionFail(RC_CFAM_ERROR);
97
98 // trace
99 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -0600100 }
101 else
102 {
103 std::stringstream ss; // log message stream
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600104 ss << "cfam 0x100d = 0x";
Ben Tyneref320152020-01-09 10:31:23 -0600105 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner9dbab8b2020-03-31 08:55:23 -0500106 ss << isr_mask;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500107 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -0600108
109 // bit 0 on "left": bit 30 = SBE vital attention
110 if (isr_val & isr_mask & 0x00000002)
111 {
Ben Tyner3fb52e52020-03-31 10:10:07 -0500112 active_attentions.emplace_back(
113 Attention::Vital, handleVital, target, i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600114 }
115
116 // bit 0 on "left": bit 1 = checkstop
117 if (isr_val & isr_mask & 0x40000000)
118 {
Ben Tynerb481d902020-03-05 10:24:23 -0600119 active_attentions.emplace_back(Attention::Checkstop,
120 handleCheckstop, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500121 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600122 }
123
124 // bit 0 on "left": bit 2 = special attention
125 if (isr_val & isr_mask & 0x20000000)
126 {
Ben Tynerb481d902020-03-05 10:24:23 -0600127 active_attentions.emplace_back(Attention::Special,
128 handleSpecial, target,
Ben Tyner3fb52e52020-03-31 10:10:07 -0500129 i_config);
Ben Tyneref320152020-01-09 10:31:23 -0600130 }
131 } // cfam 0x100d valid
132 } // cfam 0x1007 valid
133 } // fsi target enabled
134 } // next processor
135
Ben Tynerb481d902020-03-05 10:24:23 -0600136 // convert to heap, highest priority is at front
137 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
138 {
139 std::make_heap(active_attentions.begin(), active_attentions.end());
140 }
141
142 // call the attention handler until one is handled or all were attempted
143 while (false == active_attentions.empty())
144 {
145 // handle highest priority attention, done if successful
146 if (RC_SUCCESS == active_attentions.front().handle())
147 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500148 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600149 break;
150 }
151
152 // move attention to back of vector
153 std::pop_heap(active_attentions.begin(), active_attentions.end());
154
155 // remove attention from vector
156 active_attentions.pop_back();
157 }
Ben Tyneref320152020-01-09 10:31:23 -0600158}
159
160/**
161 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500162 *
163 * @param i_attention Attention object
164 * @return 0 indicates that the vital attention was successfully handled
165 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600166 */
Ben Tynerb481d902020-03-05 10:24:23 -0600167int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600168{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500169 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600170
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500171 trace<level::INFO>("vital handler started");
172
Ben Tyner3fb52e52020-03-31 10:10:07 -0500173 // if vital handling enabled, handle vital attention
174 if (false == (i_attention->getConfig()->getFlag(enVital)))
175 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500176 trace<level::INFO>("vital handling disabled");
Ben Tyner792f32f2020-06-02 08:50:47 -0500177 rc = RC_NOT_HANDLED;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500178 }
179 else
Ben Tyneref320152020-01-09 10:31:23 -0600180 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500181 eventVital();
Ben Tyneref320152020-01-09 10:31:23 -0600182 }
183
184 return rc;
185}
186
187/**
188 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500189 *
190 * @param i_attention Attention object
191 * @return 0 indicates that the checkstop attention was successfully handled
192 * 1 indicates that the checkstop attention was NOT successfully
193 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600194 */
Ben Tynerb481d902020-03-05 10:24:23 -0600195int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600196{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500197 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600198
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500199 trace<level::INFO>("checkstop handler started");
200
Ben Tyner3fb52e52020-03-31 10:10:07 -0500201 // if checkstop handling enabled, handle checkstop attention
202 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
203 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500204 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500205 }
206 else
207 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500208 // errors that were isolated
209 std::map<std::string, std::string> errors;
210
Ben Tynerdbeaf792020-05-14 08:27:18 -0500211 // analyze errors
212 if (true != analyzer::analyzeHardware(errors))
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500213 {
214 rc = RC_ANALYZER_ERROR;
215 }
216 else
217 {
218 std::stringstream ss;
219 ss << "Analyzer isolated " << errors.size() << " error(s)";
220 trace<level::INFO>(ss.str().c_str());
221
222 // add checkstop event to log
223 eventCheckstop(errors);
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 Tyner792f32f2020-06-02 08:50:47 -0500241 // The TI infor chipop will give us a pointer to the TI info data
242 uint8_t* tiInfo = nullptr; // ptr to TI info data
243 uint32_t tiInfoLen = 0; // length of TI info data
244 pdbg_target* tiInfoTarget = i_attention->getTarget(); // get TI info target
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500245
Ben Tyner792f32f2020-06-02 08:50:47 -0500246 // Get length and location of TI info data
247 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
Ben Tyneref320152020-01-09 10:31:23 -0600248
Ben Tyner792f32f2020-06-02 08:50:47 -0500249 // Note: If we want to support running this application on architectures
250 // of different endian-ness we need to handler that here. The TI data
251 // will always be written in big-endian order.
252
253 // If TI area exists and is marked valid we can assume TI occurred
254 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600255 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500256 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
Ben Tyner7e6611f2020-02-13 16:42:56 -0600257
Ben Tyner792f32f2020-06-02 08:50:47 -0500258 // trace a few known TI data area values
259 std::stringstream ss; // log message stream
260 ss << "TI data command = " << tiDataArea->command;
261 trace<level::INFO>(ss.str().c_str());
262 ss << "TI data SRC format = " << tiDataArea->srcFormat;
263 trace<level::INFO>(ss.str().c_str());
264 ss << "TI data hb_terminate_type = " << tiDataArea->hbTerminateType;
265 trace<level::INFO>(ss.str().c_str());
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500266
Ben Tyner792f32f2020-06-02 08:50:47 -0500267 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
268 {
269 trace<level::INFO>("TI (terminate immediately)");
270
271 // Call TI special attention handler
272 rc = tiHandler(tiDataArea);
273 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500274 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500275 // TI area not valid, assume breakpoint
Ben Tyner3fb52e52020-03-31 10:10:07 -0500276 else
277 {
278 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
279 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500280 trace<level::INFO>("breakpoint");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500281
282 // Call the breakpoint special attention handler
283 bpHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500284 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600285 }
Ben Tyneref320152020-01-09 10:31:23 -0600286
Ben Tyner792f32f2020-06-02 08:50:47 -0500287 // release TI data buffer
288 if (nullptr != tiInfo)
289 {
290 free(tiInfo);
291 }
292
Ben Tyner3fb52e52020-03-31 10:10:07 -0500293 if (RC_SUCCESS != rc)
294 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500295 trace<level::INFO>("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500296 }
Ben Tyneref320152020-01-09 10:31:23 -0600297
298 return rc;
299}
300
Ben Tyneref320152020-01-09 10:31:23 -0600301} // namespace attn