@@ -323,13 +323,14 @@ int iommu_probe_device(struct device *dev)
323
323
324
324
void iommu_release_device (struct device * dev )
325
325
{
326
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
326
+ const struct iommu_ops * ops ;
327
327
328
328
if (!dev -> iommu )
329
329
return ;
330
330
331
331
iommu_device_unlink (dev -> iommu -> iommu_dev , dev );
332
332
333
+ ops = dev_iommu_ops (dev );
333
334
ops -> release_device (dev );
334
335
335
336
iommu_group_remove_device (dev );
@@ -833,8 +834,10 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group,
833
834
static bool iommu_is_attach_deferred (struct iommu_domain * domain ,
834
835
struct device * dev )
835
836
{
836
- if (domain -> ops -> is_attach_deferred )
837
- return domain -> ops -> is_attach_deferred (domain , dev );
837
+ const struct iommu_ops * ops = dev_iommu_ops (dev );
838
+
839
+ if (ops -> is_attach_deferred )
840
+ return ops -> is_attach_deferred (domain , dev );
838
841
839
842
return false;
840
843
}
@@ -1252,10 +1255,10 @@ int iommu_page_response(struct device *dev,
1252
1255
struct iommu_fault_event * evt ;
1253
1256
struct iommu_fault_page_request * prm ;
1254
1257
struct dev_iommu * param = dev -> iommu ;
1258
+ const struct iommu_ops * ops = dev_iommu_ops (dev );
1255
1259
bool has_pasid = msg -> flags & IOMMU_PAGE_RESP_PASID_VALID ;
1256
- struct iommu_domain * domain = iommu_get_domain_for_dev (dev );
1257
1260
1258
- if (!domain || ! domain -> ops -> page_response )
1261
+ if (!ops -> page_response )
1259
1262
return - ENODEV ;
1260
1263
1261
1264
if (!param || !param -> fault_param )
@@ -1296,7 +1299,7 @@ int iommu_page_response(struct device *dev,
1296
1299
msg -> pasid = 0 ;
1297
1300
}
1298
1301
1299
- ret = domain -> ops -> page_response (dev , evt , msg );
1302
+ ret = ops -> page_response (dev , evt , msg );
1300
1303
list_del (& evt -> list );
1301
1304
kfree (evt );
1302
1305
break ;
@@ -1521,7 +1524,7 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_group);
1521
1524
1522
1525
static int iommu_get_def_domain_type (struct device * dev )
1523
1526
{
1524
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
1527
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
1525
1528
1526
1529
if (dev_is_pci (dev ) && to_pci_dev (dev )-> untrusted )
1527
1530
return IOMMU_DOMAIN_DMA ;
@@ -1580,17 +1583,14 @@ static int iommu_alloc_default_domain(struct iommu_group *group,
1580
1583
*/
1581
1584
static struct iommu_group * iommu_group_get_for_dev (struct device * dev )
1582
1585
{
1583
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
1586
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
1584
1587
struct iommu_group * group ;
1585
1588
int ret ;
1586
1589
1587
1590
group = iommu_group_get (dev );
1588
1591
if (group )
1589
1592
return group ;
1590
1593
1591
- if (!ops )
1592
- return ERR_PTR (- EINVAL );
1593
-
1594
1594
group = ops -> device_group (dev );
1595
1595
if (WARN_ON_ONCE (group == NULL ))
1596
1596
return ERR_PTR (- EINVAL );
@@ -1759,10 +1759,10 @@ static int __iommu_group_dma_attach(struct iommu_group *group)
1759
1759
1760
1760
static int iommu_group_do_probe_finalize (struct device * dev , void * data )
1761
1761
{
1762
- struct iommu_domain * domain = data ;
1762
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
1763
1763
1764
- if (domain -> ops -> probe_finalize )
1765
- domain -> ops -> probe_finalize (dev );
1764
+ if (ops -> probe_finalize )
1765
+ ops -> probe_finalize (dev );
1766
1766
1767
1767
return 0 ;
1768
1768
}
@@ -2020,7 +2020,7 @@ EXPORT_SYMBOL_GPL(iommu_attach_device);
2020
2020
2021
2021
int iommu_deferred_attach (struct device * dev , struct iommu_domain * domain )
2022
2022
{
2023
- const struct iommu_ops * ops = domain -> ops ;
2023
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
2024
2024
2025
2025
if (ops -> is_attach_deferred && ops -> is_attach_deferred (domain , dev ))
2026
2026
return __iommu_attach_device (domain , dev );
@@ -2579,17 +2579,17 @@ EXPORT_SYMBOL_GPL(iommu_set_pgtable_quirks);
2579
2579
2580
2580
void iommu_get_resv_regions (struct device * dev , struct list_head * list )
2581
2581
{
2582
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
2582
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
2583
2583
2584
- if (ops && ops -> get_resv_regions )
2584
+ if (ops -> get_resv_regions )
2585
2585
ops -> get_resv_regions (dev , list );
2586
2586
}
2587
2587
2588
2588
void iommu_put_resv_regions (struct device * dev , struct list_head * list )
2589
2589
{
2590
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
2590
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
2591
2591
2592
- if (ops && ops -> put_resv_regions )
2592
+ if (ops -> put_resv_regions )
2593
2593
ops -> put_resv_regions (dev , list );
2594
2594
}
2595
2595
@@ -2794,9 +2794,9 @@ iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata)
2794
2794
{
2795
2795
struct iommu_group * group ;
2796
2796
struct iommu_sva * handle = ERR_PTR (- EINVAL );
2797
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
2797
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
2798
2798
2799
- if (!ops || ! ops -> sva_bind )
2799
+ if (!ops -> sva_bind )
2800
2800
return ERR_PTR (- ENODEV );
2801
2801
2802
2802
group = iommu_group_get (dev );
@@ -2837,9 +2837,9 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
2837
2837
{
2838
2838
struct iommu_group * group ;
2839
2839
struct device * dev = handle -> dev ;
2840
- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
2840
+ const struct iommu_ops * ops = dev_iommu_ops ( dev ) ;
2841
2841
2842
- if (!ops || ! ops -> sva_unbind )
2842
+ if (!ops -> sva_unbind )
2843
2843
return ;
2844
2844
2845
2845
group = iommu_group_get (dev );
@@ -2856,9 +2856,9 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_device);
2856
2856
2857
2857
u32 iommu_sva_get_pasid (struct iommu_sva * handle )
2858
2858
{
2859
- const struct iommu_ops * ops = handle -> dev -> bus -> iommu_ops ;
2859
+ const struct iommu_ops * ops = dev_iommu_ops ( handle -> dev ) ;
2860
2860
2861
- if (!ops || ! ops -> sva_get_pasid )
2861
+ if (!ops -> sva_get_pasid )
2862
2862
return IOMMU_PASID_INVALID ;
2863
2863
2864
2864
return ops -> sva_get_pasid (handle );
0 commit comments