···23232424#include <linux/irqchip/arm-gic-v4.h>25252626+/*2727+ * WARNING: The blurb below assumes that you understand the2828+ * intricacies of GICv3, GICv4, and how a guest's view of a GICv3 gets2929+ * translated into GICv4 commands. So it effectively targets at most3030+ * two individuals. You know who you are.3131+ *3232+ * The core GICv4 code is designed to *avoid* exposing too much of the3333+ * core GIC code (that would in turn leak into the hypervisor code),3434+ * and instead provide a hypervisor agnostic interface to the HW (of3535+ * course, the astute reader will quickly realize that hypervisor3636+ * agnostic actually means KVM-specific - what were you thinking?).3737+ *3838+ * In order to achieve a modicum of isolation, we try to hide most of3939+ * the GICv4 "stuff" behind normal irqchip operations:4040+ *4141+ * - Any guest-visible VLPI is backed by a Linux interrupt (and a4242+ * physical LPI which gets unmapped when the guest maps the4343+ * VLPI). This allows the same DevID/EventID pair to be either4444+ * mapped to the LPI (host) or the VLPI (guest). Note that this is4545+ * exclusive, and you cannot have both.4646+ *4747+ * - Enabling/disabling a VLPI is done by issuing mask/unmask calls.4848+ *4949+ * - Guest INT/CLEAR commands are implemented through5050+ * irq_set_irqchip_state().5151+ *5252+ * - The *bizarre* stuff (mapping/unmapping an interrupt to a VLPI, or5353+ * issuing an INV after changing a priority) gets shoved into the5454+ * irq_set_vcpu_affinity() method. While this is quite horrible5555+ * (let's face it, this is the irqchip version of an ioctl), it5656+ * confines the crap to a single location. And map/unmap really is5757+ * about setting the affinity of a VLPI to a vcpu, so only INV is5858+ * majorly out of place. So there.5959+ *6060+ * A number of commands are simply not provided by this interface, as6161+ * they do not make direct sense. For example, MAPD is purely local to6262+ * the virtual ITS (because it references a virtual device, and the6363+ * physical ITS is still very much in charge of the physical6464+ * device). Same goes for things like MAPC (the physical ITS deals6565+ * with the actual vPE affinity, and not the braindead concept of6666+ * collection). SYNC is not provided either, as each and every command6767+ * is followed by a VSYNC. This could be relaxed in the future, should6868+ * this be seen as a bottleneck (yes, this means *never*).6969+ *7070+ * But handling VLPIs is only one side of the job of the GICv47171+ * code. The other (darker) side is to take care of the doorbell7272+ * interrupts which are delivered when a VLPI targeting a non-running7373+ * vcpu is being made pending.7474+ *7575+ * The choice made here is that each vcpu (VPE in old northern GICv47676+ * dialect) gets a single doorbell LPI, no matter how many interrupts7777+ * are targeting it. This has a nice property, which is that the7878+ * interrupt becomes a handle for the VPE, and that the hypervisor7979+ * code can manipulate it through the normal interrupt API:8080+ *8181+ * - VMs (or rather the VM abstraction that matters to the GIC)8282+ * contain an irq domain where each interrupt maps to a VPE. In8383+ * turn, this domain sits on top of the normal LPI allocator, and a8484+ * specially crafted irq_chip implementation.8585+ *8686+ * - mask/unmask do what is expected on the doorbell interrupt.8787+ *8888+ * - irq_set_affinity is used to move a VPE from one redistributor to8989+ * another.9090+ *9191+ * - irq_set_vcpu_affinity once again gets hijacked for the purpose of9292+ * creating a new sub-API, namely scheduling/descheduling a VPE9393+ * (which involves programming GICR_V{PROP,PEND}BASER) and9494+ * performing INVALL operations.9595+ */9696+2697static struct irq_domain *gic_domain;2798static const struct irq_domain_ops *vpe_domain_ops;2899