1=================== 2ACPI on Arm systems 3=================== 4 5ACPI can be used for Armv8 and Armv9 systems designed to follow 6the BSA (Arm Base System Architecture) [0] and BBR (Arm 7Base Boot Requirements) [1] specifications. Both BSA and BBR are publicly 8accessible documents. 9Arm Servers, in addition to being BSA compliant, comply with a set 10of rules defined in SBSA (Server Base System Architecture) [2]. 11 12The Arm kernel implements the reduced hardware model of ACPI version 135.1 or later. Links to the specification and all external documents 14it refers to are managed by the UEFI Forum. The specification is 15available at http://www.uefi.org/specifications and documents referenced 16by the specification can be found via http://www.uefi.org/acpi. 17 18If an Arm system does not meet the requirements of the BSA and BBR, 19or cannot be described using the mechanisms defined in the required ACPI 20specifications, then ACPI may not be a good fit for the hardware. 21 22While the documents mentioned above set out the requirements for building 23industry-standard Arm systems, they also apply to more than one operating 24system. The purpose of this document is to describe the interaction between 25ACPI and Linux only, on an Arm system -- that is, what Linux expects of 26ACPI and what ACPI can expect of Linux. 27 28 29Why ACPI on Arm? 30---------------- 31Before examining the details of the interface between ACPI and Linux, it is 32useful to understand why ACPI is being used. Several technologies already 33exist in Linux for describing non-enumerable hardware, after all. In this 34section we summarize a blog post [3] from Grant Likely that outlines the 35reasoning behind ACPI on Arm systems. Actually, we snitch a good portion 36of the summary text almost directly, to be honest. 37 38The short form of the rationale for ACPI on Arm is: 39 40- ACPI’s byte code (AML) allows the platform to encode hardware behavior, 41 while DT explicitly does not support this. For hardware vendors, being 42 able to encode behavior is a key tool used in supporting operating 43 system releases on new hardware. 44 45- ACPI’s OSPM defines a power management model that constrains what the 46 platform is allowed to do into a specific model, while still providing 47 flexibility in hardware design. 48 49- In the enterprise server environment, ACPI has established bindings (such 50 as for RAS) which are currently used in production systems. DT does not. 51 Such bindings could be defined in DT at some point, but doing so means Arm 52 and x86 would end up using completely different code paths in both firmware 53 and the kernel. 54 55- Choosing a single interface to describe the abstraction between a platform 56 and an OS is important. Hardware vendors would not be required to implement 57 both DT and ACPI if they want to support multiple operating systems. And, 58 agreeing on a single interface instead of being fragmented into per OS 59 interfaces makes for better interoperability overall. 60 61- The new ACPI governance process works well and Linux is now at the same 62 table as hardware vendors and other OS vendors. In fact, there is no 63 longer any reason to feel that ACPI only belongs to Windows or that 64 Linux is in any way secondary to Microsoft in this arena. The move of 65 ACPI governance into the UEFI forum has significantly opened up the 66 specification development process, and currently, a large portion of the 67 changes being made to ACPI are being driven by Linux. 68 69Key to the use of ACPI is the support model. For servers in general, the 70responsibility for hardware behaviour cannot solely be the domain of the 71kernel, but rather must be split between the platform and the kernel, in 72order to allow for orderly change over time. ACPI frees the OS from needing 73to understand all the minute details of the hardware so that the OS doesn’t 74need to be ported to each and every device individually. It allows the 75hardware vendors to take responsibility for power management behaviour without 76depending on an OS release cycle which is not under their control. 77 78ACPI is also important because hardware and OS vendors have already worked 79out the mechanisms for supporting a general purpose computing ecosystem. The 80infrastructure is in place, the bindings are in place, and the processes are 81in place. DT does exactly what Linux needs it to when working with vertically 82integrated devices, but there are no good processes for supporting what the 83server vendors need. Linux could potentially get there with DT, but doing so 84really just duplicates something that already works. ACPI already does what 85the hardware vendors need, Microsoft won’t collaborate on DT, and hardware 86vendors would still end up providing two completely separate firmware 87interfaces -- one for Linux and one for Windows. 88 89 90Kernel Compatibility 91-------------------- 92One of the primary motivations for ACPI is standardization, and using that 93to provide backward compatibility for Linux kernels. In the server market, 94software and hardware are often used for long periods. ACPI allows the 95kernel and firmware to agree on a consistent abstraction that can be 96maintained over time, even as hardware or software change. As long as the 97abstraction is supported, systems can be updated without necessarily having 98to replace the kernel. 99 100When a Linux driver or subsystem is first implemented using ACPI, it by 101definition ends up requiring a specific version of the ACPI specification 102-- its baseline. ACPI firmware must continue to work, even though it may 103not be optimal, with the earliest kernel version that first provides support 104for that baseline version of ACPI. There may be a need for additional drivers, 105but adding new functionality (e.g., CPU power management) should not break 106older kernel versions. Further, ACPI firmware must also work with the most 107recent version of the kernel. 108 109 110Relationship with Device Tree 111----------------------------- 112ACPI support in drivers and subsystems for Arm should never be mutually 113exclusive with DT support at compile time. 114 115At boot time the kernel will only use one description method depending on 116parameters passed from the boot loader (including kernel bootargs). 117 118Regardless of whether DT or ACPI is used, the kernel must always be capable 119of booting with either scheme (in kernels with both schemes enabled at compile 120time). 121 122 123Booting using ACPI tables 124------------------------- 125The only defined method for passing ACPI tables to the kernel on Arm 126is via the UEFI system configuration table. Just so it is explicit, this 127means that ACPI is only supported on platforms that boot via UEFI. 128 129When an Arm system boots, it can either have DT information, ACPI tables, 130or in some very unusual cases, both. If no command line parameters are used, 131the kernel will try to use DT for device enumeration; if there is no DT 132present, the kernel will try to use ACPI tables, but only if they are present. 133If neither is available, the kernel will not boot. If acpi=force is used 134on the command line, the kernel will attempt to use ACPI tables first, but 135fall back to DT if there are no ACPI tables present. The basic idea is that 136the kernel will not fail to boot unless it absolutely has no other choice. 137 138Processing of ACPI tables may be disabled by passing acpi=off on the kernel 139command line; this is the default behavior. 140 141In order for the kernel to load and use ACPI tables, the UEFI implementation 142MUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with 143the ACPI signature "RSD PTR "). If this pointer is incorrect and acpi=force 144is used, the kernel will disable ACPI and try to use DT to boot instead; the 145kernel has, in effect, determined that ACPI tables are not present at that 146point. 147 148If the pointer to the RSDP table is correct, the table will be mapped into 149the kernel by the ACPI core, using the address provided by UEFI. 150 151The ACPI core will then locate and map in all other ACPI tables provided by 152using the addresses in the RSDP table to find the XSDT (eXtended System 153Description Table). The XSDT in turn provides the addresses to all other 154ACPI tables provided by the system firmware; the ACPI core will then traverse 155this table and map in the tables listed. 156 157The ACPI core will ignore any provided RSDT (Root System Description Table). 158RSDTs have been deprecated and are ignored on arm64 since they only allow 159for 32-bit addresses. 160 161Further, the ACPI core will only use the 64-bit address fields in the FADT 162(Fixed ACPI Description Table). Any 32-bit address fields in the FADT will 163be ignored on arm64. 164 165Hardware reduced mode (see Section 4.1 of the ACPI 6.1 specification) will 166be enforced by the ACPI core on arm64. Doing so allows the ACPI core to 167run less complex code since it no longer has to provide support for legacy 168hardware from other architectures. Any fields that are not to be used for 169hardware reduced mode must be set to zero. 170 171For the ACPI core to operate properly, and in turn provide the information 172the kernel needs to configure devices, it expects to find the following 173tables (all section numbers refer to the ACPI 6.5 specification): 174 175 - RSDP (Root System Description Pointer), section 5.2.5 176 177 - XSDT (eXtended System Description Table), section 5.2.8 178 179 - FADT (Fixed ACPI Description Table), section 5.2.9 180 181 - DSDT (Differentiated System Description Table), section 182 5.2.11.1 183 184 - MADT (Multiple APIC Description Table), section 5.2.12 185 186 - GTDT (Generic Timer Description Table), section 5.2.24 187 188 - PPTT (Processor Properties Topology Table), section 5.2.30 189 190 - DBG2 (DeBuG port table 2), section 5.2.6, specifically Table 5-6. 191 192 - APMT (Arm Performance Monitoring unit Table), section 5.2.6, specifically Table 5-6. 193 194 - AGDI (Arm Generic diagnostic Dump and Reset Device Interface Table), section 5.2.6, specifically Table 5-6. 195 196 - If PCI is supported, the MCFG (Memory mapped ConFiGuration 197 Table), section 5.2.6, specifically Table 5-6. 198 199 - If booting without a console=<device> kernel parameter is 200 supported, the SPCR (Serial Port Console Redirection table), 201 section 5.2.6, specifically Table 5-6. 202 203 - If necessary to describe the I/O topology, SMMUs and GIC ITSs, 204 the IORT (Input Output Remapping Table, section 5.2.6, specifically 205 Table 5-6). 206 207 - If NUMA is supported, the following tables are required: 208 209 - SRAT (System Resource Affinity Table), section 5.2.16 210 211 - SLIT (System Locality distance Information Table), section 5.2.17 212 213 - If NUMA is supported, and the system contains heterogeneous memory, 214 the HMAT (Heterogeneous Memory Attribute Table), section 5.2.28. 215 216 - If the ACPI Platform Error Interfaces are required, the following 217 tables are conditionally required: 218 219 - BERT (Boot Error Record Table, section 18.3.1) 220 221 - EINJ (Error INJection table, section 18.6.1) 222 223 - ERST (Error Record Serialization Table, section 18.5) 224 225 - HEST (Hardware Error Source Table, section 18.3.2) 226 227 - SDEI (Software Delegated Exception Interface table, section 5.2.6, 228 specifically Table 5-6) 229 230 - AEST (Arm Error Source Table, section 5.2.6, 231 specifically Table 5-6) 232 233 - RAS2 (ACPI RAS2 feature table, section 5.2.21) 234 235 - If the system contains controllers using PCC channel, the 236 PCCT (Platform Communications Channel Table), section 14.1 237 238 - If the system contains a controller to capture board-level system state, 239 and communicates with the host via PCC, the PDTT (Platform Debug Trigger 240 Table), section 5.2.29. 241 242 - If NVDIMM is supported, the NFIT (NVDIMM Firmware Interface Table), section 5.2.26 243 244 - If video framebuffer is present, the BGRT (Boot Graphics Resource Table), section 5.2.23 245 246 - If IPMI is implemented, the SPMI (Server Platform Management Interface), 247 section 5.2.6, specifically Table 5-6. 248 249 - If the system contains a CXL Host Bridge, the CEDT (CXL Early Discovery 250 Table), section 5.2.6, specifically Table 5-6. 251 252 - If the system supports MPAM, the MPAM (Memory Partitioning And Monitoring table), section 5.2.6, 253 specifically Table 5-6. 254 255 - If the system lacks persistent storage, the IBFT (ISCSI Boot Firmware 256 Table), section 5.2.6, specifically Table 5-6. 257 258 259If the above tables are not all present, the kernel may or may not be 260able to boot properly since it may not be able to configure all of the 261devices available. This list of tables is not meant to be all inclusive; 262in some environments other tables may be needed (e.g., any of the APEI 263tables from section 18) to support specific functionality. 264 265 266ACPI Detection 267-------------- 268Drivers should determine their probe() type by checking for a null 269value for ACPI_HANDLE, or checking .of_node, or other information in 270the device structure. This is detailed further in the "Driver 271Recommendations" section. 272 273In non-driver code, if the presence of ACPI needs to be detected at 274run time, then check the value of acpi_disabled. If CONFIG_ACPI is not 275set, acpi_disabled will always be 1. 276 277 278Device Enumeration 279------------------ 280Device descriptions in ACPI should use standard recognized ACPI interfaces. 281These may contain less information than is typically provided via a Device 282Tree description for the same device. This is also one of the reasons that 283ACPI can be useful -- the driver takes into account that it may have less 284detailed information about the device and uses sensible defaults instead. 285If done properly in the driver, the hardware can change and improve over 286time without the driver having to change at all. 287 288Clocks provide an excellent example. In DT, clocks need to be specified 289and the drivers need to take them into account. In ACPI, the assumption 290is that UEFI will leave the device in a reasonable default state, including 291any clock settings. If for some reason the driver needs to change a clock 292value, this can be done in an ACPI method; all the driver needs to do is 293invoke the method and not concern itself with what the method needs to do 294to change the clock. Changing the hardware can then take place over time 295by changing what the ACPI method does, and not the driver. 296 297In DT, the parameters needed by the driver to set up clocks as in the example 298above are known as "bindings"; in ACPI, these are known as "Device Properties" 299and provided to a driver via the _DSD object. 300 301ACPI tables are described with a formal language called ASL, the ACPI 302Source Language (section 19 of the specification). This means that there 303are always multiple ways to describe the same thing -- including device 304properties. For example, device properties could use an ASL construct 305that looks like this: Name(KEY0, "value0"). An ACPI device driver would 306then retrieve the value of the property by evaluating the KEY0 object. 307However, using Name() this way has multiple problems: (1) ACPI limits 308names ("KEY0") to four characters unlike DT; (2) there is no industry 309wide registry that maintains a list of names, minimizing re-use; (3) 310there is also no registry for the definition of property values ("value0"), 311again making re-use difficult; and (4) how does one maintain backward 312compatibility as new hardware comes out? The _DSD method was created 313to solve precisely these sorts of problems; Linux drivers should ALWAYS 314use the _DSD method for device properties and nothing else. 315 316The _DSM object (ACPI Section 9.14.1) could also be used for conveying 317device properties to a driver. Linux drivers should only expect it to 318be used if _DSD cannot represent the data required, and there is no way 319to create a new UUID for the _DSD object. Note that there is even less 320regulation of the use of _DSM than there is of _DSD. Drivers that depend 321on the contents of _DSM objects will be more difficult to maintain over 322time because of this; as of this writing, the use of _DSM is the cause 323of quite a few firmware problems and is not recommended. 324 325Drivers should look for device properties in the _DSD object ONLY; the _DSD 326object is described in the ACPI specification section 6.2.5, but this only 327describes how to define the structure of an object returned via _DSD, and 328how specific data structures are defined by specific UUIDs. Linux should 329only use the _DSD Device Properties UUID [4]: 330 331 - UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 332 333Common device properties can be registered by creating a pull request to [4] so 334that they may be used across all operating systems supporting ACPI. 335Device properties that have not been registered with the UEFI Forum can be used 336but not as "uefi-" common properties. 337 338Before creating new device properties, check to be sure that they have not 339been defined before and either registered in the Linux kernel documentation 340as DT bindings, or the UEFI Forum as device properties. While we do not want 341to simply move all DT bindings into ACPI device properties, we can learn from 342what has been previously defined. 343 344If it is necessary to define a new device property, or if it makes sense to 345synthesize the definition of a binding so it can be used in any firmware, 346both DT bindings and ACPI device properties for device drivers have review 347processes. Use them both. When the driver itself is submitted for review 348to the Linux mailing lists, the device property definitions needed must be 349submitted at the same time. A driver that supports ACPI and uses device 350properties will not be considered complete without their definitions. Once 351the device property has been accepted by the Linux community, it must be 352registered with the UEFI Forum [4], which will review it again for consistency 353within the registry. This may require iteration. The UEFI Forum, though, 354will always be the canonical site for device property definitions. 355 356It may make sense to provide notice to the UEFI Forum that there is the 357intent to register a previously unused device property name as a means of 358reserving the name for later use. Other operating system vendors will 359also be submitting registration requests and this may help smooth the 360process. 361 362Once registration and review have been completed, the kernel provides an 363interface for looking up device properties in a manner independent of 364whether DT or ACPI is being used. This API should be used [5]; it can 365eliminate some duplication of code paths in driver probing functions and 366discourage divergence between DT bindings and ACPI device properties. 367 368 369Programmable Power Control Resources 370------------------------------------ 371Programmable power control resources include such resources as voltage/current 372providers (regulators) and clock sources. 373 374With ACPI, the kernel clock and regulator framework is not expected to be used 375at all. 376 377The kernel assumes that power control of these resources is represented with 378Power Resource Objects (ACPI section 7.1). The ACPI core will then handle 379correctly enabling and disabling resources as they are needed. In order to 380get that to work, ACPI assumes each device has defined D-states and that these 381can be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and _PS3; 382in ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3 is for 383turning a device full off. 384 385There are two options for using those Power Resources. They can: 386 387 - be managed in a _PSx method which gets called on entry to power 388 state Dx. 389 390 - be declared separately as power resources with their own _ON and _OFF 391 methods. They are then tied back to D-states for a particular device 392 via _PRx which specifies which power resources a device needs to be on 393 while in Dx. Kernel then tracks number of devices using a power resource 394 and calls _ON/_OFF as needed. 395 396The kernel ACPI code will also assume that the _PSx methods follow the normal 397ACPI rules for such methods: 398 399 - If either _PS0 or _PS3 is implemented, then the other method must also 400 be implemented. 401 402 - If a device requires usage or setup of a power resource when on, the ASL 403 should organize that it is allocated/enabled using the _PS0 method. 404 405 - Resources allocated or enabled in the _PS0 method should be disabled 406 or de-allocated in the _PS3 method. 407 408 - Firmware will leave the resources in a reasonable state before handing 409 over control to the kernel. 410 411Such code in _PSx methods will of course be very platform specific. But, 412this allows the driver to abstract out the interface for operating the device 413and avoid having to read special non-standard values from ACPI tables. Further, 414abstracting the use of these resources allows the hardware to change over time 415without requiring updates to the driver. 416 417 418Clocks 419------ 420ACPI makes the assumption that clocks are initialized by the firmware -- 421UEFI, in this case -- to some working value before control is handed over 422to the kernel. This has implications for devices such as UARTs, or SoC-driven 423LCD displays, for example. 424 425When the kernel boots, the clocks are assumed to be set to reasonable 426working values. If for some reason the frequency needs to change -- e.g., 427throttling for power management -- the device driver should expect that 428process to be abstracted out into some ACPI method that can be invoked 429(please see the ACPI specification for further recommendations on standard 430methods to be expected). The only exceptions to this are CPU clocks where 431CPPC provides a much richer interface than ACPI methods. If the clocks 432are not set, there is no direct way for Linux to control them. 433 434If an SoC vendor wants to provide fine-grained control of the system clocks, 435they could do so by providing ACPI methods that could be invoked by Linux 436drivers. However, this is NOT recommended and Linux drivers should NOT use 437such methods, even if they are provided. Such methods are not currently 438standardized in the ACPI specification, and using them could tie a kernel 439to a very specific SoC, or tie an SoC to a very specific version of the 440kernel, both of which we are trying to avoid. 441 442 443Driver Recommendations 444---------------------- 445DO NOT remove any DT handling when adding ACPI support for a driver. The 446same device may be used on many different systems. 447 448DO try to structure the driver so that it is data-driven. That is, set up 449a struct containing internal per-device state based on defaults and whatever 450else must be discovered by the driver probe function. Then, have the rest 451of the driver operate off of the contents of that struct. Doing so should 452allow most divergence between ACPI and DT functionality to be kept local to 453the probe function instead of being scattered throughout the driver. For 454example:: 455 456 static int device_probe_dt(struct platform_device *pdev) 457 { 458 /* DT specific functionality */ 459 ... 460 } 461 462 static int device_probe_acpi(struct platform_device *pdev) 463 { 464 /* ACPI specific functionality */ 465 ... 466 } 467 468 static int device_probe(struct platform_device *pdev) 469 { 470 ... 471 struct device_node node = pdev->dev.of_node; 472 ... 473 474 if (node) 475 ret = device_probe_dt(pdev); 476 else if (ACPI_HANDLE(&pdev->dev)) 477 ret = device_probe_acpi(pdev); 478 else 479 /* other initialization */ 480 ... 481 /* Continue with any generic probe operations */ 482 ... 483 } 484 485DO keep the MODULE_DEVICE_TABLE entries together in the driver to make it 486clear the different names the driver is probed for, both from DT and from 487ACPI:: 488 489 static struct of_device_id virtio_mmio_match[] = { 490 { .compatible = "virtio,mmio", }, 491 { } 492 }; 493 MODULE_DEVICE_TABLE(of, virtio_mmio_match); 494 495 static const struct acpi_device_id virtio_mmio_acpi_match[] = { 496 { "LNRO0005", }, 497 { } 498 }; 499 MODULE_DEVICE_TABLE(acpi, virtio_mmio_acpi_match); 500 501 502ASWG 503---- 504The ACPI specification changes regularly. During the year 2014, for instance, 505version 5.1 was released and version 6.0 substantially completed, with most of 506the changes being driven by Arm-specific requirements. Proposed changes are 507presented and discussed in the ASWG (ACPI Specification Working Group) which 508is a part of the UEFI Forum. The current version of the ACPI specification 509is 6.5 release in August 2022. 510 511Participation in this group is open to all UEFI members. Please see 512http://www.uefi.org/workinggroup for details on group membership. 513 514It is the intent of the Arm ACPI kernel code to follow the ACPI specification 515as closely as possible, and to only implement functionality that complies with 516the released standards from UEFI ASWG. As a practical matter, there will be 517vendors that provide bad ACPI tables or violate the standards in some way. 518If this is because of errors, quirks and fix-ups may be necessary, but will 519be avoided if possible. If there are features missing from ACPI that preclude 520it from being used on a platform, ECRs (Engineering Change Requests) should be 521submitted to ASWG and go through the normal approval process; for those that 522are not UEFI members, many other members of the Linux community are and would 523likely be willing to assist in submitting ECRs. 524 525 526Linux Code 527---------- 528Individual items specific to Linux on Arm, contained in the Linux 529source code, are in the list that follows: 530 531ACPI_OS_NAME 532 This macro defines the string to be returned when 533 an ACPI method invokes the _OS method. On Arm 534 systems, this macro will be "Linux" by default. 535 The command line parameter acpi_os=<string> 536 can be used to set it to some other value. The 537 default value for other architectures is "Microsoft 538 Windows NT", for example. 539 540ACPI Objects 541------------ 542Detailed expectations for ACPI tables and object are listed in the file 543Documentation/arch/arm64/acpi_object_usage.rst. 544 545 546References 547---------- 548[0] https://developer.arm.com/documentation/den0094/latest 549 document Arm-DEN-0094: "Arm Base System Architecture", version 1.0C, dated 6 Oct 2022 550 551[1] https://developer.arm.com/documentation/den0044/latest 552 Document Arm-DEN-0044: "Arm Base Boot Requirements", version 2.0G, dated 15 Apr 2022 553 554[2] https://developer.arm.com/documentation/den0029/latest 555 Document Arm-DEN-0029: "Arm Server Base System Architecture", version 7.1, dated 06 Oct 2022 556 557[3] http://www.secretlab.ca/archives/151, 558 10 Jan 2015, Copyright (c) 2015, 559 Linaro Ltd., written by Grant Likely. 560 561[4] _DSD (Device Specific Data) Implementation Guide 562 https://github.com/UEFI/DSD-Guide/blob/main/dsd-guide.pdf 563 564[5] Kernel code for the unified device 565 property interface can be found in 566 include/linux/property.h and drivers/base/property.c. 567 568 569Authors 570------- 571- Al Stone <al.stone@linaro.org> 572- Graeme Gregory <graeme.gregory@linaro.org> 573- Hanjun Guo <hanjun.guo@linaro.org> 574 575- Grant Likely <grant.likely@linaro.org>, for the "Why ACPI on ARM?" section 576