arm-vgic.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==================================================
  3. ARM Virtual Generic Interrupt Controller v2 (VGIC)
  4. ==================================================
  5. Device types supported:
  6. - KVM_DEV_TYPE_ARM_VGIC_V2 ARM Generic Interrupt Controller v2.0
  7. Only one VGIC instance may be instantiated through either this API or the
  8. legacy KVM_CREATE_IRQCHIP API. The created VGIC will act as the VM interrupt
  9. controller, requiring emulated user-space devices to inject interrupts to the
  10. VGIC instead of directly to CPUs.
  11. GICv3 implementations with hardware compatibility support allow creating a
  12. guest GICv2 through this interface. For information on creating a guest GICv3
  13. device and guest ITS devices, see arm-vgic-v3.txt. It is not possible to
  14. create both a GICv3 and GICv2 device on the same VM.
  15. Groups:
  16. KVM_DEV_ARM_VGIC_GRP_ADDR
  17. Attributes:
  18. KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit)
  19. Base address in the guest physical address space of the GIC distributor
  20. register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
  21. This address needs to be 4K aligned and the region covers 4 KByte.
  22. KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit)
  23. Base address in the guest physical address space of the GIC virtual cpu
  24. interface register mappings. Only valid for KVM_DEV_TYPE_ARM_VGIC_V2.
  25. This address needs to be 4K aligned and the region covers 4 KByte.
  26. Errors:
  27. ======= =============================================================
  28. -E2BIG Address outside of addressable IPA range
  29. -EINVAL Incorrectly aligned address
  30. -EEXIST Address already configured
  31. -ENXIO The group or attribute is unknown/unsupported for this device
  32. or hardware support is missing.
  33. -EFAULT Invalid user pointer for attr->addr.
  34. ======= =============================================================
  35. KVM_DEV_ARM_VGIC_GRP_DIST_REGS
  36. Attributes:
  37. The attr field of kvm_device_attr encodes two values::
  38. bits: | 63 .... 40 | 39 .. 32 | 31 .... 0 |
  39. values: | reserved | vcpu_index | offset |
  40. All distributor regs are (rw, 32-bit)
  41. The offset is relative to the "Distributor base address" as defined in the
  42. GICv2 specs. Getting or setting such a register has the same effect as
  43. reading or writing the register on the actual hardware from the cpu whose
  44. index is specified with the vcpu_index field. Note that most distributor
  45. fields are not banked, but return the same value regardless of the
  46. vcpu_index used to access the register.
  47. GICD_IIDR.Revision is updated when the KVM implementation of an emulated
  48. GICv2 is changed in a way directly observable by the guest or userspace.
  49. Userspace should read GICD_IIDR from KVM and write back the read value to
  50. confirm its expected behavior is aligned with the KVM implementation.
  51. Userspace should set GICD_IIDR before setting any other registers (both
  52. KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_CPU_REGS) to ensure
  53. the expected behavior. Unless GICD_IIDR has been set from userspace, writes
  54. to the interrupt group registers (GICD_IGROUPR) are ignored.
  55. Errors:
  56. ======= =====================================================
  57. -ENXIO Getting or setting this register is not yet supported
  58. -EBUSY One or more VCPUs are running
  59. -EINVAL Invalid vcpu_index supplied
  60. ======= =====================================================
  61. KVM_DEV_ARM_VGIC_GRP_CPU_REGS
  62. Attributes:
  63. The attr field of kvm_device_attr encodes two values::
  64. bits: | 63 .... 40 | 39 .. 32 | 31 .... 0 |
  65. values: | reserved | vcpu_index | offset |
  66. All CPU interface regs are (rw, 32-bit)
  67. The offset specifies the offset from the "CPU interface base address" as
  68. defined in the GICv2 specs. Getting or setting such a register has the
  69. same effect as reading or writing the register on the actual hardware.
  70. The Active Priorities Registers APRn are implementation defined, so we set a
  71. fixed format for our implementation that fits with the model of a "GICv2
  72. implementation without the security extensions" which we present to the
  73. guest. This interface always exposes four register APR[0-3] describing the
  74. maximum possible 128 preemption levels. The semantics of the register
  75. indicate if any interrupts in a given preemption level are in the active
  76. state by setting the corresponding bit.
  77. Thus, preemption level X has one or more active interrupts if and only if:
  78. APRn[X mod 32] == 0b1, where n = X / 32
  79. Bits for undefined preemption levels are RAZ/WI.
  80. Note that this differs from a CPU's view of the APRs on hardware in which
  81. a GIC without the security extensions expose group 0 and group 1 active
  82. priorities in separate register groups, whereas we show a combined view
  83. similar to GICv2's GICH_APR.
  84. For historical reasons and to provide ABI compatibility with userspace we
  85. export the GICC_PMR register in the format of the GICH_VMCR.VMPriMask
  86. field in the lower 5 bits of a word, meaning that userspace must always
  87. use the lower 5 bits to communicate with the KVM device and must shift the
  88. value left by 3 places to obtain the actual priority mask level.
  89. Errors:
  90. ======= =====================================================
  91. -ENXIO Getting or setting this register is not yet supported
  92. -EBUSY One or more VCPUs are running
  93. -EINVAL Invalid vcpu_index supplied
  94. ======= =====================================================
  95. KVM_DEV_ARM_VGIC_GRP_NR_IRQS
  96. Attributes:
  97. A value describing the number of interrupts (SGI, PPI and SPI) for
  98. this GIC instance, ranging from 64 to 1024, in increments of 32.
  99. Errors:
  100. ======= =============================================================
  101. -EINVAL Value set is out of the expected range
  102. -EBUSY Value has already be set, or GIC has already been initialized
  103. with default values.
  104. ======= =============================================================
  105. KVM_DEV_ARM_VGIC_GRP_CTRL
  106. Attributes:
  107. KVM_DEV_ARM_VGIC_CTRL_INIT
  108. request the initialization of the VGIC or ITS, no additional parameter
  109. in kvm_device_attr.addr.
  110. Errors:
  111. ======= =========================================================
  112. -ENXIO VGIC not properly configured as required prior to calling
  113. this attribute
  114. -ENODEV no online VCPU
  115. -ENOMEM memory shortage when allocating vgic internal data
  116. ======= =========================================================