Lines Matching refs:vdev
34 static bool irq_is(struct vfio_pci_core_device *vdev, int type)
36 return vdev->irq_type == type;
39 static bool is_intx(struct vfio_pci_core_device *vdev)
41 return vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX;
44 static bool is_irq_none(struct vfio_pci_core_device *vdev)
46 return !(vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX ||
47 vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX ||
48 vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX);
52 struct vfio_pci_irq_ctx *vfio_irq_ctx_get(struct vfio_pci_core_device *vdev,
55 return xa_load(&vdev->ctx, index);
58 static void vfio_irq_ctx_free(struct vfio_pci_core_device *vdev,
61 xa_erase(&vdev->ctx, index);
66 vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index)
75 ret = xa_insert(&vdev->ctx, index, ctx, GFP_KERNEL_ACCOUNT);
89 struct vfio_pci_core_device *vdev = opaque;
91 if (likely(is_intx(vdev) && !vdev->virq_disabled)) {
95 ctx = vfio_irq_ctx_get(vdev, 0);
106 static bool __vfio_pci_intx_mask(struct vfio_pci_core_device *vdev)
108 struct pci_dev *pdev = vdev->pdev;
113 lockdep_assert_held(&vdev->igate);
115 spin_lock_irqsave(&vdev->irqlock, flags);
123 if (unlikely(!is_intx(vdev))) {
124 if (vdev->pci_2_3)
129 ctx = vfio_irq_ctx_get(vdev, 0);
138 if (vdev->pci_2_3)
148 spin_unlock_irqrestore(&vdev->irqlock, flags);
152 bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev)
156 mutex_lock(&vdev->igate);
157 mask_changed = __vfio_pci_intx_mask(vdev);
158 mutex_unlock(&vdev->igate);
171 struct vfio_pci_core_device *vdev = opaque;
172 struct pci_dev *pdev = vdev->pdev;
177 spin_lock_irqsave(&vdev->irqlock, flags);
183 if (unlikely(!is_intx(vdev))) {
184 if (vdev->pci_2_3)
189 ctx = vfio_irq_ctx_get(vdev, 0);
193 if (ctx->masked && !vdev->virq_disabled) {
199 if (vdev->pci_2_3) {
209 spin_unlock_irqrestore(&vdev->irqlock, flags);
214 static void __vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
216 lockdep_assert_held(&vdev->igate);
218 if (vfio_pci_intx_unmask_handler(vdev, NULL) > 0)
219 vfio_send_intx_eventfd(vdev, NULL);
222 void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
224 mutex_lock(&vdev->igate);
225 __vfio_pci_intx_unmask(vdev);
226 mutex_unlock(&vdev->igate);
231 struct vfio_pci_core_device *vdev = dev_id;
236 ctx = vfio_irq_ctx_get(vdev, 0);
240 spin_lock_irqsave(&vdev->irqlock, flags);
242 if (!vdev->pci_2_3) {
243 disable_irq_nosync(vdev->pdev->irq);
247 pci_check_and_mask_intx(vdev->pdev)) {
252 spin_unlock_irqrestore(&vdev->irqlock, flags);
255 vfio_send_intx_eventfd(vdev, NULL);
260 static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
263 struct pci_dev *pdev = vdev->pdev;
269 if (!is_irq_none(vdev))
279 ctx = vfio_irq_ctx_alloc(vdev, 0);
304 ctx->masked = vdev->virq_disabled;
305 if (vdev->pci_2_3) {
312 vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX;
315 irqflags, ctx->name, vdev);
317 vdev->irq_type = VFIO_PCI_NUM_IRQS;
319 vfio_irq_ctx_free(vdev, ctx, 0);
326 static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev,
329 struct pci_dev *pdev = vdev->pdev;
333 ctx = vfio_irq_ctx_get(vdev, 0);
351 static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
353 struct pci_dev *pdev = vdev->pdev;
356 ctx = vfio_irq_ctx_get(vdev, 0);
361 free_irq(pdev->irq, vdev);
365 vfio_irq_ctx_free(vdev, ctx, 0);
367 vdev->irq_type = VFIO_PCI_NUM_IRQS;
381 static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msix)
383 struct pci_dev *pdev = vdev->pdev;
388 if (!is_irq_none(vdev))
392 cmd = vfio_pci_memory_lock_and_enable(vdev);
397 vfio_pci_memory_unlock_and_restore(vdev, cmd);
400 vfio_pci_memory_unlock_and_restore(vdev, cmd);
402 vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
410 vdev->msi_qmax = fls(nvec * 2 - 1) - 1;
426 static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev,
429 struct pci_dev *pdev = vdev->pdev;
437 if (irq > 0 || !msix || !vdev->has_dyn_msix)
440 cmd = vfio_pci_memory_lock_and_enable(vdev);
442 vfio_pci_memory_unlock_and_restore(vdev, cmd);
447 static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,
450 struct pci_dev *pdev = vdev->pdev;
456 ctx = vfio_irq_ctx_get(vdev, vector);
461 cmd = vfio_pci_memory_lock_and_enable(vdev);
463 vfio_pci_memory_unlock_and_restore(vdev, cmd);
467 vfio_irq_ctx_free(vdev, ctx, vector);
475 irq = vfio_msi_alloc_irq(vdev, vector, msix);
480 ctx = vfio_irq_ctx_alloc(vdev, vector);
502 cmd = vfio_pci_memory_lock_and_enable(vdev);
511 vfio_pci_memory_unlock_and_restore(vdev, cmd);
534 vfio_irq_ctx_free(vdev, ctx, vector);
538 static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
546 ret = vfio_msi_set_vector_signal(vdev, j, fd, msix);
551 vfio_msi_set_vector_signal(vdev, i, -1, msix);
557 static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix)
559 struct pci_dev *pdev = vdev->pdev;
564 xa_for_each(&vdev->ctx, i, ctx) {
567 vfio_msi_set_vector_signal(vdev, i, -1, msix);
570 cmd = vfio_pci_memory_lock_and_enable(vdev);
572 vfio_pci_memory_unlock_and_restore(vdev, cmd);
578 if (vdev->nointx)
581 vdev->irq_type = VFIO_PCI_NUM_IRQS;
587 static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev,
591 if (!is_intx(vdev) || start != 0 || count != 1)
595 __vfio_pci_intx_unmask(vdev);
599 __vfio_pci_intx_unmask(vdev);
601 struct vfio_pci_irq_ctx *ctx = vfio_irq_ctx_get(vdev, 0);
607 return vfio_virqfd_enable((void *) vdev,
618 static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev,
622 if (!is_intx(vdev) || start != 0 || count != 1)
626 __vfio_pci_intx_mask(vdev);
630 __vfio_pci_intx_mask(vdev);
638 static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev,
642 if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
643 vfio_intx_disable(vdev);
647 if (!(is_intx(vdev) || is_irq_none(vdev)) || start != 0 || count != 1)
661 if (is_intx(vdev))
662 ret = vfio_intx_set_signal(vdev, trigger);
664 ret = vfio_intx_enable(vdev, trigger);
672 if (!is_intx(vdev))
676 vfio_send_intx_eventfd(vdev, NULL);
680 vfio_send_intx_eventfd(vdev, NULL);
685 static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
693 if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
694 vfio_msi_disable(vdev, msix);
698 if (!(irq_is(vdev, index) || is_irq_none(vdev)))
705 if (vdev->irq_type == index)
706 return vfio_msi_set_block(vdev, start, count,
709 ret = vfio_msi_enable(vdev, start + count, msix);
713 ret = vfio_msi_set_block(vdev, start, count, fds, msix);
715 vfio_msi_disable(vdev, msix);
720 if (!irq_is(vdev, index))
724 ctx = vfio_irq_ctx_get(vdev, i);
793 static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev,
800 return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger,
804 static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev,
811 return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger,
815 int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags,
819 int (*func)(struct vfio_pci_core_device *vdev, unsigned index,
852 if (pci_is_pcie(vdev->pdev))
869 return func(vdev, index, start, count, flags, data);