xref: /OK3568_Linux_fs/kernel/Documentation/firmware-guide/acpi/method-customizing.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=======================================
4*4882a593SmuzhiyunLinux ACPI Custom Control Method How To
5*4882a593Smuzhiyun=======================================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun:Author: Zhang Rui <rui.zhang@intel.com>
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunLinux supports customizing ACPI control methods at runtime.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunUsers can use this to:
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun1. override an existing method which may not work correctly,
15*4882a593Smuzhiyun   or just for debugging purposes.
16*4882a593Smuzhiyun2. insert a completely new method in order to create a missing
17*4882a593Smuzhiyun   method such as _OFF, _ON, _STA, _INI, etc.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunFor these cases, it is far simpler to dynamically install a single
20*4882a593Smuzhiyuncontrol method rather than override the entire DSDT, because kernel
21*4882a593Smuzhiyunrebuild/reboot is not needed and test result can be got in minutes.
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun.. note::
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun  - Only ACPI METHOD can be overridden, any other object types like
26*4882a593Smuzhiyun    "Device", "OperationRegion", are not recognized. Methods
27*4882a593Smuzhiyun    declared inside scope operators are also not supported.
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun  - The same ACPI control method can be overridden for many times,
30*4882a593Smuzhiyun    and it's always the latest one that used by Linux/kernel.
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun  - To get the ACPI debug object output (Store (AAAA, Debug)),
33*4882a593Smuzhiyun    please run::
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun      echo 1 > /sys/module/acpi/parameters/aml_debug_output
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun1. override an existing method
39*4882a593Smuzhiyun==============================
40*4882a593Smuzhiyuna) get the ACPI table via ACPI sysfs I/F. e.g. to get the DSDT,
41*4882a593Smuzhiyun   just run "cat /sys/firmware/acpi/tables/DSDT > /tmp/dsdt.dat"
42*4882a593Smuzhiyunb) disassemble the table by running "iasl -d dsdt.dat".
43*4882a593Smuzhiyunc) rewrite the ASL code of the method and save it in a new file,
44*4882a593Smuzhiyund) package the new file (psr.asl) to an ACPI table format.
45*4882a593Smuzhiyun   Here is an example of a customized \_SB._AC._PSR method::
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun      DefinitionBlock ("", "SSDT", 1, "", "", 0x20080715)
48*4882a593Smuzhiyun      {
49*4882a593Smuzhiyun         Method (\_SB_.AC._PSR, 0, NotSerialized)
50*4882a593Smuzhiyun         {
51*4882a593Smuzhiyun            Store ("In AC _PSR", Debug)
52*4882a593Smuzhiyun            Return (ACON)
53*4882a593Smuzhiyun         }
54*4882a593Smuzhiyun      }
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun   Note that the full pathname of the method in ACPI namespace
57*4882a593Smuzhiyun   should be used.
58*4882a593Smuzhiyune) assemble the file to generate the AML code of the method.
59*4882a593Smuzhiyun   e.g. "iasl -vw 6084 psr.asl" (psr.aml is generated as a result)
60*4882a593Smuzhiyun   If parameter "-vw 6084" is not supported by your iASL compiler,
61*4882a593Smuzhiyun   please try a newer version.
62*4882a593Smuzhiyunf) mount debugfs by "mount -t debugfs none /sys/kernel/debug"
63*4882a593Smuzhiyung) override the old method via the debugfs by running
64*4882a593Smuzhiyun   "cat /tmp/psr.aml > /sys/kernel/debug/acpi/custom_method"
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun2. insert a new method
67*4882a593Smuzhiyun======================
68*4882a593SmuzhiyunThis is easier than overriding an existing method.
69*4882a593SmuzhiyunWe just need to create the ASL code of the method we want to
70*4882a593Smuzhiyuninsert and then follow the step c) ~ g) in section 1.
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun3. undo your changes
73*4882a593Smuzhiyun====================
74*4882a593SmuzhiyunThe "undo" operation is not supported for a new inserted method
75*4882a593Smuzhiyunright now, i.e. we can not remove a method currently.
76*4882a593SmuzhiyunFor an overridden method, in order to undo your changes, please
77*4882a593Smuzhiyunsave a copy of the method original ASL code in step c) section 1,
78*4882a593Smuzhiyunand redo step c) ~ g) to override the method with the original one.
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun.. note:: We can use a kernel with multiple custom ACPI method running,
82*4882a593Smuzhiyun   But each individual write to debugfs can implement a SINGLE
83*4882a593Smuzhiyun   method override. i.e. if we want to insert/override multiple
84*4882a593Smuzhiyun   ACPI methods, we need to redo step c) ~ g) for multiple times.
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun.. note:: Be aware that root can mis-use this driver to modify arbitrary
87*4882a593Smuzhiyun   memory and gain additional rights, if root's privileges got
88*4882a593Smuzhiyun   restricted (for example if root is not allowed to load additional
89*4882a593Smuzhiyun   modules after boot).
90