Lines Matching +full:fiq +full:- +full:index
1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/irqchip/arm-gic-v3.h>
24 struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_set_underflow()
26 cpuif->vgic_hcr |= ICH_HCR_UIE; in vgic_v3_set_underflow()
37 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; in vgic_v3_fold_lr_state()
38 struct vgic_v3_cpu_if *cpuif = &vgic_cpu->vgic_v3; in vgic_v3_fold_lr_state()
39 u32 model = vcpu->kvm->arch.vgic.vgic_model; in vgic_v3_fold_lr_state()
44 cpuif->vgic_hcr &= ~ICH_HCR_UIE; in vgic_v3_fold_lr_state()
46 for (lr = 0; lr < cpuif->used_lrs; lr++) { in vgic_v3_fold_lr_state()
47 u64 val = cpuif->vgic_lr[lr]; in vgic_v3_fold_lr_state()
63 /* Notify fds when the guest EOI'ed a level-triggered IRQ */ in vgic_v3_fold_lr_state()
64 if (lr_signals_eoi_mi(val) && vgic_valid_spi(vcpu->kvm, intid)) in vgic_v3_fold_lr_state()
65 kvm_notify_acked_irq(vcpu->kvm, 0, in vgic_v3_fold_lr_state()
66 intid - VGIC_NR_PRIVATE_IRQS); in vgic_v3_fold_lr_state()
68 irq = vgic_get_irq(vcpu->kvm, vcpu, intid); in vgic_v3_fold_lr_state()
72 raw_spin_lock(&irq->irq_lock); in vgic_v3_fold_lr_state()
75 deactivated = irq->active && !(val & ICH_LR_ACTIVE_BIT); in vgic_v3_fold_lr_state()
76 irq->active = !!(val & ICH_LR_ACTIVE_BIT); in vgic_v3_fold_lr_state()
78 if (irq->active && is_v2_sgi) in vgic_v3_fold_lr_state()
79 irq->active_source = cpuid; in vgic_v3_fold_lr_state()
82 if (irq->config == VGIC_CONFIG_EDGE && in vgic_v3_fold_lr_state()
84 irq->pending_latch = true; in vgic_v3_fold_lr_state()
87 irq->source |= (1 << cpuid); in vgic_v3_fold_lr_state()
93 if (irq->config == VGIC_CONFIG_LEVEL && !(val & ICH_LR_STATE)) in vgic_v3_fold_lr_state()
94 irq->pending_latch = false; in vgic_v3_fold_lr_state()
99 raw_spin_unlock(&irq->irq_lock); in vgic_v3_fold_lr_state()
100 vgic_put_irq(vcpu->kvm, irq); in vgic_v3_fold_lr_state()
103 cpuif->used_lrs = 0; in vgic_v3_fold_lr_state()
109 u32 model = vcpu->kvm->arch.vgic.vgic_model; in vgic_v3_populate_lr()
110 u64 val = irq->intid; in vgic_v3_populate_lr()
113 is_v2_sgi = (vgic_irq_is_sgi(irq->intid) && in vgic_v3_populate_lr()
116 if (irq->active) { in vgic_v3_populate_lr()
119 val |= irq->active_source << GICH_LR_PHYSID_CPUID_SHIFT; in vgic_v3_populate_lr()
126 if (irq->hw && !vgic_irq_needs_resampling(irq)) { in vgic_v3_populate_lr()
128 val |= ((u64)irq->hwintid) << ICH_LR_PHYS_ID_SHIFT; in vgic_v3_populate_lr()
134 if (irq->active) in vgic_v3_populate_lr()
137 if (irq->config == VGIC_CONFIG_LEVEL) { in vgic_v3_populate_lr()
144 if (irq->active) in vgic_v3_populate_lr()
152 if (irq->config == VGIC_CONFIG_EDGE) in vgic_v3_populate_lr()
153 irq->pending_latch = false; in vgic_v3_populate_lr()
155 if (vgic_irq_is_sgi(irq->intid) && in vgic_v3_populate_lr()
157 u32 src = ffs(irq->source); in vgic_v3_populate_lr()
160 irq->intid)) in vgic_v3_populate_lr()
163 val |= (src - 1) << GICH_LR_PHYSID_CPUID_SHIFT; in vgic_v3_populate_lr()
164 irq->source &= ~(1 << (src - 1)); in vgic_v3_populate_lr()
165 if (irq->source) { in vgic_v3_populate_lr()
166 irq->pending_latch = true; in vgic_v3_populate_lr()
173 * Level-triggered mapped IRQs are special because we only observe in vgic_v3_populate_lr()
179 irq->line_level = false; in vgic_v3_populate_lr()
181 if (irq->group) in vgic_v3_populate_lr()
184 val |= (u64)irq->priority << ICH_LR_PRIORITY_SHIFT; in vgic_v3_populate_lr()
186 vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] = val; in vgic_v3_populate_lr()
191 vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] = 0; in vgic_v3_clear_lr()
196 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_set_vmcr()
197 u32 model = vcpu->kvm->arch.vgic.vgic_model; in vgic_v3_set_vmcr()
201 vmcr = (vmcrp->ackctl << ICH_VMCR_ACK_CTL_SHIFT) & in vgic_v3_set_vmcr()
203 vmcr |= (vmcrp->fiqen << ICH_VMCR_FIQ_EN_SHIFT) & in vgic_v3_set_vmcr()
213 vmcr |= (vmcrp->cbpr << ICH_VMCR_CBPR_SHIFT) & ICH_VMCR_CBPR_MASK; in vgic_v3_set_vmcr()
214 vmcr |= (vmcrp->eoim << ICH_VMCR_EOIM_SHIFT) & ICH_VMCR_EOIM_MASK; in vgic_v3_set_vmcr()
215 vmcr |= (vmcrp->abpr << ICH_VMCR_BPR1_SHIFT) & ICH_VMCR_BPR1_MASK; in vgic_v3_set_vmcr()
216 vmcr |= (vmcrp->bpr << ICH_VMCR_BPR0_SHIFT) & ICH_VMCR_BPR0_MASK; in vgic_v3_set_vmcr()
217 vmcr |= (vmcrp->pmr << ICH_VMCR_PMR_SHIFT) & ICH_VMCR_PMR_MASK; in vgic_v3_set_vmcr()
218 vmcr |= (vmcrp->grpen0 << ICH_VMCR_ENG0_SHIFT) & ICH_VMCR_ENG0_MASK; in vgic_v3_set_vmcr()
219 vmcr |= (vmcrp->grpen1 << ICH_VMCR_ENG1_SHIFT) & ICH_VMCR_ENG1_MASK; in vgic_v3_set_vmcr()
221 cpu_if->vgic_vmcr = vmcr; in vgic_v3_set_vmcr()
226 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_get_vmcr()
227 u32 model = vcpu->kvm->arch.vgic.vgic_model; in vgic_v3_get_vmcr()
230 vmcr = cpu_if->vgic_vmcr; in vgic_v3_get_vmcr()
233 vmcrp->ackctl = (vmcr & ICH_VMCR_ACK_CTL_MASK) >> in vgic_v3_get_vmcr()
235 vmcrp->fiqen = (vmcr & ICH_VMCR_FIQ_EN_MASK) >> in vgic_v3_get_vmcr()
242 vmcrp->fiqen = 1; in vgic_v3_get_vmcr()
243 vmcrp->ackctl = 0; in vgic_v3_get_vmcr()
246 vmcrp->cbpr = (vmcr & ICH_VMCR_CBPR_MASK) >> ICH_VMCR_CBPR_SHIFT; in vgic_v3_get_vmcr()
247 vmcrp->eoim = (vmcr & ICH_VMCR_EOIM_MASK) >> ICH_VMCR_EOIM_SHIFT; in vgic_v3_get_vmcr()
248 vmcrp->abpr = (vmcr & ICH_VMCR_BPR1_MASK) >> ICH_VMCR_BPR1_SHIFT; in vgic_v3_get_vmcr()
249 vmcrp->bpr = (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT; in vgic_v3_get_vmcr()
250 vmcrp->pmr = (vmcr & ICH_VMCR_PMR_MASK) >> ICH_VMCR_PMR_SHIFT; in vgic_v3_get_vmcr()
251 vmcrp->grpen0 = (vmcr & ICH_VMCR_ENG0_MASK) >> ICH_VMCR_ENG0_SHIFT; in vgic_v3_get_vmcr()
252 vmcrp->grpen1 = (vmcr & ICH_VMCR_ENG1_MASK) >> ICH_VMCR_ENG1_SHIFT; in vgic_v3_get_vmcr()
262 struct vgic_v3_cpu_if *vgic_v3 = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_enable()
269 vgic_v3->vgic_vmcr = 0; in vgic_v3_enable()
272 * If we are emulating a GICv3, we do it in an non-GICv2-compatible in vgic_v3_enable()
274 * Also, we don't support any form of IRQ/FIQ bypass. in vgic_v3_enable()
277 if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) { in vgic_v3_enable()
278 vgic_v3->vgic_sre = (ICC_SRE_EL1_DIB | in vgic_v3_enable()
281 vcpu->arch.vgic_cpu.pendbaser = INITIAL_PENDBASER_VALUE; in vgic_v3_enable()
283 vgic_v3->vgic_sre = 0; in vgic_v3_enable()
286 vcpu->arch.vgic_cpu.num_id_bits = (kvm_vgic_global_state.ich_vtr_el2 & in vgic_v3_enable()
289 vcpu->arch.vgic_cpu.num_pri_bits = ((kvm_vgic_global_state.ich_vtr_el2 & in vgic_v3_enable()
294 vgic_v3->vgic_hcr = ICH_HCR_EN; in vgic_v3_enable()
299 struct vgic_v3_cpu_if *vgic_v3 = &vcpu->arch.vgic_cpu.vgic_v3; in vcpu_set_ich_hcr()
302 if (!kvm_has_gicv3(vcpu->kvm)) { in vcpu_set_ich_hcr()
303 vgic_v3->vgic_hcr |= ICH_HCR_TALL0 | ICH_HCR_TALL1 | ICH_HCR_TC; in vcpu_set_ich_hcr()
308 vgic_v3->vgic_hcr |= ICH_HCR_TALL0; in vcpu_set_ich_hcr()
310 vgic_v3->vgic_hcr |= ICH_HCR_TALL1; in vcpu_set_ich_hcr()
312 vgic_v3->vgic_hcr |= ICH_HCR_TC; in vcpu_set_ich_hcr()
314 vgic_v3->vgic_hcr |= ICH_HCR_TDIR; in vcpu_set_ich_hcr()
328 vcpu = irq->target_vcpu; in vgic_v3_lpi_sync_pending_status()
332 pendbase = GICR_PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser); in vgic_v3_lpi_sync_pending_status()
334 byte_offset = irq->intid / BITS_PER_BYTE; in vgic_v3_lpi_sync_pending_status()
335 bit_nr = irq->intid % BITS_PER_BYTE; in vgic_v3_lpi_sync_pending_status()
344 raw_spin_lock_irqsave(&irq->irq_lock, flags); in vgic_v3_lpi_sync_pending_status()
345 if (irq->target_vcpu != vcpu) { in vgic_v3_lpi_sync_pending_status()
346 raw_spin_unlock_irqrestore(&irq->irq_lock, flags); in vgic_v3_lpi_sync_pending_status()
349 irq->pending_latch = status; in vgic_v3_lpi_sync_pending_status()
350 vgic_queue_irq_unlock(vcpu->kvm, irq, flags); in vgic_v3_lpi_sync_pending_status()
368 struct vgic_dist *dist = &kvm->arch.vgic; in unmap_all_vpes()
371 for (i = 0; i < dist->its_vm.nr_vpes; i++) in unmap_all_vpes()
372 free_irq(dist->its_vm.vpes[i]->irq, kvm_get_vcpu(kvm, i)); in unmap_all_vpes()
377 struct vgic_dist *dist = &kvm->arch.vgic; in map_all_vpes()
380 for (i = 0; i < dist->its_vm.nr_vpes; i++) in map_all_vpes()
382 dist->its_vm.vpes[i]->irq)); in map_all_vpes()
386 * vgic_v3_save_pending_tables - Save the pending tables into guest RAM
391 struct vgic_dist *dist = &kvm->arch.vgic; in vgic_v3_save_pending_tables()
395 unsigned long index; in vgic_v3_save_pending_tables() local
400 return -ENXIO; in vgic_v3_save_pending_tables()
412 xa_for_each(&dist->lpi_xa, index, irq) { in vgic_v3_save_pending_tables()
419 vcpu = irq->target_vcpu; in vgic_v3_save_pending_tables()
423 pendbase = GICR_PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser); in vgic_v3_save_pending_tables()
425 byte_offset = irq->intid / BITS_PER_BYTE; in vgic_v3_save_pending_tables()
426 bit_nr = irq->intid % BITS_PER_BYTE; in vgic_v3_save_pending_tables()
438 is_pending = irq->pending_latch; in vgic_v3_save_pending_tables()
440 if (irq->hw && vlpi_avail) in vgic_v3_save_pending_tables()
464 * vgic_v3_rdist_overlap - check if a region overlaps with any
475 struct vgic_dist *d = &kvm->arch.vgic; in vgic_v3_rdist_overlap()
478 list_for_each_entry(rdreg, &d->rd_regions, list) { in vgic_v3_rdist_overlap()
479 if ((base + size > rdreg->base) && in vgic_v3_rdist_overlap()
480 (base < rdreg->base + vgic_v3_rd_region_size(kvm, rdreg))) in vgic_v3_rdist_overlap()
492 struct vgic_dist *d = &kvm->arch.vgic; in vgic_v3_check_base()
495 if (!IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) && in vgic_v3_check_base()
496 d->vgic_dist_base + KVM_VGIC_V3_DIST_SIZE < d->vgic_dist_base) in vgic_v3_check_base()
499 list_for_each_entry(rdreg, &d->rd_regions, list) { in vgic_v3_check_base()
503 rdreg->base, SZ_64K, sz)) in vgic_v3_check_base()
507 if (IS_VGIC_ADDR_UNDEF(d->vgic_dist_base)) in vgic_v3_check_base()
510 return !vgic_v3_rdist_overlap(kvm, d->vgic_dist_base, in vgic_v3_check_base()
515 * vgic_v3_rdist_free_slot - Look up registered rdist regions and identify one
521 * Stride between redistributors is 0 and regions are filled in the index order.
538 u32 index) in vgic_v3_rdist_region_from_index() argument
540 struct list_head *rd_regions = &kvm->arch.vgic.rd_regions; in vgic_v3_rdist_region_from_index()
544 if (rdreg->index == index) in vgic_v3_rdist_region_from_index()
553 struct vgic_dist *dist = &kvm->arch.vgic; in vgic_v3_map_resources()
558 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; in vgic_v3_map_resources()
560 if (IS_VGIC_ADDR_UNDEF(vgic_cpu->rd_iodev.base_addr)) { in vgic_v3_map_resources()
562 return -ENXIO; in vgic_v3_map_resources()
566 if (IS_VGIC_ADDR_UNDEF(dist->vgic_dist_base)) { in vgic_v3_map_resources()
568 return -ENXIO; in vgic_v3_map_resources()
573 return -EINVAL; in vgic_v3_map_resources()
581 return -EBUSY; in vgic_v3_map_resources()
596 early_param("kvm-arm.vgic_v3_group0_trap", early_group0_trap_cfg);
602 early_param("kvm-arm.vgic_v3_group1_trap", early_group1_trap_cfg);
608 early_param("kvm-arm.vgic_v3_common_trap", early_common_trap_cfg);
614 early_param("kvm-arm.vgic_v4_enable", early_gicv4_enable);
639 * vgic_v3_probe - probe for a VGICv3 compatible interrupt controller
663 if (info->has_v4) { in vgic_v3_probe()
665 kvm_vgic_global_state.has_gicv4_1 = info->has_v4_1 && gicv4_enable; in vgic_v3_probe()
673 if (!info->vcpu.start) { in vgic_v3_probe()
677 } else if (!PAGE_ALIGNED(info->vcpu.start)) { in vgic_v3_probe()
679 (unsigned long long)info->vcpu.start); in vgic_v3_probe()
681 kvm_vgic_global_state.vcpu_base = info->vcpu.start; in vgic_v3_probe()
688 kvm_info("vgic-v2@%llx\n", info->vcpu.start); in vgic_v3_probe()
735 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_load()
747 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3; in vgic_v3_put()