···2324#include <linux/irqchip/arm-gic-v4.h>2526+/*27+ * WARNING: The blurb below assumes that you understand the28+ * intricacies of GICv3, GICv4, and how a guest's view of a GICv3 gets29+ * translated into GICv4 commands. So it effectively targets at most30+ * two individuals. You know who you are.31+ *32+ * The core GICv4 code is designed to *avoid* exposing too much of the33+ * core GIC code (that would in turn leak into the hypervisor code),34+ * and instead provide a hypervisor agnostic interface to the HW (of35+ * course, the astute reader will quickly realize that hypervisor36+ * agnostic actually means KVM-specific - what were you thinking?).37+ *38+ * In order to achieve a modicum of isolation, we try to hide most of39+ * the GICv4 "stuff" behind normal irqchip operations:40+ *41+ * - Any guest-visible VLPI is backed by a Linux interrupt (and a42+ * physical LPI which gets unmapped when the guest maps the43+ * VLPI). This allows the same DevID/EventID pair to be either44+ * mapped to the LPI (host) or the VLPI (guest). Note that this is45+ * exclusive, and you cannot have both.46+ *47+ * - Enabling/disabling a VLPI is done by issuing mask/unmask calls.48+ *49+ * - Guest INT/CLEAR commands are implemented through50+ * irq_set_irqchip_state().51+ *52+ * - The *bizarre* stuff (mapping/unmapping an interrupt to a VLPI, or53+ * issuing an INV after changing a priority) gets shoved into the54+ * irq_set_vcpu_affinity() method. While this is quite horrible55+ * (let's face it, this is the irqchip version of an ioctl), it56+ * confines the crap to a single location. And map/unmap really is57+ * about setting the affinity of a VLPI to a vcpu, so only INV is58+ * majorly out of place. So there.59+ *60+ * A number of commands are simply not provided by this interface, as61+ * they do not make direct sense. For example, MAPD is purely local to62+ * the virtual ITS (because it references a virtual device, and the63+ * physical ITS is still very much in charge of the physical64+ * device). Same goes for things like MAPC (the physical ITS deals65+ * with the actual vPE affinity, and not the braindead concept of66+ * collection). SYNC is not provided either, as each and every command67+ * is followed by a VSYNC. This could be relaxed in the future, should68+ * this be seen as a bottleneck (yes, this means *never*).69+ *70+ * But handling VLPIs is only one side of the job of the GICv471+ * code. The other (darker) side is to take care of the doorbell72+ * interrupts which are delivered when a VLPI targeting a non-running73+ * vcpu is being made pending.74+ *75+ * The choice made here is that each vcpu (VPE in old northern GICv476+ * dialect) gets a single doorbell LPI, no matter how many interrupts77+ * are targeting it. This has a nice property, which is that the78+ * interrupt becomes a handle for the VPE, and that the hypervisor79+ * code can manipulate it through the normal interrupt API:80+ *81+ * - VMs (or rather the VM abstraction that matters to the GIC)82+ * contain an irq domain where each interrupt maps to a VPE. In83+ * turn, this domain sits on top of the normal LPI allocator, and a84+ * specially crafted irq_chip implementation.85+ *86+ * - mask/unmask do what is expected on the doorbell interrupt.87+ *88+ * - irq_set_affinity is used to move a VPE from one redistributor to89+ * another.90+ *91+ * - irq_set_vcpu_affinity once again gets hijacked for the purpose of92+ * creating a new sub-API, namely scheduling/descheduling a VPE93+ * (which involves programming GICR_V{PROP,PEND}BASER) and94+ * performing INVALL operations.95+ */96+97static struct irq_domain *gic_domain;98static const struct irq_domain_ops *vpe_domain_ops;99