]> Git Repo - linux.git/blobdiff - drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
Merge tag 'for-5.12-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_dma_buf.c
index e42175e1acf18b758c7ab64077c6f2496f0e4550..47e0b48dc26fd72f0a5e4869a3b0ba677e6db2da 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/dma-buf.h>
 #include <linux/dma-fence-array.h>
 #include <linux/pci-p2pdma.h>
+#include <linux/pm_runtime.h>
 
 /**
  * amdgpu_gem_prime_mmap - &drm_driver.gem_prime_mmap implementation
@@ -151,9 +152,13 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
        if (attach->dev->driver == adev->dev->driver)
                return 0;
 
+       r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+       if (r < 0)
+               goto out;
+
        r = amdgpu_bo_reserve(bo, false);
        if (unlikely(r != 0))
-               return r;
+               goto out;
 
        /*
         * We only create shared fences for internal use, but importers
@@ -165,11 +170,15 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
         */
        r = __dma_resv_make_exclusive(bo->tbo.base.resv);
        if (r)
-               return r;
+               goto out;
 
        bo->prime_shared_count++;
        amdgpu_bo_unreserve(bo);
        return 0;
+
+out:
+       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+       return r;
 }
 
 /**
@@ -189,6 +198,9 @@ static void amdgpu_dma_buf_detach(struct dma_buf *dmabuf,
 
        if (attach->dev->driver != adev->dev->driver && bo->prime_shared_count)
                bo->prime_shared_count--;
+
+       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 }
 
 /**
@@ -269,7 +281,7 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,
        case TTM_PL_TT:
                sgt = drm_prime_pages_to_sg(obj->dev,
                                            bo->tbo.ttm->pages,
-                                           bo->tbo.num_pages);
+                                           bo->tbo.ttm->num_pages);
                if (IS_ERR(sgt))
                        return sgt;
 
This page took 0.035549 seconds and 4 git commands to generate.