[RFC PATCH v2 3/5] ACPI / debugger: Add IO interface to access debugger functionalities
This patch adds /sys/kernel/debug/acpi/acpidbg, which can be used by userspace programs to access ACPICA debugger functionalities. Known issue: 1. IO flush support acpi_os_notify_command_complete() and acpi_os_wait_command_ready() can be used by acpi_dbg module to implement .flush() filesystem operation. While this patch doesn't go that far. It then becomes userspace tool's duty now to flush old commands before executing new batch mode commands. Signed-off-by: Lv Zheng --- drivers/acpi/Kconfig |2 +- drivers/acpi/Makefile |1 + drivers/acpi/acpi_dbg.c | 792 + drivers/acpi/bus.c|2 + drivers/acpi/osl.c| 55 ++- include/acpi/platform/aclinux.h |2 - include/acpi/platform/aclinuxex.h | 10 - include/linux/acpi_dbg.h | 52 +++ 8 files changed, 899 insertions(+), 17 deletions(-) create mode 100644 drivers/acpi/acpi_dbg.c create mode 100644 include/linux/acpi_dbg.h diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 25dbb76..2b89fd7 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -58,7 +58,7 @@ config ACPI_CCA_REQUIRED bool config ACPI_DEBUGGER - bool "In-kernel debugger (EXPERIMENTAL)" + bool "In-kernel debugger" select ACPI_DEBUG help Enable in-kernel debugging facilities: statistics, internal diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 675eaf3..102b5e6 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -50,6 +50,7 @@ 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 diff --git a/drivers/acpi/acpi_dbg.c b/drivers/acpi/acpi_dbg.c new file mode 100644 index 000..853ea94 --- /dev/null +++ b/drivers/acpi/acpi_dbg.c @@ -0,0 +1,792 @@ +/* + * ACPI AML interfacing support + * + * 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. + */ + +/* #define DEBUG */ +#define pr_fmt(fmt) "ACPI : AML: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +#define ACPI_AML_BUF_ALIGN (sizeof (acpi_size)) +#define ACPI_AML_BUF_SIZE PAGE_SIZE + +#define circ_count(circ) \ + (CIRC_CNT((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_count_to_end(circ) \ + (CIRC_CNT_TO_END((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_space(circ) \ + (CIRC_SPACE((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_space_to_end(circ) \ + (CIRC_SPACE_TO_END((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) + +#define ACPI_AML_OPENED0x0001 +#define ACPI_AML_CLOSED0x0002 +#define ACPI_AML_IN_USER 0x0004 /* user space is writing cmd */ +#define ACPI_AML_IN_KERN 0x0008 /* kernel space is reading cmd */ +#define ACPI_AML_OUT_USER 0x0010 /* user space is reading log */ +#define ACPI_AML_OUT_KERN 0x0020 /* kernel space is writing log */ +#define ACPI_AML_USER (ACPI_AML_IN_USER | ACPI_AML_OUT_USER) +#define ACPI_AML_KERN (ACPI_AML_IN_KERN | ACPI_AML_OUT_KERN) +#define ACPI_AML_BUSY (ACPI_AML_USER | ACPI_AML_KERN) +#define ACPI_AML_OPEN (ACPI_AML_OPENED | ACPI_AML_CLOSED) + +struct acpi_aml_io { + wait_queue_head_t wait; + unsigned long flags; + unsigned long users; + struct mutex lock; + struct task_struct *thread; + char out_buf[ACPI_AML_BUF_SIZE] __aligned(ACPI_AML_BUF_ALIGN); + struct circ_buf out_crc; + char in_buf[ACPI_AML_BUF_SIZE] __aligned(ACPI_AML_BUF_ALIGN); + struct circ_buf in_crc; + acpi_osd_exec_callback function; + void *context; + unsigned long usages; +}; + +static struct acpi_aml_io acpi_aml_io; +static bool acpi_aml_initialized; +static struct file *acpi_aml_active_reader; +static struct dentry *acpi_aml_dentry; + +static inline bool __acpi_aml_running(void) +{ + return acpi_aml_io.thread ? true : false; +} + +static inline bool __acpi_aml_access_ok(unsigned long flag) +{ + /* +* The debugger interface is in opened state (OPENED && !CLOSED), +* then it is allowed to access the debugger buffers from either +* user space or the kernel space. +* In addition, for the kernel space, only the debugger thread +* (thread ID matched) is allowed to access. +*/ + if
[RFC PATCH v2 3/5] ACPI / debugger: Add IO interface to access debugger functionalities
This patch adds /sys/kernel/debug/acpi/acpidbg, which can be used by userspace programs to access ACPICA debugger functionalities. Known issue: 1. IO flush support acpi_os_notify_command_complete() and acpi_os_wait_command_ready() can be used by acpi_dbg module to implement .flush() filesystem operation. While this patch doesn't go that far. It then becomes userspace tool's duty now to flush old commands before executing new batch mode commands. Signed-off-by: Lv Zheng--- drivers/acpi/Kconfig |2 +- drivers/acpi/Makefile |1 + drivers/acpi/acpi_dbg.c | 792 + drivers/acpi/bus.c|2 + drivers/acpi/osl.c| 55 ++- include/acpi/platform/aclinux.h |2 - include/acpi/platform/aclinuxex.h | 10 - include/linux/acpi_dbg.h | 52 +++ 8 files changed, 899 insertions(+), 17 deletions(-) create mode 100644 drivers/acpi/acpi_dbg.c create mode 100644 include/linux/acpi_dbg.h diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 25dbb76..2b89fd7 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -58,7 +58,7 @@ config ACPI_CCA_REQUIRED bool config ACPI_DEBUGGER - bool "In-kernel debugger (EXPERIMENTAL)" + bool "In-kernel debugger" select ACPI_DEBUG help Enable in-kernel debugging facilities: statistics, internal diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 675eaf3..102b5e6 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -50,6 +50,7 @@ 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 diff --git a/drivers/acpi/acpi_dbg.c b/drivers/acpi/acpi_dbg.c new file mode 100644 index 000..853ea94 --- /dev/null +++ b/drivers/acpi/acpi_dbg.c @@ -0,0 +1,792 @@ +/* + * ACPI AML interfacing support + * + * 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. + */ + +/* #define DEBUG */ +#define pr_fmt(fmt) "ACPI : AML: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +#define ACPI_AML_BUF_ALIGN (sizeof (acpi_size)) +#define ACPI_AML_BUF_SIZE PAGE_SIZE + +#define circ_count(circ) \ + (CIRC_CNT((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_count_to_end(circ) \ + (CIRC_CNT_TO_END((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_space(circ) \ + (CIRC_SPACE((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) +#define circ_space_to_end(circ) \ + (CIRC_SPACE_TO_END((circ)->head, (circ)->tail, ACPI_AML_BUF_SIZE)) + +#define ACPI_AML_OPENED0x0001 +#define ACPI_AML_CLOSED0x0002 +#define ACPI_AML_IN_USER 0x0004 /* user space is writing cmd */ +#define ACPI_AML_IN_KERN 0x0008 /* kernel space is reading cmd */ +#define ACPI_AML_OUT_USER 0x0010 /* user space is reading log */ +#define ACPI_AML_OUT_KERN 0x0020 /* kernel space is writing log */ +#define ACPI_AML_USER (ACPI_AML_IN_USER | ACPI_AML_OUT_USER) +#define ACPI_AML_KERN (ACPI_AML_IN_KERN | ACPI_AML_OUT_KERN) +#define ACPI_AML_BUSY (ACPI_AML_USER | ACPI_AML_KERN) +#define ACPI_AML_OPEN (ACPI_AML_OPENED | ACPI_AML_CLOSED) + +struct acpi_aml_io { + wait_queue_head_t wait; + unsigned long flags; + unsigned long users; + struct mutex lock; + struct task_struct *thread; + char out_buf[ACPI_AML_BUF_SIZE] __aligned(ACPI_AML_BUF_ALIGN); + struct circ_buf out_crc; + char in_buf[ACPI_AML_BUF_SIZE] __aligned(ACPI_AML_BUF_ALIGN); + struct circ_buf in_crc; + acpi_osd_exec_callback function; + void *context; + unsigned long usages; +}; + +static struct acpi_aml_io acpi_aml_io; +static bool acpi_aml_initialized; +static struct file *acpi_aml_active_reader; +static struct dentry *acpi_aml_dentry; + +static inline bool __acpi_aml_running(void) +{ + return acpi_aml_io.thread ? true : false; +} + +static inline bool __acpi_aml_access_ok(unsigned long flag) +{ + /* +* The debugger interface is in opened state (OPENED && !CLOSED), +* then it is allowed to access the debugger buffers from either +* user space or the kernel space. +* In addition, for the kernel space, only the debugger thread +* (thread ID matched) is allowed to access.