arm-vgic-v3.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==============================================================
  3. ARM Virtual Generic Interrupt Controller v3 and later (VGICv3)
  4. ==============================================================
  5. Device types supported:
  6. - KVM_DEV_TYPE_ARM_VGIC_V3 ARM Generic Interrupt Controller v3.0
  7. Only one VGIC instance may be instantiated through this API. The created VGIC
  8. will act as the VM interrupt controller, requiring emulated user-space devices
  9. to inject interrupts to the VGIC instead of directly to CPUs. It is not
  10. possible to create both a GICv3 and GICv2 on the same VM.
  11. Creating a guest GICv3 device requires a host GICv3 as well.
  12. Groups:
  13. KVM_DEV_ARM_VGIC_GRP_ADDR
  14. Attributes:
  15. KVM_VGIC_V3_ADDR_TYPE_DIST (rw, 64-bit)
  16. Base address in the guest physical address space of the GICv3 distributor
  17. register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
  18. This address needs to be 64K aligned and the region covers 64 KByte.
  19. KVM_VGIC_V3_ADDR_TYPE_REDIST (rw, 64-bit)
  20. Base address in the guest physical address space of the GICv3
  21. redistributor register mappings. There are two 64K pages for each
  22. VCPU and all of the redistributor pages are contiguous.
  23. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
  24. This address needs to be 64K aligned.
  25. KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION (rw, 64-bit)
  26. The attribute data pointed to by kvm_device_attr.addr is a __u64 value::
  27. bits: | 63 .... 52 | 51 .... 16 | 15 - 12 |11 - 0
  28. values: | count | base | flags | index
  29. - index encodes the unique redistributor region index
  30. - flags: reserved for future use, currently 0
  31. - base field encodes bits [51:16] of the guest physical base address
  32. of the first redistributor in the region.
  33. - count encodes the number of redistributors in the region. Must be
  34. greater than 0.
  35. There are two 64K pages for each redistributor in the region and
  36. redistributors are laid out contiguously within the region. Regions
  37. are filled with redistributors in the index order. The sum of all
  38. region count fields must be greater than or equal to the number of
  39. VCPUs. Redistributor regions must be registered in the incremental
  40. index order, starting from index 0.
  41. The characteristics of a specific redistributor region can be read
  42. by presetting the index field in the attr data.
  43. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3.
  44. It is invalid to mix calls with KVM_VGIC_V3_ADDR_TYPE_REDIST and
  45. KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION attributes.
  46. Errors:
  47. ======= =============================================================
  48. -E2BIG Address outside of addressable IPA range
  49. -EINVAL Incorrectly aligned address, bad redistributor region
  50. count/index, mixed redistributor region attribute usage
  51. -EEXIST Address already configured
  52. -ENOENT Attempt to read the characteristics of a non existing
  53. redistributor region
  54. -ENXIO The group or attribute is unknown/unsupported for this device
  55. or hardware support is missing.
  56. -EFAULT Invalid user pointer for attr->addr.
  57. ======= =============================================================
  58. KVM_DEV_ARM_VGIC_GRP_DIST_REGS, KVM_DEV_ARM_VGIC_GRP_REDIST_REGS
  59. Attributes:
  60. The attr field of kvm_device_attr encodes two values::
  61. bits: | 63 .... 32 | 31 .... 0 |
  62. values: | mpidr | offset |
  63. All distributor regs are (rw, 32-bit) and kvm_device_attr.addr points to a
  64. __u32 value. 64-bit registers must be accessed by separately accessing the
  65. lower and higher word.
  66. Writes to read-only registers are ignored by the kernel.
  67. KVM_DEV_ARM_VGIC_GRP_DIST_REGS accesses the main distributor registers.
  68. KVM_DEV_ARM_VGIC_GRP_REDIST_REGS accesses the redistributor of the CPU
  69. specified by the mpidr.
  70. The offset is relative to the "[Re]Distributor base address" as defined
  71. in the GICv3/4 specs. Getting or setting such a register has the same
  72. effect as reading or writing the register on real hardware, except for the
  73. following registers: GICD_STATUSR, GICR_STATUSR, GICD_ISPENDR,
  74. GICR_ISPENDR0, GICD_ICPENDR, and GICR_ICPENDR0. These registers behave
  75. differently when accessed via this interface compared to their
  76. architecturally defined behavior to allow software a full view of the
  77. VGIC's internal state.
  78. The mpidr field is used to specify which
  79. redistributor is accessed. The mpidr is ignored for the distributor.
  80. The mpidr encoding is based on the affinity information in the
  81. architecture defined MPIDR, and the field is encoded as follows::
  82. | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 |
  83. | Aff3 | Aff2 | Aff1 | Aff0 |
  84. Note that distributor fields are not banked, but return the same value
  85. regardless of the mpidr used to access the register.
  86. GICD_IIDR.Revision is updated when the KVM implementation is changed in a
  87. way directly observable by the guest or userspace. Userspace should read
  88. GICD_IIDR from KVM and write back the read value to confirm its expected
  89. behavior is aligned with the KVM implementation. Userspace should set
  90. GICD_IIDR before setting any other registers to ensure the expected
  91. behavior.
  92. The GICD_STATUSR and GICR_STATUSR registers are architecturally defined such
  93. that a write of a clear bit has no effect, whereas a write with a set bit
  94. clears that value. To allow userspace to freely set the values of these two
  95. registers, setting the attributes with the register offsets for these two
  96. registers simply sets the non-reserved bits to the value written.
  97. Accesses (reads and writes) to the GICD_ISPENDR register region and
  98. GICR_ISPENDR0 registers get/set the value of the latched pending state for
  99. the interrupts.
  100. This is identical to the value returned by a guest read from ISPENDR for an
  101. edge triggered interrupt, but may differ for level triggered interrupts.
  102. For edge triggered interrupts, once an interrupt becomes pending (whether
  103. because of an edge detected on the input line or because of a guest write
  104. to ISPENDR) this state is "latched", and only cleared when either the
  105. interrupt is activated or when the guest writes to ICPENDR. A level
  106. triggered interrupt may be pending either because the level input is held
  107. high by a device, or because of a guest write to the ISPENDR register. Only
  108. ISPENDR writes are latched; if the device lowers the line level then the
  109. interrupt is no longer pending unless the guest also wrote to ISPENDR, and
  110. conversely writes to ICPENDR or activations of the interrupt do not clear
  111. the pending status if the line level is still being held high. (These
  112. rules are documented in the GICv3 specification descriptions of the ICPENDR
  113. and ISPENDR registers.) For a level triggered interrupt the value accessed
  114. here is that of the latch which is set by ISPENDR and cleared by ICPENDR or
  115. interrupt activation, whereas the value returned by a guest read from
  116. ISPENDR is the logical OR of the latch value and the input line level.
  117. Raw access to the latch state is provided to userspace so that it can save
  118. and restore the entire GIC internal state (which is defined by the
  119. combination of the current input line level and the latch state, and cannot
  120. be deduced from purely the line level and the value of the ISPENDR
  121. registers).
  122. Accesses to GICD_ICPENDR register region and GICR_ICPENDR0 registers have
  123. RAZ/WI semantics, meaning that reads always return 0 and writes are always
  124. ignored.
  125. Errors:
  126. ====== =====================================================
  127. -ENXIO Getting or setting this register is not yet supported
  128. -EBUSY One or more VCPUs are running
  129. ====== =====================================================
  130. KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS
  131. Attributes:
  132. The attr field of kvm_device_attr encodes two values::
  133. bits: | 63 .... 32 | 31 .... 16 | 15 .... 0 |
  134. values: | mpidr | RES | instr |
  135. The mpidr field encodes the CPU ID based on the affinity information in the
  136. architecture defined MPIDR, and the field is encoded as follows::
  137. | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 |
  138. | Aff3 | Aff2 | Aff1 | Aff0 |
  139. The instr field encodes the system register to access based on the fields
  140. defined in the A64 instruction set encoding for system register access
  141. (RES means the bits are reserved for future use and should be zero)::
  142. | 15 ... 14 | 13 ... 11 | 10 ... 7 | 6 ... 3 | 2 ... 0 |
  143. | Op 0 | Op1 | CRn | CRm | Op2 |
  144. All system regs accessed through this API are (rw, 64-bit) and
  145. kvm_device_attr.addr points to a __u64 value.
  146. KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS accesses the CPU interface registers for the
  147. CPU specified by the mpidr field.
  148. CPU interface registers access is not implemented for AArch32 mode.
  149. Error -ENXIO is returned when accessed in AArch32 mode.
  150. Errors:
  151. ======= =====================================================
  152. -ENXIO Getting or setting this register is not yet supported
  153. -EBUSY VCPU is running
  154. -EINVAL Invalid mpidr or register value supplied
  155. ======= =====================================================
  156. KVM_DEV_ARM_VGIC_GRP_NR_IRQS
  157. Attributes:
  158. A value describing the number of interrupts (SGI, PPI and SPI) for
  159. this GIC instance, ranging from 64 to 1024, in increments of 32.
  160. kvm_device_attr.addr points to a __u32 value.
  161. Errors:
  162. ======= ======================================
  163. -EINVAL Value set is out of the expected range
  164. -EBUSY Value has already be set.
  165. ======= ======================================
  166. KVM_DEV_ARM_VGIC_GRP_CTRL
  167. Attributes:
  168. KVM_DEV_ARM_VGIC_CTRL_INIT
  169. request the initialization of the VGIC, no additional parameter in
  170. kvm_device_attr.addr. Must be called after all VCPUs have been created.
  171. KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES
  172. save all LPI pending bits into guest RAM pending tables.
  173. The first kB of the pending table is not altered by this operation.
  174. Errors:
  175. ======= ========================================================
  176. -ENXIO VGIC not properly configured as required prior to calling
  177. this attribute
  178. -ENODEV no online VCPU
  179. -ENOMEM memory shortage when allocating vgic internal data
  180. -EFAULT Invalid guest ram access
  181. -EBUSY One or more VCPUS are running
  182. ======= ========================================================
  183. KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO
  184. Attributes:
  185. The attr field of kvm_device_attr encodes the following values::
  186. bits: | 63 .... 32 | 31 .... 10 | 9 .... 0 |
  187. values: | mpidr | info | vINTID |
  188. The vINTID specifies which set of IRQs is reported on.
  189. The info field specifies which information userspace wants to get or set
  190. using this interface. Currently we support the following info values:
  191. VGIC_LEVEL_INFO_LINE_LEVEL:
  192. Get/Set the input level of the IRQ line for a set of 32 contiguously
  193. numbered interrupts.
  194. vINTID must be a multiple of 32.
  195. kvm_device_attr.addr points to a __u32 value which will contain a
  196. bitmap where a set bit means the interrupt level is asserted.
  197. Bit[n] indicates the status for interrupt vINTID + n.
  198. SGIs and any interrupt with a higher ID than the number of interrupts
  199. supported, will be RAZ/WI. LPIs are always edge-triggered and are
  200. therefore not supported by this interface.
  201. PPIs are reported per VCPU as specified in the mpidr field, and SPIs are
  202. reported with the same value regardless of the mpidr specified.
  203. The mpidr field encodes the CPU ID based on the affinity information in the
  204. architecture defined MPIDR, and the field is encoded as follows::
  205. | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 |
  206. | Aff3 | Aff2 | Aff1 | Aff0 |
  207. Errors:
  208. ======= =============================================
  209. -EINVAL vINTID is not multiple of 32 or info field is
  210. not VGIC_LEVEL_INFO_LINE_LEVEL
  211. ======= =============================================