xref: /OK3568_Linux_fs/kernel/Documentation/arm64/arm-acpi.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=====================
2*4882a593SmuzhiyunACPI on ARMv8 Servers
3*4882a593Smuzhiyun=====================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunACPI can be used for ARMv8 general purpose servers designed to follow
6*4882a593Smuzhiyunthe ARM SBSA (Server Base System Architecture) [0] and SBBR (Server
7*4882a593SmuzhiyunBase Boot Requirements) [1] specifications.  Please note that the SBBR
8*4882a593Smuzhiyuncan be retrieved simply by visiting [1], but the SBSA is currently only
9*4882a593Smuzhiyunavailable to those with an ARM login due to ARM IP licensing concerns.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThe ARMv8 kernel implements the reduced hardware model of ACPI version
12*4882a593Smuzhiyun5.1 or later.  Links to the specification and all external documents
13*4882a593Smuzhiyunit refers to are managed by the UEFI Forum.  The specification is
14*4882a593Smuzhiyunavailable at http://www.uefi.org/specifications and documents referenced
15*4882a593Smuzhiyunby the specification can be found via http://www.uefi.org/acpi.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunIf an ARMv8 system does not meet the requirements of the SBSA and SBBR,
18*4882a593Smuzhiyunor cannot be described using the mechanisms defined in the required ACPI
19*4882a593Smuzhiyunspecifications, then ACPI may not be a good fit for the hardware.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunWhile the documents mentioned above set out the requirements for building
22*4882a593Smuzhiyunindustry-standard ARMv8 servers, they also apply to more than one operating
23*4882a593Smuzhiyunsystem.  The purpose of this document is to describe the interaction between
24*4882a593SmuzhiyunACPI and Linux only, on an ARMv8 system -- that is, what Linux expects of
25*4882a593SmuzhiyunACPI and what ACPI can expect of Linux.
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunWhy ACPI on ARM?
29*4882a593Smuzhiyun----------------
30*4882a593SmuzhiyunBefore examining the details of the interface between ACPI and Linux, it is
31*4882a593Smuzhiyunuseful to understand why ACPI is being used.  Several technologies already
32*4882a593Smuzhiyunexist in Linux for describing non-enumerable hardware, after all.  In this
33*4882a593Smuzhiyunsection we summarize a blog post [2] from Grant Likely that outlines the
34*4882a593Smuzhiyunreasoning behind ACPI on ARMv8 servers.  Actually, we snitch a good portion
35*4882a593Smuzhiyunof the summary text almost directly, to be honest.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunThe short form of the rationale for ACPI on ARM is:
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun-  ACPI’s byte code (AML) allows the platform to encode hardware behavior,
40*4882a593Smuzhiyun   while DT explicitly does not support this.  For hardware vendors, being
41*4882a593Smuzhiyun   able to encode behavior is a key tool used in supporting operating
42*4882a593Smuzhiyun   system releases on new hardware.
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun-  ACPI’s OSPM defines a power management model that constrains what the
45*4882a593Smuzhiyun   platform is allowed to do into a specific model, while still providing
46*4882a593Smuzhiyun   flexibility in hardware design.
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun-  In the enterprise server environment, ACPI has established bindings (such
49*4882a593Smuzhiyun   as for RAS) which are currently used in production systems.  DT does not.
50*4882a593Smuzhiyun   Such bindings could be defined in DT at some point, but doing so means ARM
51*4882a593Smuzhiyun   and x86 would end up using completely different code paths in both firmware
52*4882a593Smuzhiyun   and the kernel.
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun-  Choosing a single interface to describe the abstraction between a platform
55*4882a593Smuzhiyun   and an OS is important.  Hardware vendors would not be required to implement
56*4882a593Smuzhiyun   both DT and ACPI if they want to support multiple operating systems.  And,
57*4882a593Smuzhiyun   agreeing on a single interface instead of being fragmented into per OS
58*4882a593Smuzhiyun   interfaces makes for better interoperability overall.
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun-  The new ACPI governance process works well and Linux is now at the same
61*4882a593Smuzhiyun   table as hardware vendors and other OS vendors.  In fact, there is no
62*4882a593Smuzhiyun   longer any reason to feel that ACPI only belongs to Windows or that
63*4882a593Smuzhiyun   Linux is in any way secondary to Microsoft in this arena.  The move of
64*4882a593Smuzhiyun   ACPI governance into the UEFI forum has significantly opened up the
65*4882a593Smuzhiyun   specification development process, and currently, a large portion of the
66*4882a593Smuzhiyun   changes being made to ACPI are being driven by Linux.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunKey to the use of ACPI is the support model.  For servers in general, the
69*4882a593Smuzhiyunresponsibility for hardware behaviour cannot solely be the domain of the
70*4882a593Smuzhiyunkernel, but rather must be split between the platform and the kernel, in
71*4882a593Smuzhiyunorder to allow for orderly change over time.  ACPI frees the OS from needing
72*4882a593Smuzhiyunto understand all the minute details of the hardware so that the OS doesn’t
73*4882a593Smuzhiyunneed to be ported to each and every device individually.  It allows the
74*4882a593Smuzhiyunhardware vendors to take responsibility for power management behaviour without
75*4882a593Smuzhiyundepending on an OS release cycle which is not under their control.
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunACPI is also important because hardware and OS vendors have already worked
78*4882a593Smuzhiyunout the mechanisms for supporting a general purpose computing ecosystem.  The
79*4882a593Smuzhiyuninfrastructure is in place, the bindings are in place, and the processes are
80*4882a593Smuzhiyunin place.  DT does exactly what Linux needs it to when working with vertically
81*4882a593Smuzhiyunintegrated devices, but there are no good processes for supporting what the
82*4882a593Smuzhiyunserver vendors need.  Linux could potentially get there with DT, but doing so
83*4882a593Smuzhiyunreally just duplicates something that already works.  ACPI already does what
84*4882a593Smuzhiyunthe hardware vendors need, Microsoft won’t collaborate on DT, and hardware
85*4882a593Smuzhiyunvendors would still end up providing two completely separate firmware
86*4882a593Smuzhiyuninterfaces -- one for Linux and one for Windows.
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunKernel Compatibility
90*4882a593Smuzhiyun--------------------
91*4882a593SmuzhiyunOne of the primary motivations for ACPI is standardization, and using that
92*4882a593Smuzhiyunto provide backward compatibility for Linux kernels.  In the server market,
93*4882a593Smuzhiyunsoftware and hardware are often used for long periods.  ACPI allows the
94*4882a593Smuzhiyunkernel and firmware to agree on a consistent abstraction that can be
95*4882a593Smuzhiyunmaintained over time, even as hardware or software change.  As long as the
96*4882a593Smuzhiyunabstraction is supported, systems can be updated without necessarily having
97*4882a593Smuzhiyunto replace the kernel.
98*4882a593Smuzhiyun
99*4882a593SmuzhiyunWhen a Linux driver or subsystem is first implemented using ACPI, it by
100*4882a593Smuzhiyundefinition ends up requiring a specific version of the ACPI specification
101*4882a593Smuzhiyun-- it's baseline.  ACPI firmware must continue to work, even though it may
102*4882a593Smuzhiyunnot be optimal, with the earliest kernel version that first provides support
103*4882a593Smuzhiyunfor that baseline version of ACPI.  There may be a need for additional drivers,
104*4882a593Smuzhiyunbut adding new functionality (e.g., CPU power management) should not break
105*4882a593Smuzhiyunolder kernel versions.  Further, ACPI firmware must also work with the most
106*4882a593Smuzhiyunrecent version of the kernel.
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunRelationship with Device Tree
110*4882a593Smuzhiyun-----------------------------
111*4882a593SmuzhiyunACPI support in drivers and subsystems for ARMv8 should never be mutually
112*4882a593Smuzhiyunexclusive with DT support at compile time.
113*4882a593Smuzhiyun
114*4882a593SmuzhiyunAt boot time the kernel will only use one description method depending on
115*4882a593Smuzhiyunparameters passed from the boot loader (including kernel bootargs).
116*4882a593Smuzhiyun
117*4882a593SmuzhiyunRegardless of whether DT or ACPI is used, the kernel must always be capable
118*4882a593Smuzhiyunof booting with either scheme (in kernels with both schemes enabled at compile
119*4882a593Smuzhiyuntime).
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun
122*4882a593SmuzhiyunBooting using ACPI tables
123*4882a593Smuzhiyun-------------------------
124*4882a593SmuzhiyunThe only defined method for passing ACPI tables to the kernel on ARMv8
125*4882a593Smuzhiyunis via the UEFI system configuration table.  Just so it is explicit, this
126*4882a593Smuzhiyunmeans that ACPI is only supported on platforms that boot via UEFI.
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunWhen an ARMv8 system boots, it can either have DT information, ACPI tables,
129*4882a593Smuzhiyunor in some very unusual cases, both.  If no command line parameters are used,
130*4882a593Smuzhiyunthe kernel will try to use DT for device enumeration; if there is no DT
131*4882a593Smuzhiyunpresent, the kernel will try to use ACPI tables, but only if they are present.
132*4882a593SmuzhiyunIn neither is available, the kernel will not boot.  If acpi=force is used
133*4882a593Smuzhiyunon the command line, the kernel will attempt to use ACPI tables first, but
134*4882a593Smuzhiyunfall back to DT if there are no ACPI tables present.  The basic idea is that
135*4882a593Smuzhiyunthe kernel will not fail to boot unless it absolutely has no other choice.
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunProcessing of ACPI tables may be disabled by passing acpi=off on the kernel
138*4882a593Smuzhiyuncommand line; this is the default behavior.
139*4882a593Smuzhiyun
140*4882a593SmuzhiyunIn order for the kernel to load and use ACPI tables, the UEFI implementation
141*4882a593SmuzhiyunMUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with
142*4882a593Smuzhiyunthe ACPI signature "RSD PTR ").  If this pointer is incorrect and acpi=force
143*4882a593Smuzhiyunis used, the kernel will disable ACPI and try to use DT to boot instead; the
144*4882a593Smuzhiyunkernel has, in effect, determined that ACPI tables are not present at that
145*4882a593Smuzhiyunpoint.
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunIf the pointer to the RSDP table is correct, the table will be mapped into
148*4882a593Smuzhiyunthe kernel by the ACPI core, using the address provided by UEFI.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunThe ACPI core will then locate and map in all other ACPI tables provided by
151*4882a593Smuzhiyunusing the addresses in the RSDP table to find the XSDT (eXtended System
152*4882a593SmuzhiyunDescription Table).  The XSDT in turn provides the addresses to all other
153*4882a593SmuzhiyunACPI tables provided by the system firmware; the ACPI core will then traverse
154*4882a593Smuzhiyunthis table and map in the tables listed.
155*4882a593Smuzhiyun
156*4882a593SmuzhiyunThe ACPI core will ignore any provided RSDT (Root System Description Table).
157*4882a593SmuzhiyunRSDTs have been deprecated and are ignored on arm64 since they only allow
158*4882a593Smuzhiyunfor 32-bit addresses.
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunFurther, the ACPI core will only use the 64-bit address fields in the FADT
161*4882a593Smuzhiyun(Fixed ACPI Description Table).  Any 32-bit address fields in the FADT will
162*4882a593Smuzhiyunbe ignored on arm64.
163*4882a593Smuzhiyun
164*4882a593SmuzhiyunHardware reduced mode (see Section 4.1 of the ACPI 6.1 specification) will
165*4882a593Smuzhiyunbe enforced by the ACPI core on arm64.  Doing so allows the ACPI core to
166*4882a593Smuzhiyunrun less complex code since it no longer has to provide support for legacy
167*4882a593Smuzhiyunhardware from other architectures.  Any fields that are not to be used for
168*4882a593Smuzhiyunhardware reduced mode must be set to zero.
169*4882a593Smuzhiyun
170*4882a593SmuzhiyunFor the ACPI core to operate properly, and in turn provide the information
171*4882a593Smuzhiyunthe kernel needs to configure devices, it expects to find the following
172*4882a593Smuzhiyuntables (all section numbers refer to the ACPI 6.1 specification):
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun    -  RSDP (Root System Description Pointer), section 5.2.5
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun    -  XSDT (eXtended System Description Table), section 5.2.8
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun    -  FADT (Fixed ACPI Description Table), section 5.2.9
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun    -  DSDT (Differentiated System Description Table), section
181*4882a593Smuzhiyun       5.2.11.1
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun    -  MADT (Multiple APIC Description Table), section 5.2.12
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun    -  GTDT (Generic Timer Description Table), section 5.2.24
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun    -  If PCI is supported, the MCFG (Memory mapped ConFiGuration
188*4882a593Smuzhiyun       Table), section 5.2.6, specifically Table 5-31.
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun    -  If booting without a console=<device> kernel parameter is
191*4882a593Smuzhiyun       supported, the SPCR (Serial Port Console Redirection table),
192*4882a593Smuzhiyun       section 5.2.6, specifically Table 5-31.
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun    -  If necessary to describe the I/O topology, SMMUs and GIC ITSs,
195*4882a593Smuzhiyun       the IORT (Input Output Remapping Table, section 5.2.6, specifically
196*4882a593Smuzhiyun       Table 5-31).
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun    -  If NUMA is supported, the SRAT (System Resource Affinity Table)
199*4882a593Smuzhiyun       and SLIT (System Locality distance Information Table), sections
200*4882a593Smuzhiyun       5.2.16 and 5.2.17, respectively.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunIf the above tables are not all present, the kernel may or may not be
203*4882a593Smuzhiyunable to boot properly since it may not be able to configure all of the
204*4882a593Smuzhiyundevices available.  This list of tables is not meant to be all inclusive;
205*4882a593Smuzhiyunin some environments other tables may be needed (e.g., any of the APEI
206*4882a593Smuzhiyuntables from section 18) to support specific functionality.
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun
209*4882a593SmuzhiyunACPI Detection
210*4882a593Smuzhiyun--------------
211*4882a593SmuzhiyunDrivers should determine their probe() type by checking for a null
212*4882a593Smuzhiyunvalue for ACPI_HANDLE, or checking .of_node, or other information in
213*4882a593Smuzhiyunthe device structure.  This is detailed further in the "Driver
214*4882a593SmuzhiyunRecommendations" section.
215*4882a593Smuzhiyun
216*4882a593SmuzhiyunIn non-driver code, if the presence of ACPI needs to be detected at
217*4882a593Smuzhiyunrun time, then check the value of acpi_disabled. If CONFIG_ACPI is not
218*4882a593Smuzhiyunset, acpi_disabled will always be 1.
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun
221*4882a593SmuzhiyunDevice Enumeration
222*4882a593Smuzhiyun------------------
223*4882a593SmuzhiyunDevice descriptions in ACPI should use standard recognized ACPI interfaces.
224*4882a593SmuzhiyunThese may contain less information than is typically provided via a Device
225*4882a593SmuzhiyunTree description for the same device.  This is also one of the reasons that
226*4882a593SmuzhiyunACPI can be useful -- the driver takes into account that it may have less
227*4882a593Smuzhiyundetailed information about the device and uses sensible defaults instead.
228*4882a593SmuzhiyunIf done properly in the driver, the hardware can change and improve over
229*4882a593Smuzhiyuntime without the driver having to change at all.
230*4882a593Smuzhiyun
231*4882a593SmuzhiyunClocks provide an excellent example.  In DT, clocks need to be specified
232*4882a593Smuzhiyunand the drivers need to take them into account.  In ACPI, the assumption
233*4882a593Smuzhiyunis that UEFI will leave the device in a reasonable default state, including
234*4882a593Smuzhiyunany clock settings.  If for some reason the driver needs to change a clock
235*4882a593Smuzhiyunvalue, this can be done in an ACPI method; all the driver needs to do is
236*4882a593Smuzhiyuninvoke the method and not concern itself with what the method needs to do
237*4882a593Smuzhiyunto change the clock.  Changing the hardware can then take place over time
238*4882a593Smuzhiyunby changing what the ACPI method does, and not the driver.
239*4882a593Smuzhiyun
240*4882a593SmuzhiyunIn DT, the parameters needed by the driver to set up clocks as in the example
241*4882a593Smuzhiyunabove are known as "bindings"; in ACPI, these are known as "Device Properties"
242*4882a593Smuzhiyunand provided to a driver via the _DSD object.
243*4882a593Smuzhiyun
244*4882a593SmuzhiyunACPI tables are described with a formal language called ASL, the ACPI
245*4882a593SmuzhiyunSource Language (section 19 of the specification).  This means that there
246*4882a593Smuzhiyunare always multiple ways to describe the same thing -- including device
247*4882a593Smuzhiyunproperties.  For example, device properties could use an ASL construct
248*4882a593Smuzhiyunthat looks like this: Name(KEY0, "value0").  An ACPI device driver would
249*4882a593Smuzhiyunthen retrieve the value of the property by evaluating the KEY0 object.
250*4882a593SmuzhiyunHowever, using Name() this way has multiple problems: (1) ACPI limits
251*4882a593Smuzhiyunnames ("KEY0") to four characters unlike DT; (2) there is no industry
252*4882a593Smuzhiyunwide registry that maintains a list of names, minimizing re-use; (3)
253*4882a593Smuzhiyunthere is also no registry for the definition of property values ("value0"),
254*4882a593Smuzhiyunagain making re-use difficult; and (4) how does one maintain backward
255*4882a593Smuzhiyuncompatibility as new hardware comes out?  The _DSD method was created
256*4882a593Smuzhiyunto solve precisely these sorts of problems; Linux drivers should ALWAYS
257*4882a593Smuzhiyunuse the _DSD method for device properties and nothing else.
258*4882a593Smuzhiyun
259*4882a593SmuzhiyunThe _DSM object (ACPI Section 9.14.1) could also be used for conveying
260*4882a593Smuzhiyundevice properties to a driver.  Linux drivers should only expect it to
261*4882a593Smuzhiyunbe used if _DSD cannot represent the data required, and there is no way
262*4882a593Smuzhiyunto create a new UUID for the _DSD object.  Note that there is even less
263*4882a593Smuzhiyunregulation of the use of _DSM than there is of _DSD.  Drivers that depend
264*4882a593Smuzhiyunon the contents of _DSM objects will be more difficult to maintain over
265*4882a593Smuzhiyuntime because of this; as of this writing, the use of _DSM is the cause
266*4882a593Smuzhiyunof quite a few firmware problems and is not recommended.
267*4882a593Smuzhiyun
268*4882a593SmuzhiyunDrivers should look for device properties in the _DSD object ONLY; the _DSD
269*4882a593Smuzhiyunobject is described in the ACPI specification section 6.2.5, but this only
270*4882a593Smuzhiyundescribes how to define the structure of an object returned via _DSD, and
271*4882a593Smuzhiyunhow specific data structures are defined by specific UUIDs.  Linux should
272*4882a593Smuzhiyunonly use the _DSD Device Properties UUID [5]:
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun   - UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun   - https://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
277*4882a593Smuzhiyun
278*4882a593SmuzhiyunThe UEFI Forum provides a mechanism for registering device properties [4]
279*4882a593Smuzhiyunso that they may be used across all operating systems supporting ACPI.
280*4882a593SmuzhiyunDevice properties that have not been registered with the UEFI Forum should
281*4882a593Smuzhiyunnot be used.
282*4882a593Smuzhiyun
283*4882a593SmuzhiyunBefore creating new device properties, check to be sure that they have not
284*4882a593Smuzhiyunbeen defined before and either registered in the Linux kernel documentation
285*4882a593Smuzhiyunas DT bindings, or the UEFI Forum as device properties.  While we do not want
286*4882a593Smuzhiyunto simply move all DT bindings into ACPI device properties, we can learn from
287*4882a593Smuzhiyunwhat has been previously defined.
288*4882a593Smuzhiyun
289*4882a593SmuzhiyunIf it is necessary to define a new device property, or if it makes sense to
290*4882a593Smuzhiyunsynthesize the definition of a binding so it can be used in any firmware,
291*4882a593Smuzhiyunboth DT bindings and ACPI device properties for device drivers have review
292*4882a593Smuzhiyunprocesses.  Use them both.  When the driver itself is submitted for review
293*4882a593Smuzhiyunto the Linux mailing lists, the device property definitions needed must be
294*4882a593Smuzhiyunsubmitted at the same time.  A driver that supports ACPI and uses device
295*4882a593Smuzhiyunproperties will not be considered complete without their definitions.  Once
296*4882a593Smuzhiyunthe device property has been accepted by the Linux community, it must be
297*4882a593Smuzhiyunregistered with the UEFI Forum [4], which will review it again for consistency
298*4882a593Smuzhiyunwithin the registry.  This may require iteration.  The UEFI Forum, though,
299*4882a593Smuzhiyunwill always be the canonical site for device property definitions.
300*4882a593Smuzhiyun
301*4882a593SmuzhiyunIt may make sense to provide notice to the UEFI Forum that there is the
302*4882a593Smuzhiyunintent to register a previously unused device property name as a means of
303*4882a593Smuzhiyunreserving the name for later use.  Other operating system vendors will
304*4882a593Smuzhiyunalso be submitting registration requests and this may help smooth the
305*4882a593Smuzhiyunprocess.
306*4882a593Smuzhiyun
307*4882a593SmuzhiyunOnce registration and review have been completed, the kernel provides an
308*4882a593Smuzhiyuninterface for looking up device properties in a manner independent of
309*4882a593Smuzhiyunwhether DT or ACPI is being used.  This API should be used [6]; it can
310*4882a593Smuzhiyuneliminate some duplication of code paths in driver probing functions and
311*4882a593Smuzhiyundiscourage divergence between DT bindings and ACPI device properties.
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun
314*4882a593SmuzhiyunProgrammable Power Control Resources
315*4882a593Smuzhiyun------------------------------------
316*4882a593SmuzhiyunProgrammable power control resources include such resources as voltage/current
317*4882a593Smuzhiyunproviders (regulators) and clock sources.
318*4882a593Smuzhiyun
319*4882a593SmuzhiyunWith ACPI, the kernel clock and regulator framework is not expected to be used
320*4882a593Smuzhiyunat all.
321*4882a593Smuzhiyun
322*4882a593SmuzhiyunThe kernel assumes that power control of these resources is represented with
323*4882a593SmuzhiyunPower Resource Objects (ACPI section 7.1).  The ACPI core will then handle
324*4882a593Smuzhiyuncorrectly enabling and disabling resources as they are needed.  In order to
325*4882a593Smuzhiyunget that to work, ACPI assumes each device has defined D-states and that these
326*4882a593Smuzhiyuncan be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and _PS3;
327*4882a593Smuzhiyunin ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3 is for
328*4882a593Smuzhiyunturning a device full off.
329*4882a593Smuzhiyun
330*4882a593SmuzhiyunThere are two options for using those Power Resources.  They can:
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun   -  be managed in a _PSx method which gets called on entry to power
333*4882a593Smuzhiyun      state Dx.
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun   -  be declared separately as power resources with their own _ON and _OFF
336*4882a593Smuzhiyun      methods.  They are then tied back to D-states for a particular device
337*4882a593Smuzhiyun      via _PRx which specifies which power resources a device needs to be on
338*4882a593Smuzhiyun      while in Dx.  Kernel then tracks number of devices using a power resource
339*4882a593Smuzhiyun      and calls _ON/_OFF as needed.
340*4882a593Smuzhiyun
341*4882a593SmuzhiyunThe kernel ACPI code will also assume that the _PSx methods follow the normal
342*4882a593SmuzhiyunACPI rules for such methods:
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun   -  If either _PS0 or _PS3 is implemented, then the other method must also
345*4882a593Smuzhiyun      be implemented.
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun   -  If a device requires usage or setup of a power resource when on, the ASL
348*4882a593Smuzhiyun      should organize that it is allocated/enabled using the _PS0 method.
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun   -  Resources allocated or enabled in the _PS0 method should be disabled
351*4882a593Smuzhiyun      or de-allocated in the _PS3 method.
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun   -  Firmware will leave the resources in a reasonable state before handing
354*4882a593Smuzhiyun      over control to the kernel.
355*4882a593Smuzhiyun
356*4882a593SmuzhiyunSuch code in _PSx methods will of course be very platform specific.  But,
357*4882a593Smuzhiyunthis allows the driver to abstract out the interface for operating the device
358*4882a593Smuzhiyunand avoid having to read special non-standard values from ACPI tables. Further,
359*4882a593Smuzhiyunabstracting the use of these resources allows the hardware to change over time
360*4882a593Smuzhiyunwithout requiring updates to the driver.
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun
363*4882a593SmuzhiyunClocks
364*4882a593Smuzhiyun------
365*4882a593SmuzhiyunACPI makes the assumption that clocks are initialized by the firmware --
366*4882a593SmuzhiyunUEFI, in this case -- to some working value before control is handed over
367*4882a593Smuzhiyunto the kernel.  This has implications for devices such as UARTs, or SoC-driven
368*4882a593SmuzhiyunLCD displays, for example.
369*4882a593Smuzhiyun
370*4882a593SmuzhiyunWhen the kernel boots, the clocks are assumed to be set to reasonable
371*4882a593Smuzhiyunworking values.  If for some reason the frequency needs to change -- e.g.,
372*4882a593Smuzhiyunthrottling for power management -- the device driver should expect that
373*4882a593Smuzhiyunprocess to be abstracted out into some ACPI method that can be invoked
374*4882a593Smuzhiyun(please see the ACPI specification for further recommendations on standard
375*4882a593Smuzhiyunmethods to be expected).  The only exceptions to this are CPU clocks where
376*4882a593SmuzhiyunCPPC provides a much richer interface than ACPI methods.  If the clocks
377*4882a593Smuzhiyunare not set, there is no direct way for Linux to control them.
378*4882a593Smuzhiyun
379*4882a593SmuzhiyunIf an SoC vendor wants to provide fine-grained control of the system clocks,
380*4882a593Smuzhiyunthey could do so by providing ACPI methods that could be invoked by Linux
381*4882a593Smuzhiyundrivers.  However, this is NOT recommended and Linux drivers should NOT use
382*4882a593Smuzhiyunsuch methods, even if they are provided.  Such methods are not currently
383*4882a593Smuzhiyunstandardized in the ACPI specification, and using them could tie a kernel
384*4882a593Smuzhiyunto a very specific SoC, or tie an SoC to a very specific version of the
385*4882a593Smuzhiyunkernel, both of which we are trying to avoid.
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun
388*4882a593SmuzhiyunDriver Recommendations
389*4882a593Smuzhiyun----------------------
390*4882a593SmuzhiyunDO NOT remove any DT handling when adding ACPI support for a driver.  The
391*4882a593Smuzhiyunsame device may be used on many different systems.
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunDO try to structure the driver so that it is data-driven.  That is, set up
394*4882a593Smuzhiyuna struct containing internal per-device state based on defaults and whatever
395*4882a593Smuzhiyunelse must be discovered by the driver probe function.  Then, have the rest
396*4882a593Smuzhiyunof the driver operate off of the contents of that struct.  Doing so should
397*4882a593Smuzhiyunallow most divergence between ACPI and DT functionality to be kept local to
398*4882a593Smuzhiyunthe probe function instead of being scattered throughout the driver.  For
399*4882a593Smuzhiyunexample::
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun  static int device_probe_dt(struct platform_device *pdev)
402*4882a593Smuzhiyun  {
403*4882a593Smuzhiyun         /* DT specific functionality */
404*4882a593Smuzhiyun         ...
405*4882a593Smuzhiyun  }
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun  static int device_probe_acpi(struct platform_device *pdev)
408*4882a593Smuzhiyun  {
409*4882a593Smuzhiyun         /* ACPI specific functionality */
410*4882a593Smuzhiyun         ...
411*4882a593Smuzhiyun  }
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun  static int device_probe(struct platform_device *pdev)
414*4882a593Smuzhiyun  {
415*4882a593Smuzhiyun         ...
416*4882a593Smuzhiyun         struct device_node node = pdev->dev.of_node;
417*4882a593Smuzhiyun         ...
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun         if (node)
420*4882a593Smuzhiyun                 ret = device_probe_dt(pdev);
421*4882a593Smuzhiyun         else if (ACPI_HANDLE(&pdev->dev))
422*4882a593Smuzhiyun                 ret = device_probe_acpi(pdev);
423*4882a593Smuzhiyun         else
424*4882a593Smuzhiyun                 /* other initialization */
425*4882a593Smuzhiyun                 ...
426*4882a593Smuzhiyun         /* Continue with any generic probe operations */
427*4882a593Smuzhiyun         ...
428*4882a593Smuzhiyun  }
429*4882a593Smuzhiyun
430*4882a593SmuzhiyunDO keep the MODULE_DEVICE_TABLE entries together in the driver to make it
431*4882a593Smuzhiyunclear the different names the driver is probed for, both from DT and from
432*4882a593SmuzhiyunACPI::
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun  static struct of_device_id virtio_mmio_match[] = {
435*4882a593Smuzhiyun          { .compatible = "virtio,mmio", },
436*4882a593Smuzhiyun          { }
437*4882a593Smuzhiyun  };
438*4882a593Smuzhiyun  MODULE_DEVICE_TABLE(of, virtio_mmio_match);
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun  static const struct acpi_device_id virtio_mmio_acpi_match[] = {
441*4882a593Smuzhiyun          { "LNRO0005", },
442*4882a593Smuzhiyun          { }
443*4882a593Smuzhiyun  };
444*4882a593Smuzhiyun  MODULE_DEVICE_TABLE(acpi, virtio_mmio_acpi_match);
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun
447*4882a593SmuzhiyunASWG
448*4882a593Smuzhiyun----
449*4882a593SmuzhiyunThe ACPI specification changes regularly.  During the year 2014, for instance,
450*4882a593Smuzhiyunversion 5.1 was released and version 6.0 substantially completed, with most of
451*4882a593Smuzhiyunthe changes being driven by ARM-specific requirements.  Proposed changes are
452*4882a593Smuzhiyunpresented and discussed in the ASWG (ACPI Specification Working Group) which
453*4882a593Smuzhiyunis a part of the UEFI Forum.  The current version of the ACPI specification
454*4882a593Smuzhiyunis 6.1 release in January 2016.
455*4882a593Smuzhiyun
456*4882a593SmuzhiyunParticipation in this group is open to all UEFI members.  Please see
457*4882a593Smuzhiyunhttp://www.uefi.org/workinggroup for details on group membership.
458*4882a593Smuzhiyun
459*4882a593SmuzhiyunIt is the intent of the ARMv8 ACPI kernel code to follow the ACPI specification
460*4882a593Smuzhiyunas closely as possible, and to only implement functionality that complies with
461*4882a593Smuzhiyunthe released standards from UEFI ASWG.  As a practical matter, there will be
462*4882a593Smuzhiyunvendors that provide bad ACPI tables or violate the standards in some way.
463*4882a593SmuzhiyunIf this is because of errors, quirks and fix-ups may be necessary, but will
464*4882a593Smuzhiyunbe avoided if possible.  If there are features missing from ACPI that preclude
465*4882a593Smuzhiyunit from being used on a platform, ECRs (Engineering Change Requests) should be
466*4882a593Smuzhiyunsubmitted to ASWG and go through the normal approval process; for those that
467*4882a593Smuzhiyunare not UEFI members, many other members of the Linux community are and would
468*4882a593Smuzhiyunlikely be willing to assist in submitting ECRs.
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun
471*4882a593SmuzhiyunLinux Code
472*4882a593Smuzhiyun----------
473*4882a593SmuzhiyunIndividual items specific to Linux on ARM, contained in the Linux
474*4882a593Smuzhiyunsource code, are in the list that follows:
475*4882a593Smuzhiyun
476*4882a593SmuzhiyunACPI_OS_NAME
477*4882a593Smuzhiyun                       This macro defines the string to be returned when
478*4882a593Smuzhiyun                       an ACPI method invokes the _OS method.  On ARM64
479*4882a593Smuzhiyun                       systems, this macro will be "Linux" by default.
480*4882a593Smuzhiyun                       The command line parameter acpi_os=<string>
481*4882a593Smuzhiyun                       can be used to set it to some other value.  The
482*4882a593Smuzhiyun                       default value for other architectures is "Microsoft
483*4882a593Smuzhiyun                       Windows NT", for example.
484*4882a593Smuzhiyun
485*4882a593SmuzhiyunACPI Objects
486*4882a593Smuzhiyun------------
487*4882a593SmuzhiyunDetailed expectations for ACPI tables and object are listed in the file
488*4882a593SmuzhiyunDocumentation/arm64/acpi_object_usage.rst.
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun
491*4882a593SmuzhiyunReferences
492*4882a593Smuzhiyun----------
493*4882a593Smuzhiyun[0] http://silver.arm.com
494*4882a593Smuzhiyun    document ARM-DEN-0029, or newer:
495*4882a593Smuzhiyun    "Server Base System Architecture", version 2.3, dated 27 Mar 2014
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun[1] http://infocenter.arm.com/help/topic/com.arm.doc.den0044a/Server_Base_Boot_Requirements.pdf
498*4882a593Smuzhiyun    Document ARM-DEN-0044A, or newer: "Server Base Boot Requirements, System
499*4882a593Smuzhiyun    Software on ARM Platforms", dated 16 Aug 2014
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun[2] http://www.secretlab.ca/archives/151,
502*4882a593Smuzhiyun    10 Jan 2015, Copyright (c) 2015,
503*4882a593Smuzhiyun    Linaro Ltd., written by Grant Likely.
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun[3] AMD ACPI for Seattle platform documentation
506*4882a593Smuzhiyun    http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Seattle_ACPI_Guide.pdf
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun[4] http://www.uefi.org/acpi
510*4882a593Smuzhiyun    please see the link for the "ACPI _DSD Device
511*4882a593Smuzhiyun    Property Registry Instructions"
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun[5] http://www.uefi.org/acpi
514*4882a593Smuzhiyun    please see the link for the "_DSD (Device
515*4882a593Smuzhiyun    Specific Data) Implementation Guide"
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun[6] Kernel code for the unified device
518*4882a593Smuzhiyun    property interface can be found in
519*4882a593Smuzhiyun    include/linux/property.h and drivers/base/property.c.
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun
522*4882a593SmuzhiyunAuthors
523*4882a593Smuzhiyun-------
524*4882a593Smuzhiyun- Al Stone <al.stone@linaro.org>
525*4882a593Smuzhiyun- Graeme Gregory <graeme.gregory@linaro.org>
526*4882a593Smuzhiyun- Hanjun Guo <hanjun.guo@linaro.org>
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun- Grant Likely <grant.likely@linaro.org>, for the "Why ACPI on ARM?" section
529