[PATCH v3 6/6] ACPI / debugger: Add module support for ACPI debugger

2015-11-18 Thread Lv Zheng
This patch converts AML debugger into a loadable module.

Note that, it implements driver unloading at the level dependent on the
module reference count. Which means if ACPI debugger is being used by a
userspace program, "rmmod acpi_dbg" should result in failure.

Signed-off-by: Lv Zheng 
---
 drivers/acpi/Kconfig |   12 ++-
 drivers/acpi/Makefile|2 +-
 drivers/acpi/acpi_dbg.c  |   80 --
 drivers/acpi/bus.c   |3 +-
 drivers/acpi/osl.c   |  207 --
 include/linux/acpi.h |   71 
 include/linux/acpi_dbg.h |   52 
 7 files changed, 338 insertions(+), 89 deletions(-)
 delete mode 100644 include/linux/acpi_dbg.h

diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 4de3517..c4d4a05 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -60,13 +60,23 @@ config ACPI_CCA_REQUIRED
 config ACPI_DEBUGGER
bool "In-kernel debugger"
select ACPI_DEBUG
-   depends on DEBUG_FS
help
  Enable in-kernel debugging facilities: statistics, internal
  object dump, single step control method execution.
  This is still under development, currently enabling this only
  results in the compilation of the ACPICA debugger files.
 
+if ACPI_DEBUGGER
+
+config ACPI_DEBUGGER_USER
+   tristate "Userspace debugger accessiblity"
+   depends on DEBUG_FS
+   help
+ Export /sys/kernel/debug/acpi/acpidbg for userspace utilities
+ to access the debugger functionalities.
+
+endif
+
 config ACPI_SLEEP
bool
depends on SUSPEND || HIBERNATION
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 102b5e6..c6f236f 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -50,7 +50,6 @@ acpi-y+= sysfs.o
 acpi-y += property.o
 acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
 acpi-$(CONFIG_DEBUG_FS)+= debugfs.o
-acpi-$(CONFIG_ACPI_DEBUGGER)   += acpi_dbg.o
 acpi-$(CONFIG_ACPI_NUMA)   += numa.o
 acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
 acpi-y += acpi_lpat.o
@@ -80,6 +79,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o
 obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o
 obj-$(CONFIG_ACPI_BGRT)+= bgrt.o
 obj-$(CONFIG_ACPI_CPPC_LIB)+= cppc_acpi.o
+obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
 
 # processor has its own "processor." module_param namespace
 processor-y:= processor_driver.o
diff --git a/drivers/acpi/acpi_dbg.c b/drivers/acpi/acpi_dbg.c
index abc23b2..381beb2 100644
--- a/drivers/acpi/acpi_dbg.c
+++ b/drivers/acpi/acpi_dbg.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include "internal.h"
 
 #define ACPI_AML_BUF_ALIGN (sizeof (acpi_size))
@@ -307,7 +307,7 @@ static int acpi_aml_readb_kern(void)
  * the debugger output and store the output into the debugger interface
  * buffer. Return the size of stored logs or errno.
  */
-ssize_t acpi_aml_write_log(const char *msg)
+static ssize_t acpi_aml_write_log(const char *msg)
 {
int ret = 0;
int count = 0, size = 0;
@@ -337,7 +337,6 @@ again:
}
return size > 0 ? size : ret;
 }
-EXPORT_SYMBOL(acpi_aml_write_log);
 
 /*
  * acpi_aml_read_cmd() - Capture debugger input
@@ -348,7 +347,7 @@ EXPORT_SYMBOL(acpi_aml_write_log);
  * the debugger input commands and store the input commands into the
  * debugger interface buffer. Return the size of stored commands or errno.
  */
-ssize_t acpi_aml_read_cmd(char *msg, size_t count)
+static ssize_t acpi_aml_read_cmd(char *msg, size_t count)
 {
int ret = 0;
int size = 0;
@@ -390,7 +389,6 @@ again:
}
return size > 0 ? size : ret;
 }
