arm-acpi.rst 24 KB

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