Find attention gpio rather than hard code value

Find the attention gpio by line-name (checkstop) rather than by
chip and pin number. This allows the attention handler to work on
platforms with the attention signal tied to different GPIO's.

Also fixed issue of pdbg targets not getting initialized when
attention handler is built to run in no-listener mode (build option
nlmode, the default for now).

Added/changed a few trace messages to aid in future debugging.

Changed build to not link to libpdbg using "whole-archive" strategy
as it does not seem to be needed anymore.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: Id355ce03b716cb0c86bc3418264295dcc60aabef
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index a6bd469..8c26bb3 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -59,9 +59,12 @@
     uint32_t proc;
 
     // loop through processors looking for active attentions
+    log<level::INFO>("Attention handler started");
+
     pdbg_target* target;
     pdbg_for_each_class_target("fsi", target)
     {
+        log<level::INFO>("iterating targets");
         if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
         {
             proc = pdbg_target_index(target); // get processor number
diff --git a/attn/attn_main.cpp b/attn/attn_main.cpp
index 46455b3..bd3b5c4 100644
--- a/attn/attn_main.cpp
+++ b/attn/attn_main.cpp
@@ -21,7 +21,7 @@
     };
 
     // get handle to attention GPIO line
-    line = gpiod_line_get("gpiochip0", 74);
+    line = gpiod_line_find("checkstop");
 
     if (nullptr == line)
     {
@@ -35,6 +35,9 @@
             std::make_unique<attn::AttnMonitor>(line, config, io, i_config));
 
         io.run(); // start GPIO monitor
+
+        // done with line, manually close chip (per gpiod api comments)
+        gpiod_line_close_chip(line);
     }
 
     return rc;
diff --git a/attn/attn_monitor.cpp b/attn/attn_monitor.cpp
index 13b7f15..25bdce4 100644
--- a/attn/attn_monitor.cpp
+++ b/attn/attn_monitor.cpp
@@ -26,6 +26,7 @@
             }
             else
             {
+                log<level::INFO>("Attention monitor detected active attention");
                 handleGPIOEvent(); // gpio trigger detected
             }
             return;
@@ -50,6 +51,8 @@
         {
             // active attention when gpio == 0
             case 0:
+                logMessage = "Attention monitor calling attention handler";
+                log<level::INFO>(logMessage.c_str());
                 attnHandler(iv_config);
                 break;
 
diff --git a/attn/meson.build b/attn/meson.build
index 6a0bcc2..92254db 100644
--- a/attn/meson.build
+++ b/attn/meson.build
@@ -15,10 +15,6 @@
 # dependency to link libpdbg support
 libpdbg = cmplr.find_library('pdbg')
 
-# libpdbg requires linking with "whole-archive" option
-whole_archive = declare_dependency(link_args : '-Wl,--whole-archive')
-no_whole_archive = declare_dependency(link_args : '-Wl,--no-whole-archive')
-
 # install systemd unit file
 configure_file(
     input: 'attn_handler.service',
@@ -46,7 +42,6 @@
 attn = static_library('attn_handler',
                       attn_src,
                       include_directories : incdir,
-                      dependencies : [whole_archive, libpdbg,
-                                      no_whole_archive, sdbusplus, libgpiod],
+                      dependencies : [libpdbg, sdbusplus, libgpiod],
                       cpp_args : boost_args,
                       install : true)
diff --git a/main_nl.cpp b/main_nl.cpp
index 2725860..31017ea 100644
--- a/main_nl.cpp
+++ b/main_nl.cpp
@@ -1,3 +1,5 @@
+#include <libpdbg.h>
+
 #include <analyzer/analyzer_main.hpp>
 #include <attn/attn_config.hpp>
 #include <attn/attn_main.hpp>
@@ -42,6 +44,8 @@
             {
                 attn::Config attnConfig; // default config
 
+                pdbg_targets_init(nullptr); // initialize pdbg targets
+
                 attn::attnDaemon(&attnConfig); // start daemon
             }
         }