Add recipe file for phosphor-gpio-monitor

phosphor-gpio-monitor is a generic GPIO monitor application which
can be used for any purpose where a GPIO needs to be monitored for
certain state. Due to this need, it has been added to obmc package
group.

Change-Id: I8e11e8d5567d6f4c56479b335d1f6bd9b39401fd
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor.bb b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor.bb
new file mode 100644
index 0000000..07d024e
--- /dev/null
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor.bb
@@ -0,0 +1,29 @@
+SUMMARY = "OpenPOWER Host checkstop monitor application"
+PR = "r1"
+
+inherit obmc-phosphor-systemd
+inherit obmc-phosphor-license
+inherit allarch
+
+DEPENDS += "virtual/obmc-gpio-monitor"
+RDEPENDS_${PN} += "virtual/obmc-gpio-monitor"
+
+# For now, monitoring checkstop is the only usecase
+OBMC_HOST_MONITOR_INSTANCES = "checkstop"
+
+# Copies config file having arguments for monitoring host checkstop
+# via GPIO assertion
+SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/checkstop"
+
+SYSTEMD_SERVICE_${PN} += "openpower-host-checkstop-monitor@.target"
+
+CHECKSTOP_TMPL = "openpower-host-checkstop-monitor@.target"
+CHECKSTOP_TGTFMT = "openpower-host-checkstop-monitor@{0}.target"
+CHECKSTOP_MONITOR_FMT = "${CHECKSTOP_TMPL}:${CHECKSTOP_TGTFMT}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'CHECKSTOP_MONITOR_FMT', 'OBMC_HOST_MONITOR_INSTANCES')}"
+
+GPIO_TMPL = "phosphor-gpio-monitor@.service"
+MONITOR_TGTFMT = "openpower-host-checkstop-monitor@{0}.target"
+GPIO_INSTFMT = "phosphor-gpio-monitor@{0}.service"
+MONITOR_GPIO_FMT = "../${GPIO_TMPL}:${MONITOR_TGTFMT}.wants/${GPIO_INSTFMT}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'MONITOR_GPIO_FMT', 'OBMC_HOST_MONITOR_INSTANCES')}"
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/obmc/gpio/checkstop b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/obmc/gpio/checkstop
new file mode 100644
index 0000000..1259483
--- /dev/null
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/obmc/gpio/checkstop
@@ -0,0 +1,4 @@
+PATH=/dev/input/event0
+KEY=74
+POLARITY=1
+TARGET=obmc-host-crash@0.target
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/openpower-host-checkstop-monitor@.target b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/openpower-host-checkstop-monitor@.target
new file mode 100644
index 0000000..8c2168b
--- /dev/null
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/host/checkstop-monitor/openpower-host-checkstop-monitor@.target
@@ -0,0 +1,4 @@
+[Unit]
+Description=Host instance %i checkstop monitor
+Requires=phosphor-gpio-monitor@%i.service
+RefuseManualStop=yes
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
index f9ed14b..b9c7832 100644
--- a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
@@ -21,3 +21,8 @@
 RDEPENDS_${PN}-sensors += "obmc-hwmon obmc-mgr-sensor"
 
 RDEPENDS_${PN}-debug-collector += "openpower-debug-collector"
+
+# Add checkstop monitor as part of host state management package
+# This will kick start a gpio monitor that will catch the
+# host checkstop conditions and takes necessary actions
+RDEPENDS_${PN}-host-state-mgmt += "checkstop-monitor"
diff --git a/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor.bb b/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor.bb
new file mode 100644
index 0000000..e019ed0
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor.bb
@@ -0,0 +1,25 @@
+SUMMARY = "Phosphor GPIO monitor application"
+DESCRIPTION = "Application to monitor gpio assertions"
+HOMEPAGE = "http://github.com/openbmc/phosphor-gpio-monitor"
+PR = "r1"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e3fc50a88d0a364313df4b21ef20c29e"
+inherit autotools pkgconfig
+inherit obmc-phosphor-dbus-service
+
+RPROVIDES_${PN} += "virtual/obmc-gpio-monitor"
+PROVIDES += "virtual/obmc-gpio-monitor"
+
+DEPENDS += "autoconf-archive-native"
+DEPENDS += "sdbusplus sdbusplus-native"
+DEPENDS += "phosphor-dbus-interfaces"
+DEPENDS += "phosphor-logging"
+RDEPENDS_${PN} += "libsystemd"
+RDEPENDS_${PN} += "phosphor-logging"
+
+SYSTEMD_SERVICE_${PN} += "phosphor-gpio-monitor@.service"
+
+SRC_URI += "git://github.com/openbmc/phosphor-gpio-monitor"
+SRCREV = "77ec47996d0c8b78d0f08d17fed8ff03107a1e03"
+S = "${WORKDIR}/git"
diff --git a/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-monitor@.service b/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-monitor@.service
new file mode 100644
index 0000000..37d1279
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-monitor@.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Phosphor GPIO %I monitor
+
+[Service]
+Restart=no
+Type=oneshot
+EnvironmentFile={envfiledir}/obmc/gpio/%I
+ExecStart={sbindir}/phosphor-gpio-monitor --path=${{PATH}} --key=${{KEY}} --polarity=${{POLARITY}} --target=${{TARGET}}
diff --git a/meta-phosphor/conf/distro/include/phosphor-defaults.inc b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
index 3dc3d3c..8704075 100644
--- a/meta-phosphor/conf/distro/include/phosphor-defaults.inc
+++ b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
@@ -190,5 +190,12 @@
 PREFERRED_PROVIDER_virtual/phosphor-ipmi-inventory-sel ?= \
     "${@cf_enabled(d, 'obmc-mrw', 'phosphor-ipmi-inventory-sel-mrw-native', 'phosphor-ipmi-inventory-sel-native')}"
 
+# The phosphor-gpio-monitor application is data-driven and requires an input.
+# The application then watches the passed in input event entry for the
+# change in polarity for the value matching user input. Once the required
+# condition is met, it calls into a systemd target file if one is mentioned
+# in input.
+PREFERRED_PROVIDER_virtual/obmc-gpio-monitor ?= "phosphor-gpio-monitor"
+
 OBMC_DBUS_PATH_ROOT ?= "/xyz/openbmc_project"
 OBMC_DBUS_IFACE_ROOT ?= "xyz.openbmc_project"