Add a acpicall(8) utility for debugging and tweaking purposes.
authorSascha Wildner <saw@online.de>
Mon, 31 Aug 2015 18:01:31 +0000 (20:01 +0200)
committerSascha Wildner <saw@online.de>
Mon, 31 Aug 2015 18:01:31 +0000 (20:01 +0200)
It is based on ports' sysutils/acpi_call (from Maxim Ignatenko) with
a few changes by me:

* Rename acpi_call -> acpicall.

* Ioctl handling is in the main acpi.ko module.

* To enable it, the debug.acpi.allow_method_calls tunable needs to
  be set.

* In acpi_call, the mandatory -p option was used to pass the method's
  namespace path. I removed the option and made the path acpicall(8)'s
  argument.

* Wrote a manual page and cleaned up a bit.

The separate acpiio_mcall.h file was added because ACPIIO_DO_MCALL's
argument struct uses ACPICA types, so it needs acpi.h which acpiio.h
(a public header used by some ports) so far didn't need. So to avoid
any hassle, I put the ACPIIO_DO_MCALL ioctl into a separate header
(it's only used by acpicall(8) anyway).

The changes to kdump(1) and truss(1) are to include and build with
acpi.h.

Tested-by: tollens
18 files changed:
share/man/man4/acpi.4
sys/dev/acpica/acpi.c
sys/dev/acpica/acpiio_mcall.h [new file with mode: 0644]
usr.bin/kdump/Makefile
usr.bin/kdump/mkioctls
usr.bin/truss/Makefile
usr.sbin/acpi/Makefile
usr.sbin/acpi/acpibin/acpibin.8
usr.sbin/acpi/acpicall/Makefile [new file with mode: 0644]
usr.sbin/acpi/acpicall/acpicall.8 [copied from usr.sbin/acpi/acpihelp/acpihelp.8 with 52% similarity]
usr.sbin/acpi/acpicall/acpicall.c [new file with mode: 0644]
usr.sbin/acpi/acpiconf/acpiconf.8
usr.sbin/acpi/acpidump/acpidump.8
usr.sbin/acpi/acpiexec/acpiexec.8
usr.sbin/acpi/acpihelp/acpihelp.8
usr.sbin/acpi/acpinames/acpinames.8
usr.sbin/acpi/acpixtract/acpixtract.8
usr.sbin/acpi/iasl/iasl.8

index 52dc9e5..8073cf5 100644 (file)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD: src/share/man/man4/acpi.4,v 1.61.8.1 2009/04/15 03:14:26 kensmith Exp $
 .\"
-.Dd June 21, 2015
+.Dd August 31, 2015
 .Dt ACPI 4
 .Os
 .Sh NAME
@@ -225,6 +225,11 @@ Enables loading of a custom ACPI DSDT.
 Name of the DSDT table to load, if loading is enabled.
 It is relative to
 .Pa /boot/kernel .
+.It Va debug.acpi.allow_method_calls
+If set, the
+.Xr acpicall 8
+utility can be used to directly call ACPI methods for debugging and
+tweaking purposes.
 .It Va debug.acpi.disabled
 Selectively disables portions of ACPI that are enabled by default, for
 debugging purposes.
@@ -633,6 +638,7 @@ utilities and some ACPI knowledge.
 .Xr aibs 4 ,
 .Xr loader.conf 5 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
index 5098ff2..9d5b9b4 100644 (file)
@@ -56,6 +56,7 @@
 #include "acpi.h"
 #include <dev/acpica/acpivar.h>
 #include <dev/acpica/acpiio.h>
+#include <dev/acpica/acpiio_mcall.h>
 #include "achware.h"
 #include "acnamesp.h"
 #include "acglobal.h"
@@ -293,6 +294,10 @@ SYSCTL_INT(_debug_acpi, OID_AUTO, do_powerstate, CTLFLAG_RW,
 /* Allow users to override quirks. */
 TUNABLE_INT("debug.acpi.quirks", &acpi_quirks);
 
+/* Allow to call ACPI methods from userland. */
+static int acpi_allow_mcall;
+TUNABLE_INT("debug.acpi.allow_method_calls", &acpi_allow_mcall);
+
 static int acpi_susp_bounce;
 SYSCTL_INT(_debug_acpi, OID_AUTO, suspend_bounce, CTLFLAG_RW,
     &acpi_susp_bounce, 0, "Don't actually suspend, just test devices.");
@@ -3185,6 +3190,48 @@ acpiioctl(struct dev_ioctl_args *ap)
            if (ACPI_SUCCESS(acpi_SetSleepState(sc, state)))
                error = 0;
        break;
+    case ACPIIO_DO_MCALL:
+       if (acpi_allow_mcall == 1) {
+           struct acpi_mcall_ioctl_arg *params;
+           ACPI_BUFFER result = { ACPI_ALLOCATE_BUFFER, NULL };
+           ACPI_OBJECT *resobj;
+
+           error = EINVAL;
+           params = (struct acpi_mcall_ioctl_arg *)ap->a_data;
+           params->retval = AcpiEvaluateObject(NULL, params->path,
+               &params->args, &result);
+           if (ACPI_SUCCESS(params->retval) && result.Pointer != NULL &&
+               params->result.Pointer != NULL) {
+               params->result.Length = min(params->result.Length,
+                   result.Length);
+               copyout(result.Pointer, params->result.Pointer,
+                   params->result.Length);
+               params->reslen = result.Length;
+               if (result.Length >= sizeof(ACPI_OBJECT)) {
+                   resobj = (ACPI_OBJECT *)params->result.Pointer;
+                   switch (resobj->Type) {
+                   case ACPI_TYPE_STRING:
+                       resobj->String.Pointer = (char *)
+                           ((UINT8 *)(resobj->String.Pointer) -
+                               (UINT8 *)result.Pointer +
+                               (UINT8 *)resobj);
+                       break;
+                   case ACPI_TYPE_BUFFER:
+                       resobj->Buffer.Pointer -= (UINT8 *)result.Pointer -
+                           (UINT8 *)resobj;
+                       break;
+                   }
+               }
+               error = 0;
+           }
+           if (result.Pointer != NULL)
+               AcpiOsFree(result.Pointer);
+       } else {
+               device_printf(sc->acpi_dev,
+                   "debug.acpi.allow_method_calls must be set\n");
+               error = ENXIO;
+       }
+       break;
     default:
        error = ENXIO;
        break;
diff --git a/sys/dev/acpica/acpiio_mcall.h b/sys/dev/acpica/acpiio_mcall.h
new file mode 100644 (file)
index 0000000..aef1cc0
--- /dev/null
@@ -0,0 +1,39 @@
+/*-
+ *   Copyright (C) 2011 by Maxim Ignatenko
+ *   gelraen.ua@gmail.com
+ *
+ *   All rights reserved.                                                  *
+ *                                                                         *
+ *   Redistribution and use in source and binary forms, with or without    *
+ *    modification, are permitted provided that the following conditions   *
+ *    are met:                                                             *
+ *     * Redistributions of source code must retain the above copyright    *
+ *       notice, this list of conditions and the following disclaimer.     *
+ *     * Redistributions in binary form must reproduce the above copyright *
+ *       notice, this list of conditions and the following disclaimer in   *
+ *       the documentation and/or other materials provided with the        *
+ *       distribution.                                                     *
+ *                                                                         *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   *
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     *
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  *
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      *
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   *
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  *
+ *
+ */
+
+struct acpi_mcall_ioctl_arg {
+       char            *path;
+       ACPI_OBJECT_LIST args;
+       ACPI_STATUS      retval;
+       ACPI_BUFFER      result;
+       ACPI_SIZE        reslen; /* length returned by AcpiEvaluateObject */
+};
+
+#define ACPIIO_DO_MCALL        _IOWR('X', 0x100, struct acpi_mcall_ioctl_arg)
index 6909158..89ed4a7 100644 (file)
@@ -5,7 +5,9 @@
 
 PROG=          kdump
 SRCS=          kdump.c ioctl.c kdump_subr.c subr.c
-CFLAGS+=       -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I${.CURDIR}/../../sys -I${.CURDIR}/../../sys/dev/drm/include
+CFLAGS+=       -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I${.CURDIR}/../../sys
+CFLAGS+=       -I${.CURDIR}/../../sys/dev/drm/include
+CFLAGS+=       -I${.CURDIR}/../../sys/contrib/dev/acpica/source/include
 
 CLEANFILES=    ioctl.c kdump_subr.c
 
index 089c0c4..bdce54e 100644 (file)
@@ -49,6 +49,11 @@ BEGIN {
        print "#include <netinet6/ip6_mroute.h>"
        print "#include <stdio.h>"
        print "#include <cam/cam.h>"
+       print "#define ACPI_DEBUG_OUTPUT"
+       print "#define ACPI_APPLICATION"
+       print "#include <contrib/dev/acpica/source/include/acpi.h>"
+       print "#undef ACPI_APPLICATION"
+       print "#undef ACPI_DEBUG_OUTPUT"
        print ""
        print ioctl_includes
        print "const char *ioctlname(u_long);"
index d69527a..2353657 100644 (file)
@@ -6,7 +6,9 @@ SRCS=   main.c setup.c syscalls.c syscalls.h ioctl.c ${MACHINE_ARCH}-fbsd.c
 SRCS+= i386-linux.c linux_syscalls.h
 .endif
 
-CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../sys -I${.CURDIR}/../../sys/dev/drm/include -I.
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../sys
+CFLAGS+= -I${.CURDIR}/../../sys/dev/drm/include -I.
+CFLAGS+= -I${.CURDIR}/../../sys/contrib/dev/acpica/source/include
 
 CLEANFILES+=i386l-syscalls.master syscalls.master linux_syscalls.h \
        syscalls.h ioctl.c
index deeb0fd..a512bff 100644 (file)
@@ -1,5 +1,6 @@
 SUBDIR=        \
        acpibin \
+       acpicall \
        acpiconf \
        acpidump \
        acpiexec \
index c4c456a..bc346c2 100644 (file)
@@ -55,6 +55,7 @@ Display version information.
 .El
 .Sh SEE ALSO
 .Xr acpi 4 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
diff --git a/usr.sbin/acpi/acpicall/Makefile b/usr.sbin/acpi/acpicall/Makefile
new file mode 100644 (file)
index 0000000..41431b9
--- /dev/null
@@ -0,0 +1,8 @@
+PROG=  acpicall
+MAN=   acpicall.8
+WARNS?=        6
+
+CFLAGS+=-DACPI_APPLICATION
+CFLAGS+=-DACPI_DEBUG_OUTPUT
+
+.include <bsd.prog.mk>
similarity index 52%
copy from usr.sbin/acpi/acpihelp/acpihelp.8
copy to usr.sbin/acpi/acpicall/acpicall.8
index 99683f5..6818046 100644 (file)
@@ -1,5 +1,5 @@
 .\"
-.\" Copyright (c) 2014 The DragonFly Project.  All rights reserved.
+.\" Copyright (c) 2015 The DragonFly Project.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 16, 2015
-.Dt ACPIHELP 8
+.Dd August 31, 2015
+.Dt ACPICALL 8
 .Os
 .Sh NAME
-.Nm acpihelp
-.Nd help utility for ASL operators, AML opcodes, and ACPI predefined names
+.Nm acpicall
+.Nd call ACPI methods
 .Sh SYNOPSIS
 .Nm
-.Op Ar option ...
-.Op Ar name/prefix | hex_value
+.Op Fl hv
+.Op Fl b Ar hexstring
+.Op Fl d Ar file
+.Op Fl i Ar number
+.Op Fl o Ar i | s | b | o
+.Op Fl s Ar string
+.Ar path
 .Sh DESCRIPTION
+The
+.Nm
+utility calls the ACPI method
+.Ar path
+with the arguments specified by any
+.Fl b ,
+.Fl i ,
+.Fl o ,
+and
+.Fl s
+options.
+The
+.Ar path
+argument must be a full ACPI namespace path such as
+.Pa \e_SB.PCI0.PEGR.GFX0._DSM .
+.Pp
+Note that in order to be able to use the
+.Nm
+utility, the
+.Va debug.acpi.allow_method_calls
+loader tunable must be specified in
+.Pa /boot/loader.conf .
+.Pp
 The following options are supported:
 .Bl -tag -width indent
-.It Fl a Op Ar name/prefix
-Find/Display both ASL operator and AML opcode name(s).
-.It Fl d
-Display iASL Preprocessor directives.
-.It Fl e Op Ar hex_value
-Decode ACPICA exception code.
-.It Fl h
-Display help.
-.It Fl i
-Display known ACPI Device IDs (_HID).
-.It Fl k Op Ar name/prefix
-Find/Display ASL non-operator keyword(s).
-.It Fl m Op Ar name/prefix
-Find/Display AML opcode name(s).
-.It Fl o Op Ar hex_value
-Decode hex AML opcode.
-.It Fl p Op Ar name/prefix
-Find/Display ASL predefined method name(s).
-.It Fl s Op Ar name/prefix
-Find/Display ASL operator name(s).
-.It Fl t
-Display supported ACPI tables.
-.It Fl u
-Display ACPI-related UUIDs.
+.It Fl b Ar hexstring
+Pass
+.Ar hexstring
+as a buffer argument.
+.It Fl d Ar file
+Specify the path of the ACPI control device.
+The default is
+.Pa /dev/acpi .
+.It Fl i Ar number
+Pass
+.Ar number
+as an integer argument.
+.It Fl o Ar i | s | b | o
+Choose the format to print the result in:
+.Ar ( i ) Ns nteger ,
+.Ar ( s ) Ns tring ,
+.Ar ( b ) Ns uffer ,
+or
+.Ar ( o ) Ns bject .
+.It Fl s Ar string
+Pass
+.Ar string
+as a string argument.
 .It Fl v
-Display version information.
+Increase verbosity.
 .El
+.Sh EXAMPLES
+Note that many ACPI methods are specific to the BIOS and machine in
+question, so it is impossible to present any generic examples that will
+work everywhere.
+Some familiarity with ASL and the DSDT code of the specific machine to
+be tweaked is highly recommended.
 .Pp
-If neither
-.Ar name/prefix
-nor
-.Ar hex_value
-are specified
-.Nm
-defaults to displaying all information available for the specified option.
-.Pp
-If a
-.Ar name/prefix
-but no options are specified
-.Nm
-defaults to finding ASL operator names if
-.Ar name/prefix
-does not start with an underscore, and to finding ASL predefined method
-names if
-.Ar name/prefix
-does start with an underscore.
+The following calls were successfully used to turn off the discrete
+.Tn NVIDIA
+GPU on the
+.Tn Optimus
+based
+.Tn Asus K53SV
+laptop:
+.Bd -literal
+acpicall -b "f8d886a4da0b1b47a72b6042a6b5bee0" \e
+         -i 256 -i 26 -b "01000003" "\_SB.PCI0.PEGR.GFX0._DSM"
+
+acpicall "\_SB.PCI0.PEGR.GFX0._PS3"
+.Ed
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
+.Xr acpihelp 8 ,
 .Xr acpinames 8 ,
 .Xr acpixtract 8 ,
 .Xr iasl 8
-.Pp
-.Lk https://acpica.org/documentation/
 .Sh AUTHORS
-The
 .Nm
-utility is provided by
-.Tn Intel
-as part of their
-.Sy ACPICA
-distribution.
-.Pp
+is based on the
+.Nm acpi_call
+utility by
+.An Maxim Ignatenko Aq Mt gelraen.ua@gmail.com .
 This manual page was written by
 .An Sascha Wildner .
diff --git a/usr.sbin/acpi/acpicall/acpicall.c b/usr.sbin/acpi/acpicall/acpicall.c
new file mode 100644 (file)
index 0000000..9a8f5df
--- /dev/null
@@ -0,0 +1,275 @@
+/*-
+ *   Copyright (C) 2011 by Maxim Ignatenko
+ *   gelraen.ua@gmail.com
+ *   Copyright (C) 2015  Sascha Wildner
+ *   swildner@dragonflybsd.org
+ *
+ *   All rights reserved.                                                  *
+ *                                                                         *
+ *   Redistribution and use in source and binary forms, with or without    *
+ *    modification, are permitted provided that the following conditions   *
+ *    are met:                                                             *
+ *     * Redistributions of source code must retain the above copyright    *
+ *       notice, this list of conditions and the following disclaimer.     *
+ *     * Redistributions in binary form must reproduce the above copyright *
+ *       notice, this list of conditions and the following disclaimer in   *
+ *       the documentation and/or other materials provided with the        *
+ *       distribution.                                                     *
+ *                                                                         *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   *
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     *
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  *
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      *
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   *
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  *
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <contrib/dev/acpica/source/include/acpi.h>
+#include <dev/acpica/acpiio_mcall.h>
+
+#define        MAX_ACPI_PATH   4096
+
+static char    dev_path[MAXPATHLEN] = "/dev/acpi";
+static char    method_path[MAX_ACPI_PATH] = "";
+static size_t  result_buf_size = 1024;
+static char    output_format = 'o';
+static int     verbose;
+static ACPI_OBJECT args[ACPI_METHOD_NUM_ARGS];
+static struct acpi_mcall_ioctl_arg params;
+
+static void    usage(void);
+static int     parse_buffer(ACPI_OBJECT *, char *);
+static void    print_params(struct acpi_mcall_ioctl_arg *);
+static void    print_acpi_object(ACPI_OBJECT *);
+static void    print_acpi_buffer(ACPI_BUFFER *, char);
+
+int
+main(int argc, char *argv[])
+{
+       char c;
+       int i, fd;
+
+       bzero(&params, sizeof(params));
+       params.path = method_path;
+       params.args.Count = 0;
+       params.args.Pointer = args;
+
+       while ((c = getopt(argc, argv, "vb:d:i:o:s:")) != -1) {
+               switch(c) {
+               case 'b':
+               case 'i':
+               case 's':
+                       i = params.args.Count;
+                       if (i >= ACPI_METHOD_NUM_ARGS) {
+                               fprintf(stderr,
+                                   "maximum number of %d args exceeded\n",
+                                   ACPI_METHOD_NUM_ARGS);
+                               exit(1);
+                       }
+                       switch (optopt) {
+                       case 'b':
+                               if (parse_buffer(&args[i], optarg) != 0) {
+                                       fprintf(stderr,
+                                           "unable to parse hexstring: %s\n",
+                                           optarg);
+                                       exit(1);
+                               }
+                               break;
+                       case 'i':
+                               args[i].Type = ACPI_TYPE_INTEGER;
+                               args[i].Integer.Value =
+                                   strtol(optarg, NULL, 10);
+                               break;
+                       case 's':
+                               args[i].Type = ACPI_TYPE_STRING;
+                               args[i].String.Length = strlen(optarg);
+                               args[i].String.Pointer = optarg;
+                               break;
+                       }
+                       params.args.Count++;
+                       break;
+               case 'd':
+                       strlcpy(dev_path, optarg, MAXPATHLEN);
+                       break;
+               case 'o':
+                       switch (optarg[0]) {
+                       case 'b':
+                       case 'i':
+                       case 'o':
+                       case 's':
+                               output_format = optarg[0];
+                               break;
+                       default:
+                               fprintf(stderr,
+                                   "incorrect output format: %c\n",
+                                   optarg[0]);
+                               usage();
+                               break;
+                       }
+                       break;
+               case 'v':
+                       verbose = 1;
+                       break;
+               default:
+                       usage();
+                       break;
+               }
+       }
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 1)
+               usage();
+       strlcpy(method_path, argv[0], MAX_ACPI_PATH);
+
+       params.result.Length = result_buf_size;
+       params.result.Pointer = malloc(result_buf_size);
+
+       if (params.result.Pointer == NULL) {
+               perror("malloc");
+               return 1;
+       }
+
+       if (method_path[0] == 0) {
+               fprintf(stderr,
+                   "please specify path to method with -p flag\n");
+               return 1;
+       }
+
+       if (verbose)
+               print_params(&params);
+
+       fd = open(dev_path, O_RDWR);
+       if (fd < 0) {
+               perror("open");
+               return 1;
+       }
+       if (ioctl(fd, ACPIIO_DO_MCALL, &params) == -1) {
+               perror("ioctl");
+               return 1;
+       }
+
+       if (verbose)
+               printf("status: %d\nresult: ", params.retval);
+       print_acpi_buffer(&params.result, output_format);
+       printf("\n");
+
+       return params.retval;
+}
+
+static void
+usage(void)
+{
+       fprintf(stderr,
+           "usage: acpicall [-v] [-b hexstring] [-d file] [-i number] "
+           "[-o i | s | b | o]\n");
+       fprintf(stderr, "                [-s string] path\n");
+       exit(1);
+}
+
+static int
+parse_buffer(ACPI_OBJECT *dst, char *src)
+{
+       char tmp[3] = { 0 };
+       size_t len = strlen(src) / 2, i;
+
+       dst->Type = ACPI_TYPE_BUFFER;
+       dst->Buffer.Length = len;
+       if ((dst->Buffer.Pointer = malloc(len)) == NULL) {
+               fprintf(stderr,
+                   "%s: failed to allocate %zd bytes\n", __func__, len);
+               exit(1);
+       }
+
+       for(i = 0; i < len; i++) {
+               tmp[0] = src[i * 2];
+               tmp[1] = src[i * 2 + 1];
+               dst->Buffer.Pointer[i] = strtol(tmp, NULL, 16);
+       }
+
+       return 0;
+}
+
+static void
+print_params(struct acpi_mcall_ioctl_arg *p)
+{
+       int i;
+
+       printf("path: %s\n", p->path);
+       printf("number of arguments: %d\n", p->args.Count);
+       for(i = 0; i < (int)p->args.Count; i++) {
+               printf("argument %d type: ", i + 1);
+               switch (p->args.Pointer[i].Type) {
+               case ACPI_TYPE_INTEGER:
+                       printf("integer\n");
+                       break;
+               case ACPI_TYPE_STRING:
+                       printf("string\n");
+                       break;
+               case ACPI_TYPE_BUFFER:
+                       printf("buffer\n");
+                       break;
+               }
+               printf("argument %d value: ", i + 1);
+               print_acpi_object(&(p->args.Pointer[i]));
+               printf("\n");
+       }
+}
+
+static void
+print_acpi_object(ACPI_OBJECT *obj)
+{
+       int i;
+
+       switch (obj->Type) {
+       case ACPI_TYPE_INTEGER:
+               printf("%ju", (uintmax_t)obj->Integer.Value);
+               break;
+       case ACPI_TYPE_STRING:
+               printf("%s", obj->String.Pointer);
+               break;
+       case ACPI_TYPE_BUFFER:
+               for(i = 0; i < (int)obj->Buffer.Length; i++)
+                       printf("%02x", obj->Buffer.Pointer[i]);
+               break;
+       default:
+               printf("unknown object type '%d'", obj->Type);
+               break;
+       }       
+}
+
+static void
+print_acpi_buffer(ACPI_BUFFER *buf, char format)
+{
+       int i;
+
+       switch (format) {
+       case 'i':
+               printf("%ju", (uintmax_t)*((UINT64 *)buf->Pointer));
+               break;
+       case 's':
+               printf("%s", (char *)buf->Pointer);
+               break;
+       case 'b':
+               for(i = 0; i < (int)buf->Length; i++)
+                       printf("%02x", ((UINT8 *)(buf->Pointer))[i]);
+               break;
+       case 'o':
+               print_acpi_object((ACPI_OBJECT *)buf->Pointer);
+               break;
+       }
+}
index 0de95ab..6ceef50 100644 (file)
@@ -88,6 +88,7 @@ is a shortcut for
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
 .Xr acpihelp 8 ,
index 09a9a3a..357d738 100644 (file)
@@ -73,6 +73,7 @@ Verbose mode.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpiexec 8 ,
 .Xr acpihelp 8 ,
index 70ca529..497a609 100644 (file)
@@ -102,6 +102,7 @@ to see a list of available AML Debugger commands.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpihelp 8 ,
index 99683f5..1d122f0 100644 (file)
@@ -90,6 +90,7 @@ does start with an underscore.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
index 116d8c0..8315d9a 100644 (file)
@@ -56,6 +56,7 @@ Set debug output level.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
index cadef71..ade647b 100644 (file)
@@ -54,6 +54,7 @@ Display version information.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,
index 7651b30..e29f5b1 100644 (file)
@@ -180,6 +180,7 @@ Do not insert new compiler ID for DataTables.
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
+.Xr acpicall 8 ,
 .Xr acpiconf 8 ,
 .Xr acpidump 8 ,
 .Xr acpiexec 8 ,