Lines Matching refs:kvm
52 void kvm_vgic_early_init(struct kvm *kvm) in kvm_vgic_early_init() argument
54 struct vgic_dist *dist = &kvm->arch.vgic; in kvm_vgic_early_init()
69 int kvm_vgic_create(struct kvm *kvm, u32 type) in kvm_vgic_create() argument
86 lockdep_assert_held(&kvm->lock); in kvm_vgic_create()
89 if (!lock_all_vcpus(kvm)) in kvm_vgic_create()
92 mutex_lock(&kvm->arch.config_lock); in kvm_vgic_create()
94 if (irqchip_in_kernel(kvm)) { in kvm_vgic_create()
99 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_vgic_create()
106 kvm->max_vcpus = VGIC_V2_MAX_CPUS; in kvm_vgic_create()
108 kvm->max_vcpus = VGIC_V3_MAX_CPUS; in kvm_vgic_create()
110 if (atomic_read(&kvm->online_vcpus) > kvm->max_vcpus) { in kvm_vgic_create()
115 kvm->arch.vgic.in_kernel = true; in kvm_vgic_create()
116 kvm->arch.vgic.vgic_model = type; in kvm_vgic_create()
118 kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF; in kvm_vgic_create()
121 kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF; in kvm_vgic_create()
123 INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions); in kvm_vgic_create()
126 mutex_unlock(&kvm->arch.config_lock); in kvm_vgic_create()
127 unlock_all_vcpus(kvm); in kvm_vgic_create()
138 static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) in kvm_vgic_dist_init() argument
140 struct vgic_dist *dist = &kvm->arch.vgic; in kvm_vgic_dist_init()
141 struct kvm_vcpu *vcpu0 = kvm_get_vcpu(kvm, 0); in kvm_vgic_dist_init()
188 lockdep_assert_held(&vcpu->kvm->arch.config_lock); in vgic_allocate_private_irqs_locked()
230 mutex_lock(&vcpu->kvm->arch.config_lock); in vgic_allocate_private_irqs()
232 mutex_unlock(&vcpu->kvm->arch.config_lock); in vgic_allocate_private_irqs()
249 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; in kvm_vgic_vcpu_init()
258 if (!irqchip_in_kernel(vcpu->kvm)) in kvm_vgic_vcpu_init()
270 mutex_lock(&vcpu->kvm->slots_lock); in kvm_vgic_vcpu_init()
272 mutex_unlock(&vcpu->kvm->slots_lock); in kvm_vgic_vcpu_init()
294 int vgic_init(struct kvm *kvm) in vgic_init() argument
296 struct vgic_dist *dist = &kvm->arch.vgic; in vgic_init()
301 lockdep_assert_held(&kvm->arch.config_lock); in vgic_init()
303 if (vgic_initialized(kvm)) in vgic_init()
307 if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus)) in vgic_init()
314 ret = kvm_vgic_dist_init(kvm, dist->nr_spis); in vgic_init()
319 kvm_for_each_vcpu(idx, vcpu, kvm) { in vgic_init()
325 struct vgic_irq *irq = vgic_get_irq(kvm, vcpu, i); in vgic_init()
340 vgic_put_irq(kvm, irq); in vgic_init()
352 if (vgic_supports_direct_msis(kvm)) { in vgic_init()
353 ret = vgic_v4_init(kvm); in vgic_init()
358 kvm_for_each_vcpu(idx, vcpu, kvm) in vgic_init()
361 ret = kvm_vgic_setup_default_irq_routing(kvm); in vgic_init()
365 vgic_debug_init(kvm); in vgic_init()
379 static void kvm_vgic_dist_destroy(struct kvm *kvm) in kvm_vgic_dist_destroy() argument
381 struct vgic_dist *dist = &kvm->arch.vgic; in kvm_vgic_dist_destroy()
394 vgic_v3_free_redist_region(kvm, rdreg); in kvm_vgic_dist_destroy()
400 if (vgic_supports_direct_msis(kvm)) in kvm_vgic_dist_destroy()
401 vgic_v4_teardown(kvm); in kvm_vgic_dist_destroy()
420 if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) { in __kvm_vgic_vcpu_destroy()
437 if (kvm_get_vcpu_by_id(vcpu->kvm, vcpu->vcpu_id) != vcpu) in __kvm_vgic_vcpu_destroy()
446 struct kvm *kvm = vcpu->kvm; in kvm_vgic_vcpu_destroy() local
448 mutex_lock(&kvm->slots_lock); in kvm_vgic_vcpu_destroy()
450 mutex_unlock(&kvm->slots_lock); in kvm_vgic_vcpu_destroy()
453 void kvm_vgic_destroy(struct kvm *kvm) in kvm_vgic_destroy() argument
458 mutex_lock(&kvm->slots_lock); in kvm_vgic_destroy()
459 mutex_lock(&kvm->arch.config_lock); in kvm_vgic_destroy()
461 vgic_debug_destroy(kvm); in kvm_vgic_destroy()
463 kvm_for_each_vcpu(i, vcpu, kvm) in kvm_vgic_destroy()
466 kvm_vgic_dist_destroy(kvm); in kvm_vgic_destroy()
468 mutex_unlock(&kvm->arch.config_lock); in kvm_vgic_destroy()
470 if (kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) in kvm_vgic_destroy()
471 kvm_for_each_vcpu(i, vcpu, kvm) in kvm_vgic_destroy()
474 mutex_unlock(&kvm->slots_lock); in kvm_vgic_destroy()
483 int vgic_lazy_init(struct kvm *kvm) in vgic_lazy_init() argument
487 if (unlikely(!vgic_initialized(kvm))) { in vgic_lazy_init()
494 if (kvm->arch.vgic.vgic_model != KVM_DEV_TYPE_ARM_VGIC_V2) in vgic_lazy_init()
497 mutex_lock(&kvm->arch.config_lock); in vgic_lazy_init()
498 ret = vgic_init(kvm); in vgic_lazy_init()
499 mutex_unlock(&kvm->arch.config_lock); in vgic_lazy_init()
518 int kvm_vgic_map_resources(struct kvm *kvm) in kvm_vgic_map_resources() argument
520 struct vgic_dist *dist = &kvm->arch.vgic; in kvm_vgic_map_resources()
525 if (likely(vgic_ready(kvm))) in kvm_vgic_map_resources()
528 mutex_lock(&kvm->slots_lock); in kvm_vgic_map_resources()
529 mutex_lock(&kvm->arch.config_lock); in kvm_vgic_map_resources()
530 if (vgic_ready(kvm)) in kvm_vgic_map_resources()
533 if (!irqchip_in_kernel(kvm)) in kvm_vgic_map_resources()
537 ret = vgic_v2_map_resources(kvm); in kvm_vgic_map_resources()
540 ret = vgic_v3_map_resources(kvm); in kvm_vgic_map_resources()
548 mutex_unlock(&kvm->arch.config_lock); in kvm_vgic_map_resources()
550 ret = vgic_register_dist_iodev(kvm, dist_base, type); in kvm_vgic_map_resources()
566 mutex_unlock(&kvm->arch.config_lock); in kvm_vgic_map_resources()
569 kvm_vm_dead(kvm); in kvm_vgic_map_resources()
571 mutex_unlock(&kvm->slots_lock); in kvm_vgic_map_resources()