Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 =============
0004 SSDT Overlays
0005 =============
0006 
0007 In order to support ACPI open-ended hardware configurations (e.g. development
0008 boards) we need a way to augment the ACPI configuration provided by the firmware
0009 image. A common example is connecting sensors on I2C / SPI buses on development
0010 boards.
0011 
0012 Although this can be accomplished by creating a kernel platform driver or
0013 recompiling the firmware image with updated ACPI tables, neither is practical:
0014 the former proliferates board specific kernel code while the latter requires
0015 access to firmware tools which are often not publicly available.
0016 
0017 Because ACPI supports external references in AML code a more practical
0018 way to augment firmware ACPI configuration is by dynamically loading
0019 user defined SSDT tables that contain the board specific information.
0020 
0021 For example, to enumerate a Bosch BMA222E accelerometer on the I2C bus of the
0022 Minnowboard MAX development board exposed via the LSE connector [1], the
0023 following ASL code can be used::
0024 
0025     DefinitionBlock ("minnowmax.aml", "SSDT", 1, "Vendor", "Accel", 0x00000003)
0026     {
0027         External (\_SB.I2C6, DeviceObj)
0028 
0029         Scope (\_SB.I2C6)
0030         {
0031             Device (STAC)
0032             {
0033                 Name (_HID, "BMA222E")
0034                 Name (RBUF, ResourceTemplate ()
0035                 {
0036                     I2cSerialBus (0x0018, ControllerInitiated, 0x00061A80,
0037                                 AddressingMode7Bit, "\\_SB.I2C6", 0x00,
0038                                 ResourceConsumer, ,)
0039                     GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
0040                             "\\_SB.GPO2", 0x00, ResourceConsumer, , )
0041                     { // Pin list
0042                         0
0043                     }
0044                 })
0045 
0046                 Method (_CRS, 0, Serialized)
0047                 {
0048                     Return (RBUF)
0049                 }
0050             }
0051         }
0052     }
0053 
0054 which can then be compiled to AML binary format::
0055 
0056     $ iasl minnowmax.asl
0057 
0058     Intel ACPI Component Architecture
0059     ASL Optimizing Compiler version 20140214-64 [Mar 29 2014]
0060     Copyright (c) 2000 - 2014 Intel Corporation
0061 
0062     ASL Input:     minnomax.asl - 30 lines, 614 bytes, 7 keywords
0063     AML Output:    minnowmax.aml - 165 bytes, 6 named objects, 1 executable opcodes
0064 
0065 [1] https://www.elinux.org/Minnowboard:MinnowMax#Low_Speed_Expansion_.28Top.29
0066 
0067 The resulting AML code can then be loaded by the kernel using one of the methods
0068 below.
0069 
0070 Loading ACPI SSDTs from initrd
0071 ==============================
0072 
0073 This option allows loading of user defined SSDTs from initrd and it is useful
0074 when the system does not support EFI or when there is not enough EFI storage.
0075 
0076 It works in a similar way with initrd based ACPI tables override/upgrade: SSDT
0077 AML code must be placed in the first, uncompressed, initrd under the
0078 "kernel/firmware/acpi" path. Multiple files can be used and this will translate
0079 in loading multiple tables. Only SSDT and OEM tables are allowed. See
0080 initrd_table_override.txt for more details.
0081 
0082 Here is an example::
0083 
0084     # Add the raw ACPI tables to an uncompressed cpio archive.
0085     # They must be put into a /kernel/firmware/acpi directory inside the
0086     # cpio archive.
0087     # The uncompressed cpio archive must be the first.
0088     # Other, typically compressed cpio archives, must be
0089     # concatenated on top of the uncompressed one.
0090     mkdir -p kernel/firmware/acpi
0091     cp ssdt.aml kernel/firmware/acpi
0092 
0093     # Create the uncompressed cpio archive and concatenate the original initrd
0094     # on top:
0095     find kernel | cpio -H newc --create > /boot/instrumented_initrd
0096     cat /boot/initrd >>/boot/instrumented_initrd
0097 
0098 Loading ACPI SSDTs from EFI variables
0099 =====================================
0100 
0101 This is the preferred method, when EFI is supported on the platform, because it
0102 allows a persistent, OS independent way of storing the user defined SSDTs. There
0103 is also work underway to implement EFI support for loading user defined SSDTs
0104 and using this method will make it easier to convert to the EFI loading
0105 mechanism when that will arrive. To enable it, the
0106 CONFIG_EFI_CUSTOM_SSDT_OVERLAYS shoyld be chosen to y.
0107 
0108 In order to load SSDTs from an EFI variable the ``"efivar_ssdt=..."`` kernel
0109 command line parameter can be used (the name has a limitation of 16 characters).
0110 The argument for the option is the variable name to use. If there are multiple
0111 variables with the same name but with different vendor GUIDs, all of them will
0112 be loaded.
0113 
0114 In order to store the AML code in an EFI variable the efivarfs filesystem can be
0115 used. It is enabled and mounted by default in /sys/firmware/efi/efivars in all
0116 recent distribution.
0117 
0118 Creating a new file in /sys/firmware/efi/efivars will automatically create a new
0119 EFI variable. Updating a file in /sys/firmware/efi/efivars will update the EFI
0120 variable. Please note that the file name needs to be specially formatted as
0121 "Name-GUID" and that the first 4 bytes in the file (little-endian format)
0122 represent the attributes of the EFI variable (see EFI_VARIABLE_MASK in
0123 include/linux/efi.h). Writing to the file must also be done with one write
0124 operation.
0125 
0126 For example, you can use the following bash script to create/update an EFI
0127 variable with the content from a given file::
0128 
0129     #!/bin/sh -e
0130 
0131     while [ -n "$1" ]; do
0132             case "$1" in
0133             "-f") filename="$2"; shift;;
0134             "-g") guid="$2"; shift;;
0135             *) name="$1";;
0136             esac
0137             shift
0138     done
0139 
0140     usage()
0141     {
0142             echo "Syntax: ${0##*/} -f filename [ -g guid ] name"
0143             exit 1
0144     }
0145 
0146     [ -n "$name" -a -f "$filename" ] || usage
0147 
0148     EFIVARFS="/sys/firmware/efi/efivars"
0149 
0150     [ -d "$EFIVARFS" ] || exit 2
0151 
0152     if stat -tf $EFIVARFS | grep -q -v de5e81e4; then
0153             mount -t efivarfs none $EFIVARFS
0154     fi
0155 
0156     # try to pick up an existing GUID
0157     [ -n "$guid" ] || guid=$(find "$EFIVARFS" -name "$name-*" | head -n1 | cut -f2- -d-)
0158 
0159     # use a randomly generated GUID
0160     [ -n "$guid" ] || guid="$(cat /proc/sys/kernel/random/uuid)"
0161 
0162     # efivarfs expects all of the data in one write
0163     tmp=$(mktemp)
0164     /bin/echo -ne "\007\000\000\000" | cat - $filename > $tmp
0165     dd if=$tmp of="$EFIVARFS/$name-$guid" bs=$(stat -c %s $tmp)
0166     rm $tmp
0167 
0168 Loading ACPI SSDTs from configfs
0169 ================================
0170 
0171 This option allows loading of user defined SSDTs from user space via the configfs
0172 interface. The CONFIG_ACPI_CONFIGFS option must be select and configfs must be
0173 mounted. In the following examples, we assume that configfs has been mounted in
0174 /sys/kernel/config.
0175 
0176 New tables can be loading by creating new directories in /sys/kernel/config/acpi/table
0177 and writing the SSDT AML code in the aml attribute::
0178 
0179     cd /sys/kernel/config/acpi/table
0180     mkdir my_ssdt
0181     cat ~/ssdt.aml > my_ssdt/aml