-EXPORT_SYMBOL(acpi_aml_read_cmd);
 
 static int acpi_aml_thread(void *unsed)
 {
@@ -427,7 +425,7 @@ static int acpi_aml_thread(void *unsed)
  * This function should be used to implement acpi_os_execute() which is
  * used by the ACPICA debugger to create the debugger thread.
  */
-int acpi_aml_create_thread(acpi_osd_exec_callback function, void *context)
+static int acpi_aml_create_thread(acpi_osd_exec_callback function, void 
*context)
 {
struct task_struct *t;
 
@@ -449,30 +447,27 @@ int acpi_aml_create_thread(acpi_osd_exec_callback 
function, void *context)
mutex_unlock(_aml_io.lock);
return 0;
 }
-EXPORT_SYMBOL(acpi_aml_create_thread);
 
-int acpi_aml_wait_command_ready(void)
+static int acpi_aml_wait_command_ready(bool single_step,
+  char *buffer, size_t length)
 {
acpi_status status;
 
-   if (!acpi_gbl_method_executing)
-   acpi_os_printf("\n%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
-   else
+   if (single_step)
acpi_os_printf("\n%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
+   else
+   acpi_os_printf("\n%1c ", 

[PATCH v3 6/6] ACPI / debugger: Add module support for ACPI debugger

2015-11-18 Thread Lv Zheng
This patch converts AML debugger into a loadable module.

Note that, it implements driver unloading at the level dependent on the
module reference count. Which means if ACPI debugger is being used by a
userspace program, "rmmod acpi_dbg" should result in failure.

Signed-off-by: Lv Zheng 
---
 drivers/acpi/Kconfig |   12 ++-
 drivers/acpi/Makefile|2 +-
 drivers/acpi/acpi_dbg.c  |   80 --
 drivers/acpi/bus.c   |3 +-
 drivers/acpi/osl.c   |  207 --
 include/linux/acpi.h |   71 
 include/linux/acpi_dbg.h |   52 
 7 files changed, 338 insertions(+), 89 deletions(-)
 delete mode 100644 include/linux/acpi_dbg.h

diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 4de3517..c4d4a05 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -60,13 +60,23 @@ config ACPI_CCA_REQUIRED
 config ACPI_DEBUGGER
bool "In-kernel debugger"
select ACPI_DEBUG
-   depends on DEBUG_FS
help
  Enable in-kernel debugging facilities: statistics, internal
  object dump, single step control method execution.
  This is still under development, currently enabling this only
  results in the compilation of the ACPICA debugger files.
 
+if ACPI_DEBUGGER
+
+config ACPI_DEBUGGER_USER
+   tristate "Userspace debugger accessiblity"
+   depends on DEBUG_FS
+   help
+ Export /sys/kernel/debug/acpi/acpidbg for userspace utilities
+ to access the debugger functionalities.
+
+endif
+
 config ACPI_SLEEP
bool
depends on SUSPEND || HIBERNATION
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 102b5e6..c6f236f 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -50,7 +50,6 @@ acpi-y+= sysfs.o
 acpi-y += property.o
 acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
 acpi-$(CONFIG_DEBUG_FS)+= debugfs.o
-acpi-$(CONFIG_ACPI_DEBUGGER)   += acpi_dbg.o
 acpi-$(CONFIG_ACPI_NUMA)   += numa.o
 acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
 acpi-y += acpi_lpat.o
@@ -80,6 +79,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o
 obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o
 obj-$(CONFIG_ACPI_BGRT)+= bgrt.o
 obj-$(CONFIG_ACPI_CPPC_LIB)+= cppc_acpi.o
+obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
 
 # processor has its own "processor." module_param namespace
 processor-y:= processor_driver.o
diff --git a/drivers/acpi/acpi_dbg.c b/drivers/acpi/acpi_dbg.c
index abc23b2..381beb2 100644
--- a/drivers/acpi/acpi_dbg.c
+++ b/drivers/acpi/acpi_dbg.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include "internal.h"
 
 #define ACPI_AML_BUF_ALIGN (sizeof (acpi_size))
@@ -307,7 +307,7 @@ static int acpi_aml_readb_kern(void)
  * the debugger output and store the output into the debugger interface
  * buffer. Return the size of stored logs or errno.
  */
-ssize_t acpi_aml_write_log(const char *msg)
+static ssize_t acpi_aml_write_log(const char *msg)
 {
int ret = 0;
int count = 0, size = 0;
@@ -337,7 +337,6 @@ again:
}
return size > 0 ? size : ret;
 }
-EXPORT_SYMBOL(acpi_aml_write_log);
 
 /*
  * acpi_aml_read_cmd() - Capture debugger input
@@ -348,7 +347,7 @@ EXPORT_SYMBOL(acpi_aml_write_log);
  * the debugger input commands and store the input commands into the
  * debugger interface buffer. Return the size of stored commands or errno.
  */
-ssize_t acpi_aml_read_cmd(char *msg, size_t count)
+static ssize_t acpi_aml_read_cmd(char *msg, size_t count)
 {
int ret = 0;
int size = 0;
@@ -390,7 +389,6 @@ again:
}
return size > 0 ? size : ret;
 }
-EXPORT_SYMBOL(acpi_aml_read_cmd);
 
 static int acpi_aml_thread(void *unsed)
 {
@@ -427,7 +425,7 @@ static int acpi_aml_thread(void *unsed)
  * This function should be used to implement acpi_os_execute() which is
  * used by the ACPICA debugger to create the debugger thread.
  */
-int acpi_aml_create_thread(acpi_osd_exec_callback function, void *context)
+static int acpi_aml_create_thread(acpi_osd_exec_callback function, void 
*context)
 {
struct task_struct *t;
 
@@ -449,30 +447,27 @@ int acpi_aml_create_thread(acpi_osd_exec_callback 
function, void *context)
mutex_unlock(_aml_io.lock);
return 0;
 }
-EXPORT_SYMBOL(acpi_aml_create_thread);
 
-int acpi_aml_wait_command_ready(void)
+static int acpi_aml_wait_command_ready(bool single_step,
+  char *buffer, size_t length)
 {
acpi_status status;
 
-   if (!acpi_gbl_method_executing)
-   acpi_os_printf("\n%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
-   else
+   if (single_step)
acpi_os_printf("\n%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
+   else
+   acpi_os_printf("\n%1c ",