@@ -1415,11 +1415,6 @@ static void iommu_enable_pci_caps(struct device_domain_info *info)
14151415 if (info -> pasid_supported && !pci_enable_pasid (pdev , info -> pasid_supported & ~1 ))
14161416 info -> pasid_enabled = 1 ;
14171417
1418- if (info -> pri_supported &&
1419- (info -> pasid_enabled ? pci_prg_resp_pasid_required (pdev ) : 1 ) &&
1420- !pci_reset_pri (pdev ) && !pci_enable_pri (pdev , PRQ_DEPTH ))
1421- info -> pri_enabled = 1 ;
1422-
14231418 if (info -> ats_supported && pci_ats_page_aligned (pdev ) &&
14241419 !pci_enable_ats (pdev , VTD_PAGE_SHIFT )) {
14251420 info -> ats_enabled = 1 ;
@@ -1442,11 +1437,6 @@ static void iommu_disable_pci_caps(struct device_domain_info *info)
14421437 domain_update_iotlb (info -> domain );
14431438 }
14441439
1445- if (info -> pri_enabled ) {
1446- pci_disable_pri (pdev );
1447- info -> pri_enabled = 0 ;
1448- }
1449-
14501440 if (info -> pasid_enabled ) {
14511441 pci_disable_pasid (pdev );
14521442 info -> pasid_enabled = 0 ;
@@ -4667,23 +4657,48 @@ static int intel_iommu_enable_sva(struct device *dev)
46674657
46684658static int intel_iommu_enable_iopf (struct device * dev )
46694659{
4660+ struct pci_dev * pdev = dev_is_pci (dev ) ? to_pci_dev (dev ) : NULL ;
46704661 struct device_domain_info * info = dev_iommu_priv_get (dev );
46714662 struct intel_iommu * iommu ;
46724663 int ret ;
46734664
4674- if (!info || !info -> ats_enabled || !info -> pri_enabled )
4665+ if (!pdev || ! info || !info -> ats_enabled || !info -> pri_supported )
46754666 return - ENODEV ;
4667+
4668+ if (info -> pri_enabled )
4669+ return - EBUSY ;
4670+
46764671 iommu = info -> iommu ;
46774672 if (!iommu )
46784673 return - EINVAL ;
46794674
4675+ /* PASID is required in PRG Response Message. */
4676+ if (info -> pasid_enabled && !pci_prg_resp_pasid_required (pdev ))
4677+ return - EINVAL ;
4678+
4679+ ret = pci_reset_pri (pdev );
4680+ if (ret )
4681+ return ret ;
4682+
46804683 ret = iopf_queue_add_device (iommu -> iopf_queue , dev );
46814684 if (ret )
46824685 return ret ;
46834686
46844687 ret = iommu_register_device_fault_handler (dev , iommu_queue_iopf , dev );
46854688 if (ret )
4686- iopf_queue_remove_device (iommu -> iopf_queue , dev );
4689+ goto iopf_remove_device ;
4690+
4691+ ret = pci_enable_pri (pdev , PRQ_DEPTH );
4692+ if (ret )
4693+ goto iopf_unregister_handler ;
4694+ info -> pri_enabled = 1 ;
4695+
4696+ return 0 ;
4697+
4698+ iopf_unregister_handler :
4699+ iommu_unregister_device_fault_handler (dev );
4700+ iopf_remove_device :
4701+ iopf_queue_remove_device (iommu -> iopf_queue , dev );
46874702
46884703 return ret ;
46894704}
@@ -4694,6 +4709,20 @@ static int intel_iommu_disable_iopf(struct device *dev)
46944709 struct intel_iommu * iommu = info -> iommu ;
46954710 int ret ;
46964711
4712+ if (!info -> pri_enabled )
4713+ return - EINVAL ;
4714+
4715+ /*
4716+ * PCIe spec states that by clearing PRI enable bit, the Page
4717+ * Request Interface will not issue new page requests, but has
4718+ * outstanding page requests that have been transmitted or are
4719+ * queued for transmission. This is supposed to be called after
4720+ * the device driver has stopped DMA, all PASIDs have been
4721+ * unbound and the outstanding PRQs have been drained.
4722+ */
4723+ pci_disable_pri (to_pci_dev (dev ));
4724+ info -> pri_enabled = 0 ;
4725+
46974726 ret = iommu_unregister_device_fault_handler (dev );
46984727 if (ret )
46994728 return ret ;
0 commit comments