@@ -218,10 +218,29 @@ static void load_gpu(struct drm_device *dev)
218218 mutex_unlock (& init_lock );
219219}
220220
221+ /**
222+ * msm_context_vm - lazily create the context's VM
223+ *
224+ * @dev: the drm device
225+ * @ctx: the context
226+ *
227+ * The VM is lazily created, so that userspace has a chance to opt-in to having
228+ * a userspace managed VM before the VM is created.
229+ *
230+ * Note that this does not return a reference to the VM. Once the VM is created,
231+ * it exists for the lifetime of the context.
232+ */
233+ struct drm_gpuvm * msm_context_vm (struct drm_device * dev , struct msm_context * ctx )
234+ {
235+ struct msm_drm_private * priv = dev -> dev_private ;
236+ if (!ctx -> vm )
237+ ctx -> vm = msm_gpu_create_private_vm (priv -> gpu , current );
238+ return ctx -> vm ;
239+ }
240+
221241static int context_init (struct drm_device * dev , struct drm_file * file )
222242{
223243 static atomic_t ident = ATOMIC_INIT (0 );
224- struct msm_drm_private * priv = dev -> dev_private ;
225244 struct msm_context * ctx ;
226245
227246 ctx = kzalloc (sizeof (* ctx ), GFP_KERNEL );
@@ -234,7 +253,6 @@ static int context_init(struct drm_device *dev, struct drm_file *file)
234253 kref_init (& ctx -> ref );
235254 msm_submitqueue_init (dev , ctx );
236255
237- ctx -> vm = msm_gpu_create_private_vm (priv -> gpu , current );
238256 file -> driver_priv = ctx ;
239257
240258 ctx -> seqno = atomic_inc_return (& ident );
@@ -413,7 +431,7 @@ static int msm_ioctl_gem_info_iova(struct drm_device *dev,
413431 * Don't pin the memory here - just get an address so that userspace can
414432 * be productive
415433 */
416- return msm_gem_get_iova (obj , ctx -> vm , iova );
434+ return msm_gem_get_iova (obj , msm_context_vm ( dev , ctx ) , iova );
417435}
418436
419437static int msm_ioctl_gem_info_set_iova (struct drm_device * dev ,
@@ -422,18 +440,19 @@ static int msm_ioctl_gem_info_set_iova(struct drm_device *dev,
422440{
423441 struct msm_drm_private * priv = dev -> dev_private ;
424442 struct msm_context * ctx = file -> driver_priv ;
443+ struct drm_gpuvm * vm = msm_context_vm (dev , ctx );
425444
426445 if (!priv -> gpu )
427446 return - EINVAL ;
428447
429448 /* Only supported if per-process address space is supported: */
430- if (priv -> gpu -> vm == ctx -> vm )
449+ if (priv -> gpu -> vm == vm )
431450 return UERR (EOPNOTSUPP , dev , "requires per-process pgtables" );
432451
433452 if (should_fail (& fail_gem_iova , obj -> size ))
434453 return - ENOMEM ;
435454
436- return msm_gem_set_iova (obj , ctx -> vm , iova );
455+ return msm_gem_set_iova (obj , vm , iova );
437456}
438457
439458static int msm_ioctl_gem_info_set_metadata (struct drm_gem_object * obj ,
0 commit comments