ssdt-overlays.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =============
  3. SSDT Overlays
  4. =============
  5. In order to support ACPI open-ended hardware configurations (e.g. development
  6. boards) we need a way to augment the ACPI configuration provided by the firmware
  7. image. A common example is connecting sensors on I2C / SPI buses on development
  8. boards.
  9. Although this can be accomplished by creating a kernel platform driver or
  10. recompiling the firmware image with updated ACPI tables, neither is practical:
  11. the former proliferates board specific kernel code while the latter requires
  12. access to firmware tools which are often not publicly available.
  13. Because ACPI supports external references in AML code a more practical
  14. way to augment firmware ACPI configuration is by dynamically loading
  15. user defined SSDT tables that contain the board specific information.
  16. For example, to enumerate a Bosch BMA222E accelerometer on the I2C bus of the
  17. Minnowboard MAX development board exposed via the LSE connector [1], the
  18. following ASL code can be used::
  19. DefinitionBlock ("minnowmax.aml", "SSDT", 1, "Vendor", "Accel", 0x00000003)
  20. {
  21. External (\_SB.I2C6, DeviceObj)
  22. Scope (\_SB.I2C6)
  23. {
  24. Device (STAC)
  25. {
  26. Name (_HID, "BMA222E")
  27. Name (RBUF, ResourceTemplate ()
  28. {
  29. I2cSerialBus (0x0018, ControllerInitiated, 0x00061A80,
  30. AddressingMode7Bit, "\\_SB.I2C6", 0x00,
  31. ResourceConsumer, ,)
  32. GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
  33. "\\_SB.GPO2", 0x00, ResourceConsumer, , )
  34. { // Pin list
  35. 0
  36. }
  37. })
  38. Method (_CRS, 0, Serialized)
  39. {
  40. Return (RBUF)
  41. }
  42. }
  43. }
  44. }
  45. which can then be compiled to AML binary format::
  46. $ iasl minnowmax.asl
  47. Intel ACPI Component Architecture
  48. ASL Optimizing Compiler version 20140214-64 [Mar 29 2014]
  49. Copyright (c) 2000 - 2014 Intel Corporation
  50. ASL Input: minnomax.asl - 30 lines, 614 bytes, 7 keywords
  51. AML Output: minnowmax.aml - 165 bytes, 6 named objects, 1 executable opcodes
  52. [1] https://www.elinux.org/Minnowboard:MinnowMax#Low_Speed_Expansion_.28Top.29
  53. The resulting AML code can then be loaded by the kernel using one of the methods
  54. below.
  55. Loading ACPI SSDTs from initrd
  56. ==============================
  57. This option allows loading of user defined SSDTs from initrd and it is useful
  58. when the system does not support EFI or when there is not enough EFI storage.
  59. It works in a similar way with initrd based ACPI tables override/upgrade: SSDT
  60. AML code must be placed in the first, uncompressed, initrd under the
  61. "kernel/firmware/acpi" path. Multiple files can be used and this will translate
  62. in loading multiple tables. Only SSDT and OEM tables are allowed. See
  63. initrd_table_override.txt for more details.
  64. Here is an example::
  65. # Add the raw ACPI tables to an uncompressed cpio archive.
  66. # They must be put into a /kernel/firmware/acpi directory inside the
  67. # cpio archive.
  68. # The uncompressed cpio archive must be the first.
  69. # Other, typically compressed cpio archives, must be
  70. # concatenated on top of the uncompressed one.
  71. mkdir -p kernel/firmware/acpi
  72. cp ssdt.aml kernel/firmware/acpi
  73. # Create the uncompressed cpio archive and concatenate the original initrd
  74. # on top:
  75. find kernel | cpio -H newc --create > /boot/instrumented_initrd
  76. cat /boot/initrd >>/boot/instrumented_initrd
  77. Loading ACPI SSDTs from EFI variables
  78. =====================================
  79. This is the preferred method, when EFI is supported on the platform, because it
  80. allows a persistent, OS independent way of storing the user defined SSDTs. There
  81. is also work underway to implement EFI support for loading user defined SSDTs
  82. and using this method will make it easier to convert to the EFI loading
  83. mechanism when that will arrive. To enable it, the
  84. CONFIG_EFI_CUSTOM_SSDT_OVERLAYS should be chosen to y.
  85. In order to load SSDTs from an EFI variable the ``"efivar_ssdt=..."`` kernel
  86. command line parameter can be used (the name has a limitation of 16 characters).
  87. The argument for the option is the variable name to use. If there are multiple
  88. variables with the same name but with different vendor GUIDs, all of them will
  89. be loaded.
  90. In order to store the AML code in an EFI variable the efivarfs filesystem can be
  91. used. It is enabled and mounted by default in /sys/firmware/efi/efivars in all
  92. recent distribution.
  93. Creating a new file in /sys/firmware/efi/efivars will automatically create a new
  94. EFI variable. Updating a file in /sys/firmware/efi/efivars will update the EFI
  95. variable. Please note that the file name needs to be specially formatted as
  96. "Name-GUID" and that the first 4 bytes in the file (little-endian format)
  97. represent the attributes of the EFI variable (see EFI_VARIABLE_MASK in
  98. include/linux/efi.h). Writing to the file must also be done with one write
  99. operation.
  100. For example, you can use the following bash script to create/update an EFI
  101. variable with the content from a given file::
  102. #!/bin/sh -e
  103. while [ -n "$1" ]; do
  104. case "$1" in
  105. "-f") filename="$2"; shift;;
  106. "-g") guid="$2"; shift;;
  107. *) name="$1";;
  108. esac
  109. shift
  110. done
  111. usage()
  112. {
  113. echo "Syntax: ${0##*/} -f filename [ -g guid ] name"
  114. exit 1
  115. }
  116. [ -n "$name" -a -f "$filename" ] || usage
  117. EFIVARFS="/sys/firmware/efi/efivars"
  118. [ -d "$EFIVARFS" ] || exit 2
  119. if stat -tf $EFIVARFS | grep -q -v de5e81e4; then
  120. mount -t efivarfs none $EFIVARFS
  121. fi
  122. # try to pick up an existing GUID
  123. [ -n "$guid" ] || guid=$(find "$EFIVARFS" -name "$name-*" | head -n1 | cut -f2- -d-)
  124. # use a randomly generated GUID
  125. [ -n "$guid" ] || guid="$(cat /proc/sys/kernel/random/uuid)"
  126. # efivarfs expects all of the data in one write
  127. tmp=$(mktemp)
  128. /bin/echo -ne "\007\000\000\000" | cat - $filename > $tmp
  129. dd if=$tmp of="$EFIVARFS/$name-$guid" bs=$(stat -c %s $tmp)
  130. rm $tmp
  131. Loading ACPI SSDTs from configfs
  132. ================================
  133. This option allows loading of user defined SSDTs from user space via the configfs
  134. interface. The CONFIG_ACPI_CONFIGFS option must be select and configfs must be
  135. mounted. In the following examples, we assume that configfs has been mounted in
  136. /sys/kernel/config.
  137. New tables can be loading by creating new directories in /sys/kernel/config/acpi/table
  138. and writing the SSDT AML code in the aml attribute::
  139. cd /sys/kernel/config/acpi/table
  140. mkdir my_ssdt
  141. cat ~/ssdt.aml > my_ssdt/aml