method-customizing.rst 3.3 KB

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