drm/msm: Add msm_gem_get_and_pin_iova()
authorJordan Crouse <jcrouse@codeaurora.org>
Wed, 7 Nov 2018 22:35:50 +0000 (15:35 -0700)
committerRob Clark <robdclark@gmail.com>
Tue, 11 Dec 2018 18:05:32 +0000 (13:05 -0500)
Add a new function to get and pin the iova memory in one
step (basically renaming the old msm_gem_get_iova function)
and switch msm_gem_get_iova() to only allocate an iova but
not map it in the IOMMU. This is only currently used by
msm_ioctl_gem_info() since all other users of of the iova
expect that the memory be immediately available.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rob Clark <robdclark@gmail.com>
12 files changed:
drivers/gpu/drm/msm/adreno/adreno_gpu.c
drivers/gpu/drm/msm/disp/mdp4/mdp4_crtc.c
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
drivers/gpu/drm/msm/dsi/dsi_host.c
drivers/gpu/drm/msm/msm_drv.c
drivers/gpu/drm/msm/msm_drv.h
drivers/gpu/drm/msm/msm_fb.c
drivers/gpu/drm/msm/msm_fbdev.c
drivers/gpu/drm/msm/msm_gem.c
drivers/gpu/drm/msm/msm_gem_submit.c
drivers/gpu/drm/msm/msm_gpu.c

index 789f7afe1851f11eeb59d5a8c9ecad593721dfb4..7ab2788e33b664d3e877fbe4cc0cd08918f47148 100644 (file)
@@ -209,7 +209,8 @@ int adreno_hw_init(struct msm_gpu *gpu)
                if (!ring)
                        continue;
 
