[PATCH v3 5/6] tools/power/acpi: Add userspace AML interface support

2015-11-18 Thread Lv Zheng
This patch adds a userspace tool to access Linux kernel AML debugger
interface.

Tow modes are supported by this tool:
1. Interactive: Users are able to launch a debugging shell to talk with
   in-kernel AML debugger.
   Note that it's user duty to ensure kernel runtime integrity by using
   this debugging tool:
   A. Some control methods evaluated by the users may result in kernel
  panics if those control methods shouldn't be evaluated by the OSPMs
  according to the current BIOS/OS configurations.
   B. Currently if a single stepping evaluation couldn't run to an end,
  then the synchronization primitives acquired by the evaluation may
  block normal OSPM control method evaluations.
2. Batch: Users are able to execute debugger commands in a script.
   Note that in addition to the above duties, it's user duty to ensure
   script runtime integrity by using this debugging tool in this mode:
   C. Currently only those commands that are not used for single stepping
  are suitable to be used in this mode.
   D. If the execution of the command may cause a failure that could result
  in an endless kernel execution, the execution of the script may also
  get blocked.
To exit the utility, currently "exit/quit" commands are recommended, but
ctrl-C" can also be used.

Signed-off-by: Lv Zheng 
---
 tools/power/acpi/Makefile|   16 +-
 tools/power/acpi/tools/acpidbg/Makefile  |   27 ++
 tools/power/acpi/tools/acpidbg/acpidbg.c |  438 ++
 3 files changed, 473 insertions(+), 8 deletions(-)
 create mode 100644 tools/power/acpi/tools/acpidbg/Makefile
 create mode 100644 tools/power/acpi/tools/acpidbg/acpidbg.c

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index e882c83..a8bf908 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -10,18 +10,18 @@
 
 include ../../scripts/Makefile.include
 
-all: acpidump ec
-clean: acpidump_clean ec_clean
-install: acpidump_install ec_install
-uninstall: acpidump_uninstall ec_uninstall
+all: acpidbg acpidump ec
+clean: acpidbg_clean acpidump_clean ec_clean
+install: acpidbg_install acpidump_install ec_install
+uninstall: acpidbg_uninstall acpidump_uninstall ec_uninstall
 
-acpidump ec: FORCE
+acpidbg acpidump ec: FORCE
$(call descend,tools/$@,all)
-acpidump_clean ec_clean:
+acpidbg_clean acpidump_clean ec_clean:
$(call descend,tools/$(@:_clean=),clean)
-acpidump_install ec_install:
+acpidbg_install acpidump_install ec_install:
$(call descend,tools/$(@:_install=),install)
-acpidump_uninstall ec_uninstall:
+acpidbg_uninstall acpidump_uninstall ec_uninstall:
$(call descend,tools/$(@:_uninstall=),uninstall)
 
 .PHONY: FORCE
diff --git a/tools/power/acpi/tools/acpidbg/Makefile 
b/tools/power/acpi/tools/acpidbg/Makefile
new file mode 100644
index 000..352df4b
--- /dev/null
+++ b/tools/power/acpi/tools/acpidbg/Makefile
@@ -0,0 +1,27 @@
+# tools/power/acpi/tools/acpidbg/Makefile - ACPI tool Makefile
+#
+# Copyright (c) 2015, Intel Corporation
+#   Author: Lv Zheng 
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+
+include ../../Makefile.config
+
+TOOL = acpidbg
+vpath %.c \
+   ../../../../../drivers/acpi/acpica\
+   ../../common\
+   ../../os_specific/service_layers\
+   .
+CFLAGS += -DACPI_APPLICATION -DACPI_SINGLE_THREAD -DACPI_DEBUGGER\
+   -I.\
+   -I../../../../../drivers/acpi/acpica\
+   -I../../../../../include
+LDFLAGS += -lpthread
+TOOL_OBJS = \
+   acpidbg.o
+
+include ../../Makefile.rules
diff --git a/tools/power/acpi/tools/acpidbg/acpidbg.c 
b/tools/power/acpi/tools/acpidbg/acpidbg.c
new file mode 100644
index 000..d070fcc
--- /dev/null
+++ b/tools/power/acpi/tools/acpidbg/acpidbg.c
@@ -0,0 +1,438 @@
+/*
+ * ACPI AML interfacing userspace utility
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Authors: Lv Zheng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+
+/* Headers not included by include/acpi/platform/aclinux.h */
+#include 
+#include 
+#include 
+#include 
+
+#define ACPI_AML_FILE  "/sys/kernel/debug/acpi/acpidbg"
+#define ACPI_AML_SEC_TICK  1
+#define ACPI_AML_USEC_PEEK 200
+#define ACPI_AML_BUF_SIZE  4096
+
+#define ACPI_AML_BATCH_WRITE_CMD   0x00 /* Write command to kernel */
+#define ACPI_AML_BATCH_READ_LOG0x01 /* Read log from kernel */
+#define ACPI_AML_BATCH_WRITE_LOG   0x02 /* Write log to console */
+
+#define ACPI_AML_LOG_START 0x00
+#define ACPI_AML_PROMPT_START  0x01
+#define ACPI_AML_PROMPT_STOP   0x02
+#define ACPI_AML_LOG_STOP  0x03
+#define ACPI_AML_PROMPT_ROLL  

