162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci======================================= 462306a36Sopenharmony_ciLinux ACPI Custom Control Method How To 562306a36Sopenharmony_ci======================================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci:Author: Zhang Rui <rui.zhang@intel.com> 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciLinux supports customizing ACPI control methods at runtime. 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciUsers can use this to: 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci1. override an existing method which may not work correctly, 1562306a36Sopenharmony_ci or just for debugging purposes. 1662306a36Sopenharmony_ci2. insert a completely new method in order to create a missing 1762306a36Sopenharmony_ci method such as _OFF, _ON, _STA, _INI, etc. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciFor these cases, it is far simpler to dynamically install a single 2062306a36Sopenharmony_cicontrol method rather than override the entire DSDT, because kernel 2162306a36Sopenharmony_cirebuild/reboot is not needed and test result can be got in minutes. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci.. note:: 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci - Only ACPI METHOD can be overridden, any other object types like 2662306a36Sopenharmony_ci "Device", "OperationRegion", are not recognized. Methods 2762306a36Sopenharmony_ci declared inside scope operators are also not supported. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci - The same ACPI control method can be overridden for many times, 3062306a36Sopenharmony_ci and it's always the latest one that used by Linux/kernel. 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci - To get the ACPI debug object output (Store (AAAA, Debug)), 3362306a36Sopenharmony_ci please run:: 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci echo 1 > /sys/module/acpi/parameters/aml_debug_output 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci1. override an existing method 3962306a36Sopenharmony_ci============================== 4062306a36Sopenharmony_cia) get the ACPI table via ACPI sysfs I/F. e.g. to get the DSDT, 4162306a36Sopenharmony_ci just run "cat /sys/firmware/acpi/tables/DSDT > /tmp/dsdt.dat" 4262306a36Sopenharmony_cib) disassemble the table by running "iasl -d dsdt.dat". 4362306a36Sopenharmony_cic) rewrite the ASL code of the method and save it in a new file, 4462306a36Sopenharmony_cid) package the new file (psr.asl) to an ACPI table format. 4562306a36Sopenharmony_ci Here is an example of a customized \_SB._AC._PSR method:: 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci DefinitionBlock ("", "SSDT", 1, "", "", 0x20080715) 4862306a36Sopenharmony_ci { 4962306a36Sopenharmony_ci Method (\_SB_.AC._PSR, 0, NotSerialized) 5062306a36Sopenharmony_ci { 5162306a36Sopenharmony_ci Store ("In AC _PSR", Debug) 5262306a36Sopenharmony_ci Return (ACON) 5362306a36Sopenharmony_ci } 5462306a36Sopenharmony_ci } 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci Note that the full pathname of the method in ACPI namespace 5762306a36Sopenharmony_ci should be used. 5862306a36Sopenharmony_cie) assemble the file to generate the AML code of the method. 5962306a36Sopenharmony_ci e.g. "iasl -vw 6084 psr.asl" (psr.aml is generated as a result) 6062306a36Sopenharmony_ci If parameter "-vw 6084" is not supported by your iASL compiler, 6162306a36Sopenharmony_ci please try a newer version. 6262306a36Sopenharmony_cif) mount debugfs by "mount -t debugfs none /sys/kernel/debug" 6362306a36Sopenharmony_cig) override the old method via the debugfs by running 6462306a36Sopenharmony_ci "cat /tmp/psr.aml > /sys/kernel/debug/acpi/custom_method" 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci2. insert a new method 6762306a36Sopenharmony_ci====================== 6862306a36Sopenharmony_ciThis is easier than overriding an existing method. 6962306a36Sopenharmony_ciWe just need to create the ASL code of the method we want to 7062306a36Sopenharmony_ciinsert and then follow the step c) ~ g) in section 1. 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci3. undo your changes 7362306a36Sopenharmony_ci==================== 7462306a36Sopenharmony_ciThe "undo" operation is not supported for a new inserted method 7562306a36Sopenharmony_ciright now, i.e. we can not remove a method currently. 7662306a36Sopenharmony_ciFor an overridden method, in order to undo your changes, please 7762306a36Sopenharmony_cisave a copy of the method original ASL code in step c) section 1, 7862306a36Sopenharmony_ciand redo step c) ~ g) to override the method with the original one. 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci.. note:: We can use a kernel with multiple custom ACPI method running, 8262306a36Sopenharmony_ci But each individual write to debugfs can implement a SINGLE 8362306a36Sopenharmony_ci method override. i.e. if we want to insert/override multiple 8462306a36Sopenharmony_ci ACPI methods, we need to redo step c) ~ g) for multiple times. 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci.. note:: Be aware that root can mis-use this driver to modify arbitrary 8762306a36Sopenharmony_ci memory and gain additional rights, if root's privileges got 8862306a36Sopenharmony_ci restricted (for example if root is not allowed to load additional 8962306a36Sopenharmony_ci modules after boot). 90