@@ -407,14 +407,28 @@ EXPORT_SYMBOL_GPL(dev_iommu_priv_set);
407
407
* Init the dev->iommu and dev->iommu_group in the struct device and get the
408
408
* driver probed
409
409
*/
410
- static int iommu_init_device (struct device * dev , const struct iommu_ops * ops )
410
+ static int iommu_init_device (struct device * dev )
411
411
{
412
+ const struct iommu_ops * ops ;
412
413
struct iommu_device * iommu_dev ;
413
414
struct iommu_group * group ;
414
415
int ret ;
415
416
416
417
if (!dev_iommu_get (dev ))
417
418
return - ENOMEM ;
419
+ /*
420
+ * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
421
+ * instances with non-NULL fwnodes, and client devices should have been
422
+ * identified with a fwspec by this point. Otherwise, we can currently
423
+ * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
424
+ * be present, and that any of their registered instances has suitable
425
+ * ops for probing, and thus cheekily co-opt the same mechanism.
426
+ */
427
+ ops = iommu_fwspec_ops (dev -> iommu -> fwspec );
428
+ if (!ops ) {
429
+ ret = - ENODEV ;
430
+ goto err_free ;
431
+ }
418
432
419
433
if (!try_module_get (ops -> owner )) {
420
434
ret = - EINVAL ;
@@ -517,22 +531,10 @@ DEFINE_MUTEX(iommu_probe_device_lock);
517
531
518
532
static int __iommu_probe_device (struct device * dev , struct list_head * group_list )
519
533
{
520
- const struct iommu_ops * ops ;
521
534
struct iommu_group * group ;
522
535
struct group_device * gdev ;
523
536
int ret ;
524
537
525
- /*
526
- * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
527
- * instances with non-NULL fwnodes, and client devices should have been
528
- * identified with a fwspec by this point. Otherwise, we can currently
529
- * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
530
- * be present, and that any of their registered instances has suitable
531
- * ops for probing, and thus cheekily co-opt the same mechanism.
532
- */
533
- ops = iommu_fwspec_ops (dev_iommu_fwspec_get (dev ));
534
- if (!ops )
535
- return - ENODEV ;
536
538
/*
537
539
* Serialise to avoid races between IOMMU drivers registering in
538
540
* parallel and/or the "replay" calls from ACPI/OF code via client
@@ -546,7 +548,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
546
548
if (dev -> iommu_group )
547
549
return 0 ;
548
550
549
- ret = iommu_init_device (dev , ops );
551
+ ret = iommu_init_device (dev );
550
552
if (ret )
551
553
return ret ;
552
554
0 commit comments