diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2011-11-28 08:36:36 -0500 |
---|---|---|
committer | Joerg Roedel <joerg.roedel@amd.com> | 2011-12-14 06:09:39 -0500 |
commit | 175d6146738b3d04e1adcaa4a971a3b2b0dbd8af (patch) | |
tree | 02fea4cc4c1205db6d922be017b5bd65359ed3d7 /drivers/iommu | |
parent | 8736b2c331030733c5d619170dc6e9ef211a4039 (diff) |
iommu/amd: Add invalid_ppr callback
This callback can be used to change the PRI response code
sent to a device when a PPR fault fails.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'drivers/iommu')
-rw-r--r-- | drivers/iommu/amd_iommu_v2.c | 57 |
1 files changed, 55 insertions, 2 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 | } |
829 | EXPORT_SYMBOL(amd_iommu_free_device); | 851 | EXPORT_SYMBOL(amd_iommu_free_device); |
830 | 852 | ||
853 | int 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 | |||
877 | out_unlock: | ||
878 | spin_unlock_irqrestore(&state_lock, flags); | ||
879 | |||
880 | return ret; | ||
881 | } | ||
882 | EXPORT_SYMBOL(amd_iommu_set_invalid_ppr_cb); | ||
883 | |||
831 | static int __init amd_iommu_v2_init(void) | 884 | static int __init amd_iommu_v2_init(void) |
832 | { | 885 | { |
833 | size_t state_table_size; | 886 | size_t state_table_size; |