acpi_cpu_hotplug.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. QEMU<->ACPI BIOS CPU hotplug interface
  2. ======================================
  3. QEMU supports CPU hotplug via ACPI. This document
  4. describes the interface between QEMU and the ACPI BIOS.
  5. ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add
  6. and hot-remove events.
  7. Legacy ACPI CPU hotplug interface registers
  8. -------------------------------------------
  9. CPU present bitmap for:
  10. - ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access)
  11. - PIIX-PM (IO port 0xaf00-0xaf1f, 1-byte access)
  12. - One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only.
  13. - The first DWORD in bitmap is used in write mode to switch from legacy
  14. to modern CPU hotplug interface, write 0 into it to do switch.
  15. QEMU sets corresponding CPU bit on hot-add event and issues SCI
  16. with GPE.2 event set. CPU present map is read by ACPI BIOS GPE.2 handler
  17. to notify OS about CPU hot-add events. CPU hot-remove isn't supported.
  18. Modern ACPI CPU hotplug interface registers
  19. -------------------------------------------
  20. Register block base address:
  21. - ICH9-LPC IO port 0x0cd8
  22. - PIIX-PM IO port 0xaf00
  23. Register block size:
  24. - ACPI_CPU_HOTPLUG_REG_LEN = 12
  25. All accesses to registers described below, imply little-endian byte order.
  26. Reserved registers behavior:
  27. - write accesses are ignored
  28. - read accesses return all bits set to 0.
  29. The last stored value in 'CPU selector' must refer to a possible CPU, otherwise
  30. - reads from any register return 0
  31. - writes to any other register are ignored until valid value is stored into it
  32. On QEMU start, 'CPU selector' is initialized to a valid value, on reset it
  33. keeps the current value.
  34. Read access behavior
  35. ^^^^^^^^^^^^^^^^^^^^
  36. offset [0x0-0x3]
  37. Command data 2: (DWORD access)
  38. If value last stored in 'Command field' is:
  39. 0:
  40. reads as 0x0
  41. 3:
  42. upper 32 bits of architecture specific CPU ID value
  43. other values:
  44. reserved
  45. offset [0x4]
  46. CPU device status fields: (1 byte access)
  47. bits:
  48. 0:
  49. Device is enabled and may be used by guest
  50. 1:
  51. Device insert event, used to distinguish device for which
  52. no device check event to OSPM was issued.
  53. It's valid only when bit 0 is set.
  54. 2:
  55. Device remove event, used to distinguish device for which
  56. no device eject request to OSPM was issued. Firmware must
  57. ignore this bit.
  58. 3:
  59. reserved and should be ignored by OSPM
  60. 4:
  61. if set to 1, OSPM requests firmware to perform device eject.
  62. 5-7:
  63. reserved and should be ignored by OSPM
  64. offset [0x5-0x7]
  65. reserved
  66. offset [0x8]
  67. Command data: (DWORD access)
  68. If value last stored in 'Command field' is one of:
  69. 0:
  70. contains 'CPU selector' value of a CPU with pending event[s]
  71. 3:
  72. lower 32 bits of architecture specific CPU ID value
  73. (in x86 case: APIC ID)
  74. otherwise:
  75. contains 0
  76. Write access behavior
  77. ^^^^^^^^^^^^^^^^^^^^^
  78. offset [0x0-0x3]
  79. CPU selector: (DWORD access)
  80. Selects active CPU device. All following accesses to other
  81. registers will read/store data from/to selected CPU.
  82. Valid values: [0 .. max_cpus)
  83. offset [0x4]
  84. CPU device control fields: (1 byte access)
  85. bits:
  86. 0:
  87. reserved, OSPM must clear it before writing to register.
  88. 1:
  89. if set to 1 clears device insert event, set by OSPM
  90. after it has emitted device check event for the
  91. selected CPU device
  92. 2:
  93. if set to 1 clears device remove event, set by OSPM
  94. after it has emitted device eject request for the
  95. selected CPU device.
  96. 3:
  97. if set to 1 initiates device eject, set by OSPM when it
  98. triggers CPU device removal and calls _EJ0 method or by firmware
  99. when bit #4 is set. In case bit #4 were set, it's cleared as
  100. part of device eject.
  101. 4:
  102. if set to 1, OSPM hands over device eject to firmware.
  103. Firmware shall issue device eject request as described above
  104. (bit #3) and OSPM should not touch device eject bit (#3) in case
  105. it's asked firmware to perform CPU device eject.
  106. 5-7:
  107. reserved, OSPM must clear them before writing to register
  108. offset[0x5]
  109. Command field: (1 byte access)
  110. value:
  111. 0:
  112. selects a CPU device with inserting/removing events and
  113. following reads from 'Command data' register return
  114. selected CPU ('CPU selector' value).
  115. If no CPU with events found, the current 'CPU selector' doesn't
  116. change and corresponding insert/remove event flags are not modified.
  117. 1:
  118. following writes to 'Command data' register set OST event
  119. register in QEMU
  120. 2:
  121. following writes to 'Command data' register set OST status
  122. register in QEMU
  123. 3:
  124. following reads from 'Command data' and 'Command data 2' return
  125. architecture specific CPU ID value for currently selected CPU.
  126. other values:
  127. reserved
  128. offset [0x6-0x7]
  129. reserved
  130. offset [0x8]
  131. Command data: (DWORD access)
  132. If last stored 'Command field' value is:
  133. 1:
  134. stores value into OST event register
  135. 2:
  136. stores value into OST status register, triggers
  137. ACPI_DEVICE_OST QMP event from QEMU to external applications
  138. with current values of OST event and status registers.
  139. other values:
  140. reserved
  141. Typical usecases
  142. ----------------
  143. (x86) Detecting and enabling modern CPU hotplug interface
  144. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  145. QEMU starts with legacy CPU hotplug interface enabled. Detecting and
  146. switching to modern interface is based on the 2 legacy CPU hotplug features:
  147. #. Writes into CPU bitmap are ignored.
  148. #. CPU bitmap always has bit #0 set, corresponding to boot CPU.
  149. Use following steps to detect and enable modern CPU hotplug interface:
  150. #. Store 0x0 to the 'CPU selector' register, attempting to switch to modern mode
  151. #. Store 0x0 to the 'CPU selector' register, to ensure valid selector value
  152. #. Store 0x0 to the 'Command field' register
  153. #. Read the 'Command data 2' register.
  154. If read value is 0x0, the modern interface is enabled.
  155. Otherwise legacy or no CPU hotplug interface available
  156. Get a cpu with pending event
  157. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  158. #. Store 0x0 to the 'CPU selector' register.
  159. #. Store 0x0 to the 'Command field' register.
  160. #. Read the 'CPU device status fields' register.
  161. #. If both bit #1 and bit #2 are clear in the value read, there is no CPU
  162. with a pending event and selected CPU remains unchanged.
  163. #. Otherwise, read the 'Command data' register. The value read is the
  164. selector of the CPU with the pending event (which is already selected).
  165. Enumerate CPUs present/non present CPUs
  166. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  167. #. Set the present CPU count to 0.
  168. #. Set the iterator to 0.
  169. #. Store 0x0 to the 'CPU selector' register, to ensure that it's in
  170. a valid state and that access to other registers won't be ignored.
  171. #. Store 0x0 to the 'Command field' register to make 'Command data'
  172. register return 'CPU selector' value of selected CPU
  173. #. Read the 'CPU device status fields' register.
  174. #. If bit #0 is set, increment the present CPU count.
  175. #. Increment the iterator.
  176. #. Store the iterator to the 'CPU selector' register.
  177. #. Read the 'Command data' register.
  178. #. If the value read is not zero, goto 05.
  179. #. Otherwise store 0x0 to the 'CPU selector' register, to put it
  180. into a valid state and exit.
  181. The iterator at this point equals "max_cpus".