From patchwork Sun Mar 25 10:59:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10306589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB0E7605BD for ; Sun, 25 Mar 2018 11:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CAF22855C for ; Sun, 25 Mar 2018 11:00:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9129129042; Sun, 25 Mar 2018 11:00:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EF6F29042 for ; Sun, 25 Mar 2018 11:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753264AbeCYLAV (ORCPT ); Sun, 25 Mar 2018 07:00:21 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37152 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752577AbeCYLAI (ORCPT ); Sun, 25 Mar 2018 07:00:08 -0400 Received: by mail-wm0-f65.google.com with SMTP id r131so3701193wmb.2; Sun, 25 Mar 2018 04:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vCGY06RJ5Lq2OAe9BUfditdbs1jONExtXlRLaImSE+8=; b=DVDcq5qRhnk4alCeqATWqlCaca3y7KoeR9ikD/3mIUoPZ/VII8c855nBX7lCbJk5Ea h/SLRJOIDqPxuL9FXmvzZT+H0J1S955T2XddWJaEvFMMdVFid+EiQLJWdP0yziJ+K783 CWG5qV9x3xvr6ghNh/MfNtlgKuPcs5xPdos60kBkCApc3Fh6NaOwBZm1/O9nTlFP35ip aTB5GOImQJ8O1e1JdRN2VgRnPEWvzN/biYiQjRA0mPrKYahsrfYHIuBSRAh6eOz7JMKF Gx47j7+KvwPIy+HIVcoT31eBJyfE3MoIpFmO4fGg9mnciczC7W1wYaQwbXief3XennJG +vIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vCGY06RJ5Lq2OAe9BUfditdbs1jONExtXlRLaImSE+8=; b=C6onaw1lbSgdBzIhf8Zj89WYvT4g2pvq9HAq1IwUNuI1/pa5SoDAWQRRUa0DJw1C3U uuiJmHTcTsRY8sODWnJ0kIeyQF4MuYISz4EL8s7ArF8q44WvTdMjjQ63PwBpE8Gff0Gd VsjTmvKXgcDg7VVIsPpmz8nyWtdzeOO3nN5UVX9EpwovYfOsEsjOLmP0hrIdp5dCR3Z2 Hf5Hv93ow0kgPaY/xu5vy6dIPEHyrdgu8yy8g6s78SaZF0assWgGJChb7bdL1EKZEwC5 6L36RcXBlZdg4NTd6pZX8sqDD9RaPOsFz+xS/rotAZJAFdmi1rJ+CirgDMMy5ArOeuFl R/Fw== X-Gm-Message-State: AElRT7FEDVW8t60j1vYPaKc93hAGeumQjK4WLyMURma9daOjo1g2Cxsh V3XEwvXQwi/N7ioWRouxpWcAGg== X-Google-Smtp-Source: AG47ELtlZ0bGtUsB16/1hJ7HvxHB1Lw24XGa3wJQAbyrnEjIjTU4d5rlfbtenuUwnoSVo0YRtyea5g== X-Received: by 10.28.149.71 with SMTP id x68mr13791277wmd.78.1521975607380; Sun, 25 Mar 2018 04:00:07 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:80f2:8bcd:4355:2edc]) by smtp.gmail.com with ESMTPSA id z3sm20492230wme.3.2018.03.25.04.00.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Mar 2018 04:00:06 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] drm/amdgpu: add amdgpu_gem_attach Date: Sun, 25 Mar 2018 12:59:59 +0200 Message-Id: <20180325110000.2238-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180325110000.2238-1-christian.koenig@amd.com> References: <20180325110000.2238-1-christian.koenig@amd.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check if we can do peer2peer on the PCIe bus. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c index 2566268806c3..133596df0775 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c @@ -134,6 +134,29 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev, return obj; } +static int amdgpu_gem_attach(struct dma_buf *dma_buf, struct device *dev, + struct dma_buf_attachment *attach) +{ + 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) + return 0; + + if (!dev_is_pci(dev)) + goto no_peer2peer; + + if (!pci_peer_traffic_supported(adev->pdev, to_pci_dev(dev))) + goto no_peer2peer; + + return 0; + +no_peer2peer: + attach->peer2peer = false; + return 0; +} + static struct sg_table * amdgpu_gem_map_dma_buf(struct dma_buf_attachment *attach, enum dma_data_direction dir) @@ -274,6 +297,7 @@ static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf, } static const struct dma_buf_ops amdgpu_dmabuf_ops = { + .attach = amdgpu_gem_attach, .map_dma_buf = amdgpu_gem_map_dma_buf, .unmap_dma_buf = amdgpu_gem_unmap_dma_buf, .release = drm_gem_dmabuf_release,