@@ -199,6 +199,11 @@ static inline void context_set_domain_id(struct context_entry *context,
199
199
context -> hi |= (value & ((1 << 16 ) - 1 )) << 8 ;
200
200
}
201
201
202
+ static inline void context_set_pasid (struct context_entry * context )
203
+ {
204
+ context -> lo |= CONTEXT_PASIDE ;
205
+ }
206
+
202
207
static inline int context_domain_id (struct context_entry * c )
203
208
{
204
209
return ((c -> hi >> 8 ) & 0xffff );
@@ -1350,21 +1355,18 @@ static void __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did,
1350
1355
}
1351
1356
1352
1357
static struct device_domain_info *
1353
- iommu_support_dev_iotlb (struct dmar_domain * domain , struct intel_iommu * iommu ,
1354
- u8 bus , u8 devfn )
1358
+ domain_lookup_dev_info (struct dmar_domain * domain ,
1359
+ struct intel_iommu * iommu , u8 bus , u8 devfn )
1355
1360
{
1356
1361
struct device_domain_info * info ;
1357
1362
unsigned long flags ;
1358
1363
1359
- if (!iommu -> qi )
1360
- return NULL ;
1361
-
1362
1364
spin_lock_irqsave (& domain -> lock , flags );
1363
1365
list_for_each_entry (info , & domain -> devices , link ) {
1364
1366
if (info -> iommu == iommu && info -> bus == bus &&
1365
1367
info -> devfn == devfn ) {
1366
1368
spin_unlock_irqrestore (& domain -> lock , flags );
1367
- return info -> ats_supported ? info : NULL ;
1369
+ return info ;
1368
1370
}
1369
1371
}
1370
1372
spin_unlock_irqrestore (& domain -> lock , flags );
@@ -1389,7 +1391,7 @@ static void domain_update_iotlb(struct dmar_domain *domain)
1389
1391
spin_unlock_irqrestore (& domain -> lock , flags );
1390
1392
}
1391
1393
1392
- static void iommu_enable_dev_iotlb (struct device_domain_info * info )
1394
+ static void iommu_enable_pci_caps (struct device_domain_info * info )
1393
1395
{
1394
1396
struct pci_dev * pdev ;
1395
1397
@@ -1412,7 +1414,6 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info)
1412
1414
info -> pfsid = pci_dev_id (pf_pdev );
1413
1415
}
1414
1416
1415
- #ifdef CONFIG_INTEL_IOMMU_SVM
1416
1417
/* The PCIe spec, in its wisdom, declares that the behaviour of
1417
1418
the device if you enable PASID support after ATS support is
1418
1419
undefined. So always enable PASID support on devices which
@@ -1425,7 +1426,7 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info)
1425
1426
(info -> pasid_enabled ? pci_prg_resp_pasid_required (pdev ) : 1 ) &&
1426
1427
!pci_reset_pri (pdev ) && !pci_enable_pri (pdev , PRQ_DEPTH ))
1427
1428
info -> pri_enabled = 1 ;
1428
- #endif
1429
+
1429
1430
if (info -> ats_supported && pci_ats_page_aligned (pdev ) &&
1430
1431
!pci_enable_ats (pdev , VTD_PAGE_SHIFT )) {
1431
1432
info -> ats_enabled = 1 ;
@@ -1448,16 +1449,16 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
1448
1449
info -> ats_enabled = 0 ;
1449
1450
domain_update_iotlb (info -> domain );
1450
1451
}
1451
- #ifdef CONFIG_INTEL_IOMMU_SVM
1452
+
1452
1453
if (info -> pri_enabled ) {
1453
1454
pci_disable_pri (pdev );
1454
1455
info -> pri_enabled = 0 ;
1455
1456
}
1457
+
1456
1458
if (info -> pasid_enabled ) {
1457
1459
pci_disable_pasid (pdev );
1458
1460
info -> pasid_enabled = 0 ;
1459
1461
}
1460
- #endif
1461
1462
}
1462
1463
1463
1464
static void __iommu_flush_dev_iotlb (struct device_domain_info * info ,
@@ -1907,7 +1908,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
1907
1908
u8 bus , u8 devfn )
1908
1909
{
1909
1910
struct device_domain_info * info =
1910
- iommu_support_dev_iotlb (domain , iommu , bus , devfn );
1911
+ domain_lookup_dev_info (domain , iommu , bus , devfn );
1911
1912
u16 did = domain_id_iommu (domain , iommu );
1912
1913
int translation = CONTEXT_TT_MULTI_LEVEL ;
1913
1914
struct context_entry * context ;
@@ -1980,6 +1981,8 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
1980
1981
context_set_sm_dte (context );
1981
1982
if (info && info -> pri_supported )
1982
1983
context_set_sm_pre (context );
1984
+ if (info && info -> pasid_supported )
1985
+ context_set_pasid (context );
1983
1986
} else {
1984
1987
struct dma_pte * pgd = domain -> pgd ;
1985
1988
int agaw ;
@@ -2037,7 +2040,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
2037
2040
} else {
2038
2041
iommu_flush_write_buffer (iommu );
2039
2042
}
2040
- iommu_enable_dev_iotlb (info );
2043
+ iommu_enable_pci_caps (info );
2041
2044
2042
2045
ret = 0 ;
2043
2046
@@ -4574,52 +4577,6 @@ static void intel_iommu_get_resv_regions(struct device *device,
4574
4577
list_add_tail (& reg -> list , head );
4575
4578
}
4576
4579
4577
- int intel_iommu_enable_pasid (struct intel_iommu * iommu , struct device * dev )
4578
- {
4579
- struct device_domain_info * info = dev_iommu_priv_get (dev );
4580
- struct context_entry * context ;
4581
- struct dmar_domain * domain ;
4582
- u64 ctx_lo ;
4583
- int ret ;
4584
-
4585
- domain = info -> domain ;
4586
- if (!domain )
4587
- return - EINVAL ;
4588
-
4589
- spin_lock (& iommu -> lock );
4590
- ret = - EINVAL ;
4591
- if (!info -> pasid_supported )
4592
- goto out ;
4593
-
4594
- context = iommu_context_addr (iommu , info -> bus , info -> devfn , 0 );
4595
- if (WARN_ON (!context ))
4596
- goto out ;
4597
-
4598
- ctx_lo = context [0 ].lo ;
4599
-
4600
- if (!(ctx_lo & CONTEXT_PASIDE )) {
4601
- ctx_lo |= CONTEXT_PASIDE ;
4602
- context [0 ].lo = ctx_lo ;
4603
- wmb ();
4604
- iommu -> flush .flush_context (iommu ,
4605
- domain_id_iommu (domain , iommu ),
4606
- PCI_DEVID (info -> bus , info -> devfn ),
4607
- DMA_CCMD_MASK_NOBIT ,
4608
- DMA_CCMD_DEVICE_INVL );
4609
- }
4610
-
4611
- /* Enable PASID support in the device, if it wasn't already */
4612
- if (!info -> pasid_enabled )
4613
- iommu_enable_dev_iotlb (info );
4614
-
4615
- ret = 0 ;
4616
-
4617
- out :
4618
- spin_unlock (& iommu -> lock );
4619
-
4620
- return ret ;
4621
- }
4622
-
4623
4580
static struct iommu_group * intel_iommu_device_group (struct device * dev )
4624
4581
{
4625
4582
if (dev_is_pci (dev ))
@@ -4643,9 +4600,6 @@ static int intel_iommu_enable_sva(struct device *dev)
4643
4600
if (!(iommu -> flags & VTD_FLAG_SVM_CAPABLE ))
4644
4601
return - ENODEV ;
4645
4602
4646
- if (intel_iommu_enable_pasid (iommu , dev ))
4647
- return - ENODEV ;
4648
-
4649
4603
if (!info -> pasid_enabled || !info -> pri_enabled || !info -> ats_enabled )
4650
4604
return - EINVAL ;
4651
4605
0 commit comments