From patchwork Thu Jul 9 17:42:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 6757701 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F25709F319 for ; Thu, 9 Jul 2015 17:44:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 235FA20607 for ; Thu, 9 Jul 2015 17:44:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 317A320606 for ; Thu, 9 Jul 2015 17:44:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC6636ECFC; Thu, 9 Jul 2015 10:44:26 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ig0-f170.google.com (mail-ig0-f170.google.com [209.85.213.170]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E58A6ECFC for ; Thu, 9 Jul 2015 10:44:25 -0700 (PDT) Received: by igoe12 with SMTP id e12so19116789igo.1 for ; Thu, 09 Jul 2015 10:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RjUkX2WiqHF8/49foMCBBLBF7Ko46+1D8zFN9dA+MIk=; b=PUsK7uXDhEjzJBNTOFnk/aW6fYWCv3Ok9+KQgloE9HhAKlDUb92X2cyD78RfjCywyM 1vYix+2qbm/LkP5xGTttAAHaO88a25DTOjpcR9oRBR/xMAzVMOtYVcyydBZhfw3xfDui QxHopv0m7ppZXGFFoVTsYCep2lKj0X78W0UZk3n4OyyNa0CtoH36QxjBEQwBRa66H21j U1Z47DKia0RArId/dXwXTwEVk9i11B2o7uPswg1/fsgtuEKea3d15IkbLrfKtCBJr7w4 GpMhlIbaKld8gg1AUtEHH8bRAVdQWo7ARMb/r8BSHZ7QM3UbwubmJhhYk+URt4VRsEUt DAXg== X-Received: by 10.50.49.34 with SMTP id r2mr1453641ign.66.1436463864585; Thu, 09 Jul 2015 10:44:24 -0700 (PDT) Received: from mothership.world.mentorg.com (c-50-152-159-227.hsd1.ca.comcast.net. [50.152.159.227]) by smtp.googlemail.com with ESMTPSA id l62sm4620485iol.36.2015.07.09.10.44.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jul 2015 10:44:24 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH] drm: use dma_map_sg_attrs for GEM CMA objects Date: Thu, 9 Jul 2015 10:42:49 -0700 Message-Id: <1436463769-26777-1-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <559D9B45.1020306@mentor.com> References: <559D9B45.1020306@mentor.com> Cc: Steve Longerbeam X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The GEM CMA helper allocates GEM objects with dma_alloc_writecombine(), so the objects are cache coherent, and the exporter methods for these objects can skip cache sync. To accomplish this a dma atrribute is added to drm_gem_object, and is used with dma_map_sg_attrs/dma_unmap_sg_attrs in drm_gem_map_dma_buf/drm_gem_map_detach. GEM CMA sets the attribute to DMA_ATTR_SKIP_CPU_SYNC when the object is allocated in drm_gem_cma_create(). Signed-off-by: Steve Longerbeam --- drivers/gpu/drm/drm_gem.c | 1 + drivers/gpu/drm/drm_gem_cma_helper.c | 2 ++ drivers/gpu/drm/drm_prime.c | 7 ++++--- include/drm/drm_gem.h | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 16a1647..f7f4531 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -169,6 +169,7 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->handle_count = 0; obj->size = size; drm_vma_node_reset(&obj->vma_node); + init_dma_attrs(&obj->dma_attrs); } EXPORT_SYMBOL(drm_gem_private_object_init); diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index bd75f30..73c949a 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -75,6 +75,8 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size) goto error; } + dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &gem_obj->dma_attrs); + return cma_obj; error: diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 9f935f5..9eaa8d3 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -153,8 +153,8 @@ static void drm_gem_map_detach(struct dma_buf *dma_buf, sgt = prime_attach->sgt; if (sgt) { if (prime_attach->dir != DMA_NONE) - dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents, - prime_attach->dir); + dma_unmap_sg_attrs(attach->dev, sgt->sgl, sgt->nents, + prime_attach->dir, &obj->dma_attrs); sg_free_table(sgt); } @@ -201,7 +201,8 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, sgt = obj->dev->driver->gem_prime_get_sg_table(obj); if (!IS_ERR(sgt)) { - if (!dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir)) { + if (!dma_map_sg_attrs(attach->dev, sgt->sgl, sgt->nents, + dir, &obj->dma_attrs)) { sg_free_table(sgt); kfree(sgt); sgt = ERR_PTR(-ENOMEM); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 7a592d7..f5546bf 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -104,6 +104,11 @@ struct drm_gem_object { struct dma_buf *dma_buf; /** + * dma_attrs - DMA attributes for this GEM object + */ + struct dma_attrs dma_attrs; + + /** * import_attach - dma buf attachment backing this object * * Any foreign dma_buf imported as a gem object has this set to the