From patchwork Thu Jan 24 18:02:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10779791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BE0C139A for ; Thu, 24 Jan 2019 18:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10E1E32765 for ; Thu, 24 Jan 2019 18:03:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EEF332798; Thu, 24 Jan 2019 18:03:13 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B50613277D for ; Thu, 24 Jan 2019 18:03:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 799C56F1FE; Thu, 24 Jan 2019 18:03:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7048C6F1FC for ; Thu, 24 Jan 2019 18:03:04 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id m22so4077438wml.3 for ; Thu, 24 Jan 2019 10:03:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m+WKmHd+Dq1Qlfz+9CGjxOGNtrFVvxi844a0kiegVwY=; b=jWkfQw9zGkW2OvhoAHS/ZkSdTC02wzmMnjDb27BdJLV7SIVrIAKbBWlZ6Nk7ehaSpN 6RfsDSPsOSWrGuMc1DZ14K3z59iRBmEIfMPUkRM9i9oUyvsxe82ZzPXg1Btz7vxSZNXS MYv1498MtjVlvo5TevjoTXW7+Krw4WBZ3s4wOUxTvQNw6vLjc3CupP97iLUwPHvWnzrN jl9ppCXvzeQ5ovQC5wUreDg3lLPvSLNPB6+DAvf4SZQUMpRHTnOXcBCxgO+Jbs45Lslm HJ1+IoO9aqqeckIkrC5fUumb/bq6w3dZsZZhtvZkhun5Vnbq3oLJb3FXcxZNI9G1Ujd2 XNoQ== X-Gm-Message-State: AJcUukeqBQ4J5ahUb9IqOc20ITbN6unQraNBt8lN/B6KkNuq/fgNWSIa KSRVaPxPKpgzLw3N8Zzbf44= X-Google-Smtp-Source: ALg8bN7GA/l/sJtJnLfwe4TK5JfRENQPw4e8IZIb5n09m1AoyCz8BooRZZxr4SeYdgDB5/qtgs+Juw== X-Received: by 2002:a1c:dc02:: with SMTP id t2mr3608183wmg.78.1548352982843; Thu, 24 Jan 2019 10:03:02 -0800 (PST) Received: from localhost (pD9E51040.dip0.t-ipconnect.de. [217.229.16.64]) by smtp.gmail.com with ESMTPSA id k128sm81400958wmd.37.2019.01.24.10.03.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 10:03:02 -0800 (PST) From: Thierry Reding To: Thierry Reding Subject: [PATCH v2 04/13] gpu: host1x: Use direct DMA with IOMMU API usage Date: Thu, 24 Jan 2019 19:02:45 +0100 Message-Id: <20190124180254.20080-5-thierry.reding@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190124180254.20080-1-thierry.reding@gmail.com> References: <20190124180254.20080-1-thierry.reding@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-tegra@vger.kernel.org, Dmitry Osipenko , dri-devel@lists.freedesktop.org, Mikko Perttunen Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding If we use the IOMMU API directly to map buffers into host1x' IOVA space, we must make sure that the DMA API doesn't already set up a mapping, or else translation will fail. The direct DMA API allows us to allocate memory that will not be mapped through an IOMMU automatically. Signed-off-by: Thierry Reding Reviewed-by: Dmitry Osipenko --- drivers/gpu/host1x/cdma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/host1x/cdma.c b/drivers/gpu/host1x/cdma.c index 91df51e631b2..ccde23a0109c 100644 --- a/drivers/gpu/host1x/cdma.c +++ b/drivers/gpu/host1x/cdma.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ static void host1x_pushbuffer_destroy(struct push_buffer *pb) */ static int host1x_pushbuffer_init(struct push_buffer *pb) { + unsigned long attrs = DMA_ATTR_WRITE_COMBINE; struct host1x_cdma *cdma = pb_to_cdma(pb); struct host1x *host1x = cdma_to_host1x(cdma); struct iova *alloc; @@ -91,8 +93,8 @@ static int host1x_pushbuffer_init(struct push_buffer *pb) size = iova_align(&host1x->iova, size); - pb->mapped = dma_alloc_wc(host1x->dev, size, &pb->phys, - GFP_KERNEL); + pb->mapped = dma_direct_alloc(host1x->dev, size, &pb->phys, + GFP_KERNEL, attrs); if (!pb->mapped) return -ENOMEM; @@ -127,7 +129,10 @@ static int host1x_pushbuffer_init(struct push_buffer *pb) iommu_free_iova: __free_iova(&host1x->iova, alloc); iommu_free_mem: - dma_free_wc(host1x->dev, size, pb->mapped, pb->phys); + if (host1x->domain) + dma_direct_free(host1x->dev, size, pb->mapped, pb->phys, attrs); + else + dma_free_wc(host1x->dev, size, pb->mapped, pb->phys); return err; }