-               ret = msm_gem_get_iova(ring->bo, gpu->aspace, &ring->iova);
+               ret = msm_gem_get_and_pin_iova(ring->bo, gpu->aspace,
+                       &ring->iova);
                if (ret) {
                        ring->iova = 0;
                        DRM_DEV_ERROR(gpu->dev->dev,
index b91706cee2b8ee06074c16463e5c7ebab8fafa47..ef6884f1fc34746ae356efefeae0cd03d655edd5 100644 (file)
@@ -384,7 +384,7 @@ static void update_cursor(struct drm_crtc *crtc)
                if (next_bo) {
                        /* take a obj ref + iova ref when we start scanning out: */
                        drm_gem_object_get(next_bo);
-                       msm_gem_get_iova(next_bo, kms->aspace, &iova);
+                       msm_gem_get_and_pin_iova(next_bo, kms->aspace, &iova);
 
                        /* enable cursor: */
                        mdp4_write(mdp4_kms, REG_MDP4_DMA_CURSOR_SIZE(dma),
@@ -442,7 +442,7 @@ static int mdp4_crtc_cursor_set(struct drm_crtc *crtc,
        }
 
        if (cursor_bo) {
-               ret = msm_gem_get_iova(cursor_bo, kms->aspace, &iova);
+               ret = msm_gem_get_and_pin_iova(cursor_bo, kms->aspace, &iova);
                if (ret)
                        goto fail;
        } else {
index 481c0d231149bb1456a128bfa5db816fac8b39d7..9fd6b9b2dbcb45d9787233e2c922a4b427bbe7e9 100644 (file)
@@ -538,7 +538,7 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)
                goto fail;
        }
 
-       ret = msm_gem_get_iova(mdp4_kms->blank_cursor_bo, kms->aspace,
+       ret = msm_gem_get_and_pin_iova(mdp4_kms->blank_cursor_bo, kms->aspace,
                        &mdp4_kms->blank_cursor_iova);
        if (ret) {
                DRM_DEV_ERROR(dev->dev, "could not pin blank-cursor bo: %d\n", ret);
index 413b5221101786a0c647b8ebf08539247d8d14a4..c7cc276575fb9d646360c63af77bc3d548aba402 100644 (file)
@@ -903,7 +903,7 @@ static int mdp5_crtc_cursor_set(struct drm_crtc *crtc,
        if (!cursor_bo)
                return -ENOENT;
 
-       ret = msm_gem_get_iova(cursor_bo, kms->aspace,
+       ret = msm_gem_get_and_pin_iova(cursor_bo, kms->aspace,
                        &mdp5_crtc->cursor.iova);
        if (ret)
                return -EINVAL;
index eba901584035bdda5422d9d8e646d8f8a1b0ef57..99122767abf437ecdacee28ccadc3f9a3cfede8f 100644 (file)
@@ -1248,7 +1248,7 @@ int dsi_dma_base_get_6g(struct msm_dsi_host *msm_host, uint64_t *dma_base)
        if (!dma_base)
                return -EINVAL;
 
-       return msm_gem_get_iova(msm_host->tx_gem_obj,
+       return msm_gem_get_and_pin_iova(msm_host->tx_gem_obj,
                                priv->kms->aspace, dma_base);
 }
 
index cf960dc7898270e4a4bee97753abb6779b48186d..3f8ed21dfffbdd513c57bc3538c9e8977e8bfa98 100644 (file)
@@ -868,6 +868,10 @@ static int msm_ioctl_gem_info_iova(struct drm_device *dev,
        if (!priv->gpu)
                return -EINVAL;
 
+       /*
+        * Don't pin the memory here - just get an address so that userspace can
+        * be productive
+        */
        return msm_gem_get_iova(obj, priv->gpu->aspace, iova);
 }
 
index 63b28b69b2ab177334e3571a0bfea42b0359976f..4372505a0bdab58b44dd6f1e388a4e539110842f 100644 (file)
@@ -271,6 +271,8 @@ vm_fault_t msm_gem_fault(struct vm_fault *vmf);
 uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
 int msm_gem_get_iova(struct drm_gem_object *obj,
                struct msm_gem_address_space *aspace, uint64_t *iova);
+int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
+               struct msm_gem_address_space *aspace, uint64_t *iova);
 uint64_t msm_gem_iova(struct drm_gem_object *obj,
                struct msm_gem_address_space *aspace);
 struct page **msm_gem_get_pages(struct drm_gem_object *obj);
index 475191fcf412102290e594938f052ef7bdb1d053..4e1e435db5a6eae967d47f013595459eb5f6a70a 100644 (file)
@@ -66,7 +66,7 @@ int msm_framebuffer_prepare(struct drm_framebuffer *fb,
        uint64_t iova;
 
        for (i = 0; i < n; i++) {
-               ret = msm_gem_get_iova(fb->obj[i], aspace, &iova);
+               ret = msm_gem_get_and_pin_iova(fb->obj[i], aspace, &iova);
                DBG("FB[%u]: iova[%d]: %08llx (%d)", fb->base.id, i, iova, ret);
                if (ret)
                        return ret;
index f94cbbbf38344cc58b489c0440b623855e7f618f..c03e860ba737f8d56d0759c239b416086c66fb55 100644 (file)
@@ -104,7 +104,7 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,
         * in panic (ie. lock-safe, etc) we could avoid pinning the
         * buffer now:
         */
-       ret = msm_gem_get_iova(bo, priv->kms->aspace, &paddr);
+       ret = msm_gem_get_and_pin_iova(bo, priv->kms->aspace, &paddr);
        if (ret) {
                DRM_DEV_ERROR(dev->dev, "failed to get buffer obj iova: %d\n", ret);
                goto fail_unlock;
index f24c9fe37aaa25c39e72d02a217bb1008a8e0b8e..75a1f50f8f57c8d65f706c6719f11d70b32ef59d 100644 (file)
@@ -408,9 +408,8 @@ static int msm_gem_pin_iova(struct drm_gem_object *obj,
                        obj->size >> PAGE_SHIFT);
 }
 
-
-/* get iova, taking a reference.  Should have a matching put */
-int msm_gem_get_iova(struct drm_gem_object *obj,
+/* get iova and pin it. Should have a matching put */
+int msm_gem_get_and_pin_iova(struct drm_gem_object *obj,
                struct msm_gem_address_space *aspace, uint64_t *iova)
 {
        struct msm_gem_object *msm_obj = to_msm_bo(obj);
@@ -431,8 +430,23 @@ int msm_gem_get_iova(struct drm_gem_object *obj,
        return ret;
 }
 
+/* Get an iova but don't pin the memory behind it */
+int msm_gem_get_iova(struct drm_gem_object *obj,
+               struct msm_gem_address_space *aspace, uint64_t *iova)
+{
+       struct msm_gem_object *msm_obj = to_msm_bo(obj);
+       int ret;
+
+       mutex_lock(&msm_obj->lock);
+       ret = msm_gem_get_iova_locked(obj, aspace, iova);
+       mutex_unlock(&msm_obj->lock);
+
+       return ret;
+}
+
+
 /* get iova without taking a reference, used in places where you have
- * already done a 'msm_gem_get_iova()'.
+ * already done a 'msm_gem_get_and_pin_iova' or 'msm_gem_get_iova'
  */
 uint64_t msm_gem_iova(struct drm_gem_object *obj,
                struct msm_gem_address_space *aspace)
@@ -1072,7 +1086,7 @@ static void *_msm_gem_kernel_new(struct drm_device *dev, uint32_t size,
                return ERR_CAST(obj);
 
        if (iova) {
-               ret = msm_gem_get_iova(obj, aspace, iova);
+               ret = msm_gem_get_and_pin_iova(obj, aspace, iova);
                if (ret)
                        goto err;
        }
index e31be7417f944a0693f07ff27c42cb655bccc713..1322179386f66c36fe3b8c82b9a528382316aa07 100644 (file)
@@ -270,7 +270,7 @@ static int submit_pin_objects(struct msm_gem_submit *submit)
                uint64_t iova;
 
                /* if locking succeeded, pin bo: */
-               ret = msm_gem_get_iova(&msm_obj->base,
+               ret = msm_gem_get_and_pin_iova(&msm_obj->base,
                                submit->gpu->aspace, &iova);
 
                if (ret)
index 3e2b3568d932fac9224a0da74137cf71fcef1457..fcfff333ed96e436b45a9aa720532b28c1112716 100644 (file)
@@ -773,7 +773,7 @@ void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
 
                /* submit takes a reference to the bo and iova until retired: */
                drm_gem_object_get(&msm_obj->base);
-               msm_gem_get_iova(&msm_obj->base,
+               msm_gem_get_and_pin_iova(&msm_obj->base,
                                submit->gpu->aspace, &iova);
 
                if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)