Re: [PATCH v4 4/7] ACPI / debugger: Add IO interface to access debugger functionalities

2015-12-03 Thread Rafael J. Wysocki
On Thursday, December 03, 2015 02:27:41 PM Andy Lutomirski wrote:
> On Wed, Dec 2, 2015 at 6:43 PM, Lv Zheng  wrote:
> > This patch adds /sys/kernel/debug/acpi/acpidbg, which can be used by
> > userspace programs to access ACPICA debugger functionalities.
> 
> What's this one generated against?  My Kconfig contains:
> 
> config ACPI_DEBUGGER
> bool "In-kernel debugger (EXPERIMENTAL)"
> select ACPI_DEBUG
> 
> which isn't quite the same as what you generated this against.  I'm
> starting with 4.4-rc3.

Probably on top of linux-next (or my linux-next branch).

There's a fix commit against Kconfig in my tree which is going to be pushed
for 4.4-rc4 tomorrow.

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 4/7] ACPI / debugger: Add IO interface to access debugger functionalities

2015-12-03 Thread Andy Lutomirski
On Wed, Dec 2, 2015 at 6:43 PM, Lv Zheng  wrote:
> This patch adds /sys/kernel/debug/acpi/acpidbg, which can be used by
> userspace programs to access ACPICA debugger functionalities.

What's this one generated against?  My Kconfig contains:

config ACPI_DEBUGGER
bool "In-kernel debugger (EXPERIMENTAL)"
select ACPI_DEBUG

which isn't quite the same as what you generated this against.  I'm
starting with 4.4-rc3.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 4/7] ACPI / debugger: Add IO interface to access debugger functionalities

2015-12-02 Thread Lv Zheng
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  |3 +-
 drivers/acpi/Makefile |1 +
 drivers/acpi/acpi_dbg.c   |  779 +
 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, 887 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 5eef4cb..2a7e6d4 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -58,8 +58,9 @@ config ACPI_CCA_REQUIRED
bool
 
 config ACPI_DEBUGGER
-   bool "AML debugger interface (EXPERIMENTAL)"
+   bool "AML debugger interface"
select ACPI_DEBUG
+   depends on DEBUG_FS
help
  Enable in-kernel debugging of AML facilities: statistics, internal
  object dump, single step control method execution.
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..abc23b2
--- /dev/null
+++ b/drivers/acpi/acpi_dbg.c
@@ -0,0 +1,779 @@
+/*
+ * 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 debug