Lines Matching full:vdev

26 	struct vfio_pci_core_device	*vdev;  member
35 static bool irq_is(struct vfio_pci_core_device *vdev, int type) in irq_is() argument
37 return vdev->irq_type == type; in irq_is()
40 static bool is_intx(struct vfio_pci_core_device *vdev) in is_intx() argument
42 return vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX; in is_intx()
45 static bool is_irq_none(struct vfio_pci_core_device *vdev) in is_irq_none() argument
47 return !(vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX || in is_irq_none()
48 vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX || in is_irq_none()
49 vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX); in is_irq_none()
53 struct vfio_pci_irq_ctx *vfio_irq_ctx_get(struct vfio_pci_core_device *vdev, in vfio_irq_ctx_get() argument
56 return xa_load(&vdev->ctx, index); in vfio_irq_ctx_get()
59 static void vfio_irq_ctx_free(struct vfio_pci_core_device *vdev, in vfio_irq_ctx_free() argument
62 xa_erase(&vdev->ctx, index); in vfio_irq_ctx_free()
67 vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index) in vfio_irq_ctx_alloc() argument
76 ret = xa_insert(&vdev->ctx, index, ctx, GFP_KERNEL_ACCOUNT); in vfio_irq_ctx_alloc()
90 struct vfio_pci_core_device *vdev = opaque; in vfio_send_intx_eventfd() local
92 if (likely(is_intx(vdev) && !vdev->virq_disabled)) { in vfio_send_intx_eventfd()
102 static bool __vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) in __vfio_pci_intx_mask() argument
104 struct pci_dev *pdev = vdev->pdev; in __vfio_pci_intx_mask()
109 lockdep_assert_held(&vdev->igate); in __vfio_pci_intx_mask()
111 spin_lock_irqsave(&vdev->irqlock, flags); in __vfio_pci_intx_mask()
119 if (unlikely(!is_intx(vdev))) { in __vfio_pci_intx_mask()
120 if (vdev->pci_2_3) in __vfio_pci_intx_mask()
125 ctx = vfio_irq_ctx_get(vdev, 0); in __vfio_pci_intx_mask()
134 if (vdev->pci_2_3) in __vfio_pci_intx_mask()
144 spin_unlock_irqrestore(&vdev->irqlock, flags); in __vfio_pci_intx_mask()
148 bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) in vfio_pci_intx_mask() argument
152 mutex_lock(&vdev->igate); in vfio_pci_intx_mask()
153 mask_changed = __vfio_pci_intx_mask(vdev); in vfio_pci_intx_mask()
154 mutex_unlock(&vdev->igate); in vfio_pci_intx_mask()
167 struct vfio_pci_core_device *vdev = opaque; in vfio_pci_intx_unmask_handler() local
168 struct pci_dev *pdev = vdev->pdev; in vfio_pci_intx_unmask_handler()
173 spin_lock_irqsave(&vdev->irqlock, flags); in vfio_pci_intx_unmask_handler()
179 if (unlikely(!is_intx(vdev))) { in vfio_pci_intx_unmask_handler()
180 if (vdev->pci_2_3) in vfio_pci_intx_unmask_handler()
185 if (ctx->masked && !vdev->virq_disabled) { in vfio_pci_intx_unmask_handler()
191 if (vdev->pci_2_3) { in vfio_pci_intx_unmask_handler()
201 spin_unlock_irqrestore(&vdev->irqlock, flags); in vfio_pci_intx_unmask_handler()
206 static void __vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) in __vfio_pci_intx_unmask() argument
208 struct vfio_pci_irq_ctx *ctx = vfio_irq_ctx_get(vdev, 0); in __vfio_pci_intx_unmask()
210 lockdep_assert_held(&vdev->igate); in __vfio_pci_intx_unmask()
212 if (vfio_pci_intx_unmask_handler(vdev, ctx) > 0) in __vfio_pci_intx_unmask()
213 vfio_send_intx_eventfd(vdev, ctx); in __vfio_pci_intx_unmask()
216 void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) in vfio_pci_intx_unmask() argument
218 mutex_lock(&vdev->igate); in vfio_pci_intx_unmask()
219 __vfio_pci_intx_unmask(vdev); in vfio_pci_intx_unmask()
220 mutex_unlock(&vdev->igate); in vfio_pci_intx_unmask()
226 struct vfio_pci_core_device *vdev = ctx->vdev; in vfio_intx_handler() local
230 spin_lock_irqsave(&vdev->irqlock, flags); in vfio_intx_handler()
232 if (!vdev->pci_2_3) { in vfio_intx_handler()
233 disable_irq_nosync(vdev->pdev->irq); in vfio_intx_handler()
237 pci_check_and_mask_intx(vdev->pdev)) { in vfio_intx_handler()
242 spin_unlock_irqrestore(&vdev->irqlock, flags); in vfio_intx_handler()
245 vfio_send_intx_eventfd(vdev, ctx); in vfio_intx_handler()
250 static int vfio_intx_enable(struct vfio_pci_core_device *vdev, in vfio_intx_enable() argument
253 struct pci_dev *pdev = vdev->pdev; in vfio_intx_enable()
259 if (!is_irq_none(vdev)) in vfio_intx_enable()
269 ctx = vfio_irq_ctx_alloc(vdev, 0); in vfio_intx_enable()
277 ctx->vdev = vdev; in vfio_intx_enable()
297 ctx->masked = vdev->virq_disabled; in vfio_intx_enable()
298 if (vdev->pci_2_3) { in vfio_intx_enable()
305 vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX; in vfio_intx_enable()
307 if (!vdev->pci_2_3) in vfio_intx_enable()
313 if (!vdev->pci_2_3) in vfio_intx_enable()
315 vdev->irq_type = VFIO_PCI_NUM_IRQS; in vfio_intx_enable()
317 vfio_irq_ctx_free(vdev, ctx, 0); in vfio_intx_enable()
324 static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, in vfio_intx_set_signal() argument
327 struct pci_dev *pdev = vdev->pdev; in vfio_intx_set_signal()
331 ctx = vfio_irq_ctx_get(vdev, 0); in vfio_intx_set_signal()
349 static void vfio_intx_disable(struct vfio_pci_core_device *vdev) in vfio_intx_disable() argument
351 struct pci_dev *pdev = vdev->pdev; in vfio_intx_disable()
354 ctx = vfio_irq_ctx_get(vdev, 0); in vfio_intx_disable()
360 if (!vdev->pci_2_3) in vfio_intx_disable()
365 vfio_irq_ctx_free(vdev, ctx, 0); in vfio_intx_disable()
367 vdev->irq_type = VFIO_PCI_NUM_IRQS; in vfio_intx_disable()
381 static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msix) in vfio_msi_enable() argument
383 struct pci_dev *pdev = vdev->pdev; in vfio_msi_enable()
388 if (!is_irq_none(vdev)) in vfio_msi_enable()
392 cmd = vfio_pci_memory_lock_and_enable(vdev); in vfio_msi_enable()
397 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_enable()
400 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_enable()
402 vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX : in vfio_msi_enable()
410 vdev->msi_qmax = fls(nvec * 2 - 1) - 1; in vfio_msi_enable()
426 static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev, in vfio_msi_alloc_irq() argument
429 struct pci_dev *pdev = vdev->pdev; in vfio_msi_alloc_irq()
437 if (irq > 0 || !msix || !vdev->has_dyn_msix) in vfio_msi_alloc_irq()
440 cmd = vfio_pci_memory_lock_and_enable(vdev); in vfio_msi_alloc_irq()
442 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_alloc_irq()
447 static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, in vfio_msi_set_vector_signal() argument
450 struct pci_dev *pdev = vdev->pdev; in vfio_msi_set_vector_signal()
456 ctx = vfio_irq_ctx_get(vdev, vector); in vfio_msi_set_vector_signal()
461 cmd = vfio_pci_memory_lock_and_enable(vdev); in vfio_msi_set_vector_signal()
463 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_set_vector_signal()
467 vfio_irq_ctx_free(vdev, ctx, vector); in vfio_msi_set_vector_signal()
475 irq = vfio_msi_alloc_irq(vdev, vector, msix); in vfio_msi_set_vector_signal()
480 ctx = vfio_irq_ctx_alloc(vdev, vector); in vfio_msi_set_vector_signal()
502 cmd = vfio_pci_memory_lock_and_enable(vdev); in vfio_msi_set_vector_signal()
511 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_set_vector_signal()
530 vfio_irq_ctx_free(vdev, ctx, vector); in vfio_msi_set_vector_signal()
534 static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start, in vfio_msi_set_block() argument
542 ret = vfio_msi_set_vector_signal(vdev, j, fd, msix); in vfio_msi_set_block()
547 vfio_msi_set_vector_signal(vdev, i, -1, msix); in vfio_msi_set_block()
553 static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix) in vfio_msi_disable() argument
555 struct pci_dev *pdev = vdev->pdev; in vfio_msi_disable()
560 xa_for_each(&vdev->ctx, i, ctx) { in vfio_msi_disable()
563 vfio_msi_set_vector_signal(vdev, i, -1, msix); in vfio_msi_disable()
566 cmd = vfio_pci_memory_lock_and_enable(vdev); in vfio_msi_disable()
568 vfio_pci_memory_unlock_and_restore(vdev, cmd); in vfio_msi_disable()
574 if (vdev->nointx) in vfio_msi_disable()
577 vdev->irq_type = VFIO_PCI_NUM_IRQS; in vfio_msi_disable()
583 static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, in vfio_pci_set_intx_unmask() argument
587 if (!is_intx(vdev) || start != 0 || count != 1) in vfio_pci_set_intx_unmask()
591 __vfio_pci_intx_unmask(vdev); in vfio_pci_set_intx_unmask()
595 __vfio_pci_intx_unmask(vdev); in vfio_pci_set_intx_unmask()
597 struct vfio_pci_irq_ctx *ctx = vfio_irq_ctx_get(vdev, 0); in vfio_pci_set_intx_unmask()
603 return vfio_virqfd_enable((void *) vdev, in vfio_pci_set_intx_unmask()
614 static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev, in vfio_pci_set_intx_mask() argument
618 if (!is_intx(vdev) || start != 0 || count != 1) in vfio_pci_set_intx_mask()
622 __vfio_pci_intx_mask(vdev); in vfio_pci_set_intx_mask()
626 __vfio_pci_intx_mask(vdev); in vfio_pci_set_intx_mask()
634 static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, in vfio_pci_set_intx_trigger() argument
638 if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { in vfio_pci_set_intx_trigger()
639 vfio_intx_disable(vdev); in vfio_pci_set_intx_trigger()
643 if (!(is_intx(vdev) || is_irq_none(vdev)) || start != 0 || count != 1) in vfio_pci_set_intx_trigger()
657 if (is_intx(vdev)) in vfio_pci_set_intx_trigger()
658 ret = vfio_intx_set_signal(vdev, trigger); in vfio_pci_set_intx_trigger()
660 ret = vfio_intx_enable(vdev, trigger); in vfio_pci_set_intx_trigger()
668 if (!is_intx(vdev)) in vfio_pci_set_intx_trigger()
672 vfio_send_intx_eventfd(vdev, vfio_irq_ctx_get(vdev, 0)); in vfio_pci_set_intx_trigger()
676 vfio_send_intx_eventfd(vdev, vfio_irq_ctx_get(vdev, 0)); in vfio_pci_set_intx_trigger()
681 static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, in vfio_pci_set_msi_trigger() argument
689 if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { in vfio_pci_set_msi_trigger()
690 vfio_msi_disable(vdev, msix); in vfio_pci_set_msi_trigger()
694 if (!(irq_is(vdev, index) || is_irq_none(vdev))) in vfio_pci_set_msi_trigger()
701 if (vdev->irq_type == index) in vfio_pci_set_msi_trigger()
702 return vfio_msi_set_block(vdev, start, count, in vfio_pci_set_msi_trigger()
705 ret = vfio_msi_enable(vdev, start + count, msix); in vfio_pci_set_msi_trigger()
709 ret = vfio_msi_set_block(vdev, start, count, fds, msix); in vfio_pci_set_msi_trigger()
711 vfio_msi_disable(vdev, msix); in vfio_pci_set_msi_trigger()
716 if (!irq_is(vdev, index)) in vfio_pci_set_msi_trigger()
720 ctx = vfio_irq_ctx_get(vdev, i); in vfio_pci_set_msi_trigger()
734 static int vfio_pci_set_ctx_trigger_single(struct vfio_pci_core_device *vdev, in vfio_pci_set_ctx_trigger_single() argument
744 lockdep_is_held(&vdev->igate)); in vfio_pci_set_ctx_trigger_single()
754 return vfio_pci_eventfd_replace_locked(vdev, peventfd, NULL); in vfio_pci_set_ctx_trigger_single()
766 lockdep_is_held(&vdev->igate)); in vfio_pci_set_ctx_trigger_single()
781 return vfio_pci_eventfd_replace_locked(vdev, in vfio_pci_set_ctx_trigger_single()
791 ret = vfio_pci_eventfd_replace_locked(vdev, in vfio_pci_set_ctx_trigger_single()
803 static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev, in vfio_pci_set_err_trigger() argument
810 return vfio_pci_set_ctx_trigger_single(vdev, &vdev->err_trigger, in vfio_pci_set_err_trigger()
814 static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev, in vfio_pci_set_req_trigger() argument
821 return vfio_pci_set_ctx_trigger_single(vdev, &vdev->req_trigger, in vfio_pci_set_req_trigger()
825 int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, in vfio_pci_set_irqs_ioctl() argument
829 int (*func)(struct vfio_pci_core_device *vdev, unsigned index, in vfio_pci_set_irqs_ioctl()
862 if (pci_is_pcie(vdev->pdev)) in vfio_pci_set_irqs_ioctl()
879 return func(vdev, index, start, count, flags, data); in vfio_pci_set_irqs_ioctl()