blob: 8cc06ed7cd332af3257edd7cf33a838319c03601 [file] [log] [blame]
Ben Tyner87eabc62020-05-14 17:56:54 -05001#include <libpdbg.h>
2
Ben Tyner0205f3b2020-02-24 10:24:47 -06003#include <analyzer/analyzer_main.hpp>
Ben Tyner8c2f8b22020-03-27 10:39:31 -05004#include <boost/interprocess/ipc/message_queue.hpp>
Ben Tyner7212d212020-03-31 09:44:41 -05005#include <cli.hpp>
Ben Tyner8c2f8b22020-03-27 10:39:31 -05006#include <listener.hpp>
Ben Tyner0205f3b2020-02-24 10:24:47 -06007
8/**
9 * @brief Attention handler application main()
10 *
11 * This is the main interface to the hardware diagnostics application. This
12 * application will either be loaded as a daemon for monitoring the attention
13 * gpio or it will be loaded as an application to analyze hardware and
14 * diagnose hadrware error conditions.
15 *
Ben Tyner8c2f8b22020-03-27 10:39:31 -050016 * Usage:
17 * --analyze: Analyze the hardware
18 * --start: Start the attention handler
19 * --stop: Stop the attention handler
20 * --all <on|off>: All attention handling
21 * --vital <on|off>: Vital attention handling
22 * --checkstop <on|off>: Checkstop attention handling
23 * --terminate <on|off>: Terminate Immiediately attention handling
24 * --breakpoints <on|off>: Breakpoint attention handling
Ben Tyner0205f3b2020-02-24 10:24:47 -060025 *
Ben Tyner8c2f8b22020-03-27 10:39:31 -050026 * Example: openpower-hw-diags --start --vital off
Ben Tyner0205f3b2020-02-24 10:24:47 -060027 *
28 * @return 0 = success
29 */
30int main(int argc, char* argv[])
31{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050032 int rc = RC_SUCCESS; // assume success
Ben Tyner0205f3b2020-02-24 10:24:47 -060033
Ben Tyner8c2f8b22020-03-27 10:39:31 -050034 using namespace boost::interprocess;
Ben Tyner3fb52e52020-03-31 10:10:07 -050035
Ben Tyner8c2f8b22020-03-27 10:39:31 -050036 if (argc == 1)
Ben Tyner0205f3b2020-02-24 10:24:47 -060037 {
Ben Tyner8c2f8b22020-03-27 10:39:31 -050038 printf("openpower-hw-diags <options>\n");
39 printf("options:\n");
40 printf(" --analyze: Analyze the hardware\n");
41 printf(" --start: Start the attention handler\n");
42 printf(" --stop: Stop the attention handler\n");
43 printf(" --all <on|off>: All attention handling\n");
44 printf(" --vital <on|off>: Vital attention handling\n");
45 printf(" --checkstop <on|off>: Checkstop attention handling\n");
46 printf(" --terminate <on|off>: Terminate Immediately attention "
47 "handling\n");
48 printf(" --breakpoints <on|off>: Breakpoint attention handling\n");
Ben Tyner0205f3b2020-02-24 10:24:47 -060049 }
Ben Tyner0205f3b2020-02-24 10:24:47 -060050 else
51 {
Ben Tyner87eabc62020-05-14 17:56:54 -050052 // Pdbg targets should only be initialized once according to
53 // libpdbg documentation. Initializing them here will make sure
54 // they are initialized for the attention handler, invocation of
55 // the analyzer via attention handler and direct invocation of
56 // the analyzer via command line (--analyze).
57
58 pdbg_targets_init(nullptr); // nullptr == use default fdt
Ben Tyner8c2f8b22020-03-27 10:39:31 -050059
60 // Either analyze (application mode) or daemon mode
61 if (true == getCliOption(argv, argv + argc, "--analyze"))
Ben Tyner0205f3b2020-02-24 10:24:47 -060062 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050063 // errors that were isolated
64 std::map<std::string, std::string> errors;
65
66 rc = analyzer::analyzeHardware(errors); // analyze hardware
67 if (RC_SUCCESS == rc)
68 {
69 // TODO - add error processing/display
70
Ben Tyner87eabc62020-05-14 17:56:54 -050071 printf("analyzer isolated %i error(s)\n", (int)errors.size());
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050072 }
73 else
74 {
75 printf("analyzer/isolator error encountered\n");
76 }
Ben Tyner0205f3b2020-02-24 10:24:47 -060077 }
Ben Tyner8c2f8b22020-03-27 10:39:31 -050078 // daemon mode
79 else
80 {
Ben Tynerd70033a2020-06-09 15:59:29 -050081 // Handle pending attentions
82 attn::Config attnConfig;
83 attn::attnHandler(&attnConfig);
84
Ben Tyner8c2f8b22020-03-27 10:39:31 -050085 // assume listener is not running
86 bool listenerStarted = false;
87 bool newListener = false;
Ben Tyner0205f3b2020-02-24 10:24:47 -060088
Ben Tyner8c2f8b22020-03-27 10:39:31 -050089 pthread_t ptidListener; // handle to listener thread
90
91 // see if listener is already started
92 listenerStarted = listenerMqExists();
93
94 // listener is not running so start it
95 if (false == listenerStarted)
96 {
97 // create listener thread
98 if (0 ==
99 pthread_create(&ptidListener, NULL, &threadListener, NULL))
100 {
101 listenerStarted = true;
102 newListener = true;
103 }
104 else
105 {
106 rc = 1;
107 }
108 }
109
110 // listener was running or just started
111 if (true == listenerStarted)
112 {
113 // If we created a new listener this instance of
114 // openpower-hw-diags will become our daemon (it will not exit
115 // until stopped).
116 if (true == newListener)
117 {
118 bool listenerReady = false;
119
120 // It may take some time for the listener to become ready,
121 // we will wait until the message queue has been created
122 // before starting to communicate with our daemon.
123 while (false == listenerReady)
124 {
125 usleep(500);
126 listenerReady = listenerMqExists();
127 }
128 }
129
130 // send cmd line to listener thread
131 if (argc != sendCmdLine(argc, argv))
132 {
133 rc = 1;
134 }
135
136 // if this is a new listener let it run until "stopped"
137 if (true == newListener)
138 {
139 pthread_join(ptidListener, NULL);
140 }
141 }
142 }
143 }
Ben Tyner0205f3b2020-02-24 10:24:47 -0600144 return rc;
145}