From patchwork Fri Feb 1 13:28:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1034761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZUWFjEyY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43rdGq6zLpz9sDr for ; Sat, 2 Feb 2019 00:28:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbfBAN2t (ORCPT ); Fri, 1 Feb 2019 08:28:49 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39099 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726190AbfBAN2t (ORCPT ); Fri, 1 Feb 2019 08:28:49 -0500 Received: by mail-wr1-f65.google.com with SMTP id t27so7090345wra.6 for ; Fri, 01 Feb 2019 05:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M+gIEmjmEfyRDTbiyXayJggt4p3R2KwhPClEdJJcpg0=; b=ZUWFjEyYh5SWPddKops/GRn4H/kaztJlDRgireCpkZJdvyj+/2fk/g1cKd1TiBM1KF F9yRIjiJ/ekQG1pGg0X7z8oNLenSaSc/kXER2pVAPsnkHw7lsntf7uDo6KkleZ3VgJzd bIcDSdKfKALCiAptZ3oO6IcmNtehzko1tPBHghZA6CGqQ/2/pzd9fwPP06zPNtItlKpe IspqNKBsgWKXiaQxuRf8MnMdWbuicHjC+ho/GA+eaax+f/s4OlsKGbUKKbTaxTYytt22 4COQSemdPPL99SiIruCEZ/Swdo1zXGsH+JT24Qx5f6VL1AZXnv5Ws9XkWAHjqblI9Hp/ nX8Q== 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+gIEmjmEfyRDTbiyXayJggt4p3R2KwhPClEdJJcpg0=; b=WIfpcMNqrC6QXd0/F1mbg5Ndg6077Bd4ZN7ii1fmCjQxaHu/h9Xzauds7xyC9nwBuO R+y85bhmxLKJgHmoNMnaom4ZgtcP8caWCOmJAJPirg/lC9yULkkCu4Lbn/Fbp+Sf9uRs EF23f35fRU5MK62JeugYss7AbX3dckKvEXxNDhT4AIF0blscrICyZLkkRogOGm7yY33x RJItPrc6QGMDbJ3us47pzXSU51Lmp0srEB8Z54d9BUkF9ZGSGHs3rkthbq9ASFMINtBR ORoEfascgdpXKAc2H4BT+j4M+8Qrrjs6DtPVNOERQscDm0pOk92jQKvlOav4/oo1JTQ6 8ADA== X-Gm-Message-State: AHQUAuapqbojBaG3REP0RwZoWrZMAQwMEzwri5urH72AMuyc7gTwf6xY bMVcKC1WvIU09apg1IWTAbE/Psof9XY= X-Google-Smtp-Source: AHgI3IZ1kdoXbef8UKih1NlEts6BfxBEx7p1rQPsXieAXJkwE38yIuzbyd1lj0sEMFykJIZdiO7ACA== X-Received: by 2002:adf:be0f:: with SMTP id n15mr26247143wrh.267.1549027727464; Fri, 01 Feb 2019 05:28:47 -0800 (PST) Received: from localhost (pD9E51040.dip0.t-ipconnect.de. [217.229.16.64]) by smtp.gmail.com with ESMTPSA id w18sm8240966wru.54.2019.02.01.05.28.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Feb 2019 05:28:46 -0800 (PST) From: Thierry Reding To: Thierry Reding Cc: Mikko Perttunen , Dmitry Osipenko , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 05/16] gpu: host1x: Use direct DMA with IOMMU API usage Date: Fri, 1 Feb 2019 14:28:26 +0100 Message-Id: <20190201132837.12327-6-thierry.reding@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190201132837.12327-1-thierry.reding@gmail.com> References: <20190201132837.12327-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org 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. Reviewed-by: Dmitry Osipenko Signed-off-by: Thierry Reding Reviewed-by: Dmitry Osipenko Tested-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 e2d106fa3c0b..a96c4dd1e449 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; }