ssdt-overlays.txt 6.1 KB

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