← Documents Documentation/admin-guide/acpi/ssdt-overlays.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / ACPI

SSDT Overlays

Board-specific ACPI 정보를 AML SSDT로 작성하고 initrd·EFI variable·configfs를 통해 동적으로 load하는 방법을 설명합니다.

Source pathDocumentation/admin-guide/acpi/ssdt-overlays.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Overlay purpose and AML

ssdt-overlays.rst:1-69

Firmware를 다시 만들지 않고 board-specific I2C/SPI device를 ACPI namespace에 추가합니다.

initrd loading

ssdt-overlays.rst:70-97

첫 uncompressed initrd의 kernel/firmware/acpi에 SSDT/OEM AML을 둡니다.

EFI variable loading

ssdt-overlays.rst:98-167

efivar_ssdt parameter와 Name-GUID single-write 형식으로 persistent AML을 저장합니다.

configfs loading

ssdt-overlays.rst:168-181

acpi/table 아래 instance를 만들고 aml attribute에 SSDT를 씁니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

SSDT overlay의 목적과 ASL 예제

1-69

이 GPL-2.0 문서는 SSDT overlay를 설명합니다. Development board처럼 hardware 구성을 계속 확장할 수 있는 ACPI system에서는 firmware image가 제공한 ACPI configuration에 정보를 보태는 방법이 필요합니다. 흔한 예는 development board의 I2C 또는 SPI bus에 sensor를 연결하는 경우입니다.

Kernel platform driver를 만들거나 수정된 ACPI table로 firmware image를 다시 compile할 수도 있지만 실용적이지 않습니다. 전자는 board-specific kernel code를 늘리고, 후자는 대개 공개되지 않은 firmware tool에 접근해야 합니다.

ACPI AML code는 external reference를 지원하므로 board-specific 정보를 담은 user-defined SSDT table을 동적으로 load하는 편이 더 실용적입니다.

예제는 Minnowboard MAX development board의 LSE connector에 노출된 I2C bus에서 Bosch BMA222E accelerometer를 enumerate합니다. ASL은 `\_SB.I2C6`를 external device로 선언하고 `STAC` device의 `_HID`, I2C address `0x0018`, controller path, GPIO interrupt와 `_CRS` resource method를 정의합니다.

    DefinitionBlock ("minnowmax.aml", "SSDT", 1, "Vendor", "Accel", 0x00000003)
    {
        External (\_SB.I2C6, DeviceObj)

        Scope (\_SB.I2C6)
        {
            Device (STAC)
            {
                Name (_HID, "BMA222E")
                Name (RBUF, ResourceTemplate ()
                {
                    I2cSerialBus (0x0018, ControllerInitiated, 0x00061A80,
                                AddressingMode7Bit, "\\_SB.I2C6", 0x00,
                                ResourceConsumer, ,)
                    GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
                            "\\_SB.GPO2", 0x00, ResourceConsumer, , )
                    { // Pin list
                        0
                    }
                })

                Method (_CRS, 0, Serialized)
                {
                    Return (RBUF)
                }
            }
        }
    }

`iasl minnowmax.asl`로 ASL을 AML binary로 compile합니다. 예제 compiler는 30-line, 614-byte ASL을 165-byte AML과 named object 6개, executable opcode 1개로 변환합니다.

which can then be compiled to AML binary format::

    $ iasl minnowmax.asl

    Intel ACPI Component Architecture
    ASL Optimizing Compiler version 20140214-64 [Mar 29 2014]
    Copyright (c) 2000 - 2014 Intel Corporation

    ASL Input:     minnomax.asl - 30 lines, 614 bytes, 7 keywords
    AML Output:    minnowmax.aml - 165 bytes, 6 named objects, 1 executable opcodes

[1] https://www.elinux.org/Minnowboard:MinnowMax#Low_Speed_Expansion_.28Top.29

생성된 AML은 아래의 initrd, EFI variable 또는 configfs 방식 중 하나로 kernel에 load할 수 있습니다.

Why dynamic SSDT overlays
ApproachBenefitCost or limitation
Platform driverKernel-native enumerationProliferates board-specific code
Recompile firmwareChanges firmware ACPI directlyRequires often-unavailable firmware tools
Dynamic SSDTKeeps board data outside kernel and firmwareRequires AML build and a loading path

Firmware ACPI 구성을 확장하는 세 접근의 trade-off입니다.

ASL to runtime device
Write board-specific ASLCompile with iaslProduce SSDT AMLLoad through initrd / EFI / configfsEnumerate BMA222E on I2C6

Board-specific description이 runtime ACPI namespace에 들어가는 흐름입니다.

initrd에서 ACPI SSDT load

70-97

이 방식은 user-defined SSDT를 initrd에서 load하며, system이 EFI를 지원하지 않거나 EFI storage가 부족할 때 유용합니다.

Initrd 기반 ACPI table override/upgrade와 비슷하게 SSDT AML을 첫 번째 uncompressed initrd의 `kernel/firmware/acpi` path에 둡니다. File 여러 개를 두면 table 여러 개를 load합니다. SSDT와 OEM table만 허용하며 자세한 내용은 `initrd_table_override.txt`를 참조합니다.

