18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci=========================
48c2ecf20Sopenharmony_ciXICS interrupt controller
58c2ecf20Sopenharmony_ci=========================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciDevice type supported: KVM_DEV_TYPE_XICS
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciGroups:
108c2ecf20Sopenharmony_ci  1. KVM_DEV_XICS_GRP_SOURCES
118c2ecf20Sopenharmony_ci       Attributes:
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci         One per interrupt source, indexed by the source number.
148c2ecf20Sopenharmony_ci  2. KVM_DEV_XICS_GRP_CTRL
158c2ecf20Sopenharmony_ci       Attributes:
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci         2.1 KVM_DEV_XICS_NR_SERVERS (write only)
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci  The kvm_device_attr.addr points to a __u32 value which is the number of
208c2ecf20Sopenharmony_ci  interrupt server numbers (ie, highest possible vcpu id plus one).
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci  Errors:
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci    =======  ==========================================
258c2ecf20Sopenharmony_ci    -EINVAL  Value greater than KVM_MAX_VCPU_ID.
268c2ecf20Sopenharmony_ci    -EFAULT  Invalid user pointer for attr->addr.
278c2ecf20Sopenharmony_ci    -EBUSY   A vcpu is already connected to the device.
288c2ecf20Sopenharmony_ci    =======  ==========================================
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciThis device emulates the XICS (eXternal Interrupt Controller
318c2ecf20Sopenharmony_ciSpecification) defined in PAPR.  The XICS has a set of interrupt
328c2ecf20Sopenharmony_cisources, each identified by a 20-bit source number, and a set of
338c2ecf20Sopenharmony_ciInterrupt Control Presentation (ICP) entities, also called "servers",
348c2ecf20Sopenharmony_cieach associated with a virtual CPU.
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciThe ICP entities are created by enabling the KVM_CAP_IRQ_ARCH
378c2ecf20Sopenharmony_cicapability for each vcpu, specifying KVM_CAP_IRQ_XICS in args[0] and
388c2ecf20Sopenharmony_cithe interrupt server number (i.e. the vcpu number from the XICS's
398c2ecf20Sopenharmony_cipoint of view) in args[1] of the kvm_enable_cap struct.  Each ICP has
408c2ecf20Sopenharmony_ci64 bits of state which can be read and written using the
418c2ecf20Sopenharmony_ciKVM_GET_ONE_REG and KVM_SET_ONE_REG ioctls on the vcpu.  The 64 bit
428c2ecf20Sopenharmony_cistate word has the following bitfields, starting at the
438c2ecf20Sopenharmony_cileast-significant end of the word:
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci* Unused, 16 bits
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci* Pending interrupt priority, 8 bits
488c2ecf20Sopenharmony_ci  Zero is the highest priority, 255 means no interrupt is pending.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci* Pending IPI (inter-processor interrupt) priority, 8 bits
518c2ecf20Sopenharmony_ci  Zero is the highest priority, 255 means no IPI is pending.
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci* Pending interrupt source number, 24 bits
548c2ecf20Sopenharmony_ci  Zero means no interrupt pending, 2 means an IPI is pending
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci* Current processor priority, 8 bits
578c2ecf20Sopenharmony_ci  Zero is the highest priority, meaning no interrupts can be
588c2ecf20Sopenharmony_ci  delivered, and 255 is the lowest priority.
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciEach source has 64 bits of state that can be read and written using
618c2ecf20Sopenharmony_cithe KVM_GET_DEVICE_ATTR and KVM_SET_DEVICE_ATTR ioctls, specifying the
628c2ecf20Sopenharmony_ciKVM_DEV_XICS_GRP_SOURCES attribute group, with the attribute number being
638c2ecf20Sopenharmony_cithe interrupt source number.  The 64 bit state word has the following
648c2ecf20Sopenharmony_cibitfields, starting from the least-significant end of the word:
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci* Destination (server number), 32 bits
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci  This specifies where the interrupt should be sent, and is the
698c2ecf20Sopenharmony_ci  interrupt server number specified for the destination vcpu.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci* Priority, 8 bits
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci  This is the priority specified for this interrupt source, where 0 is
748c2ecf20Sopenharmony_ci  the highest priority and 255 is the lowest.  An interrupt with a
758c2ecf20Sopenharmony_ci  priority of 255 will never be delivered.
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci* Level sensitive flag, 1 bit
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci  This bit is 1 for a level-sensitive interrupt source, or 0 for
808c2ecf20Sopenharmony_ci  edge-sensitive (or MSI).
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci* Masked flag, 1 bit
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci  This bit is set to 1 if the interrupt is masked (cannot be delivered
858c2ecf20Sopenharmony_ci  regardless of its priority), for example by the ibm,int-off RTAS
868c2ecf20Sopenharmony_ci  call, or 0 if it is not masked.
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci* Pending flag, 1 bit
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci  This bit is 1 if the source has a pending interrupt, otherwise 0.
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciOnly one XICS instance may be created per VM.
93