aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/iommu/amd_iommu_v2.c57
-rw-r--r--include/linux/amd-iommu.h34
2 files changed, 86 insertions, 5 deletions
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index abdb8396f89a..fe812e2a0474 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -62,6 +62,7 @@ struct device_state {
62 struct iommu_domain *domain; 62 struct iommu_domain *domain;
63 int pasid_levels; 63 int pasid_levels;
64 int max_pasids; 64 int max_pasids;
65 amd_iommu_invalid_ppr_cb inv_ppr_cb;
65 spinlock_t lock; 66 spinlock_t lock;
66 wait_queue_head_t wq; 67 wait_queue_head_t wq;
67}; 68};
@@ -505,10 +506,31 @@ static void do_fault(struct work_struct *work)
505 npages = get_user_pages(fault->state->task, fault->state->mm, 506 npages = get_user_pages(fault->state->task, fault->state->mm,
506 fault->address, 1, write, 0, &page, NULL); 507 fault->address, 1, write, 0, &page, NULL);
507 508
508 if (npages == 1) 509 if (npages == 1) {
509 put_page(page); 510 put_page(page);
510 else 511 } else if (fault->dev_state->inv_ppr_cb) {
512 int status;
513
514 status = fault->dev_state->inv_ppr_cb(fault->dev_state->pdev,
515 fault->pasid,
516 fault->address,
517 fault->flags);
518 switch (status) {
519 case AMD_IOMMU_INV_PRI_RSP_SUCCESS:
520 set_pri_tag_status(fault->state, fault->tag, PPR_SUCCESS);
521 break;
522 case AMD_IOMMU_INV_PRI_RSP_INVALID:
523 set_pri_tag_status(fault->state, fault->tag, PPR_INVALID);
524 break;
525 case AMD_IOMMU_INV_PRI_RSP_FAIL:
526 set_pri_tag_status(fault->state, fault->tag, PPR_FAILURE);
527 break;
528 default:
529 BUG();
530 }
531 } else {
511 set_pri_tag_status(fault->state, fault->tag, PPR_INVALID); 532 set_pri_tag_status(fault->state, fault->tag, PPR_INVALID);
533 }
512 534
513 finish_pri_tag(fault->dev_state, fault->state, fault->tag); 535 finish_pri_tag(fault->dev_state, fault->state, fault->tag);
514 536
@@ -828,6 +850,37 @@ void amd_iommu_free_device(struct pci_dev *pdev)
828} 850}
829EXPORT_SYMBOL(amd_iommu_free_device); 851EXPORT_SYMBOL(amd_iommu_free_device);
830 852
853int amd_iommu_set_invalid_ppr_cb(struct pci_dev *pdev,
854 amd_iommu_invalid_ppr_cb cb)
855{
856 struct device_state *dev_state;
857 unsigned long flags;
858 u16 devid;
859 int ret;
860
861 if (!amd_iommu_v2_supported())
862 return -ENODEV;
863
864 devid = device_id(pdev);
865
866 spin_lock_irqsave(&state_lock, flags);
867
868 ret = -EINVAL;
869 dev_state = state_table[devid];
870 if (dev_state == NULL)
871 goto out_unlock;
872
873 dev_state->inv_ppr_cb = cb;
874
875 ret = 0;
876
877out_unlock:
878 spin_unlock_irqrestore(&state_lock, flags);
879
880 return ret;
881}
882EXPORT_SYMBOL(amd_iommu_set_invalid_ppr_cb);
883
831static int __init amd_iommu_v2_init(void) 884static int __init amd_iommu_v2_init(void)
832{ 885{
833 size_t state_table_size; 886 size_t state_table_size;
diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h
index 23e21e15dfab..06688c42167d 100644
--- a/include/linux/amd-iommu.h
+++ b/include/linux/amd-iommu.h
@@ -28,9 +28,6 @@ struct task_struct;
28struct pci_dev; 28struct pci_dev;
29 29
30extern int amd_iommu_detect(void); 30extern int amd_iommu_detect(void);
31extern int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid,
32 struct task_struct *task);
33extern void amd_iommu_unbind_pasid(struct pci_dev *pdev, int pasid);
34 31
35 32
36/** 33/**
@@ -91,6 +88,37 @@ extern int amd_iommu_bind_pasid(struct pci_dev *pdev, int pasid,
91 */ 88 */
92extern void amd_iommu_unbind_pasid(struct pci_dev *pdev, int pasid); 89extern void amd_iommu_unbind_pasid(struct pci_dev *pdev, int pasid);
93 90
91/**
92 * amd_iommu_set_invalid_ppr_cb() - Register a call-back for failed
93 * PRI requests
94 * @pdev: The PCI device the call-back should be registered for
95 * @cb: The call-back function
96 *
97 * The IOMMUv2 driver invokes this call-back when it is unable to
98 * successfully handle a PRI request. The device driver can then decide
99 * which PRI response the device should see. Possible return values for
100 * the call-back are:
101 *
102 * - AMD_IOMMU_INV_PRI_RSP_SUCCESS - Send SUCCESS back to the device
103 * - AMD_IOMMU_INV_PRI_RSP_INVALID - Send INVALID back to the device
104 * - AMD_IOMMU_INV_PRI_RSP_FAIL - Send Failure back to the device,
105 * the device is required to disable
106 * PRI when it receives this response
107 *
108 * The function returns 0 on success or negative value on error.
109 */
110#define AMD_IOMMU_INV_PRI_RSP_SUCCESS 0
111#define AMD_IOMMU_INV_PRI_RSP_INVALID 1
112#define AMD_IOMMU_INV_PRI_RSP_FAIL 2
113
114typedef int (*amd_iommu_invalid_ppr_cb)(struct pci_dev *pdev,
115 int pasid,
116 unsigned long address,
117 u16);
118
119extern int amd_iommu_set_invalid_ppr_cb(struct pci_dev *pdev,
120 amd_iommu_invalid_ppr_cb cb);
121
94#else 122#else
95 123
96static inline int amd_iommu_detect(void) { return -ENODEV; } 124static inline int amd_iommu_detect(void) { return -ENODEV; }