Here is an example::

    # Add the raw ACPI tables to an uncompressed cpio archive.
    # They must be put into a /kernel/firmware/acpi directory inside the
    # cpio archive.
    # The uncompressed cpio archive must be the first.
    # Other, typically compressed cpio archives, must be
    # concatenated on top of the uncompressed one.
    mkdir -p kernel/firmware/acpi
    cp ssdt.aml kernel/firmware/acpi

    # Create the uncompressed cpio archive and concatenate the original initrd
    # on top:
    find kernel | cpio -H newc --create > /boot/instrumented_initrd
    cat /boot/initrd >>/boot/instrumented_initrd
SSDT loading from initrd
Place ssdt.aml in kernel/firmware/acpiCreate uncompressed newc cpioAppend original initrdBoot instrumented_initrdKernel loads SSDT/OEM tables

Uncompressed ACPI archive가 기존 initrd보다 먼저 오도록 packaging합니다.

EFI variable에서 ACPI SSDT load

98-167

Platform이 EFI를 지원하면 EFI variable 방식이 선호됩니다. User-defined SSDT를 지속적이고 OS-independent하게 저장할 수 있고, 향후 EFI loading mechanism으로 전환하기도 쉽습니다. 활성화하려면 `CONFIG_EFI_CUSTOM_SSDT_OVERLAYS=y`를 선택합니다.

Kernel command line의 `efivar_ssdt=...` parameter로 읽을 variable name을 지정합니다. 이름은 16 characters로 제한됩니다. 같은 이름이면서 vendor GUID가 다른 variable이 여러 개라면 모두 load합니다.

AML은 `efivarfs`를 통해 EFI variable에 저장합니다. 최근 distribution에서는 기본적으로 `/sys/firmware/efi/efivars`에 활성화·mount됩니다. 이 directory에 file을 만들면 EFI variable을 새로 만들고 기존 file을 갱신하면 variable도 갱신합니다.

File name은 `Name-GUID` 형식이어야 합니다. File의 첫 4 bytes는 little-endian EFI variable attribute이며 `include/linux/efi.h`의 `EFI_VARIABLE_MASK`를 따릅니다. File write는 반드시 한 번의 write operation으로 수행해야 합니다.

EFI SSDT constraints
ConstraintRequired value
Kernel configCONFIG_EFI_CUSTOM_SSDT_OVERLAYS=y
Kernel parameterefivar_ssdt=<variable-name>
Name limit16 characters
efivarfs location/sys/firmware/efi/efivars
File nameName-GUID
First bytes4-byte little-endian EFI attributes
Write semanticsAll data in one write operation

EFI variable로 AML을 저장하고 찾는 데 필요한 형식입니다.

예제 shell script는 `-f filename`, 선택적 `-g guid`, variable name을 parse합니다. `efivarfs`가 없으면 종료하고 필요하면 mount합니다. 기존 GUID를 찾되 없으면 random UUID를 생성합니다. Attribute bytes `07 00 00 00`과 AML file을 temporary file로 합친 뒤 정확한 byte count로 한 번에 `dd`하고 temporary file을 지웁니다.

For example, you can use the following bash script to create/update an EFI
variable with the content from a given file::

    #!/bin/sh -e

    while [ -n "$1" ]; do
            case "$1" in
            "-f") filename="$2"; shift;;
            "-g") guid="$2"; shift;;
            *) name="$1";;
            esac
            shift
    done

    usage()
    {
            echo "Syntax: ${0##*/} -f filename [ -g guid ] name"
            exit 1
    }

    [ -n "$name" -a -f "$filename" ] || usage

    EFIVARFS="/sys/firmware/efi/efivars"

    [ -d "$EFIVARFS" ] || exit 2

    if stat -tf $EFIVARFS | grep -q -v de5e81e4; then
            mount -t efivarfs none $EFIVARFS
    fi

    # try to pick up an existing GUID
    [ -n "$guid" ] || guid=$(find "$EFIVARFS" -name "$name-*" | head -n1 | cut -f2- -d-)

    # use a randomly generated GUID
    [ -n "$guid" ] || guid="$(cat /proc/sys/kernel/random/uuid)"

    # efivarfs expects all of the data in one write
    tmp=$(mktemp)
    /bin/echo -ne "\007\000\000\000" | cat - $filename > $tmp
    dd if=$tmp of="$EFIVARFS/$name-$guid" bs=$(stat -c %s $tmp)
    rm $tmp
EFI variable update script
Parse filename, GUID and nameEnsure efivarfs is mountedReuse matching GUID or generate UUIDPrefix 4 attribute bytesWrite Name-GUID in one dd

기존 GUID 재사용과 single-write 제약을 만족하는 순서입니다.

configfs에서 ACPI SSDT load

168-181

Configfs 방식은 userspace에서 configfs interface를 통해 user-defined SSDT를 load합니다. `CONFIG_ACPI_CONFIGFS` option을 선택하고 configfs를 mount해야 합니다. 예제는 `/sys/kernel/config`에 mount됐다고 가정합니다.

`/sys/kernel/config/acpi/table` 아래 새 directory를 만들고 SSDT AML code를 그 directory의 `aml` attribute에 쓰면 새 table을 load합니다.

New tables can be loading by creating new directories in /sys/kernel/config/acpi/table
and writing the SSDT AML code in the aml attribute::

    cd /sys/kernel/config/acpi/table
    mkdir my_ssdt
    cat ~/ssdt.aml > my_ssdt/aml
Configfs SSDT load
CONFIG_ACPI_CONFIGFS enabledMount configfs at /sys/kernel/configmkdir acpi/table/my_ssdtWrite ssdt.aml to my_ssdt/amlKernel loads table

Directory creation이 table instance를 만들고 aml write가 내용을 load합니다.