acpi-interface.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. .. SPDX-License-Identifier: GPL-2.0-or-later
  2. ==================
  3. ACPI WMI interface
  4. ==================
  5. The ACPI WMI interface is a proprietary extension of the ACPI specification made
  6. by Microsoft to allow hardware vendors to embed WMI (Windows Management Instrumentation)
  7. objects inside their ACPI firmware. Typical functions implemented over ACPI WMI
  8. are hotkey events on modern notebooks and configuration of BIOS options.
  9. PNP0C14 ACPI device
  10. -------------------
  11. Discovery of WMI objects is handled by defining ACPI devices with a PNP ID
  12. of ``PNP0C14``. These devices will contain a set of ACPI buffers and methods
  13. used for mapping and execution of WMI methods and/or queries. If there exist
  14. multiple of such devices, then each device is required to have a
  15. unique ACPI UID.
  16. _WDG buffer
  17. -----------
  18. The ``_WDG`` buffer is used to discover WMI objects and is required to be
  19. static. Its internal structure consists of data blocks with a size of 20 bytes,
  20. containing the following data:
  21. ======= =============== =====================================================
  22. Offset Size (in bytes) Content
  23. ======= =============== =====================================================
  24. 0x00 16 128 bit Variant 2 object GUID.
  25. 0x10 2 2 character method ID or single byte notification ID.
  26. 0x12 1 Object instance count.
  27. 0x13 1 Object flags.
  28. ======= =============== =====================================================
  29. The WMI object flags control whether the method or notification ID is used:
  30. - 0x1: Data block is expensive to collect.
  31. - 0x2: Data block contains WMI methods.
  32. - 0x4: Data block contains ASCIZ string.
  33. - 0x8: Data block describes a WMI event, use notification ID instead
  34. of method ID.
  35. Each WMI object GUID can appear multiple times inside a system.
  36. The method/notification ID is used to construct the ACPI method names used for
  37. interacting with the WMI object.
  38. WQxx ACPI methods
  39. -----------------
  40. If a data block does not contain WMI methods, then its content can be retrieved
  41. by this required ACPI method. The last two characters of the ACPI method name
  42. are the method ID of the data block to query. Their single parameter is an
  43. integer describing the instance which should be queried. This parameter can be
  44. omitted if the data block contains only a single instance.
  45. WSxx ACPI methods
  46. -----------------
  47. Similar to the ``WQxx`` ACPI methods, except that it is optional and takes an
  48. additional buffer as its second argument. The instance argument also cannot
  49. be omitted.
  50. WMxx ACPI methods
  51. -----------------
  52. Used for executing WMI methods associated with a data block. The last two
  53. characters of the ACPI method name are the method ID of the data block
  54. containing the WMI methods. Their first parameter is a integer describing the
  55. instance which methods should be executed. The second parameter is an integer
  56. describing the WMI method ID to execute, and the third parameter is a buffer
  57. containing the WMI method parameters. If the data block is marked as containing
  58. an ASCIZ string, then this buffer should contain an ASCIZ string. The ACPI
  59. method will return the result of the executed WMI method.
  60. WExx ACPI methods
  61. -----------------
  62. Used for optionally enabling/disabling WMI events, the last two characters of
  63. the ACPI method are the notification ID of the data block describing the WMI
  64. event as hexadecimal value. Their first parameter is an integer with a value
  65. of 0 if the WMI event should be disabled, other values will enable
  66. the WMI event.
  67. Those ACPI methods are always called even for WMI events not registered as
  68. being expensive to collect to match the behavior of the Windows driver.
  69. WCxx ACPI methods
  70. -----------------
  71. Similar to the ``WExx`` ACPI methods, except that instead of WMI events it controls
  72. data collection of data blocks registered as being expensive to collect. Thus the
  73. last two characters of the ACPI method name are the method ID of the data block
  74. to enable/disable.
  75. Those ACPI methods are also called before setting data blocks to match the
  76. behavior of the Windows driver.
  77. _WED ACPI method
  78. ----------------
  79. Used to retrieve additional WMI event data, its single parameter is a integer
  80. holding the notification ID of the event. This method should be evaluated every
  81. time an ACPI notification is received, since some ACPI implementations use a
  82. queue to store WMI event data items. This queue will overflow after a couple
  83. of WMI events are received without retrieving the associated WMI event data.
  84. Conversion rules for ACPI data types
  85. ------------------------------------
  86. Consumers of the ACPI-WMI interface use binary buffers to exchange data with the WMI driver core,
  87. with the internal structure of the buffer being only know to the consumers. The WMI driver core is
  88. thus responsible for converting the data inside the buffer into an appropriate ACPI data type for
  89. consumption by the ACPI firmware. Additionally, any data returned by the various ACPI methods needs
  90. to be converted back into a binary buffer.
  91. The layout of said buffers is defined by the MOF description of the WMI method or data block in
  92. question [1]_:
  93. =============== ======================================================================= =========
  94. Data Type Layout Alignment
  95. =============== ======================================================================= =========
  96. ``string`` Starts with an unsigned 16-bit little endian integer specifying 2 bytes
  97. the length of the string data in bytes, followed by the string data
  98. encoded as UTF-16LE with **optional** NULL termination and padding.
  99. Keep in mind that some firmware implementations might depend on the
  100. terminating NULL character to be present. Also the padding should
  101. always be performed with NULL characters.
  102. ``boolean`` Single byte where 0 means ``false`` and nonzero means ``true``. 1 byte
  103. ``sint8`` Signed 8-bit integer. 1 byte
  104. ``uint8`` Unsigned 8-bit integer. 1 byte
  105. ``sint16`` Signed 16-bit little endian integer. 2 bytes
  106. ``uint16`` Unsigned 16-bit little endian integer. 2 bytes
  107. ``sint32`` Signed 32-bit little endian integer. 4 bytes
  108. ``uint32`` Unsigned 32-bit little endian integer. 4 bytes
  109. ``sint64`` Signed 64-bit little endian integer. 8 bytes
  110. ``uint64`` Unsigned 64-bit little endian integer. 8 bytes
  111. ``datetime`` A fixed-length 25-character UTF-16LE string with the format 2 bytes
  112. *yyyymmddhhmmss.mmmmmmsutc* where *yyyy* is the 4-digit year, *mm* is
  113. the 2-digit month, *dd* is the 2-digit day, *hh* is the 2-digit hour
  114. based on a 24-hour clock, *mm* is the 2-digit minute, *ss* is the
  115. 2-digit second, *mmmmmm* is the 6-digit microsecond, *s* is a plus or
  116. minus character depending on whether *utc* is a positive or negative
  117. offset from UTC (or a colon if the date is an interval). Unpopulated
  118. fields should be filled with asterisks.
  119. =============== ======================================================================= =========
  120. Arrays should be aligned based on the alignment of their base type, while objects should be
  121. aligned based on the largest alignment of an element inside them.
  122. All buffers returned by the WMI driver core are 8-byte aligned. When converting ACPI data types
  123. into such buffers the following conversion rules apply:
  124. =============== ============================================================
  125. ACPI Data Type Converted into
  126. =============== ============================================================
  127. Buffer Copied as-is.
  128. Integer Converted into a ``uint32``.
  129. String Converted into a ``string`` with a terminating NULL character
  130. to match the behavior the of the Windows driver.
  131. Package Each element inside the package is converted with alignment
  132. of the resulting data types being respected. Nested packages
  133. are not allowed.
  134. =============== ============================================================
  135. The Windows driver does attempt to handle nested packages, but this results in internal data
  136. structures (``_ACPI_METHOD_ARGUMENT_V1``) erroneously being copied into the resulting buffer.
  137. ACPI firmware implementations should thus not return nested packages from ACPI methods
  138. associated with the ACPI-WMI interface.
  139. References
  140. ==========
  141. .. [1] https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/driver-defined-wmi-data-items