Commit b8c415e3 authored by Alex Deucher's avatar Alex Deucher

drm/amdgpu: take runtime pm reference when we attach a buffer

And drop it when we detach.  If the shared buffer is in vram,
we need to make sure we don't put the device into runtime
suspend.
Acked-by: default avatarShashank Sharma <shashank.sharma@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 65e05ca7
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/dma-fence-array.h> #include <linux/dma-fence-array.h>
#include <linux/pci-p2pdma.h> #include <linux/pci-p2pdma.h>
#include <linux/pm_runtime.h>
/** /**
* amdgpu_gem_prime_mmap - &drm_driver.gem_prime_mmap implementation * amdgpu_gem_prime_mmap - &drm_driver.gem_prime_mmap implementation
...@@ -151,9 +152,13 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, ...@@ -151,9 +152,13 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
if (attach->dev->driver == adev->dev->driver) if (attach->dev->driver == adev->dev->driver)
return 0; return 0;
r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
if (r < 0)
goto out;
r = amdgpu_bo_reserve(bo, false); r = amdgpu_bo_reserve(bo, false);
if (unlikely(r != 0)) if (unlikely(r != 0))
return r; goto out;
/* /*
* We only create shared fences for internal use, but importers * We only create shared fences for internal use, but importers
...@@ -165,11 +170,15 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, ...@@ -165,11 +170,15 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
*/ */
r = __dma_resv_make_exclusive(bo->tbo.base.resv); r = __dma_resv_make_exclusive(bo->tbo.base.resv);
if (r) if (r)
return r; goto out;
bo->prime_shared_count++; bo->prime_shared_count++;
amdgpu_bo_unreserve(bo); amdgpu_bo_unreserve(bo);
return 0; 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, ...@@ -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) if (attach->dev->driver != adev->dev->driver && bo->prime_shared_count)
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);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment