From patchwork Tue Oct 29 10:40:49 2019 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: 11218005 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78D1814DB for ; Tue, 29 Oct 2019 14:36:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 605A22087E for ; Tue, 29 Oct 2019 14:36:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 605A22087E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C4C06EB81; Tue, 29 Oct 2019 14:36:31 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id 172736E4DE; Tue, 29 Oct 2019 10:40:58 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id 6so1687497wmf.0; Tue, 29 Oct 2019 03:40:57 -0700 (PDT) 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=EZZU5bRYdYPxvxkSBZwgeMdYqb5VQhKicOFsE9+pkSY=; b=T+yzqjOGi8yemVHzY805YRzLHOEgkYwTu7IgGb0nKz9cSec1/6WAK6TExqkHGfeTGA IRumn5egYivJg/DzD81ropHSFe1ZbZLeJ2TZ6ndI3j8IPvAJxWTHH95lNYuyrGiuG0zu jrDT9CDbYoDKUmWMHZWHfKTD/8f33Xn2mAunZesIQlp1S4/No426CazZ9T0VjnFPacKV YpZw4MMdPsuUFw0VXtk7Ef6GrjQzv1rWga/8TpCIvonPvkhgzyrjlkfxNPJqk7OSZAHx pK7+vDI3LGMYdMVSAkYLCwwqL6yCsZJ2XwsbkBw8Fqu5w3fFbTLE1T52TMx44ArzGN6f 1a/g== X-Gm-Message-State: APjAAAWnsBts0E89XT/mkH8ojdG1G2WoUQO2Q5AXZYHqptA+ots597Df dZ/P5SgY9+xmltRg38P44RLYHcSU X-Google-Smtp-Source: APXvYqxOu+hFqNuLcI9KSzwSAHPMqQVYZfk3AOs6kdG9rEF6QoxKiO5ihOtgGXhcYFTY4wmJpNflTA== X-Received: by 2002:a1c:8055:: with SMTP id b82mr3524726wmd.176.1572345656392; Tue, 29 Oct 2019 03:40:56 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:c5d9:7998:9ca6:452]) by smtp.gmail.com with ESMTPSA id v10sm2910210wmg.48.2019.10.29.03.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 03:40:55 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, sumit.semwal@linaro.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Tue, 29 Oct 2019 11:40:49 +0100 Message-Id: <20191029104049.9011-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029104049.9011-1-christian.koenig@amd.com> References: <20191029104049.9011-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 29 Oct 2019 14:36:30 +0000 X-Mailman-Original-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=EZZU5bRYdYPxvxkSBZwgeMdYqb5VQhKicOFsE9+pkSY=; b=Dj4uC/vktCWtrANQoSxJclNWtNkY5zJn3/9hTtftnAotFWTFgBzPzJZKYLNCEaiCrf W48UYacMEJZ9EZutXNqaIxDmKTVKib8I6Y8JsWOZDwIZ05TIdGInHhVtzds4E6PouqBs 6s1Ci1kJ4y/Tts5wHkQS+VkAKIfaoSEwLKR5Ej0Wu0kurlVCxUeSsOz5k9rbc+zABhZT /ok9pzC/BBsLJdxHNwsnrm+cMfpvQG49uRJbKHuPQqRGa/vfhQx5xWClcjdn8nQJFE/h 0eKGh17x1VEMsRSeNIZ1b+Rr0AUeS7PZovqyCURgRqmE6NUIisJK+Pie9F9ArCMGsytF XGtA== Subject: [Intel-gfx] [PATCH 5/5] drm/amdgpu: implement amdgpu_gem_prime_move_notify X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Implement the importer side of unpinned DMA-buf handling. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 28 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 +++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c index 3629cfe53aad..af39553c51ad 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c @@ -456,7 +456,33 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) return ERR_PTR(ret); } +/** + * amdgpu_dma_buf_move_notify - &attach.move_notify implementation + * + * @attach: the DMA-buf attachment + * + * Invalidate the DMA-buf attachment, making sure that the we re-create the + * mapping before the next use. + */ +static void +amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach) +{ + struct ttm_operation_ctx ctx = { false, false }; + struct drm_gem_object *obj = attach->importer_priv; + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); + struct ttm_placement placement = {}; + int r; + + if (bo->tbo.mem.mem_type == TTM_PL_SYSTEM) + return; + + r = ttm_bo_validate(&bo->tbo, &placement, &ctx); + if (r) + DRM_ERROR("Failed to invalidate DMA-buf import (%d))\n", r); +} + static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops = { + .move_notify = amdgpu_dma_buf_move_notify }; /** @@ -492,7 +518,7 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev, return obj; attach = dma_buf_dynamic_attach(dma_buf, dev->dev, - &amdgpu_dma_buf_attach_ops, NULL); + &amdgpu_dma_buf_attach_ops, obj); if (IS_ERR(attach)) { drm_gem_object_put(obj); return ERR_CAST(attach); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index ac776d2620eb..cfa46341c9a7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -861,6 +861,9 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, return 0; } + if (bo->tbo.base.import_attach) + dma_buf_pin(bo->tbo.base.import_attach); + bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; /* force to pin into visible video ram */ if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) @@ -944,6 +947,9 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo) amdgpu_bo_subtract_pin_size(bo); + if (bo->tbo.base.import_attach) + dma_buf_unpin(bo->tbo.base.import_attach); + for (i = 0; i < bo->placement.num_placement; i++) { bo->placements[i].lpfn = 0; bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;