xref: /openbmc/linux/Documentation/arch/arm64/arm-acpi.rst (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
16aeadf78SLinus Torvalds===================
26aeadf78SLinus TorvaldsACPI on Arm systems
36aeadf78SLinus Torvalds===================
4e4624435SJonathan Corbet
56aeadf78SLinus TorvaldsACPI can be used for Armv8 and Armv9 systems designed to follow
66aeadf78SLinus Torvaldsthe BSA (Arm Base System Architecture) [0] and BBR (Arm
76aeadf78SLinus TorvaldsBase Boot Requirements) [1] specifications.  Both BSA and BBR are publicly
86aeadf78SLinus Torvaldsaccessible documents.
96aeadf78SLinus TorvaldsArm Servers, in addition to being BSA compliant, comply with a set
106aeadf78SLinus Torvaldsof rules defined in SBSA (Server Base System Architecture) [2].
11e4624435SJonathan Corbet
126aeadf78SLinus TorvaldsThe Arm kernel implements the reduced hardware model of ACPI version
13e4624435SJonathan Corbet5.1 or later.  Links to the specification and all external documents
14e4624435SJonathan Corbetit refers to are managed by the UEFI Forum.  The specification is
15e4624435SJonathan Corbetavailable at http://www.uefi.org/specifications and documents referenced
16e4624435SJonathan Corbetby the specification can be found via http://www.uefi.org/acpi.
17e4624435SJonathan Corbet
186aeadf78SLinus TorvaldsIf an Arm system does not meet the requirements of the BSA and BBR,
19e4624435SJonathan Corbetor cannot be described using the mechanisms defined in the required ACPI
20e4624435SJonathan Corbetspecifications, then ACPI may not be a good fit for the hardware.
21e4624435SJonathan Corbet
22e4624435SJonathan CorbetWhile the documents mentioned above set out the requirements for building
236aeadf78SLinus Torvaldsindustry-standard Arm systems, they also apply to more than one operating
24e4624435SJonathan Corbetsystem.  The purpose of this document is to describe the interaction between
256aeadf78SLinus TorvaldsACPI and Linux only, on an Arm system -- that is, what Linux expects of
26e4624435SJonathan CorbetACPI and what ACPI can expect of Linux.
27e4624435SJonathan Corbet
28e4624435SJonathan Corbet
296aeadf78SLinus TorvaldsWhy ACPI on Arm?
30e4624435SJonathan Corbet----------------
31e4624435SJonathan CorbetBefore examining the details of the interface between ACPI and Linux, it is
32e4624435SJonathan Corbetuseful to understand why ACPI is being used.  Several technologies already
33e4624435SJonathan Corbetexist in Linux for describing non-enumerable hardware, after all.  In this
346aeadf78SLinus Torvaldssection we summarize a blog post [3] from Grant Likely that outlines the
356aeadf78SLinus Torvaldsreasoning behind ACPI on Arm systems.  Actually, we snitch a good portion
36e4624435SJonathan Corbetof the summary text almost directly, to be honest.
37e4624435SJonathan Corbet
386aeadf78SLinus TorvaldsThe short form of the rationale for ACPI on Arm is:
39e4624435SJonathan Corbet
40e4624435SJonathan Corbet-  ACPI’s byte code (AML) allows the platform to encode hardware behavior,
41e4624435SJonathan Corbet   while DT explicitly does not support this.  For hardware vendors, being
42e4624435SJonathan Corbet   able to encode behavior is a key tool used in supporting operating
43e4624435SJonathan Corbet   system releases on new hardware.
44e4624435SJonathan Corbet
45e4624435SJonathan Corbet-  ACPI’s OSPM defines a power management model that constrains what the
46e4624435SJonathan Corbet   platform is allowed to do into a specific model, while still providing
47e4624435SJonathan Corbet   flexibility in hardware design.
48e4624435SJonathan Corbet
49e4624435SJonathan Corbet-  In the enterprise server environment, ACPI has established bindings (such
50e4624435SJonathan Corbet   as for RAS) which are currently used in production systems.  DT does not.
516aeadf78SLinus Torvalds   Such bindings could be defined in DT at some point, but doing so means Arm
52e4624435SJonathan Corbet   and x86 would end up using completely different code paths in both firmware
53e4624435SJonathan Corbet   and the kernel.
54e4624435SJonathan Corbet
55e4624435SJonathan Corbet-  Choosing a single interface to describe the abstraction between a platform
56e4624435SJonathan Corbet   and an OS is important.  Hardware vendors would not be required to implement
57e4624435SJonathan Corbet   both DT and ACPI if they want to support multiple operating systems.  And,
58e4624435SJonathan Corbet   agreeing on a single interface instead of being fragmented into per OS
59e4624435SJonathan Corbet   interfaces makes for better interoperability overall.
60e4624435SJonathan Corbet
61e4624435SJonathan Corbet-  The new ACPI governance process works well and Linux is now at the same
62e4624435SJonathan Corbet   table as hardware vendors and other OS vendors.  In fact, there is no
63e4624435SJonathan Corbet   longer any reason to feel that ACPI only belongs to Windows or that
64e4624435SJonathan Corbet   Linux is in any way secondary to Microsoft in this arena.  The move of
65e4624435SJonathan Corbet   ACPI governance into the UEFI forum has significantly opened up the
66e4624435SJonathan Corbet   specification development process, and currently, a large portion of the
67e4624435SJonathan Corbet   changes being made to ACPI are being driven by Linux.
68e4624435SJonathan Corbet
69e4624435SJonathan CorbetKey to the use of ACPI is the support model.  For servers in general, the
70e4624435SJonathan Corbetresponsibility for hardware behaviour cannot solely be the domain of the
71e4624435SJonathan Corbetkernel, but rather must be split between the platform and the kernel, in
72e4624435SJonathan Corbetorder to allow for orderly change over time.  ACPI frees the OS from needing
73e4624435SJonathan Corbetto understand all the minute details of the hardware so that the OS doesn’t
74e4624435SJonathan Corbetneed to be ported to each and every device individually.  It allows the
75e4624435SJonathan Corbethardware vendors to take responsibility for power management behaviour without
76e4624435SJonathan Corbetdepending on an OS release cycle which is not under their control.
77e4624435SJonathan Corbet
78e4624435SJonathan CorbetACPI is also important because hardware and OS vendors have already worked
79e4624435SJonathan Corbetout the mechanisms for supporting a general purpose computing ecosystem.  The
80e4624435SJonathan Corbetinfrastructure is in place, the bindings are in place, and the processes are
81e4624435SJonathan Corbetin place.  DT does exactly what Linux needs it to when working with vertically
82e4624435SJonathan Corbetintegrated devices, but there are no good processes for supporting what the
83e4624435SJonathan Corbetserver vendors need.  Linux could potentially get there with DT, but doing so
84e4624435SJonathan Corbetreally just duplicates something that already works.  ACPI already does what
85e4624435SJonathan Corbetthe hardware vendors need, Microsoft won’t collaborate on DT, and hardware
86e4624435SJonathan Corbetvendors would still end up providing two completely separate firmware
87e4624435SJonathan Corbetinterfaces -- one for Linux and one for Windows.
88e4624435SJonathan Corbet
89e4624435SJonathan Corbet
90e4624435SJonathan CorbetKernel Compatibility
91e4624435SJonathan Corbet--------------------
92e4624435SJonathan CorbetOne of the primary motivations for ACPI is standardization, and using that
93e4624435SJonathan Corbetto provide backward compatibility for Linux kernels.  In the server market,
94e4624435SJonathan Corbetsoftware and hardware are often used for long periods.  ACPI allows the
95e4624435SJonathan Corbetkernel and firmware to agree on a consistent abstraction that can be
96e4624435SJonathan Corbetmaintained over time, even as hardware or software change.  As long as the
97e4624435SJonathan Corbetabstraction is supported, systems can be updated without necessarily having
98e4624435SJonathan Corbetto replace the kernel.
99e4624435SJonathan Corbet
100e4624435SJonathan CorbetWhen a Linux driver or subsystem is first implemented using ACPI, it by
101e4624435SJonathan Corbetdefinition ends up requiring a specific version of the ACPI specification
102*d56b699dSBjorn Helgaas-- its baseline.  ACPI firmware must continue to work, even though it may
103e4624435SJonathan Corbetnot be optimal, with the earliest kernel version that first provides support
104e4624435SJonathan Corbetfor that baseline version of ACPI.  There may be a need for additional drivers,
105e4624435SJonathan Corbetbut adding new functionality (e.g., CPU power management) should not break
106e4624435SJonathan Corbetolder kernel versions.  Further, ACPI firmware must also work with the most
107e4624435SJonathan Corbetrecent version of the kernel.
108e4624435SJonathan Corbet
109e4624435SJonathan Corbet
110e4624435SJonathan CorbetRelationship with Device Tree
111e4624435SJonathan Corbet-----------------------------
1126aeadf78SLinus TorvaldsACPI support in drivers and subsystems for Arm should never be mutually
113e4624435SJonathan Corbetexclusive with DT support at compile time.
114e4624435SJonathan Corbet
115e4624435SJonathan CorbetAt boot time the kernel will only use one description method depending on
116e4624435SJonathan Corbetparameters passed from the boot loader (including kernel bootargs).
117e4624435SJonathan Corbet
118e4624435SJonathan CorbetRegardless of whether DT or ACPI is used, the kernel must always be capable
119e4624435SJonathan Corbetof booting with either scheme (in kernels with both schemes enabled at compile
120e4624435SJonathan Corbettime).
121e4624435SJonathan Corbet
122e4624435SJonathan Corbet
123e4624435SJonathan CorbetBooting using ACPI tables
124e4624435SJonathan Corbet-------------------------
1256aeadf78SLinus TorvaldsThe only defined method for passing ACPI tables to the kernel on Arm
126e4624435SJonathan Corbetis via the UEFI system configuration table.  Just so it is explicit, this
127e4624435SJonathan Corbetmeans that ACPI is only supported on platforms that boot via UEFI.
128e4624435SJonathan Corbet
1296aeadf78SLinus TorvaldsWhen an Arm system boots, it can either have DT information, ACPI tables,
130e4624435SJonathan Corbetor in some very unusual cases, both.  If no command line parameters are used,
131e4624435SJonathan Corbetthe kernel will try to use DT for device enumeration; if there is no DT
132e4624435SJonathan Corbetpresent, the kernel will try to use ACPI tables, but only if they are present.
133e4624435SJonathan CorbetIn neither is available, the kernel will not boot.  If acpi=force is used
134e4624435SJonathan Corbeton the command line, the kernel will attempt to use ACPI tables first, but
135e4624435SJonathan Corbetfall back to DT if there are no ACPI tables present.  The basic idea is that
136e4624435SJonathan Corbetthe kernel will not fail to boot unless it absolutely has no other choice.
137e4624435SJonathan Corbet
138e4624435SJonathan CorbetProcessing of ACPI tables may be disabled by passing acpi=off on the kernel
139e4624435SJonathan Corbetcommand line; this is the default behavior.
140e4624435SJonathan Corbet
141e4624435SJonathan CorbetIn order for the kernel to load and use ACPI tables, the UEFI implementation
142e4624435SJonathan CorbetMUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with
143e4624435SJonathan Corbetthe ACPI signature "RSD PTR ").  If this pointer is incorrect and acpi=force
144e4624435SJonathan Corbetis used, the kernel will disable ACPI and try to use DT to boot instead; the
145e4624435SJonathan Corbetkernel has, in effect, determined that ACPI tables are not present at that
146e4624435SJonathan Corbetpoint.
147e4624435SJonathan Corbet
148e4624435SJonathan CorbetIf the pointer to the RSDP table is correct, the table will be mapped into
149e4624435SJonathan Corbetthe kernel by the ACPI core, using the address provided by UEFI.
150e4624435SJonathan Corbet
151e4624435SJonathan CorbetThe ACPI core will then locate and map in all other ACPI tables provided by
152e4624435SJonathan Corbetusing the addresses in the RSDP table to find the XSDT (eXtended System
153e4624435SJonathan CorbetDescription Table).  The XSDT in turn provides the addresses to all other
154e4624435SJonathan CorbetACPI tables provided by the system firmware; the ACPI core will then traverse
155e4624435SJonathan Corbetthis table and map in the tables listed.
156e4624435SJonathan Corbet
157e4624435SJonathan CorbetThe ACPI core will ignore any provided RSDT (Root System Description Table).
158e4624435SJonathan CorbetRSDTs have been deprecated and are ignored on arm64 since they only allow
159e4624435SJonathan Corbetfor 32-bit addresses.
160e4624435SJonathan Corbet
161e4624435SJonathan CorbetFurther, the ACPI core will only use the 64-bit address fields in the FADT
162e4624435SJonathan Corbet(Fixed ACPI Description Table).  Any 32-bit address fields in the FADT will
163e4624435SJonathan Corbetbe ignored on arm64.
164e4624435SJonathan Corbet
165e4624435SJonathan CorbetHardware reduced mode (see Section 4.1 of the ACPI 6.1 specification) will
166e4624435SJonathan Corbetbe enforced by the ACPI core on arm64.  Doing so allows the ACPI core to
167e4624435SJonathan Corbetrun less complex code since it no longer has to provide support for legacy
168e4624435SJonathan Corbethardware from other architectures.  Any fields that are not to be used for
169e4624435SJonathan Corbethardware reduced mode must be set to zero.
170e4624435SJonathan Corbet
171e4624435SJonathan CorbetFor the ACPI core to operate properly, and in turn provide the information
172e4624435SJonathan Corbetthe kernel needs to configure devices, it expects to find the following
1736aeadf78SLinus Torvaldstables (all section numbers refer to the ACPI 6.5 specification):
174e4624435SJonathan Corbet
175e4624435SJonathan Corbet    -  RSDP (Root System Description Pointer), section 5.2.5
176e4624435SJonathan Corbet
177e4624435SJonathan Corbet    -  XSDT (eXtended System Description Table), section 5.2.8
178e4624435SJonathan Corbet
179e4624435SJonathan Corbet    -  FADT (Fixed ACPI Description Table), section 5.2.9
180e4624435SJonathan Corbet
181e4624435SJonathan Corbet    -  DSDT (Differentiated System Description Table), section
182e4624435SJonathan Corbet       5.2.11.1
183e4624435SJonathan Corbet
184e4624435SJonathan Corbet    -  MADT (Multiple APIC Description Table), section 5.2.12
185e4624435SJonathan Corbet
186e4624435SJonathan Corbet    -  GTDT (Generic Timer Description Table), section 5.2.24
187e4624435SJonathan Corbet
1886aeadf78SLinus Torvalds    -  PPTT (Processor Properties Topology Table), section 5.2.30
1896aeadf78SLinus Torvalds
1906aeadf78SLinus Torvalds    -  DBG2 (DeBuG port table 2), section 5.2.6, specifically Table 5-6.
1916aeadf78SLinus Torvalds
1926aeadf78SLinus Torvalds    -  APMT (Arm Performance Monitoring unit Table), section 5.2.6, specifically Table 5-6.
1936aeadf78SLinus Torvalds
1946aeadf78SLinus Torvalds    -  AGDI (Arm Generic diagnostic Dump and Reset Device Interface Table), section 5.2.6, specifically Table 5-6.
1956aeadf78SLinus Torvalds
196e4624435SJonathan Corbet    -  If PCI is supported, the MCFG (Memory mapped ConFiGuration
1976aeadf78SLinus Torvalds       Table), section 5.2.6, specifically Table 5-6.
198e4624435SJonathan Corbet
199e4624435SJonathan Corbet    -  If booting without a console=<device> kernel parameter is
200e4624435SJonathan Corbet       supported, the SPCR (Serial Port Console Redirection table),
2016aeadf78SLinus Torvalds       section 5.2.6, specifically Table 5-6.
202e4624435SJonathan Corbet
203e4624435SJonathan Corbet    -  If necessary to describe the I/O topology, SMMUs and GIC ITSs,
204e4624435SJonathan Corbet       the IORT (Input Output Remapping Table, section 5.2.6, specifically
2056aeadf78SLinus Torvalds       Table 5-6).
206e4624435SJonathan Corbet
2076aeadf78SLinus Torvalds    -  If NUMA is supported, the following tables are required:
2086aeadf78SLinus Torvalds
2096aeadf78SLinus Torvalds       - SRAT (System Resource Affinity Table), section 5.2.16
2106aeadf78SLinus Torvalds
2116aeadf78SLinus Torvalds       - SLIT (System Locality distance Information Table), section 5.2.17
2126aeadf78SLinus Torvalds
2136aeadf78SLinus Torvalds    -  If NUMA is supported, and the system contains heterogeneous memory,
2146aeadf78SLinus Torvalds       the HMAT (Heterogeneous Memory Attribute Table), section 5.2.28.
2156aeadf78SLinus Torvalds
2166aeadf78SLinus Torvalds    -  If the ACPI Platform Error Interfaces are required, the following
2176aeadf78SLinus Torvalds       tables are conditionally required:
2186aeadf78SLinus Torvalds
2196aeadf78SLinus Torvalds       - BERT (Boot Error Record Table, section 18.3.1)
2206aeadf78SLinus Torvalds
2216aeadf78SLinus Torvalds       - EINJ (Error INJection table, section 18.6.1)
2226aeadf78SLinus Torvalds
2236aeadf78SLinus Torvalds       - ERST (Error Record Serialization Table, section 18.5)
2246aeadf78SLinus Torvalds
2256aeadf78SLinus Torvalds       - HEST (Hardware Error Source Table, section 18.3.2)
2266aeadf78SLinus Torvalds
2276aeadf78SLinus Torvalds       - SDEI (Software Delegated Exception Interface table, section 5.2.6,
2286aeadf78SLinus Torvalds         specifically Table 5-6)
2296aeadf78SLinus Torvalds
2306aeadf78SLinus Torvalds       - AEST (Arm Error Source Table, section 5.2.6,
2316aeadf78SLinus Torvalds         specifically Table 5-6)
2326aeadf78SLinus Torvalds
2336aeadf78SLinus Torvalds       - RAS2 (ACPI RAS2 feature table, section 5.2.21)
2346aeadf78SLinus Torvalds
2356aeadf78SLinus Torvalds    -  If the system contains controllers using PCC channel, the
2366aeadf78SLinus Torvalds       PCCT (Platform Communications Channel Table), section 14.1
2376aeadf78SLinus Torvalds
2386aeadf78SLinus Torvalds    -  If the system contains a controller to capture board-level system state,
2396aeadf78SLinus Torvalds       and communicates with the host via PCC, the PDTT (Platform Debug Trigger
2406aeadf78SLinus Torvalds       Table), section 5.2.29.
2416aeadf78SLinus Torvalds
2426aeadf78SLinus Torvalds    -  If NVDIMM is supported, the NFIT (NVDIMM Firmware Interface Table), section 5.2.26
2436aeadf78SLinus Torvalds
2446aeadf78SLinus Torvalds    -  If video framebuffer is present, the BGRT (Boot Graphics Resource Table), section 5.2.23
2456aeadf78SLinus Torvalds
2466aeadf78SLinus Torvalds    -  If IPMI is implemented, the SPMI (Server Platform Management Interface),
2476aeadf78SLinus Torvalds       section 5.2.6, specifically Table 5-6.
2486aeadf78SLinus Torvalds
2496aeadf78SLinus Torvalds    -  If the system contains a CXL Host Bridge, the CEDT (CXL Early Discovery
2506aeadf78SLinus Torvalds       Table), section 5.2.6, specifically Table 5-6.
2516aeadf78SLinus Torvalds
2526aeadf78SLinus Torvalds    -  If the system supports MPAM, the MPAM (Memory Partitioning And Monitoring table), section 5.2.6,
2536aeadf78SLinus Torvalds       specifically Table 5-6.
2546aeadf78SLinus Torvalds
2556aeadf78SLinus Torvalds    -  If the system lacks persistent storage, the IBFT (ISCSI Boot Firmware
2566aeadf78SLinus Torvalds       Table), section 5.2.6, specifically Table 5-6.
2576aeadf78SLinus Torvalds
258e4624435SJonathan Corbet
259e4624435SJonathan CorbetIf the above tables are not all present, the kernel may or may not be
260e4624435SJonathan Corbetable to boot properly since it may not be able to configure all of the
261e4624435SJonathan Corbetdevices available.  This list of tables is not meant to be all inclusive;
262e4624435SJonathan Corbetin some environments other tables may be needed (e.g., any of the APEI
263e4624435SJonathan Corbettables from section 18) to support specific functionality.
264e4624435SJonathan Corbet
265e4624435SJonathan Corbet
266e4624435SJonathan CorbetACPI Detection
267e4624435SJonathan Corbet--------------
268e4624435SJonathan CorbetDrivers should determine their probe() type by checking for a null
269e4624435SJonathan Corbetvalue for ACPI_HANDLE, or checking .of_node, or other information in
270e4624435SJonathan Corbetthe device structure.  This is detailed further in the "Driver
271e4624435SJonathan CorbetRecommendations" section.
272e4624435SJonathan Corbet
273e4624435SJonathan CorbetIn non-driver code, if the presence of ACPI needs to be detected at
274e4624435SJonathan Corbetrun time, then check the value of acpi_disabled. If CONFIG_ACPI is not
275e4624435SJonathan Corbetset, acpi_disabled will always be 1.
276e4624435SJonathan Corbet
277e4624435SJonathan Corbet
278e4624435SJonathan CorbetDevice Enumeration
279e4624435SJonathan Corbet------------------
280e4624435SJonathan CorbetDevice descriptions in ACPI should use standard recognized ACPI interfaces.
281e4624435SJonathan CorbetThese may contain less information than is typically provided via a Device
282e4624435SJonathan CorbetTree description for the same device.  This is also one of the reasons that
283e4624435SJonathan CorbetACPI can be useful -- the driver takes into account that it may have less
284e4624435SJonathan Corbetdetailed information about the device and uses sensible defaults instead.
285e4624435SJonathan CorbetIf done properly in the driver, the hardware can change and improve over
286e4624435SJonathan Corbettime without the driver having to change at all.
287e4624435SJonathan Corbet
288e4624435SJonathan CorbetClocks provide an excellent example.  In DT, clocks need to be specified
289e4624435SJonathan Corbetand the drivers need to take them into account.  In ACPI, the assumption
290e4624435SJonathan Corbetis that UEFI will leave the device in a reasonable default state, including
291e4624435SJonathan Corbetany clock settings.  If for some reason the driver needs to change a clock
292e4624435SJonathan Corbetvalue, this can be done in an ACPI method; all the driver needs to do is
293e4624435SJonathan Corbetinvoke the method and not concern itself with what the method needs to do
294e4624435SJonathan Corbetto change the clock.  Changing the hardware can then take place over time
295e4624435SJonathan Corbetby changing what the ACPI method does, and not the driver.
296e4624435SJonathan Corbet
297e4624435SJonathan CorbetIn DT, the parameters needed by the driver to set up clocks as in the example
298e4624435SJonathan Corbetabove are known as "bindings"; in ACPI, these are known as "Device Properties"
299e4624435SJonathan Corbetand provided to a driver via the _DSD object.
300e4624435SJonathan Corbet
301e4624435SJonathan CorbetACPI tables are described with a formal language called ASL, the ACPI
302e4624435SJonathan CorbetSource Language (section 19 of the specification).  This means that there
303e4624435SJonathan Corbetare always multiple ways to describe the same thing -- including device
304e4624435SJonathan Corbetproperties.  For example, device properties could use an ASL construct
305e4624435SJonathan Corbetthat looks like this: Name(KEY0, "value0").  An ACPI device driver would
306e4624435SJonathan Corbetthen retrieve the value of the property by evaluating the KEY0 object.
307e4624435SJonathan CorbetHowever, using Name() this way has multiple problems: (1) ACPI limits
308e4624435SJonathan Corbetnames ("KEY0") to four characters unlike DT; (2) there is no industry
309e4624435SJonathan Corbetwide registry that maintains a list of names, minimizing re-use; (3)
310e4624435SJonathan Corbetthere is also no registry for the definition of property values ("value0"),
311e4624435SJonathan Corbetagain making re-use difficult; and (4) how does one maintain backward
312e4624435SJonathan Corbetcompatibility as new hardware comes out?  The _DSD method was created
313e4624435SJonathan Corbetto solve precisely these sorts of problems; Linux drivers should ALWAYS
314e4624435SJonathan Corbetuse the _DSD method for device properties and nothing else.
315e4624435SJonathan Corbet
316e4624435SJonathan CorbetThe _DSM object (ACPI Section 9.14.1) could also be used for conveying
317e4624435SJonathan Corbetdevice properties to a driver.  Linux drivers should only expect it to
318e4624435SJonathan Corbetbe used if _DSD cannot represent the data required, and there is no way
319e4624435SJonathan Corbetto create a new UUID for the _DSD object.  Note that there is even less
320e4624435SJonathan Corbetregulation of the use of _DSM than there is of _DSD.  Drivers that depend
321e4624435SJonathan Corbeton the contents of _DSM objects will be more difficult to maintain over
322e4624435SJonathan Corbettime because of this; as of this writing, the use of _DSM is the cause
323e4624435SJonathan Corbetof quite a few firmware problems and is not recommended.
324e4624435SJonathan Corbet
325e4624435SJonathan CorbetDrivers should look for device properties in the _DSD object ONLY; the _DSD
326e4624435SJonathan Corbetobject is described in the ACPI specification section 6.2.5, but this only
327e4624435SJonathan Corbetdescribes how to define the structure of an object returned via _DSD, and
328e4624435SJonathan Corbethow specific data structures are defined by specific UUIDs.  Linux should
3296aeadf78SLinus Torvaldsonly use the _DSD Device Properties UUID [4]:
330e4624435SJonathan Corbet
331e4624435SJonathan Corbet   - UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
332e4624435SJonathan Corbet
3336aeadf78SLinus TorvaldsCommon device properties can be registered by creating a pull request to [4] so
3346aeadf78SLinus Torvaldsthat they may be used across all operating systems supporting ACPI.
3356aeadf78SLinus TorvaldsDevice properties that have not been registered with the UEFI Forum can be used
3366aeadf78SLinus Torvaldsbut not as "uefi-" common properties.
337e4624435SJonathan Corbet
338e4624435SJonathan CorbetBefore creating new device properties, check to be sure that they have not
339e4624435SJonathan Corbetbeen defined before and either registered in the Linux kernel documentation
340e4624435SJonathan Corbetas DT bindings, or the UEFI Forum as device properties.  While we do not want
341e4624435SJonathan Corbetto simply move all DT bindings into ACPI device properties, we can learn from
342e4624435SJonathan Corbetwhat has been previously defined.
343e4624435SJonathan Corbet
344e4624435SJonathan CorbetIf it is necessary to define a new device property, or if it makes sense to
345e4624435SJonathan Corbetsynthesize the definition of a binding so it can be used in any firmware,
346e4624435SJonathan Corbetboth DT bindings and ACPI device properties for device drivers have review
347e4624435SJonathan Corbetprocesses.  Use them both.  When the driver itself is submitted for review
348e4624435SJonathan Corbetto the Linux mailing lists, the device property definitions needed must be
349e4624435SJonathan Corbetsubmitted at the same time.  A driver that supports ACPI and uses device
350e4624435SJonathan Corbetproperties will not be considered complete without their definitions.  Once
351e4624435SJonathan Corbetthe device property has been accepted by the Linux community, it must be
352e4624435SJonathan Corbetregistered with the UEFI Forum [4], which will review it again for consistency
353e4624435SJonathan Corbetwithin the registry.  This may require iteration.  The UEFI Forum, though,
354e4624435SJonathan Corbetwill always be the canonical site for device property definitions.
355e4624435SJonathan Corbet
356e4624435SJonathan CorbetIt may make sense to provide notice to the UEFI Forum that there is the
357e4624435SJonathan Corbetintent to register a previously unused device property name as a means of
358e4624435SJonathan Corbetreserving the name for later use.  Other operating system vendors will
359e4624435SJonathan Corbetalso be submitting registration requests and this may help smooth the
360e4624435SJonathan Corbetprocess.
361e4624435SJonathan Corbet
362e4624435SJonathan CorbetOnce registration and review have been completed, the kernel provides an
363e4624435SJonathan Corbetinterface for looking up device properties in a manner independent of
3646aeadf78SLinus Torvaldswhether DT or ACPI is being used.  This API should be used [5]; it can
365e4624435SJonathan Corbeteliminate some duplication of code paths in driver probing functions and
366e4624435SJonathan Corbetdiscourage divergence between DT bindings and ACPI device properties.
367e4624435SJonathan Corbet
368e4624435SJonathan Corbet
369e4624435SJonathan CorbetProgrammable Power Control Resources
370e4624435SJonathan Corbet------------------------------------
371e4624435SJonathan CorbetProgrammable power control resources include such resources as voltage/current
372e4624435SJonathan Corbetproviders (regulators) and clock sources.
373e4624435SJonathan Corbet
374e4624435SJonathan CorbetWith ACPI, the kernel clock and regulator framework is not expected to be used
375e4624435SJonathan Corbetat all.
376e4624435SJonathan Corbet
377e4624435SJonathan CorbetThe kernel assumes that power control of these resources is represented with
378e4624435SJonathan CorbetPower Resource Objects (ACPI section 7.1).  The ACPI core will then handle
379e4624435SJonathan Corbetcorrectly enabling and disabling resources as they are needed.  In order to
380e4624435SJonathan Corbetget that to work, ACPI assumes each device has defined D-states and that these
381e4624435SJonathan Corbetcan be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and _PS3;
382e4624435SJonathan Corbetin ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3 is for
383e4624435SJonathan Corbetturning a device full off.
384e4624435SJonathan Corbet
385e4624435SJonathan CorbetThere are two options for using those Power Resources.  They can:
386e4624435SJonathan Corbet
387e4624435SJonathan Corbet   -  be managed in a _PSx method which gets called on entry to power
388e4624435SJonathan Corbet      state Dx.
389e4624435SJonathan Corbet
390e4624435SJonathan Corbet   -  be declared separately as power resources with their own _ON and _OFF
391e4624435SJonathan Corbet      methods.  They are then tied back to D-states for a particular device
392e4624435SJonathan Corbet      via _PRx which specifies which power resources a device needs to be on
393e4624435SJonathan Corbet      while in Dx.  Kernel then tracks number of devices using a power resource
394e4624435SJonathan Corbet      and calls _ON/_OFF as needed.
395e4624435SJonathan Corbet
396e4624435SJonathan CorbetThe kernel ACPI code will also assume that the _PSx methods follow the normal
397e4624435SJonathan CorbetACPI rules for such methods:
398e4624435SJonathan Corbet
399e4624435SJonathan Corbet   -  If either _PS0 or _PS3 is implemented, then the other method must also
400e4624435SJonathan Corbet      be implemented.
401e4624435SJonathan Corbet
402e4624435SJonathan Corbet   -  If a device requires usage or setup of a power resource when on, the ASL
403e4624435SJonathan Corbet      should organize that it is allocated/enabled using the _PS0 method.
404e4624435SJonathan Corbet
405e4624435SJonathan Corbet   -  Resources allocated or enabled in the _PS0 method should be disabled
406e4624435SJonathan Corbet      or de-allocated in the _PS3 method.
407e4624435SJonathan Corbet
408e4624435SJonathan Corbet   -  Firmware will leave the resources in a reasonable state before handing
409e4624435SJonathan Corbet      over control to the kernel.
410e4624435SJonathan Corbet
411e4624435SJonathan CorbetSuch code in _PSx methods will of course be very platform specific.  But,
412e4624435SJonathan Corbetthis allows the driver to abstract out the interface for operating the device
413e4624435SJonathan Corbetand avoid having to read special non-standard values from ACPI tables. Further,
414e4624435SJonathan Corbetabstracting the use of these resources allows the hardware to change over time
415e4624435SJonathan Corbetwithout requiring updates to the driver.
416e4624435SJonathan Corbet
417e4624435SJonathan Corbet
418e4624435SJonathan CorbetClocks
419e4624435SJonathan Corbet------
420e4624435SJonathan CorbetACPI makes the assumption that clocks are initialized by the firmware --
421e4624435SJonathan CorbetUEFI, in this case -- to some working value before control is handed over
422e4624435SJonathan Corbetto the kernel.  This has implications for devices such as UARTs, or SoC-driven
423e4624435SJonathan CorbetLCD displays, for example.
424e4624435SJonathan Corbet
425e4624435SJonathan CorbetWhen the kernel boots, the clocks are assumed to be set to reasonable
426e4624435SJonathan Corbetworking values.  If for some reason the frequency needs to change -- e.g.,
427e4624435SJonathan Corbetthrottling for power management -- the device driver should expect that
428e4624435SJonathan Corbetprocess to be abstracted out into some ACPI method that can be invoked
429e4624435SJonathan Corbet(please see the ACPI specification for further recommendations on standard
430e4624435SJonathan Corbetmethods to be expected).  The only exceptions to this are CPU clocks where
431e4624435SJonathan CorbetCPPC provides a much richer interface than ACPI methods.  If the clocks
432e4624435SJonathan Corbetare not set, there is no direct way for Linux to control them.
433e4624435SJonathan Corbet
434e4624435SJonathan CorbetIf an SoC vendor wants to provide fine-grained control of the system clocks,
435e4624435SJonathan Corbetthey could do so by providing ACPI methods that could be invoked by Linux
436e4624435SJonathan Corbetdrivers.  However, this is NOT recommended and Linux drivers should NOT use
437e4624435SJonathan Corbetsuch methods, even if they are provided.  Such methods are not currently
438e4624435SJonathan Corbetstandardized in the ACPI specification, and using them could tie a kernel
439e4624435SJonathan Corbetto a very specific SoC, or tie an SoC to a very specific version of the
440e4624435SJonathan Corbetkernel, both of which we are trying to avoid.
441e4624435SJonathan Corbet
442e4624435SJonathan Corbet
443e4624435SJonathan CorbetDriver Recommendations
444e4624435SJonathan Corbet----------------------
445e4624435SJonathan CorbetDO NOT remove any DT handling when adding ACPI support for a driver.  The
446e4624435SJonathan Corbetsame device may be used on many different systems.
447e4624435SJonathan Corbet
448e4624435SJonathan CorbetDO try to structure the driver so that it is data-driven.  That is, set up
449e4624435SJonathan Corbeta struct containing internal per-device state based on defaults and whatever
450e4624435SJonathan Corbetelse must be discovered by the driver probe function.  Then, have the rest
451e4624435SJonathan Corbetof the driver operate off of the contents of that struct.  Doing so should
452e4624435SJonathan Corbetallow most divergence between ACPI and DT functionality to be kept local to
453e4624435SJonathan Corbetthe probe function instead of being scattered throughout the driver.  For
454e4624435SJonathan Corbetexample::
455e4624435SJonathan Corbet
456e4624435SJonathan Corbet  static int device_probe_dt(struct platform_device *pdev)
457e4624435SJonathan Corbet  {
458e4624435SJonathan Corbet         /* DT specific functionality */
459e4624435SJonathan Corbet         ...
460e4624435SJonathan Corbet  }
461e4624435SJonathan Corbet
462e4624435SJonathan Corbet  static int device_probe_acpi(struct platform_device *pdev)
463e4624435SJonathan Corbet  {
464e4624435SJonathan Corbet         /* ACPI specific functionality */
465e4624435SJonathan Corbet         ...
466e4624435SJonathan Corbet  }
467e4624435SJonathan Corbet
468e4624435SJonathan Corbet  static int device_probe(struct platform_device *pdev)
469e4624435SJonathan Corbet  {
470e4624435SJonathan Corbet         ...
471e4624435SJonathan Corbet         struct device_node node = pdev->dev.of_node;
472e4624435SJonathan Corbet         ...
473e4624435SJonathan Corbet
474e4624435SJonathan Corbet         if (node)
475e4624435SJonathan Corbet                 ret = device_probe_dt(pdev);
476e4624435SJonathan Corbet         else if (ACPI_HANDLE(&pdev->dev))
477e4624435SJonathan Corbet                 ret = device_probe_acpi(pdev);
478e4624435SJonathan Corbet         else
479e4624435SJonathan Corbet                 /* other initialization */
480e4624435SJonathan Corbet                 ...
481e4624435SJonathan Corbet         /* Continue with any generic probe operations */
482e4624435SJonathan Corbet         ...
483e4624435SJonathan Corbet  }
484e4624435SJonathan Corbet
485e4624435SJonathan CorbetDO keep the MODULE_DEVICE_TABLE entries together in the driver to make it
486e4624435SJonathan Corbetclear the different names the driver is probed for, both from DT and from
487e4624435SJonathan CorbetACPI::
488e4624435SJonathan Corbet
489e4624435SJonathan Corbet  static struct of_device_id virtio_mmio_match[] = {
490e4624435SJonathan Corbet          { .compatible = "virtio,mmio", },
491e4624435SJonathan Corbet          { }
492e4624435SJonathan Corbet  };
493e4624435SJonathan Corbet  MODULE_DEVICE_TABLE(of, virtio_mmio_match);
494e4624435SJonathan Corbet
495e4624435SJonathan Corbet  static const struct acpi_device_id virtio_mmio_acpi_match[] = {
496e4624435SJonathan Corbet          { "LNRO0005", },
497e4624435SJonathan Corbet          { }
498e4624435SJonathan Corbet  };
499e4624435SJonathan Corbet  MODULE_DEVICE_TABLE(acpi, virtio_mmio_acpi_match);
500e4624435SJonathan Corbet
501e4624435SJonathan Corbet
502e4624435SJonathan CorbetASWG
503e4624435SJonathan Corbet----
504e4624435SJonathan CorbetThe ACPI specification changes regularly.  During the year 2014, for instance,
505e4624435SJonathan Corbetversion 5.1 was released and version 6.0 substantially completed, with most of
5066aeadf78SLinus Torvaldsthe changes being driven by Arm-specific requirements.  Proposed changes are
507e4624435SJonathan Corbetpresented and discussed in the ASWG (ACPI Specification Working Group) which
508e4624435SJonathan Corbetis a part of the UEFI Forum.  The current version of the ACPI specification
5096aeadf78SLinus Torvaldsis 6.5 release in August 2022.
510e4624435SJonathan Corbet
511e4624435SJonathan CorbetParticipation in this group is open to all UEFI members.  Please see
512e4624435SJonathan Corbethttp://www.uefi.org/workinggroup for details on group membership.
513e4624435SJonathan Corbet
5146aeadf78SLinus TorvaldsIt is the intent of the Arm ACPI kernel code to follow the ACPI specification
515e4624435SJonathan Corbetas closely as possible, and to only implement functionality that complies with
516e4624435SJonathan Corbetthe released standards from UEFI ASWG.  As a practical matter, there will be
517e4624435SJonathan Corbetvendors that provide bad ACPI tables or violate the standards in some way.
518e4624435SJonathan CorbetIf this is because of errors, quirks and fix-ups may be necessary, but will
519e4624435SJonathan Corbetbe avoided if possible.  If there are features missing from ACPI that preclude
520e4624435SJonathan Corbetit from being used on a platform, ECRs (Engineering Change Requests) should be
521e4624435SJonathan Corbetsubmitted to ASWG and go through the normal approval process; for those that
522e4624435SJonathan Corbetare not UEFI members, many other members of the Linux community are and would
523e4624435SJonathan Corbetlikely be willing to assist in submitting ECRs.
524e4624435SJonathan Corbet
525e4624435SJonathan Corbet
526e4624435SJonathan CorbetLinux Code
527e4624435SJonathan Corbet----------
5286aeadf78SLinus TorvaldsIndividual items specific to Linux on Arm, contained in the Linux
529e4624435SJonathan Corbetsource code, are in the list that follows:
530e4624435SJonathan Corbet
531e4624435SJonathan CorbetACPI_OS_NAME
532e4624435SJonathan Corbet                       This macro defines the string to be returned when
5336aeadf78SLinus Torvalds                       an ACPI method invokes the _OS method.  On Arm
534e4624435SJonathan Corbet                       systems, this macro will be "Linux" by default.
535e4624435SJonathan Corbet                       The command line parameter acpi_os=<string>
536e4624435SJonathan Corbet                       can be used to set it to some other value.  The
537e4624435SJonathan Corbet                       default value for other architectures is "Microsoft
538e4624435SJonathan Corbet                       Windows NT", for example.
539e4624435SJonathan Corbet
540e4624435SJonathan CorbetACPI Objects
541e4624435SJonathan Corbet------------
542e4624435SJonathan CorbetDetailed expectations for ACPI tables and object are listed in the file
543e4624435SJonathan CorbetDocumentation/arch/arm64/acpi_object_usage.rst.
544e4624435SJonathan Corbet
545e4624435SJonathan Corbet
546e4624435SJonathan CorbetReferences
547e4624435SJonathan Corbet----------
5486aeadf78SLinus Torvalds[0] https://developer.arm.com/documentation/den0094/latest
5496aeadf78SLinus Torvalds    document Arm-DEN-0094: "Arm Base System Architecture", version 1.0C, dated 6 Oct 2022
550e4624435SJonathan Corbet
5516aeadf78SLinus Torvalds[1] https://developer.arm.com/documentation/den0044/latest
5526aeadf78SLinus Torvalds    Document Arm-DEN-0044: "Arm Base Boot Requirements", version 2.0G, dated 15 Apr 2022
553e4624435SJonathan Corbet
5546aeadf78SLinus Torvalds[2] https://developer.arm.com/documentation/den0029/latest
5556aeadf78SLinus Torvalds    Document Arm-DEN-0029: "Arm Server Base System Architecture", version 7.1, dated 06 Oct 2022
5566aeadf78SLinus Torvalds
5576aeadf78SLinus Torvalds[3] http://www.secretlab.ca/archives/151,
558e4624435SJonathan Corbet    10 Jan 2015, Copyright (c) 2015,
559e4624435SJonathan Corbet    Linaro Ltd., written by Grant Likely.
560e4624435SJonathan Corbet
5616aeadf78SLinus Torvalds[4] _DSD (Device Specific Data) Implementation Guide
5626aeadf78SLinus Torvalds    https://github.com/UEFI/DSD-Guide/blob/main/dsd-guide.pdf
563e4624435SJonathan Corbet
5646aeadf78SLinus Torvalds[5] Kernel code for the unified device
565e4624435SJonathan Corbet    property interface can be found in
566e4624435SJonathan Corbet    include/linux/property.h and drivers/base/property.c.
567e4624435SJonathan Corbet
568e4624435SJonathan Corbet
569e4624435SJonathan CorbetAuthors
570e4624435SJonathan Corbet-------
571e4624435SJonathan Corbet- Al Stone <al.stone@linaro.org>
572e4624435SJonathan Corbet- Graeme Gregory <graeme.gregory@linaro.org>
573e4624435SJonathan Corbet- Hanjun Guo <hanjun.guo@linaro.org>
574e4624435SJonathan Corbet
575e4624435SJonathan Corbet- Grant Likely <grant.likely@linaro.org>, for the "Why ACPI on ARM?" section
576