Check if we can do peer2peer on the PCIe bus.

Signed-off-by: Christian König <christian.koe...@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index af103b7e21e8..a290ae830b11 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
@@ -39,6 +39,7 @@
 #include <drm/amdgpu_drm.h>
 #include <linux/dma-buf.h>
 #include <linux/dma-fence-array.h>
+#include <linux/pci-p2pdma.h>
 
 /**
  * amdgpu_gem_prime_vmap - &dma_buf_ops.vmap implementation
@@ -254,13 +255,27 @@ static int amdgpu_gem_dma_buf_attach(struct dma_buf 
*dma_buf,
 {
        struct drm_gem_object *obj = dma_buf->priv;
        struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+       struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+
+       if (!attach->peer2peer)
+               goto no_peer2peer;
+
+       if (!dev_is_pci(attach->dev))
+               goto no_peer2peer;
+
+       if (pci_p2pdma_distance_many(adev->pdev, &attach->dev, 1, true) < 0)
+               goto no_peer2peer;
+
+       return 0;
+
+no_peer2peer:
+       attach->peer2peer = false;
 
        /* Make sure the buffer is pinned when userspace didn't set GTT as
         * preferred domain. This avoid ping/pong situations with scan out BOs.
         */
        if (!(bo->preferred_domains & AMDGPU_GEM_DOMAIN_GTT))
                attach->invalidate = NULL;
-
        return 0;
 }
 
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to