1717#include <linux/slab.h>
1818#include <linux/fsl/mc.h>
1919
20+ #include "iommu-priv.h"
21+
2022static int of_iommu_xlate (struct device * dev ,
2123 struct of_phandle_args * iommu_spec )
2224{
2325 const struct iommu_ops * ops ;
24- struct fwnode_handle * fwnode = & iommu_spec -> np -> fwnode ;
2526 int ret ;
2627
27- ops = iommu_ops_from_fwnode (fwnode );
28- if ((ops && !ops -> of_xlate ) ||
29- !of_device_is_available (iommu_spec -> np ))
28+ if (!of_device_is_available (iommu_spec -> np ))
3029 return - ENODEV ;
3130
32- ret = iommu_fwspec_init (dev , fwnode , ops );
31+ ret = iommu_fwspec_init (dev , of_fwnode_handle (iommu_spec -> np ));
32+ if (ret == - EPROBE_DEFER )
33+ return driver_deferred_probe_check_state (dev );
3334 if (ret )
3435 return ret ;
35- /*
36- * The otherwise-empty fwspec handily serves to indicate the specific
37- * IOMMU device we're waiting for, which will be useful if we ever get
38- * a proper probe-ordering dependency mechanism in future.
39- */
40- if (!ops )
41- return driver_deferred_probe_check_state (dev );
4236
43- if (!try_module_get (ops -> owner ))
37+ ops = iommu_ops_from_fwnode (& iommu_spec -> np -> fwnode );
38+ if (!ops -> of_xlate || !try_module_get (ops -> owner ))
4439 return - ENODEV ;
4540
4641 ret = ops -> of_xlate (dev , iommu_spec );
@@ -115,22 +110,16 @@ static int of_iommu_configure_device(struct device_node *master_np,
115110int of_iommu_configure (struct device * dev , struct device_node * master_np ,
116111 const u32 * id )
117112{
118- struct iommu_fwspec * fwspec ;
119113 int err ;
120114
121115 if (!master_np )
122116 return - ENODEV ;
123117
124118 /* Serialise to make dev->iommu stable under our potential fwspec */
125119 mutex_lock (& iommu_probe_device_lock );
126- fwspec = dev_iommu_fwspec_get (dev );
127- if (fwspec ) {
128- if (fwspec -> ops ) {
129- mutex_unlock (& iommu_probe_device_lock );
130- return 0 ;
131- }
132- /* In the deferred case, start again from scratch */
133- iommu_fwspec_free (dev );
120+ if (dev_iommu_fwspec_get (dev )) {
121+ mutex_unlock (& iommu_probe_device_lock );
122+ return 0 ;
134123 }
135124
136125 /*
@@ -150,20 +139,17 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
150139 } else {
151140 err = of_iommu_configure_device (master_np , dev , id );
152141 }
153- mutex_unlock (& iommu_probe_device_lock );
154142
155- if (err == - ENODEV || err == - EPROBE_DEFER )
156- return err ;
157143 if (err )
158- goto err_log ;
144+ iommu_fwspec_free (dev );
145+ mutex_unlock (& iommu_probe_device_lock );
159146
160- err = iommu_probe_device (dev );
161- if (err )
162- goto err_log ;
163- return 0 ;
147+ if (!err && dev -> bus )
148+ err = iommu_probe_device (dev );
149+
150+ if (err && err != - EPROBE_DEFER )
151+ dev_dbg (dev , "Adding to IOMMU failed: %d\n" , err );
164152
165- err_log :
166- dev_dbg (dev , "Adding to IOMMU failed: %pe\n" , ERR_PTR (err ));
167153 return err ;
168154}
169155
0 commit comments