build: add enable-aspeed-p2a option and download header

Add an option to enable using the aspeed-p2a-ctrl driver on the BMC.

Change-Id: I058d130e8729822676953313cc1f5b31a1807cf4
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/configure.ac b/configure.ac
index f345d8a..4d8d76a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,21 @@
     AX_APPEND_COMPILE_FLAGS([-DNUVOTON_LPC], [CXXFLAGS])
 ])
 
+AC_ARG_ENABLE([aspeed-p2a],
+    AS_HELP_STRING([--enable-aspeed-p2a],
+                   [Enable external transfers using Aspeed PCI-to-AHB]))
+AS_IF([test "x$enable_aspeed_p2a" = "xyes"], [
+    AC_CHECK_HEADER(linux/aspeed-p2a-ctrl.h,
+                    [HAVE_UAPI_LINUX_P2A_CTRL_H=""],
+                    [HAVE_UAPI_LINUX_P2A_CTRL_H="-I linux/aspeed-p2a-ctrl.h"])
+    AS_IF([test "$HAVE_UAPI_LINUX_P2A_CTRL_H" != ""],
+        AC_MSG_WARN([Could not find linux/aspeed-p2a-ctrl.h: Attempting to download locally for building from openbmc/linux/+/dev-5.0])
+        AC_SUBST([PCI_BMC_DL],
+                 [`mkdir -p linux;wget https://raw.githubusercontent.com/openbmc/linux/dev-5.0/include/uapi/linux/aspeed-p2a-ctrl.h -O linux/aspeed-p2a-ctrl.h`])
+    )
+    AX_APPEND_COMPILE_FLAGS([-DASPEED_P2A], [CXXFLAGS])
+])
+
 AC_ARG_VAR(STATIC_HANDLER_STAGED_NAME, [The file to use for staging the firmware update.])
 AS_IF([test "x$STATIC_HANDLER_STAGED_NAME" == "x"], [STATIC_HANDLER_STAGED_NAME="/run/initramfs/bmc-image"])
 AC_DEFINE_UNQUOTED([STATIC_HANDLER_STAGED_NAME], ["$STATIC_HANDLER_STAGED_NAME"], [The file to use for staging the firmware update.])