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