[PATCH v3 5/6] tools/power/acpi: Add userspace AML interface support

2015-11-18 Thread Lv Zheng
This patch adds a userspace tool to access Linux kernel AML debugger
interface.

Tow modes are supported by this tool:
1. Interactive: Users are able to launch a debugging shell to talk with
   in-kernel AML debugger.
   Note that it's user duty to ensure kernel runtime integrity by using
   this debugging tool:
   A. Some control methods evaluated by the users may result in kernel
  panics if those control methods shouldn't be evaluated by the OSPMs
  according to the current BIOS/OS configurations.
   B. Currently if a single stepping evaluation couldn't run to an end,
  then the synchronization primitives acquired by the evaluation may
  block normal OSPM control method evaluations.
2. Batch: Users are able to execute debugger commands in a script.
   Note that in addition to the above duties, it's user duty to ensure
   script runtime integrity by using this debugging tool in this mode:
   C. Currently only those commands that are not used for single stepping
  are suitable to be used in this mode.
   D. If the execution of the command may cause a failure that could result
  in an endless kernel execution, the execution of the script may also
  get blocked.
To exit the utility, currently "exit/quit" commands are recommended, but
ctrl-C" can also be used.

Signed-off-by: Lv Zheng 
---
 tools/power/acpi/Makefile|   16 +-
 tools/power/acpi/tools/acpidbg/Makefile  |   27 ++
 tools/power/acpi/tools/acpidbg/acpidbg.c |  438 ++
 3 files changed, 473 insertions(+), 8 deletions(-)
 create mode 100644 tools/power/acpi/tools/acpidbg/Makefile
 create mode 100644 tools/power/acpi/tools/acpidbg/acpidbg.c

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index e882c83..a8bf908 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -10,18 +10,18 @@
 
 include ../../scripts/Makefile.include
 
-all: acpidump ec
-clean: acpidump_clean ec_clean
-install: acpidump_install ec_install
-uninstall: acpidump_uninstall ec_uninstall
+all: acpidbg acpidump ec
+clean: acpidbg_clean acpidump_clean ec_clean
+install: acpidbg_install acpidump_install ec_install
+uninstall: acpidbg_uninstall acpidump_uninstall ec_uninstall
 
-acpidump ec: FORCE
+acpidbg acpidump ec: FORCE
$(call descend,tools/$@,all)
-acpidump_clean ec_clean:
+acpidbg_clean acpidump_clean ec_clean:
$(call descend,tools/$(@:_clean=),clean)
-acpidump_install ec_install:
+acpidbg_install acpidump_install ec_install:
$(call descend,tools/$(@:_install=),install)
-acpidump_uninstall ec_uninstall:
+acpidbg_uninstall acpidump_uninstall ec_uninstall:
$(call descend,tools/$(@:_uninstall=),uninstall)
 
 .PHONY: FORCE
diff --git a/tools/power/acpi/tools/acpidbg/Makefile 
b/tools/power/acpi/tools/acpidbg/Makefile
new file mode 100644
index 000..352df4b
--- /dev/null
+++ b/tools/power/acpi/tools/acpidbg/Makefile
@@ -0,0 +1,27 @@
+# tools/power/acpi/tools/acpidbg/Makefile - ACPI tool Makefile
+#
+# Copyright (c) 2015, Intel Corporation
+#   Author: Lv Zheng 
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+
+include ../../Makefile.config
+
+TOOL = acpidbg
+vpath %.c \
+   ../../../../../drivers/acpi/acpica\
+   ../../common\
+   ../../os_specific/service_layers\
+   .
+CFLAGS += -DACPI_APPLICATION -DACPI_SINGLE_THREAD -DACPI_DEBUGGER\
+   -I.\
+   -I../../../../../drivers/acpi/acpica\
+   -I../../../../../include
+LDFLAGS += -lpthread
+TOOL_OBJS = \
+   acpidbg.o
+
+include ../../Makefile.rules
diff --git a/tools/power/acpi/tools/acpidbg/acpidbg.c 
b/tools/power/acpi/tools/acpidbg/acpidbg.c
new file mode 100644
index 000..d070fcc
--- /dev/null
+++ b/tools/power/acpi/tools/acpidbg/acpidbg.c
@@ -0,0 +1,438 @@
+/*
+ * ACPI AML interfacing userspace utility
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Authors: Lv Zheng 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+
+/* Headers not included by include/acpi/platform/aclinux.h */
+#include 
+#include 
+#include 
+#include 
+
+#define ACPI_AML_FILE  "/sys/kernel/debug/acpi/acpidbg"
+#define ACPI_AML_SEC_TICK  1
+#define ACPI_AML_USEC_PEEK 200
+#define ACPI_AML_BUF_SIZE  4096
+
+#define ACPI_AML_BATCH_WRITE_CMD   0x00 /* Write command to kernel */
+#define ACPI_AML_BATCH_READ_LOG0x01 /* Read log from kernel */
+#define ACPI_AML_BATCH_WRITE_LOG   0x02 /* Write log to console */
+
+#define ACPI_AML_LOG_START 0x00
+#define ACPI_AML_PROMPT_START  0x01
+#define ACPI_AML_PROMPT_STOP   0x02
+#define