All of lore.kernel.org
 help / color / mirror / Atom feed
* Introduce acpi_validate and ec_acces in tools/power/acpi
@ 2014-04-07 13:16 Thomas Renninger
  2014-04-07 13:16 ` [PATCH 1/4] tools/power/acpi: Minor bugfixes Thomas Renninger
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Thomas Renninger @ 2014-04-07 13:16 UTC (permalink / raw)
  To: rjw; +Cc: lv.zheng, linux-acpi

Hi Rafael,

these are tools we already have packaged in our acpica package for quite
a while:
  - acpi_validate  (disassemble and recompile dumped ACPI tables, or a
                    provided acpidump file. It references all SSDTs/DSDTs,
                    which people often do not know or is cumbersome to do).
  - ec_access       is the userspace tool for the ec_sys EC debug driver.
                    Formerly only the thinkpad_acpi driver could do this.
                    This got proplery moved into a ec_sys debug driver and
                    ec_access can monitor changes e.g. every second of the
                    EC registers, nicely shows them to find out about
                    EC problems.

IMO both perfectly fit into tools/power/acpi.
Other candidates could be:
  - acpi_genl       (Monitor ACPI events)
                    https://01.org/linux-acpi/utilities
  - wmidump         This one can interpret WMI objects from a raw _WDG
                    buffer (part of DSDT/SSDT BIOS code).

I didn't use the last one often, but it seem to be really useful if you
implement ACPI WMI stuff.

If you agree with these patches, can you please queue them up for the
next kernel release, please.

Tested: Created a tarball with tools/power/acpi directory added and
        include/acpi copied into and build them separately as a package via
        our build service via:
make -C %{acpi_tools_dir} CFLAGS="-DDEFINE_ALTERNATE_TYPES
        -DACPI_USE_SYSTEM_INTTYPES=0 -I ../../include %{optflags}"
make -C %{acpi_tools_dir} install DESTDIR="%{buildroot}" mandir=%{_mandir}


Thanks a lot,

      Thomas


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] tools/power/acpi: Minor bugfixes
  2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
@ 2014-04-07 13:16 ` Thomas Renninger
  2014-04-08  2:19   ` Zheng, Lv
  2014-04-07 13:16 ` [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory Thomas Renninger
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Thomas Renninger @ 2014-04-07 13:16 UTC (permalink / raw)
  To: rjw; +Cc: lv.zheng, linux-acpi, Thomas Renninger

- bindir is created, but sbindir is used -> fix that
- the debug parts are there twice (copy paste bug?). Remove one of the
  exact same parts

Signed-off-by: Thomas Renninger <trenn@suse.de>
---
 tools/power/acpi/Makefile |   11 +----------
 1 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index d9186a2..c2c0f20 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -89,15 +89,6 @@ else
 	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
 endif
 
-# if DEBUG is enabled, then we do not strip or optimize
-ifeq ($(strip $(DEBUG)),true)
-	CFLAGS += -O1 -g -DDEBUG
-	STRIPCMD = /bin/true -Since_we_are_debugging
-else
-	CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
-	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
-endif
-
 # --- ACPIDUMP BEGIN ---
 
 vpath %.c \
@@ -128,7 +119,7 @@ clean:
 	-rm -f $(OUTPUT)acpidump
 
 install-tools:
-	$(INSTALL) -d $(DESTDIR)${bindir}
+	$(INSTALL) -d $(DESTDIR)${sbindir}
 	$(INSTALL_PROGRAM) $(OUTPUT)acpidump $(DESTDIR)${sbindir}
 
 install-man:
-- 
1.7.6.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory
  2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
  2014-04-07 13:16 ` [PATCH 1/4] tools/power/acpi: Minor bugfixes Thomas Renninger
@ 2014-04-07 13:16 ` Thomas Renninger
  2014-04-08  1:58   ` Zheng, Lv
  2014-04-07 13:16 ` [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables Thomas Renninger
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Thomas Renninger @ 2014-04-07 13:16 UTC (permalink / raw)
  To: rjw; +Cc: lv.zheng, linux-acpi, Thomas Renninger

Not sure why such a huge Makefile is needed to compile one file...
Anyway, I splitted up general variables/info and kept them in main
tools/power/acpi/Makefile
And created a new acpidump specific Makefile inside:
tools/power/acpi/tools/acpidump/Makefile

While this already is a cleanup worth by itself, I will add a new
tool making use of this new structure with a follow up submit.

Signed-off-by: Thomas Renninger <trenn@suse.de>
---
 tools/power/acpi/Makefile                |   94 +++++++++---------------------
 tools/power/acpi/tools/acpidump/Makefile |   27 +++++++++
 2 files changed, 55 insertions(+), 66 deletions(-)
 create mode 100644 tools/power/acpi/tools/acpidump/Makefile

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index c2c0f20..d97dada 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -8,28 +8,19 @@
 # as published by the Free Software Foundation; version 2
 # of the License.
 
-OUTPUT=./
-ifeq ("$(origin O)", "command line")
-	OUTPUT := $(O)/
-endif
-
-ifneq ($(OUTPUT),)
-# check that the output directory actually exists
-OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
-$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
-endif
+SUBDIRS = tools/acpidump
 
 # --- CONFIGURATION BEGIN ---
 
 # Set the following to `true' to make a unstripped, unoptimized
 # binary. Leave this set to `false' for production use.
-DEBUG ?=	true
+export DEBUG ?=	true
 
 # make the build silent. Set this to something else to make it noisy again.
 V ?=		false
 
 # Prefix to the directories we're installing to
-DESTDIR ?=
+export DESTDIR ?=
 
 # --- CONFIGURATION END ---
 
@@ -37,39 +28,37 @@ DESTDIR ?=
 # do not need to be changed. Please note that DESTDIR is
 # added in front of any of them
 
-bindir ?=	/usr/bin
-sbindir ?=	/usr/sbin
-mandir ?=	/usr/man
+export bindir ?=	/usr/bin
+export sbindir ?=	/usr/sbin
+export mandir ?=	/usr/man
 
 # Toolchain: what tools do we use, and what options do they need:
 
-INSTALL = /usr/bin/install -c
-INSTALL_PROGRAM = ${INSTALL}
-INSTALL_DATA  = ${INSTALL} -m 644
-INSTALL_SCRIPT = ${INSTALL_PROGRAM}
+export INSTALL = /usr/bin/install -c
+export INSTALL_PROGRAM = ${INSTALL}
+export INSTALL_DATA  = ${INSTALL} -m 644
+export INSTALL_SCRIPT = ${INSTALL_PROGRAM}
 
 # If you are running a cross compiler, you may want to set this
 # to something more interesting, like "arm-linux-".  If you want
 # to compile vs uClibc, that can be done here as well.
-CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
-CC = $(CROSS)gcc
-LD = $(CROSS)gcc
-STRIP = $(CROSS)strip
-HOSTCC = gcc
+export CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
+export CC = $(CROSS)gcc
+export LD = $(CROSS)gcc
+export STRIP = $(CROSS)strip
+export HOSTCC = gcc
 
 # check if compiler option is supported
 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
 
 # use '-Os' optimization if available, else use -O2
-OPTIMIZATION := $(call cc-supports,-Os,-O2)
+export OPTIMIZATION := $(call cc-supports,-Os,-O2)
 
-WARNINGS := -Wall
+export WARNINGS := -Wall
 WARNINGS += $(call cc-supports,-Wstrict-prototypes)
 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
 
-KERNEL_INCLUDE := ../../../include
-CFLAGS += -D_LINUX -DDEFINE_ALTERNATE_TYPES -I$(KERNEL_INCLUDE)
-CFLAGS += $(WARNINGS)
+export CFLAGS += $(WARNINGS)
 
 ifeq ($(strip $(V)),false)
 	QUIET=@
@@ -83,52 +72,25 @@ export QUIET ECHO
 # if DEBUG is enabled, then we do not strip or optimize
 ifeq ($(strip $(DEBUG)),true)
 	CFLAGS += -O1 -g -DDEBUG
-	STRIPCMD = /bin/true -Since_we_are_debugging
+	export STRIPCMD = /bin/true -Since_we_are_debugging
 else
 	CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
-	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
+	export STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
 endif
 
-# --- ACPIDUMP BEGIN ---
-
-vpath %.c \
-	tools/acpidump
-
-DUMP_OBJS = \
-	acpidump.o
-
-DUMP_OBJS := $(addprefix $(OUTPUT)tools/acpidump/,$(DUMP_OBJS))
+all: $(SUBDIRS)
+	$(foreach dir,$(SUBDIRS),make -C $(dir);)
 
-$(OUTPUT)acpidump: $(DUMP_OBJS)
-	$(ECHO) "  LD      " $@
-	$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $(DUMP_OBJS) -L$(OUTPUT) -o $@
-	$(QUIET) $(STRIPCMD) $@
-
-$(OUTPUT)tools/acpidump/%.o: %.c
-	$(ECHO) "  CC      " $@
-	$(QUIET) $(CC) -c $(CFLAGS) -o $@ $<
-
-# --- ACPIDUMP END ---
-
-all: $(OUTPUT)acpidump
-	echo $(OUTPUT)
 
 clean:
-	-find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
+	-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
 	 | xargs rm -f
-	-rm -f $(OUTPUT)acpidump
-
-install-tools:
-	$(INSTALL) -d $(DESTDIR)${sbindir}
-	$(INSTALL_PROGRAM) $(OUTPUT)acpidump $(DESTDIR)${sbindir}
-
-install-man:
-	$(INSTALL_DATA) -D man/acpidump.8 $(DESTDIR)${mandir}/man8/acpidump.8
+	$(foreach dir,$(SUBDIRS),make -C $(dir) clean;)
 
-install: all install-tools install-man
+install: 
+	$(foreach dir,$(SUBDIRS),make -C $(dir) install;)
 
 uninstall:
-	- rm -f $(DESTDIR)${sbindir}/acpidump
-	- rm -f $(DESTDIR)${mandir}/man8/acpidump.8
+	$(foreach dir,$(SUBDIRS),make -C $(dir) uninstall;)
 
-.PHONY: all utils install-tools install-man install uninstall clean
+.PHONY: all install uninstall clean
diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile
new file mode 100644
index 0000000..4d0f993
--- /dev/null
+++ b/tools/power/acpi/tools/acpidump/Makefile
@@ -0,0 +1,27 @@
+KERNEL_INCLUDE := ../../../../../include
+CFLAGS += -D_LINUX -DACPI_USE_SYSTEM_INTTYPES=0 -DDEFINE_ALTERNATE_TYPES -I$(KERNEL_INCLUDE)
+
+acpidump: acpidump.o
+	$(ECHO) "  LD      " $@
+	$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $< -o $@
+	$(QUIET) $(STRIPCMD) $@
+
+%.o: %.c
+	$(ECHO) "  CC      " $@
+	$(QUIET) $(CC) -c $(CFLAGS) -o $@ $<
+
+all: acpidump
+
+install: 
+	$(INSTALL) -d $(DESTDIR)${sbindir}
+	$(INSTALL_PROGRAM) acpidump $(DESTDIR)${sbindir}
+	$(INSTALL_DATA) -D ../../man/acpidump.8 $(DESTDIR)${mandir}/man8/acpidump.8
+
+uninstall:
+	- rm -f $(DESTDIR)${sbindir}/acpidump
+	- rm -f $(DESTDIR)${mandir}/man8/acpidump.8
+
+clean:
+	-rm -f $(OUTPUT)acpidump
+
+.PHONY: all install uninstall
-- 
1.7.6.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables
  2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
  2014-04-07 13:16 ` [PATCH 1/4] tools/power/acpi: Minor bugfixes Thomas Renninger
  2014-04-07 13:16 ` [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory Thomas Renninger
@ 2014-04-07 13:16 ` Thomas Renninger
  2014-04-08  2:34   ` Zheng, Lv
  2014-04-07 13:16 ` [PATCH 4/4] tools/power/acpi: Introduce ec_access.c - tool to access the Embedded Controller (EC) safely for debugging purposes Thomas Renninger
  2014-04-08  2:09 ` Introduce acpi_validate and ec_acces in tools/power/acpi Zheng, Lv
  4 siblings, 1 reply; 10+ messages in thread
From: Thomas Renninger @ 2014-04-07 13:16 UTC (permalink / raw)
  To: rjw; +Cc: lv.zheng, linux-acpi, Thomas Renninger

The used iasl compiler shares the same code base as the kernel.
Warnings or errors mostly point to bad BIOSes.
These errors should get reported to the BIOS vendors and may indicated that
acpica (kernel ACPI parts) need compatibility adjustings.


Why is an extra tool needed for this?

The dynamic ACPI Source Language (ASL) parts are located in DSDT and often
multiple SSDT tables. Those often have dependencies to each other and the iasl
compiler often cannot resolve external symbols correctly if they are not
passed as external tables (iasl -e option) when tables get disassembled.
This quickly leads to false positive errors.
This tool makes sure disassembling and recompilation is done correctly.

This tool is also made for ACPI BIOS table verification for BIOS vendors and
hardware certification tools for distributions.
Hardware which supports Linux must/should not show any warnings or errors.
Remarks and optimization hints in the logs can be used to further enhance
the ACPI BIOS code.
Warnings and errors mostly describe the issues in a way, so that they can
get passed to and used by BIOS developers to fix the problems easily.

Signed-off-by: Thomas Renninger <trenn@suse.de>
---
 tools/power/acpi/Makefile            |    3 +
 tools/power/acpi/man/acpidump.8      |    3 +
 tools/power/acpi/tools/acpi_validate |  201 ++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+), 0 deletions(-)
 create mode 100755 tools/power/acpi/tools/acpi_validate

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index d97dada..a033cfe 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -89,8 +89,11 @@ clean:
 
 install: 
 	$(foreach dir,$(SUBDIRS),make -C $(dir) install;)
+	$(INSTALL_PROGRAM) -D tools/acpi_validate $(DESTDIR)${bindir}/acpi_validate
+
 
 uninstall:
 	$(foreach dir,$(SUBDIRS),make -C $(dir) uninstall;)
+	- rm -f $(DESTDIR)${bindir}/acpi_validate
 
 .PHONY: all install uninstall clean
diff --git a/tools/power/acpi/man/acpidump.8 b/tools/power/acpi/man/acpidump.8
index adfa991..302b602 100644
--- a/tools/power/acpi/man/acpidump.8
+++ b/tools/power/acpi/man/acpidump.8
@@ -53,6 +53,9 @@ ACPICA: https://acpica.org/
 /sys/firmware/acpi/tables/dynamic/*
 .fi
 
+.SH "SEE ALSO"
+.BR acpi_validate (8)
+
 .PP
 .SH AUTHOR
 .nf
diff --git a/tools/power/acpi/tools/acpi_validate b/tools/power/acpi/tools/acpi_validate
new file mode 100755
index 0000000..40701bf
--- /dev/null
+++ b/tools/power/acpi/tools/acpi_validate
@@ -0,0 +1,201 @@
+#!/bin/bash
+#
+# Copyright (c) 2012 SUSE Linux Products GmbH
+# Thomas Renninger <trenn@suse.de>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+#
+                                                                             
+OUTPUT_DIR="$PWD"
+VERBOSE=0
+# Disable remarks and resource checks. The latter often/mostly generates
+# false positive warnings. Can be overridden via -c option
+COMPILE_OPTIONS="-sa -cr -vr -in"
+DISASSEMBLE_OPTIONS="-in"
+OUTPUT="/dev/null"
+ACPIDUMP=""
+MUST_BE_ROOT=1
+
+function usage()
+{
+    echo "acpi_validate [ -o output_dir ] [ -v ] [ -a acpidump ]"
+    echo "              [ -c compile_options ] [ -d disassemble_options ]"
+    echo
+    echo "This tool extracts, disassembles and recompiles ACPI BIOS tables."
+    echo "The disassembled files will be copied into the local or specified"
+    echo "output directory (-o option)."
+    echo
+    echo "The underlying iasl compiler verifies and may complain about"
+    echo "correctness of some of the BIOS tables."
+    echo "These can give a pointer to possible malfunction of the system."
+    echo
+    echo "If you think you found a bug in the iasl compiler or related tools,"
+    echo "you can ask here for help: devel@acpica.org"
+    echo "You may also want to ask there if you are not sure whether it really"
+    echo "is a BIOS bug."
+    echo
+    echo "If you are sure you found a BIOS issue, complain to your hardware vendor."
+    echo "The iasl compiler typically provides a description of the warning/error in a way,"
+    echo "so that BIOS authors can easily fix it."
+    echo
+    echo "Options"
+    echo "   -o output_dir: Copy tables to this directory instead of local one"
+    echo "   -v:          : be more verbose"
+    echo "   -a acpidump  : Use this acpidump file"
+    echo "                  instead of the tables from the local machine"
+    echo "   -d options   : Pass iasl disassemble options"
+    echo "   -c options   : Pass iasl compile options"
+    echo "                  will override -sa -cr -vr (default options)"
+    echo "   -h           : Show help"
+    exit 1
+}
+
+while getopts hva:o:c:d: name ; do
+    case $name in
+        o)
+	    OUTPUT_DIR="$OPTARG"
+	    if [ ! -d "$OUTPUT_DIR" ];then
+		mkdir "$OUTPUT_DIR"
+		if [[ $? != 0 ]];then
+		    echo "Cannot create directory $OUTPUT_DIR"
+		    exit 1
+		fi
+	    elif [ ! -w "$OUTPUT_DIR" ];then
+		echo "Cannot write into directory $OUTPUT_DIR"
+		exit 1
+	    fi
+
+	    [[ $VERBOSE == 1 ]] && echo "Installing for architecture: $OUTPUT_DIR"
+	    ;;
+        a)
+	    ACPIDUMP="$OPTARG"
+	    if [ ! -r "$ACPIDUMP" ];then
+		echo "$ACPIDUMP does not exist"
+		exit 1
+	    fi
+	    [[ $VERBOSE == 1 ]] && echo "acpidump file: $ACPIDUMP"
+	    MUST_BE_ROOT=0
+	    ;;
+        c)
+	    COMPILE_OPTIONS="$OPTARG"
+	    [[ $VERBOSE == 1 ]] && echo "Compile options: $COMPILE_OPTIONS"
+	    ;;
+        c)
+	    DISASSEMBLE_OPTIONS="$OPTARG"
+	    [[ $VERBOSE == 1 ]] && echo "Disassemble options: $DISASSEMBLE_OPTIONS"
+	    ;;
+        v)
+            VERBOSE=1
+	    OUTPUT="1"
+            ;;
+        ?)
+	    usage
+	    ;;
+    esac
+done
+shift $(($OPTIND -1))
+
+if [[ $MUST_BE_ROOT == 1 ]] && [ "$(id -u)" != "0" ]; then
+   echo "This script must be run as root"
+   echo "(or use -a acpidump option and pass already dumped acpi tables)"
+   exit 1
+fi
+
+shopt -s nocasematch
+TEMP_DIR=$(mktemp -d)
+[[ $VERBOSE == 1 ]] && echo "Using temporary directory: $TEMP_DIR"
+
+if [ -r "$ACPIDUMP" ];then
+    cp "$ACPIDUMP" "$TEMP_DIR"/acpidump
+fi
+
+pushd "$TEMP_DIR" >/dev/null
+
+mkdir log
+mkdir err
+if [ ! -r acpidump ];then
+    acpidump >acpidump
+fi
+acpixtract -a acpidump >&$OUTPUT 2>&1
+
+
+# ACPICA changed from uppercase to lowercase, try to find both:
+SDTs=$(ls [SD]DST*.dat 2>/dev/null)
+SDTs="${SDTs}$(ls [sd]sdt*.dat 2>/dev/null)"
+
+for file in *.dat;do
+    table=${file/.dat/}
+    # Enable case insensitive pattern matching
+
+    case $file in
+	[DS]SDT*.dat | [sd]sdt*.dat)
+		# Use other [sd]sdt*.dat tables to reference possible
+		# external symbols. Pass the table itself for disassembling
+		# comma separted.
+		# For example you we have:
+		# dsdt.dat ssdt1 ssdt2.dat
+		# and the current table to disassemble is ssdt1.dat the
+		# command has to be:
+		# iasl -e dsdt.dat,ssdt2.dat -d ssdt1.dat
+
+		# Get rid of the table which gets disassembled
+		# could have leading or trailing whitespace depending whether
+		# it is at the end or the beginning of the list
+		REF_TABLE_LIST=${SDTs/[[:space:]]$file/}
+		REF_TABLE_LIST=${REF_TABLE_LIST/$file[[:space:]]/}
+		# Convert the whitespace list into a comma separated one:
+		REF_TABLE_LIST=${REF_TABLE_LIST//[[:space:]]/,}
+		if [ "$REF_TABLE_LIST" != "" ];then
+		    FINAL_DISASSEMBLE_OPTIONS="-e ${REF_TABLE_LIST} $DISASSEMBLE_OPTIONS"
+		else
+		    FINAL_DISASSEMBLE_OPTIONS="$DISASSEMBLE_OPTIONS"
+		fi
+		echo "stdout and stderr of $file disassembling:" >log/${table}.log
+		[[ $VERBOSE == 1 ]] && echo "iasl $FINAL_DISASSEMBLE_OPTIONS -d $file 1>>log/${table}.log 2>&1"
+		iasl $FINAL_DISASSEMBLE_OPTIONS -d $file 1>>log/${table}.log 2>&1
+		[[ $VERBOSE == 1 ]] && echo "iasl $COMPILE_OPTIONS ${table}.dsl 1>>log/${table}.log 2>>err/${table}.err"
+		iasl $COMPILE_OPTIONS ${table}.dsl 1>>log/${table}.log 2>>err/${table}.err
+		;;
+	*.dat)
+		iasl -d $file 1>log/${table}.log 2>&1
+		iasl -sa ${table}.dsl 1>log/${table}.log 2>err/${table}.err
+		;;
+    esac
+done
+
+# remove empty error files
+rm $(find err -size 0)
+ERR_TABLES=$(ls err)
+ERR_TABLES=${ERR_TABLES//.err/}
+
+popd >/dev/null
+cp -r "$TEMP_DIR"/* "$OUTPUT_DIR"
+
+if [[ $VERBOSE == 1 ]];then
+    echo "Temporary directory (undeleted): $TEMP_DIR"
+else
+    rm -rf "$TEMP_DIR"
+fi
+
+if [ "$ERR_TABLES" = "" ];then
+    echo "No errors or warnings detected"
+    exit 0
+else
+    echo "These tables have warnings or errors (details in "$OUTPUT_DIR"/err directory):"
+    for err in $ERR_TABLES;do
+	echo -n $err $'\t'
+	sed -n -e 's/Compilation complete. \(.* Errors, .* Warnings\).*/\1/p' "$OUTPUT_DIR"/log/$err.log
+    done
+    exit 1
+fi
-- 
1.7.6.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] tools/power/acpi: Introduce ec_access.c - tool to access the Embedded Controller (EC) safely for debugging purposes
  2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
                   ` (2 preceding siblings ...)
  2014-04-07 13:16 ` [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables Thomas Renninger
@ 2014-04-07 13:16 ` Thomas Renninger
  2014-04-08  2:09 ` Introduce acpi_validate and ec_acces in tools/power/acpi Zheng, Lv
  4 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2014-04-07 13:16 UTC (permalink / raw)
  To: rjw; +Cc: lv.zheng, linux-acpi, Thomas Renninger

This userspace tool accesses the EC through the ec_sys debug driver
(through /sys/kernel/debug/ec/ec0/io).
The EC command/data registers cannot be accessed directly, because they could
get accessed by the ACPI interpreter in parallel.
The ec_sys driver synchronizes userspace (debug) access with the ACPI
interpreter.

Signed-off-by: Thomas Renninger <trenn@suse.de>
---
 tools/power/acpi/Makefile             |    2 +-
 tools/power/acpi/tools/ec/Makefile    |   22 +++
 tools/power/acpi/tools/ec/ec_access.c |  238 +++++++++++++++++++++++++++++++++
 3 files changed, 261 insertions(+), 1 deletions(-)
 create mode 100644 tools/power/acpi/tools/ec/Makefile
 create mode 100644 tools/power/acpi/tools/ec/ec_access.c

diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index a033cfe..690b938 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -8,7 +8,7 @@
 # as published by the Free Software Foundation; version 2
 # of the License.
 
-SUBDIRS = tools/acpidump
+SUBDIRS = tools/acpidump tools/ec
 
 # --- CONFIGURATION BEGIN ---
 
diff --git a/tools/power/acpi/tools/ec/Makefile b/tools/power/acpi/tools/ec/Makefile
new file mode 100644
index 0000000..7c2a69c
--- /dev/null
+++ b/tools/power/acpi/tools/ec/Makefile
@@ -0,0 +1,22 @@
+ec_access: ec_access.o
+	$(ECHO) "  LD      " $@
+	$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $< -o $@
+	$(QUIET) $(STRIPCMD) $@
+
+%.o: %.c
+	$(ECHO) "  CC      " $@
+	$(QUIET) $(CC) -c $(CFLAGS) -o $@ $<
+
+all: ec_access
+
+install: 
+	$(INSTALL) -d $(DESTDIR)${sbindir}
+	$(INSTALL_PROGRAM) ec_access $(DESTDIR)${sbindir}
+
+uninstall:
+	- rm -f $(DESTDIR)${sbindir}/ec_access
+
+clean:
+	-rm -f $(OUTPUT)ec_access
+
+.PHONY: all install uninstall
diff --git a/tools/power/acpi/tools/ec/ec_access.c b/tools/power/acpi/tools/ec/ec_access.c
new file mode 100644
index 0000000..6b8aaed
--- /dev/null
+++ b/tools/power/acpi/tools/ec/ec_access.c
@@ -0,0 +1,238 @@
+/*
+ * ec_access.c
+ *
+ * Copyright (C) 2010 SUSE Linux Products GmbH
+ * Author:
+ *      Thomas Renninger <trenn@suse.de>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ */
+
+#include <fcntl.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
+#define EC_SPACE_SIZE 256
+#define SYSFS_PATH "/sys/kernel/debug/ec/ec0/io"
+
+/* TBD/Enhancements:
+   - Provide param for accessing different ECs (not supported by kernel yet)
+*/
+
+static int read_mode = -1;
+static int sleep_time;
+static int write_byte_offset = -1;
+static int read_byte_offset = -1;
+static uint8_t write_value = -1;
+
+void usage(char progname[], int exit_status)
+{
+	printf("Usage:\n");
+	printf("1) %s -r [-s sleep]\n", basename(progname));
+	printf("2) %s -b byte_offset\n", basename(progname));
+	printf("3) %s -w byte_offset -v value\n\n", basename(progname));
+
+	puts("\t-r [-s sleep]      : Dump EC registers");
+	puts("\t                     If sleep is given, sleep x seconds,");
+	puts("\t                     re-read EC registers and show changes");
+	puts("\t-b offset          : Read value at byte_offset (in hex)");
+	puts("\t-w offset -v value : Write value at byte_offset");
+	puts("\t-h                 : Print this help\n\n");
+	puts("Offsets and values are in hexadecimal number sytem.");
+	puts("The offset and value must be between 0 and 0xff.");
+	exit(exit_status);
+}
+
+void parse_opts(int argc, char *argv[])
+{
+	int c;
+
+	while ((c = getopt(argc, argv, "rs:b:w:v:h")) != -1) {
+
+		switch (c) {
+		case 'r':
+			if (read_mode != -1)
+				usage(argv[0], EXIT_FAILURE);
+			read_mode = 1;
+			break;
+		case 's':
+			if (read_mode != -1 && read_mode != 1)
+				usage(argv[0], EXIT_FAILURE);
+
+			sleep_time = atoi(optarg);
+			if (sleep_time <= 0) {
+				sleep_time = 0;
+				usage(argv[0], EXIT_FAILURE);
+				printf("Bad sleep time: %s\n", optarg);
+			}
+			break;
+		case 'b':
+			if (read_mode != -1)
+				usage(argv[0], EXIT_FAILURE);
+			read_mode = 1;
+			read_byte_offset = strtoul(optarg, NULL, 16);
+			break;
+		case 'w':
+			if (read_mode != -1)
+				usage(argv[0], EXIT_FAILURE);
+			read_mode = 0;
+			write_byte_offset = strtoul(optarg, NULL, 16);
+			break;
+		case 'v':
+			write_value = strtoul(optarg, NULL, 16);
+			break;
+		case 'h':
+			usage(argv[0], EXIT_SUCCESS);
+		default:
+			fprintf(stderr, "Unknown option!\n");
+			usage(argv[0], EXIT_FAILURE);
+		}
+	}
+	if (read_mode == 0) {
+		if (write_byte_offset < 0 ||
+		    write_byte_offset >= EC_SPACE_SIZE) {
+			fprintf(stderr, "Wrong byte offset 0x%.2x, valid: "
+				"[0-0x%.2x]\n",
+				write_byte_offset, EC_SPACE_SIZE - 1);
+			usage(argv[0], EXIT_FAILURE);
+		}
+		if (write_value < 0 ||
+		    write_value >= 255) {
+			fprintf(stderr, "Wrong byte offset 0x%.2x, valid:"
+				"[0-0xff]\n", write_byte_offset);
+			usage(argv[0], EXIT_FAILURE);
+		}
+	}
+	if (read_mode == 1 && read_byte_offset != -1) {
+		if (read_byte_offset < -1 ||
+		    read_byte_offset >= EC_SPACE_SIZE) {
+			fprintf(stderr, "Wrong byte offset 0x%.2x, valid: "
+				"[0-0x%.2x]\n",
+				read_byte_offset, EC_SPACE_SIZE - 1);
+			usage(argv[0], EXIT_FAILURE);
+		}
+	}
+	/* Add additional parameter checks here */
+}
+
+void dump_ec(int fd)
+{
+	char buf[EC_SPACE_SIZE];
+	char buf2[EC_SPACE_SIZE];
+	int byte_off, bytes_read;
+
+	bytes_read = read(fd, buf, EC_SPACE_SIZE);
+
+	if (bytes_read == -1)
+		err(EXIT_FAILURE, "Could not read from %s\n", SYSFS_PATH);
+
+	if (bytes_read != EC_SPACE_SIZE)
+		fprintf(stderr, "Could only read %d bytes\n", bytes_read);
+
+	printf("     00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E  0F");
+	for (byte_off = 0; byte_off < bytes_read; byte_off++) {
+		if ((byte_off % 16) == 0)
+			printf("\n%.2X: ", byte_off);
+		printf(" %.2x ", (uint8_t)buf[byte_off]);
+	}
+	printf("\n");
+
+	if (!sleep_time)
+		return;
+
+	printf("\n");
+	lseek(fd, 0, SEEK_SET);
+	sleep(sleep_time);
+
+	bytes_read = read(fd, buf2, EC_SPACE_SIZE);
+
+	if (bytes_read == -1)
+		err(EXIT_FAILURE, "Could not read from %s\n", SYSFS_PATH);
+
+	if (bytes_read != EC_SPACE_SIZE)
+		fprintf(stderr, "Could only read %d bytes\n", bytes_read);
+
+	printf("     00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E  0F");
+	for (byte_off = 0; byte_off < bytes_read; byte_off++) {
+		if ((byte_off % 16) == 0)
+			printf("\n%.2X: ", byte_off);
+
+		if (buf[byte_off] == buf2[byte_off])
+			printf(" %.2x ", (uint8_t)buf2[byte_off]);
+		else
+			printf("*%.2x ", (uint8_t)buf2[byte_off]);
+	}
+	printf("\n");
+}
+
+void read_ec_val(int fd, int byte_offset)
+{
+	uint8_t buf;
+	int error;
+
+	error = lseek(fd, byte_offset, SEEK_SET);
+	if (error != byte_offset)
+		err(EXIT_FAILURE, "Cannot set offset to 0x%.2x", byte_offset);
+
+	error = read(fd, &buf, 1);
+	if (error != 1)
+		err(EXIT_FAILURE, "Could not read byte 0x%.2x from %s\n",
+		    byte_offset, SYSFS_PATH);
+	printf("0x%.2x\n", buf);
+	return;
+}
+
+void write_ec_val(int fd, int byte_offset, uint8_t value)
+{
+	int error;
+
+	error = lseek(fd, byte_offset, SEEK_SET);
+	if (error != byte_offset)
+		err(EXIT_FAILURE, "Cannot set offset to 0x%.2x", byte_offset);
+
+	error = write(fd, &value, 1);
+	if (error != 1)
+		err(EXIT_FAILURE, "Cannot write value 0x%.2x to offset 0x%.2x",
+		    value, byte_offset);
+}
+
+int main(int argc, char *argv[])
+{
+	int file_mode = O_RDONLY;
+	int fd;
+
+	parse_opts(argc, argv);
+
+	if (read_mode == 0)
+		file_mode = O_WRONLY;
+	else if (read_mode == 1)
+		file_mode = O_RDONLY;
+	else
+		usage(argv[0], EXIT_FAILURE);
+
+	fd = open(SYSFS_PATH, file_mode);
+	if (fd == -1)
+		err(EXIT_FAILURE, "%s", SYSFS_PATH);
+
+	if (read_mode)
+		if (read_byte_offset == -1)
+			dump_ec(fd);
+		else if (read_byte_offset < 0 ||
+			 read_byte_offset >= EC_SPACE_SIZE)
+			usage(argv[0], EXIT_FAILURE);
+		else
+			read_ec_val(fd, read_byte_offset);
+	else
+		write_ec_val(fd, write_byte_offset, write_value);
+	close(fd);
+
+	exit(EXIT_SUCCESS);
+}
-- 
1.7.6.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* RE: [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory
  2014-04-07 13:16 ` [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory Thomas Renninger
@ 2014-04-08  1:58   ` Zheng, Lv
  0 siblings, 0 replies; 10+ messages in thread
From: Zheng, Lv @ 2014-04-08  1:58 UTC (permalink / raw)
  To: Thomas Renninger, rjw; +Cc: linux-acpi

Hi, Thomas

> From: Thomas Renninger [mailto:trenn@suse.de]
> Sent: Monday, April 07, 2014 9:17 PM
> 
> Not sure why such a huge Makefile is needed to compile one file...

The huge Makefile is generated to include release automation of ACPICA's acpidump.
It's no longer 1 file, but bunch of files that originally can only be found in ACPICA repo.
I noticed that Rafael had merged the 20140325 ACPICA release into the bleeding-edge branch.
So you need to rebase this series on top of linux-pm/bleeding-edge.

> Anyway, I splitted up general variables/info and kept them in main
> tools/power/acpi/Makefile
> And created a new acpidump specific Makefile inside:
> tools/power/acpi/tools/acpidump/Makefile
> 
> While this already is a cleanup worth by itself, I will add a new
> tool making use of this new structure with a follow up submit.
> 
> Signed-off-by: Thomas Renninger <trenn@suse.de>
> ---
>  tools/power/acpi/Makefile                |   94 +++++++++---------------------
>  tools/power/acpi/tools/acpidump/Makefile |   27 +++++++++
>  2 files changed, 55 insertions(+), 66 deletions(-)
>  create mode 100644 tools/power/acpi/tools/acpidump/Makefile
> 
> diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
> index c2c0f20..d97dada 100644
> --- a/tools/power/acpi/Makefile
> +++ b/tools/power/acpi/Makefile
> @@ -8,28 +8,19 @@
>  # as published by the Free Software Foundation; version 2
>  # of the License.
> 
> -OUTPUT=./
> -ifeq ("$(origin O)", "command line")
> -	OUTPUT := $(O)/
> -endif
> -
> -ifneq ($(OUTPUT),)
> -# check that the output directory actually exists
> -OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
> -$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
> -endif
> +SUBDIRS = tools/acpidump
> 
>  # --- CONFIGURATION BEGIN ---
> 
>  # Set the following to `true' to make a unstripped, unoptimized
>  # binary. Leave this set to `false' for production use.
> -DEBUG ?=	true
> +export DEBUG ?=	true
> 
>  # make the build silent. Set this to something else to make it noisy again.
>  V ?=		false
> 
>  # Prefix to the directories we're installing to
> -DESTDIR ?=
> +export DESTDIR ?=
> 
>  # --- CONFIGURATION END ---
> 
> @@ -37,39 +28,37 @@ DESTDIR ?=
>  # do not need to be changed. Please note that DESTDIR is
>  # added in front of any of them
> 
> -bindir ?=	/usr/bin
> -sbindir ?=	/usr/sbin
> -mandir ?=	/usr/man
> +export bindir ?=	/usr/bin
> +export sbindir ?=	/usr/sbin
> +export mandir ?=	/usr/man
> 
>  # Toolchain: what tools do we use, and what options do they need:
> 
> -INSTALL = /usr/bin/install -c
> -INSTALL_PROGRAM = ${INSTALL}
> -INSTALL_DATA  = ${INSTALL} -m 644
> -INSTALL_SCRIPT = ${INSTALL_PROGRAM}
> +export INSTALL = /usr/bin/install -c
> +export INSTALL_PROGRAM = ${INSTALL}
> +export INSTALL_DATA  = ${INSTALL} -m 644
> +export INSTALL_SCRIPT = ${INSTALL_PROGRAM}
> 
>  # If you are running a cross compiler, you may want to set this
>  # to something more interesting, like "arm-linux-".  If you want
>  # to compile vs uClibc, that can be done here as well.
> -CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
> -CC = $(CROSS)gcc
> -LD = $(CROSS)gcc
> -STRIP = $(CROSS)strip
> -HOSTCC = gcc
> +export CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
> +export CC = $(CROSS)gcc
> +export LD = $(CROSS)gcc
> +export STRIP = $(CROSS)strip
> +export HOSTCC = gcc
> 
>  # check if compiler option is supported
>  cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
> 
>  # use '-Os' optimization if available, else use -O2
> -OPTIMIZATION := $(call cc-supports,-Os,-O2)
> +export OPTIMIZATION := $(call cc-supports,-Os,-O2)
> 
> -WARNINGS := -Wall
> +export WARNINGS := -Wall
>  WARNINGS += $(call cc-supports,-Wstrict-prototypes)
>  WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
> 
> -KERNEL_INCLUDE := ../../../include
> -CFLAGS += -D_LINUX -DDEFINE_ALTERNATE_TYPES -I$(KERNEL_INCLUDE)
> -CFLAGS += $(WARNINGS)
> +export CFLAGS += $(WARNINGS)
> 
>  ifeq ($(strip $(V)),false)
>  	QUIET=@
> @@ -83,52 +72,25 @@ export QUIET ECHO
>  # if DEBUG is enabled, then we do not strip or optimize
>  ifeq ($(strip $(DEBUG)),true)
>  	CFLAGS += -O1 -g -DDEBUG
> -	STRIPCMD = /bin/true -Since_we_are_debugging
> +	export STRIPCMD = /bin/true -Since_we_are_debugging
>  else
>  	CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
> -	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
> +	export STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
>  endif
> 
> -# --- ACPIDUMP BEGIN ---
> -
> -vpath %.c \
> -	tools/acpidump

The "vpath" is required by the new acpidump.
As the new utility will reuse source files in the drivers/acpi/acpica folder to find ACPICA source code shared with this utility.

> -
> -DUMP_OBJS = \
> -	acpidump.o
> -
> -DUMP_OBJS := $(addprefix $(OUTPUT)tools/acpidump/,$(DUMP_OBJS))
> +all: $(SUBDIRS)
> +	$(foreach dir,$(SUBDIRS),make -C $(dir);)
> 
> -$(OUTPUT)acpidump: $(DUMP_OBJS)
> -	$(ECHO) "  LD      " $@
> -	$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $(DUMP_OBJS) -L$(OUTPUT) -o $@
> -	$(QUIET) $(STRIPCMD) $@
> -
> -$(OUTPUT)tools/acpidump/%.o: %.c
> -	$(ECHO) "  CC      " $@
> -	$(QUIET) $(CC) -c $(CFLAGS) -o $@ $<
> -
> -# --- ACPIDUMP END ---
> -
> -all: $(OUTPUT)acpidump
> -	echo $(OUTPUT)
> 
>  clean:
> -	-find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
> +	-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
>  	 | xargs rm -f
> -	-rm -f $(OUTPUT)acpidump
> -
> -install-tools:
> -	$(INSTALL) -d $(DESTDIR)${sbindir}
> -	$(INSTALL_PROGRAM) $(OUTPUT)acpidump $(DESTDIR)${sbindir}
> -
> -install-man:
> -	$(INSTALL_DATA) -D man/acpidump.8 $(DESTDIR)${mandir}/man8/acpidump.8
> +	$(foreach dir,$(SUBDIRS),make -C $(dir) clean;)
> 
> -install: all install-tools install-man
> +install:
> +	$(foreach dir,$(SUBDIRS),make -C $(dir) install;)
> 
>  uninstall:
> -	- rm -f $(DESTDIR)${sbindir}/acpidump
> -	- rm -f $(DESTDIR)${mandir}/man8/acpidump.8
> +	$(foreach dir,$(SUBDIRS),make -C $(dir) uninstall;)
> 
> -.PHONY: all utils install-tools install-man install uninstall clean
> +.PHONY: all install uninstall clean
> diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile

The Makefile is put under tools/power/acpi because ACPICA release automation will put some shared files into "common" and "os_specific" folder.
If you are going to move the build commands into a tools/power/acpi/tools/acpidump/Makefile, you need to test using the recent upstream branch that contains the acpidump release.

> new file mode 100644
> index 0000000..4d0f993
> --- /dev/null
> +++ b/tools/power/acpi/tools/acpidump/Makefile
> @@ -0,0 +1,27 @@
> +KERNEL_INCLUDE := ../../../../../include
> +CFLAGS += -D_LINUX -DACPI_USE_SYSTEM_INTTYPES=0 -DDEFINE_ALTERNATE_TYPES -I$(KERNEL_INCLUDE)
> +
> +acpidump: acpidump.o
> +	$(ECHO) "  LD      " $@
> +	$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $< -o $@
> +	$(QUIET) $(STRIPCMD) $@
> +
> +%.o: %.c
> +	$(ECHO) "  CC      " $@
> +	$(QUIET) $(CC) -c $(CFLAGS) -o $@ $<

I think this breaks new acpidump compilation.
vpath is needed as drivers/acpi/acpica, tools/power/acpi/common, tools/power/acpi/os_specific source files need to be compiled.

> +
> +all: acpidump
> +
> +install:
> +	$(INSTALL) -d $(DESTDIR)${sbindir}
> +	$(INSTALL_PROGRAM) acpidump $(DESTDIR)${sbindir}
> +	$(INSTALL_DATA) -D ../../man/acpidump.8 $(DESTDIR)${mandir}/man8/acpidump.8
> +
> +uninstall:
> +	- rm -f $(DESTDIR)${sbindir}/acpidump
> +	- rm -f $(DESTDIR)${mandir}/man8/acpidump.8
> +
> +clean:
> +	-rm -f $(OUTPUT)acpidump
> +
> +.PHONY: all install uninstall
> --
> 1.7.6.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Introduce acpi_validate and ec_acces in tools/power/acpi
  2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
                   ` (3 preceding siblings ...)
  2014-04-07 13:16 ` [PATCH 4/4] tools/power/acpi: Introduce ec_access.c - tool to access the Embedded Controller (EC) safely for debugging purposes Thomas Renninger
@ 2014-04-08  2:09 ` Zheng, Lv
  4 siblings, 0 replies; 10+ messages in thread
From: Zheng, Lv @ 2014-04-08  2:09 UTC (permalink / raw)
  To: Thomas Renninger, rjw; +Cc: linux-acpi

Hi, Thomas

> From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of Thomas Renninger
> Sent: Monday, April 07, 2014 9:17 PM
> 
> Hi Rafael,
> 
> these are tools we already have packaged in our acpica package for quite
> a while:
>   - acpi_validate  (disassemble and recompile dumped ACPI tables, or a
>                     provided acpidump file. It references all SSDTs/DSDTs,
>                     which people often do not know or is cumbersome to do).
>   - ec_access       is the userspace tool for the ec_sys EC debug driver.
>                     Formerly only the thinkpad_acpi driver could do this.
>                     This got proplery moved into a ec_sys debug driver and
>                     ec_access can monitor changes e.g. every second of the
>                     EC registers, nicely shows them to find out about
>                     EC problems.
> 
> IMO both perfectly fit into tools/power/acpi.
> Other candidates could be:
>   - acpi_genl       (Monitor ACPI events)
>                     https://01.org/linux-acpi/utilities
>   - wmidump         This one can interpret WMI objects from a raw _WDG
>                     buffer (part of DSDT/SSDT BIOS code).
> 
> I didn't use the last one often, but it seem to be really useful if you
> implement ACPI WMI stuff.
> 
> If you agree with these patches, can you please queue them up for the
> next kernel release, please.
> 
> Tested: Created a tarball with tools/power/acpi directory added and
>         include/acpi copied into and build them separately as a package via
>         our build service via:
> make -C %{acpi_tools_dir} CFLAGS="-DDEFINE_ALTERNATE_TYPES
>         -DACPI_USE_SYSTEM_INTTYPES=0 -I ../../include %{optflags}"
> make -C %{acpi_tools_dir} install DESTDIR="%{buildroot}" mandir=%{_mandir}

Please also do the tools build tests with the DEBUG environment switched.
Something like:
make DEBUG=true ....
make DEBUG=false ...

Thanks and best regards
-Lv

> 
> 
> Thanks a lot,
> 
>       Thomas
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 1/4] tools/power/acpi: Minor bugfixes
  2014-04-07 13:16 ` [PATCH 1/4] tools/power/acpi: Minor bugfixes Thomas Renninger
@ 2014-04-08  2:19   ` Zheng, Lv
  2014-04-21 21:10     ` Rafael J. Wysocki
  0 siblings, 1 reply; 10+ messages in thread
From: Zheng, Lv @ 2014-04-08  2:19 UTC (permalink / raw)
  To: Thomas Renninger, rjw; +Cc: linux-acpi

Hi, Thomas

This one looks fine.
Build tests are all passed.
Thanks for fixing issues.

Best regards
-Lv

> From: Thomas Renninger [mailto:trenn@suse.de]
> Sent: Monday, April 07, 2014 9:17 PM
> 
> - bindir is created, but sbindir is used -> fix that
> - the debug parts are there twice (copy paste bug?). Remove one of the
>   exact same parts
> 
> Signed-off-by: Thomas Renninger <trenn@suse.de>
> ---
>  tools/power/acpi/Makefile |   11 +----------
>  1 files changed, 1 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
> index d9186a2..c2c0f20 100644
> --- a/tools/power/acpi/Makefile
> +++ b/tools/power/acpi/Makefile
> @@ -89,15 +89,6 @@ else
>  	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
>  endif
> 
> -# if DEBUG is enabled, then we do not strip or optimize
> -ifeq ($(strip $(DEBUG)),true)
> -	CFLAGS += -O1 -g -DDEBUG
> -	STRIPCMD = /bin/true -Since_we_are_debugging
> -else
> -	CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
> -	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
> -endif
> -
>  # --- ACPIDUMP BEGIN ---
> 
>  vpath %.c \
> @@ -128,7 +119,7 @@ clean:
>  	-rm -f $(OUTPUT)acpidump
> 
>  install-tools:
> -	$(INSTALL) -d $(DESTDIR)${bindir}
> +	$(INSTALL) -d $(DESTDIR)${sbindir}
>  	$(INSTALL_PROGRAM) $(OUTPUT)acpidump $(DESTDIR)${sbindir}
> 
>  install-man:
> --
> 1.7.6.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables
  2014-04-07 13:16 ` [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables Thomas Renninger
@ 2014-04-08  2:34   ` Zheng, Lv
  0 siblings, 0 replies; 10+ messages in thread
From: Zheng, Lv @ 2014-04-08  2:34 UTC (permalink / raw)
  To: Thomas Renninger, rjw; +Cc: linux-acpi

HI, Thomas

> From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of Thomas Renninger
> Sent: Monday, April 07, 2014 9:17 PM
> 
> The used iasl compiler shares the same code base as the kernel.
> Warnings or errors mostly point to bad BIOSes.
> These errors should get reported to the BIOS vendors and may indicated that
> acpica (kernel ACPI parts) need compatibility adjustings.
> 
> 
> Why is an extra tool needed for this?
> 
> The dynamic ACPI Source Language (ASL) parts are located in DSDT and often
> multiple SSDT tables. Those often have dependencies to each other and the iasl
> compiler often cannot resolve external symbols correctly if they are not
> passed as external tables (iasl -e option) when tables get disassembled.
> This quickly leads to false positive errors.
> This tool makes sure disassembling and recompilation is done correctly.
> 
> This tool is also made for ACPI BIOS table verification for BIOS vendors and
> hardware certification tools for distributions.
> Hardware which supports Linux must/should not show any warnings or errors.
> Remarks and optimization hints in the logs can be used to further enhance
> the ACPI BIOS code.
> Warnings and errors mostly describe the issues in a way, so that they can
> get passed to and used by BIOS developers to fix the problems easily.
> 
> Signed-off-by: Thomas Renninger <trenn@suse.de>
> ---
>  tools/power/acpi/Makefile            |    3 +
>  tools/power/acpi/man/acpidump.8      |    3 +
>  tools/power/acpi/tools/acpi_validate |  201 ++++++++++++++++++++++++++++++++++
>  3 files changed, 207 insertions(+), 0 deletions(-)
>  create mode 100755 tools/power/acpi/tools/acpi_validate
> 
> diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
> index d97dada..a033cfe 100644
> --- a/tools/power/acpi/Makefile
> +++ b/tools/power/acpi/Makefile
> @@ -89,8 +89,11 @@ clean:
> 
>  install:
>  	$(foreach dir,$(SUBDIRS),make -C $(dir) install;)
> +	$(INSTALL_PROGRAM) -D tools/acpi_validate $(DESTDIR)${bindir}/acpi_validate
> +
> 
>  uninstall:
>  	$(foreach dir,$(SUBDIRS),make -C $(dir) uninstall;)
> +	- rm -f $(DESTDIR)${bindir}/acpi_validate
> 
>  .PHONY: all install uninstall clean
> diff --git a/tools/power/acpi/man/acpidump.8 b/tools/power/acpi/man/acpidump.8
> index adfa991..302b602 100644
> --- a/tools/power/acpi/man/acpidump.8
> +++ b/tools/power/acpi/man/acpidump.8
> @@ -53,6 +53,9 @@ ACPICA: https://acpica.org/
>  /sys/firmware/acpi/tables/dynamic/*
>  .fi
> 
> +.SH "SEE ALSO"
> +.BR acpi_validate (8)
> +
>  .PP
>  .SH AUTHOR
>  .nf

This diff block also need to be rebased on top of new acpidump release.

> diff --git a/tools/power/acpi/tools/acpi_validate b/tools/power/acpi/tools/acpi_validate
> new file mode 100755
> index 0000000..40701bf
> --- /dev/null
> +++ b/tools/power/acpi/tools/acpi_validate
> @@ -0,0 +1,201 @@
> +#!/bin/bash
> +#
> +# Copyright (c) 2012 SUSE Linux Products GmbH
> +# Thomas Renninger <trenn@suse.de>
> +#
> +# This program is free software; you can redistribute it and/or modify it
> +# under the terms and conditions of the GNU General Public License,
> +# version 2, as published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> +# more details.
> +#
> +# You should have received a copy of the GNU General Public License along with
> +# this program; if not, write to the Free Software Foundation, Inc.,
> +# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> +#
> +
> +OUTPUT_DIR="$PWD"
> +VERBOSE=0
> +# Disable remarks and resource checks. The latter often/mostly generates
> +# false positive warnings. Can be overridden via -c option
> +COMPILE_OPTIONS="-sa -cr -vr -in"
> +DISASSEMBLE_OPTIONS="-in"
> +OUTPUT="/dev/null"
> +ACPIDUMP=""
> +MUST_BE_ROOT=1
> +
> +function usage()
> +{
> +    echo "acpi_validate [ -o output_dir ] [ -v ] [ -a acpidump ]"
> +    echo "              [ -c compile_options ] [ -d disassemble_options ]"
> +    echo
> +    echo "This tool extracts, disassembles and recompiles ACPI BIOS tables."
> +    echo "The disassembled files will be copied into the local or specified"
> +    echo "output directory (-o option)."
> +    echo
> +    echo "The underlying iasl compiler verifies and may complain about"
> +    echo "correctness of some of the BIOS tables."
> +    echo "These can give a pointer to possible malfunction of the system."
> +    echo
> +    echo "If you think you found a bug in the iasl compiler or related tools,"
> +    echo "you can ask here for help: devel@acpica.org"
> +    echo "You may also want to ask there if you are not sure whether it really"
> +    echo "is a BIOS bug."
> +    echo
> +    echo "If you are sure you found a BIOS issue, complain to your hardware vendor."
> +    echo "The iasl compiler typically provides a description of the warning/error in a way,"
> +    echo "so that BIOS authors can easily fix it."
> +    echo
> +    echo "Options"
> +    echo "   -o output_dir: Copy tables to this directory instead of local one"
> +    echo "   -v:          : be more verbose"
> +    echo "   -a acpidump  : Use this acpidump file"
> +    echo "                  instead of the tables from the local machine"
> +    echo "   -d options   : Pass iasl disassemble options"
> +    echo "   -c options   : Pass iasl compile options"
> +    echo "                  will override -sa -cr -vr (default options)"
> +    echo "   -h           : Show help"
> +    exit 1
> +}
> +
> +while getopts hva:o:c:d: name ; do
> +    case $name in
> +        o)
> +	    OUTPUT_DIR="$OPTARG"
> +	    if [ ! -d "$OUTPUT_DIR" ];then
> +		mkdir "$OUTPUT_DIR"
> +		if [[ $? != 0 ]];then
> +		    echo "Cannot create directory $OUTPUT_DIR"
> +		    exit 1
> +		fi
> +	    elif [ ! -w "$OUTPUT_DIR" ];then
> +		echo "Cannot write into directory $OUTPUT_DIR"
> +		exit 1
> +	    fi
> +
> +	    [[ $VERBOSE == 1 ]] && echo "Installing for architecture: $OUTPUT_DIR"
> +	    ;;
> +        a)
> +	    ACPIDUMP="$OPTARG"
> +	    if [ ! -r "$ACPIDUMP" ];then
> +		echo "$ACPIDUMP does not exist"
> +		exit 1
> +	    fi
> +	    [[ $VERBOSE == 1 ]] && echo "acpidump file: $ACPIDUMP"
> +	    MUST_BE_ROOT=0
> +	    ;;
> +        c)
> +	    COMPILE_OPTIONS="$OPTARG"
> +	    [[ $VERBOSE == 1 ]] && echo "Compile options: $COMPILE_OPTIONS"
> +	    ;;
> +        c)
> +	    DISASSEMBLE_OPTIONS="$OPTARG"
> +	    [[ $VERBOSE == 1 ]] && echo "Disassemble options: $DISASSEMBLE_OPTIONS"
> +	    ;;
> +        v)
> +            VERBOSE=1
> +	    OUTPUT="1"
> +            ;;
> +        ?)
> +	    usage
> +	    ;;
> +    esac
> +done
> +shift $(($OPTIND -1))
> +
> +if [[ $MUST_BE_ROOT == 1 ]] && [ "$(id -u)" != "0" ]; then
> +   echo "This script must be run as root"
> +   echo "(or use -a acpidump option and pass already dumped acpi tables)"
> +   exit 1
> +fi
> +
> +shopt -s nocasematch
> +TEMP_DIR=$(mktemp -d)
> +[[ $VERBOSE == 1 ]] && echo "Using temporary directory: $TEMP_DIR"
> +
> +if [ -r "$ACPIDUMP" ];then
> +    cp "$ACPIDUMP" "$TEMP_DIR"/acpidump
> +fi
> +
> +pushd "$TEMP_DIR" >/dev/null
> +
> +mkdir log
> +mkdir err
> +if [ ! -r acpidump ];then
> +    acpidump >acpidump

New acpidump can dump OSPM using tables (acpidump -c) and BIOS provided tables (acpidump without options).
So do we need to allow users to switch between the dumped tables using a script option?

> +fi
> +acpixtract -a acpidump >&$OUTPUT 2>&1

New acpidump can do this directly without using acpixtract (acpidump -b).
Since acpixtract is not shipped in the kernel, possibly we need to use "acpidump -b" here?

Thanks and best regards
-Lv

> +
> +
> +# ACPICA changed from uppercase to lowercase, try to find both:
> +SDTs=$(ls [SD]DST*.dat 2>/dev/null)
> +SDTs="${SDTs}$(ls [sd]sdt*.dat 2>/dev/null)"
> +
> +for file in *.dat;do
> +    table=${file/.dat/}
> +    # Enable case insensitive pattern matching
> +
> +    case $file in
> +	[DS]SDT*.dat | [sd]sdt*.dat)
> +		# Use other [sd]sdt*.dat tables to reference possible
> +		# external symbols. Pass the table itself for disassembling
> +		# comma separted.
> +		# For example you we have:
> +		# dsdt.dat ssdt1 ssdt2.dat
> +		# and the current table to disassemble is ssdt1.dat the
> +		# command has to be:
> +		# iasl -e dsdt.dat,ssdt2.dat -d ssdt1.dat
> +
> +		# Get rid of the table which gets disassembled
> +		# could have leading or trailing whitespace depending whether
> +		# it is at the end or the beginning of the list
> +		REF_TABLE_LIST=${SDTs/[[:space:]]$file/}
> +		REF_TABLE_LIST=${REF_TABLE_LIST/$file[[:space:]]/}
> +		# Convert the whitespace list into a comma separated one:
> +		REF_TABLE_LIST=${REF_TABLE_LIST//[[:space:]]/,}
> +		if [ "$REF_TABLE_LIST" != "" ];then
> +		    FINAL_DISASSEMBLE_OPTIONS="-e ${REF_TABLE_LIST} $DISASSEMBLE_OPTIONS"
> +		else
> +		    FINAL_DISASSEMBLE_OPTIONS="$DISASSEMBLE_OPTIONS"
> +		fi
> +		echo "stdout and stderr of $file disassembling:" >log/${table}.log
> +		[[ $VERBOSE == 1 ]] && echo "iasl $FINAL_DISASSEMBLE_OPTIONS -d $file 1>>log/${table}.log 2>&1"
> +		iasl $FINAL_DISASSEMBLE_OPTIONS -d $file 1>>log/${table}.log 2>&1
> +		[[ $VERBOSE == 1 ]] && echo "iasl $COMPILE_OPTIONS ${table}.dsl 1>>log/${table}.log 2>>err/${table}.err"
> +		iasl $COMPILE_OPTIONS ${table}.dsl 1>>log/${table}.log 2>>err/${table}.err
> +		;;
> +	*.dat)
> +		iasl -d $file 1>log/${table}.log 2>&1
> +		iasl -sa ${table}.dsl 1>log/${table}.log 2>err/${table}.err
> +		;;
> +    esac
> +done
> +
> +# remove empty error files
> +rm $(find err -size 0)
> +ERR_TABLES=$(ls err)
> +ERR_TABLES=${ERR_TABLES//.err/}
> +
> +popd >/dev/null
> +cp -r "$TEMP_DIR"/* "$OUTPUT_DIR"
> +
> +if [[ $VERBOSE == 1 ]];then
> +    echo "Temporary directory (undeleted): $TEMP_DIR"
> +else
> +    rm -rf "$TEMP_DIR"
> +fi
> +
> +if [ "$ERR_TABLES" = "" ];then
> +    echo "No errors or warnings detected"
> +    exit 0
> +else
> +    echo "These tables have warnings or errors (details in "$OUTPUT_DIR"/err directory):"
> +    for err in $ERR_TABLES;do
> +	echo -n $err $'\t'
> +	sed -n -e 's/Compilation complete. \(.* Errors, .* Warnings\).*/\1/p' "$OUTPUT_DIR"/log/$err.log
> +    done
> +    exit 1
> +fi
> --
> 1.7.6.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] tools/power/acpi: Minor bugfixes
  2014-04-08  2:19   ` Zheng, Lv
@ 2014-04-21 21:10     ` Rafael J. Wysocki
  0 siblings, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2014-04-21 21:10 UTC (permalink / raw)
  To: Zheng, Lv; +Cc: Thomas Renninger, linux-acpi

On Tuesday, April 08, 2014 02:19:20 AM Zheng, Lv wrote:
> Hi, Thomas
> 
> This one looks fine.
> Build tests are all passed.
> Thanks for fixing issues.

OK, queued up for the next pull request, thanks!

Rafael


> > From: Thomas Renninger [mailto:trenn@suse.de]
> > Sent: Monday, April 07, 2014 9:17 PM
> > 
> > - bindir is created, but sbindir is used -> fix that
> > - the debug parts are there twice (copy paste bug?). Remove one of the
> >   exact same parts
> > 
> > Signed-off-by: Thomas Renninger <trenn@suse.de>
> > ---
> >  tools/power/acpi/Makefile |   11 +----------
> >  1 files changed, 1 insertions(+), 10 deletions(-)
> > 
> > diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
> > index d9186a2..c2c0f20 100644
> > --- a/tools/power/acpi/Makefile
> > +++ b/tools/power/acpi/Makefile
> > @@ -89,15 +89,6 @@ else
> >  	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
> >  endif
> > 
> > -# if DEBUG is enabled, then we do not strip or optimize
> > -ifeq ($(strip $(DEBUG)),true)
> > -	CFLAGS += -O1 -g -DDEBUG
> > -	STRIPCMD = /bin/true -Since_we_are_debugging
> > -else
> > -	CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
> > -	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
> > -endif
> > -
> >  # --- ACPIDUMP BEGIN ---
> > 
> >  vpath %.c \
> > @@ -128,7 +119,7 @@ clean:
> >  	-rm -f $(OUTPUT)acpidump
> > 
> >  install-tools:
> > -	$(INSTALL) -d $(DESTDIR)${bindir}
> > +	$(INSTALL) -d $(DESTDIR)${sbindir}
> >  	$(INSTALL_PROGRAM) $(OUTPUT)acpidump $(DESTDIR)${sbindir}
> > 
> >  install-man:
> > --
> > 1.7.6.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-04-21 20:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-07 13:16 Introduce acpi_validate and ec_acces in tools/power/acpi Thomas Renninger
2014-04-07 13:16 ` [PATCH 1/4] tools/power/acpi: Minor bugfixes Thomas Renninger
2014-04-08  2:19   ` Zheng, Lv
2014-04-21 21:10     ` Rafael J. Wysocki
2014-04-07 13:16 ` [PATCH 2/4] tools/power/acpi: Make makefile work per subdirectory Thomas Renninger
2014-04-08  1:58   ` Zheng, Lv
2014-04-07 13:16 ` [PATCH 3/4] tools/power/acpi: Introduce acpi_validate with manpage for easy validation of ACPI BIOS tables Thomas Renninger
2014-04-08  2:34   ` Zheng, Lv
2014-04-07 13:16 ` [PATCH 4/4] tools/power/acpi: Introduce ec_access.c - tool to access the Embedded Controller (EC) safely for debugging purposes Thomas Renninger
2014-04-08  2:09 ` Introduce acpi_validate and ec_acces in tools/power/acpi Zheng, Lv

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.