1 #include <libpdbg.h> 2 3 #include <analyzer/analyzer_main.hpp> 4 #include <boost/interprocess/ipc/message_queue.hpp> 5 #include <cli.hpp> 6 #include <listener.hpp> 7 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 hardware error conditions. 15 * 16 * 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 25 * 26 * Example: openpower-hw-diags --start --vital off 27 * 28 * @return 0 = success 29 */ 30 int main(int argc, char* argv[]) 31 { 32 int rc = RC_SUCCESS; // assume success 33 34 using namespace boost::interprocess; 35 36 if (argc == 1) 37 { 38 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"); 49 } 50 else 51 { 52 // 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 59 60 // Either analyze (application mode) or daemon mode 61 if (true == getCliOption(argv, argv + argc, "--analyze")) 62 { 63 attn::DumpParameters dumpParameters; 64 analyzer::analyzeHardware(dumpParameters); // analyze hardware 65 } 66 // daemon mode 67 else 68 { 69 // Handle pending attentions 70 attn::Config attnConfig; 71 attn::attnHandler(&attnConfig); 72 73 // assume listener is not running 74 bool listenerStarted = false; 75 bool newListener = false; 76 77 pthread_t ptidListener; // handle to listener thread 78 79 // see if listener is already started 80 listenerStarted = listenerMqExists(); 81 82 // listener is not running so start it 83 if (false == listenerStarted) 84 { 85 // create listener thread 86 if (0 == 87 pthread_create(&ptidListener, NULL, &threadListener, NULL)) 88 { 89 listenerStarted = true; 90 newListener = true; 91 } 92 else 93 { 94 rc = 1; 95 } 96 } 97 98 // listener was running or just started 99 if (true == listenerStarted) 100 { 101 // If we created a new listener this instance of 102 // openpower-hw-diags will become our daemon (it will not exit 103 // until stopped). 104 if (true == newListener) 105 { 106 bool listenerReady = false; 107 108 // It may take some time for the listener to become ready, 109 // we will wait until the message queue has been created 110 // before starting to communicate with our daemon. 111 while (false == listenerReady) 112 { 113 usleep(500); 114 listenerReady = listenerMqExists(); 115 } 116 } 117 118 // send cmd line to listener thread 119 if (argc != sendCmdLine(argc, argv)) 120 { 121 rc = 1; 122 } 123 124 // if this is a new listener let it run until "stopped" 125 if (true == newListener) 126 { 127 pthread_join(ptidListener, NULL); 128 } 129 } 130 } 131 } 132 return rc; 133 } 134