From patchwork Mon Oct 28 12:37:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="MuwMV2cB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPL1DbHz9sPL for ; Mon, 28 Oct 2019 23:37:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389043AbfJ1MhZ (ORCPT ); Mon, 28 Oct 2019 08:37:25 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34812 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbfJ1MhZ (ORCPT ); Mon, 28 Oct 2019 08:37:25 -0400 Received: by mail-wm1-f66.google.com with SMTP id v3so9442407wmh.1 for ; Mon, 28 Oct 2019 05:37:24 -0700 (PDT) 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=Bg9aLkLfUTKxfTeyqBBqYQUC6FBcU6JFCGZpsj7ndqo=; b=MuwMV2cBGxuqCseG0mrSuo2oEvO+qF05OvTD8L+6lNTugvzPzoiKT+VY9diDTdYKG8 acfPCvEoUa9+cFd0RDm2Lw4lyQCNTAmY/zlOUrU+IbaMfpKN19jayd4th1nY6KvNTAD4 ADRVRtQ21cB6xqaHotOeynOJUsLGOMEQis5E6HOvf69sIbLOPmXgz4V68rl6PZRNTLIy XnfDvtD+YT8iT+c2ABJjzJcgiGpBCUtTwx9Su9y/famXUIvv4sksw7ze1towVxWUHaBF vUukp4WxovOCCi8WVyEM2LLZqADbaFzfaKmYfScJYqba4qlkw5LKfRsz3VKn52kbB7JQ tQcg== 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=Bg9aLkLfUTKxfTeyqBBqYQUC6FBcU6JFCGZpsj7ndqo=; b=D4BgYDP+bEF6/cxO93lWcDrV+MCJ6QIyBtQDM++wOzMYtfi5/jcNOqIUGEJqqIQBWv 8CCCDiKtRTGmankaXt3IBtnDfqYNJtWzAe1kKzXvegmD8j6mrb0QBvSfnAVt+aaxyeX/ edfKbdC/A0WuckuJ/+1pc1i53sPeol/iVnTsUUj1G9Fi7oElfXrW8Sv2ceUT2PF6MBBo kRsEKrWxg0uw8PxLiHH1dqNRCW+50GlGVLRyE7lhzFxgWtQUb6Ryfm6oGcjZPcB8/vUo 5EGyrwvWB6Ak2JKfvMHHKq3F53vbQQeFEH6olV2hYi/Ip85+bvPYqFeD1AG5l//QhGwP SkSg== X-Gm-Message-State: APjAAAWK818cRkR0pA9YTrQr/3sdhJ+9kB7S68LMu8PfyoCW2CGXlmn4 4Eu3YJNkTWKTaQjtyNi4n8Y= X-Google-Smtp-Source: APXvYqxpcT29LVgI0DeFwPxEVNHmlij5DXWLor/hWFeN/TxAmFIMyCHnv/wteFbMeZzEJoUhBzKEYQ== X-Received: by 2002:a7b:c04c:: with SMTP id u12mr14331126wmc.134.1572266243371; Mon, 28 Oct 2019 05:37:23 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id s5sm6636457wmj.37.2019.10.28.05.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:22 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 01/12] memory: tegra: Add gr2d and gr3d to DRM IOMMU group Date: Mon, 28 Oct 2019 13:37:07 +0100 Message-Id: <20191028123718.3890217-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 All of the devices making up the Tegra DRM device want to share a single IOMMU domain. Put them into a single group to allow them to do that. Signed-off-by: Thierry Reding --- drivers/memory/tegra/tegra114.c | 10 ++++++---- drivers/memory/tegra/tegra124.c | 8 +++++--- drivers/memory/tegra/tegra30.c | 11 +++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/memory/tegra/tegra114.c b/drivers/memory/tegra/tegra114.c index ac8351b5beeb..48ef01c3ff90 100644 --- a/drivers/memory/tegra/tegra114.c +++ b/drivers/memory/tegra/tegra114.c @@ -909,16 +909,18 @@ static const struct tegra_smmu_swgroup tegra114_swgroups[] = { { .name = "tsec", .swgroup = TEGRA_SWGROUP_TSEC, .reg = 0x294 }, }; -static const unsigned int tegra114_group_display[] = { +static const unsigned int tegra114_group_drm[] = { TEGRA_SWGROUP_DC, TEGRA_SWGROUP_DCB, + TEGRA_SWGROUP_G2, + TEGRA_SWGROUP_NV, }; static const struct tegra_smmu_group_soc tegra114_groups[] = { { - .name = "display", - .swgroups = tegra114_group_display, - .num_swgroups = ARRAY_SIZE(tegra114_group_display), + .name = "drm", + .swgroups = tegra114_group_drm, + .num_swgroups = ARRAY_SIZE(tegra114_group_drm), }, }; diff --git a/drivers/memory/tegra/tegra124.c b/drivers/memory/tegra/tegra124.c index 5d0ccb2be206..62b30b1b9677 100644 --- a/drivers/memory/tegra/tegra124.c +++ b/drivers/memory/tegra/tegra124.c @@ -974,16 +974,18 @@ static const struct tegra_smmu_swgroup tegra124_swgroups[] = { { .name = "vi", .swgroup = TEGRA_SWGROUP_VI, .reg = 0x280 }, }; -static const unsigned int tegra124_group_display[] = { +static const unsigned int tegra124_group_drm[] = { TEGRA_SWGROUP_DC, TEGRA_SWGROUP_DCB, + TEGRA_SWGROUP_GPU, + TEGRA_SWGROUP_VIC, }; static const struct tegra_smmu_group_soc tegra124_groups[] = { { .name = "display", - .swgroups = tegra124_group_display, - .num_swgroups = ARRAY_SIZE(tegra124_group_display), + .swgroups = tegra124_group_drm, + .num_swgroups = ARRAY_SIZE(tegra124_group_drm), }, }; diff --git a/drivers/memory/tegra/tegra30.c b/drivers/memory/tegra/tegra30.c index 14788fc2f9e8..8947bee6d032 100644 --- a/drivers/memory/tegra/tegra30.c +++ b/drivers/memory/tegra/tegra30.c @@ -931,16 +931,19 @@ static const struct tegra_smmu_swgroup tegra30_swgroups[] = { { .name = "isp", .swgroup = TEGRA_SWGROUP_ISP, .reg = 0x258 }, }; -static const unsigned int tegra30_group_display[] = { +static const unsigned int tegra30_group_drm[] = { TEGRA_SWGROUP_DC, TEGRA_SWGROUP_DCB, + TEGRA_SWGROUP_G2, + TEGRA_SWGROUP_NV, + TEGRA_SWGROUP_NV2, }; static const struct tegra_smmu_group_soc tegra30_groups[] = { { - .name = "display", - .swgroups = tegra30_group_display, - .num_swgroups = ARRAY_SIZE(tegra30_group_display), + .name = "drm", + .swgroups = tegra30_group_drm, + .num_swgroups = ARRAY_SIZE(tegra30_group_drm), }, }; From patchwork Mon Oct 28 12:37:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="fXmfyYMC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPN6zYGz9sPK for ; Mon, 28 Oct 2019 23:37:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389097AbfJ1Mh2 (ORCPT ); Mon, 28 Oct 2019 08:37:28 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53161 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbfJ1Mh2 (ORCPT ); Mon, 28 Oct 2019 08:37:28 -0400 Received: by mail-wm1-f67.google.com with SMTP id p21so9276545wmg.2 for ; Mon, 28 Oct 2019 05:37:26 -0700 (PDT) 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=oCHEmXXyh53/Om/kiUXuXh86NdIS0vexI4+H1W2Xp5I=; b=fXmfyYMCWAFqXTbkafRDiO7nIaVYgGmns3mbWRILUheNV0Ygs3QVAA4MSUj74xn+X0 RIvTBtkHzjjjEdi8S57hQhOxpDZuoYjha2snqT9r0dhqhsO78u/m3XUY6HLl7ipaEp0Z bsOaqxXSWDEIWnmNf1w5AMbwQS0XU178eDr953Atziv7kmSzuciAtfJeLqJf3psdruj1 oFn2smkc/dvAKF4GmPA+Lsemmvu5KS7v8uVJ7cPtJMBmTldNKS3rqhrxsT/eJJAiZLt5 hMAzmcLU50D4hY+fNq4QDzTN1Ghtd3OTGtzRewwx+1I3aWS7FzN7tT5P/XOf8WYlY7T+ qnTQ== 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=oCHEmXXyh53/Om/kiUXuXh86NdIS0vexI4+H1W2Xp5I=; b=e/Ew4Myo8nDeWNoi/LNJUbbaxoKVZ1Qd0oeSOJQ8f5ESja78VWV2dX/SQjjPJ1h/GV tYk/1xXCYKDlAlKlerppVrwKchcNDJSX7mWsnNIj8sRk7B1qN9JImARA/nYgBIsXqApg diKsdAelqiDHmsb6XNZTNCyduo8nDKBDlteCdUhdEf4ltWOgrU5zLE5lYaWgAc9arB2j dqNu/B7RdHIrMnSH9CDlsNd9noUi9UKICxgX0qs+OWMO7dI9f3xwmAh2RNcGh5QMJpOn v3Mt7lzm+0Az72Hwgxpw4OQ9RekYLUoWa9RiBnUhL8imu1kBlFLmapeNwSzubR6PmopR 2zrQ== X-Gm-Message-State: APjAAAWwYF2m2jtaLmnnEkAzmVQ60GN6sXM+UiHWTjqNzp8AUGDmRH+L wK5DMovIS6R6fHIDoRlO+vs= X-Google-Smtp-Source: APXvYqxKTVo0gNkcafsJPzYUnp7dMEHUOHzkaXiXS7chO1ZrcborvqZ8eiKYPfEaKln4zBhENH/72w== X-Received: by 2002:a1c:dd06:: with SMTP id u6mr16225544wmg.109.1572266245547; Mon, 28 Oct 2019 05:37:25 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id b1sm11557745wru.83.2019.10.28.05.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:24 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 02/12] drm/tegra: Simplify IOMMU group selection Date: Mon, 28 Oct 2019 13:37:08 +0100 Message-Id: <20191028123718.3890217-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 All the devices that make up the DRM device are now part of the same IOMMU group. This simplifies the handling of the IOMMU attachment and also avoids exhausting the number of IOMMUs available on early Tegra SoC generations. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/dc.c | 2 +- drivers/gpu/drm/tegra/drm.c | 34 ++++++++++++++++++++-------------- drivers/gpu/drm/tegra/drm.h | 3 +-- drivers/gpu/drm/tegra/gr2d.c | 2 +- drivers/gpu/drm/tegra/gr3d.c | 2 +- drivers/gpu/drm/tegra/vic.c | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 54966f538141..36c36b295ab1 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -2014,7 +2014,7 @@ static int tegra_dc_init(struct host1x_client *client) if (!dc->syncpt) dev_warn(dc->dev, "failed to allocate syncpoint\n"); - err = host1x_client_iommu_attach(client, true); + err = host1x_client_iommu_attach(client); if (err < 0) { dev_err(client->dev, "failed to attach to domain: %d\n", err); return err; diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 7480f575188d..9a1c1694604a 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -904,7 +904,7 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra, return 0; } -int host1x_client_iommu_attach(struct host1x_client *client, bool shared) +int host1x_client_iommu_attach(struct host1x_client *client) { struct drm_device *drm = dev_get_drvdata(client->parent); struct tegra_drm *tegra = drm->dev_private; @@ -912,29 +912,30 @@ int host1x_client_iommu_attach(struct host1x_client *client, bool shared) int err; if (tegra->domain) { + struct iommu_domain *domain; + group = iommu_group_get(client->dev); if (!group) { dev_err(client->dev, "failed to get IOMMU group\n"); return -ENODEV; } - if (!shared || (shared && (group != tegra->group))) { #if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) - if (client->dev->archdata.mapping) { - struct dma_iommu_mapping *mapping = - to_dma_iommu_mapping(client->dev); - arm_iommu_detach_device(client->dev); - arm_iommu_release_mapping(mapping); - } + if (client->dev->archdata.mapping) { + struct dma_iommu_mapping *mapping = + to_dma_iommu_mapping(client->dev); + arm_iommu_detach_device(client->dev); + arm_iommu_release_mapping(mapping); + } #endif + + domain = iommu_get_domain_for_dev(client->dev); + if (domain != tegra->domain) { err = iommu_attach_group(tegra->domain, group); if (err < 0) { iommu_group_put(group); return err; } - - if (shared && !tegra->group) - tegra->group = group; } } @@ -947,12 +948,17 @@ void host1x_client_iommu_detach(struct host1x_client *client) { struct drm_device *drm = dev_get_drvdata(client->parent); struct tegra_drm *tegra = drm->dev_private; + struct iommu_domain *domain; if (client->group) { - if (client->group == tegra->group) { + /* + * Devices that are part of the same group may no longer be + * attached to a domain at this point because their group may + * have been detached by an earlier client. + */ + domain = iommu_get_domain_for_dev(client->dev); + if (domain) iommu_detach_group(tegra->domain, client->group); - tegra->group = NULL; - } iommu_group_put(client->group); } diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index 8b812bb52e5b..28f2820a7371 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -36,7 +36,6 @@ struct tegra_drm { struct drm_device *drm; struct iommu_domain *domain; - struct iommu_group *group; struct mutex mm_lock; struct drm_mm mm; @@ -100,7 +99,7 @@ int tegra_drm_register_client(struct tegra_drm *tegra, struct tegra_drm_client *client); int tegra_drm_unregister_client(struct tegra_drm *tegra, struct tegra_drm_client *client); -int host1x_client_iommu_attach(struct host1x_client *client, bool shared); +int host1x_client_iommu_attach(struct host1x_client *client); void host1x_client_iommu_detach(struct host1x_client *client); int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c index 5d5af9a05c18..1fc4e56c7cc5 100644 --- a/drivers/gpu/drm/tegra/gr2d.c +++ b/drivers/gpu/drm/tegra/gr2d.c @@ -50,7 +50,7 @@ static int gr2d_init(struct host1x_client *client) goto put; } - err = host1x_client_iommu_attach(client, false); + err = host1x_client_iommu_attach(client); if (err < 0) { dev_err(client->dev, "failed to attach to domain: %d\n", err); goto free; diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c index c249a6bd8d51..24fae0f64032 100644 --- a/drivers/gpu/drm/tegra/gr3d.c +++ b/drivers/gpu/drm/tegra/gr3d.c @@ -59,7 +59,7 @@ static int gr3d_init(struct host1x_client *client) goto put; } - err = host1x_client_iommu_attach(client, false); + err = host1x_client_iommu_attach(client); if (err < 0) { dev_err(client->dev, "failed to attach to domain: %d\n", err); goto free; diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index d34b1ada422c..603f41ed4b81 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -187,7 +187,7 @@ static int vic_init(struct host1x_client *client) struct vic *vic = to_vic(drm); int err; - err = host1x_client_iommu_attach(client, false); + err = host1x_client_iommu_attach(client); if (err < 0) { dev_err(vic->dev, "failed to attach to domain: %d\n", err); return err; From patchwork Mon Oct 28 12:37:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="vemlLMCW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPR3Bcwz9sPK for ; Mon, 28 Oct 2019 23:37:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbfJ1Mhb (ORCPT ); Mon, 28 Oct 2019 08:37:31 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53996 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389093AbfJ1Mha (ORCPT ); Mon, 28 Oct 2019 08:37:30 -0400 Received: by mail-wm1-f67.google.com with SMTP id n7so9274736wmc.3 for ; Mon, 28 Oct 2019 05:37:28 -0700 (PDT) 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=EPOnpXDyGYq/dSQZFWsPMEbqvrED0YWkaamNYDQK338=; b=vemlLMCW9674nFf3lYNNPdQO1uwyR23j2sCfYArUdKD5HaKwxyFjF6wrJdL3Ig+qR6 Y0J1uYz7BV6JbGTJn37YDT4/Tdh6acZUjW8cyAm/DKSidIzsWo1Bxucal2HDxqMo/3dy 7tqK0QX9LqSsANG0fKBU4F4F+mUHs/KdJ7WpZjDmo9rBqwzJzOmMj6f7irIUuzHAJ4rm kn3jJrZiWae5HaVPvrC+jAQK9jSE1oCKapVsLE2v3koDSSdiB0Om+Ppb1r54eK4qSUpy ToBhK+sUZb1MMoTd+h2132JzB50ayKGlXXYJYPPHh451nB1Mqw6S5BwWdwQhbdfWjC3S XmUw== 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=EPOnpXDyGYq/dSQZFWsPMEbqvrED0YWkaamNYDQK338=; b=feUXyFPK7hhbRAQ2mgABiNSyefhB60JNrWsmi7f2eZY2pQ/DmCQn40TJ25CiQjKwil LTDADmSJnqBGqQv2q5lcSmPN1ko910/J7fgY+CAoU3dZp3BiZrVOTjB6GdDHHf8cGPYm 2fxNwQcY8QLiWY3u8dIFoBdZrxGzjjOMqvOzli9+aw2MxqpcKUjD1ZIpJhcjJbzmZO1t mGxG2hAAYbw50GAWDSntHPaqpxz3CxuCBJZi3xBsHshyoyh8MGbCUtdx+HKdP403vLSh W4+7OUfHskqohjweQsS7QYqiPCVtEQhbLN/DnKHiNSCa26bXI0LrEKpzjAUusK4Fpl6h M6nA== X-Gm-Message-State: APjAAAXvMtjMN6BHNG0GRQWLv6jJD/pPZVzWuoyyBExDYjcAO8CY9M6w Xv7OMlSVG9ZJMis4hlGRYAc= X-Google-Smtp-Source: APXvYqztZlmUZhZoNCFZ0ah+tFbQBoRqbeo9L72jsb/i6ZYlDKsf5WwXIvYW6JjcJAW40w8VCs5A9g== X-Received: by 2002:a1c:64d4:: with SMTP id y203mr15587137wmb.27.1572266247858; Mon, 28 Oct 2019 05:37:27 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id d202sm11919141wmd.47.2019.10.28.05.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:26 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 03/12] gpu: host1x: Overhaul host1x_bo_{pin,unpin}() API Date: Mon, 28 Oct 2019 13:37:09 +0100 Message-Id: <20191028123718.3890217-4-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 The host1x_bo_pin() and host1x_bo_unpin() APIs are used to pin and unpin buffers during host1x job submission. Pinning currently returns the SG table and the DMA address (an IOVA if an IOMMU is used or a physical address if no IOMMU is used) of the buffer. The DMA address is only used for buffers that are relocated, whereas the host1x driver will map gather buffers into its own IOVA space so that they can be processed by the CDMA engine. This approach has a couple of issues. On one hand it's not very useful to return a DMA address for the buffer if host1x doesn't need it. On the other hand, returning the SG table of the buffer is suboptimal because a single SG table cannot be shared for multiple mappings, because the DMA address is stored within the SG table, and the DMA address may be different for different devices. Subsequent patches will move the host1x driver over to the DMA API which doesn't work with a single shared SG table. Fix this by returning a new SG table each time a buffer is pinned. This allows the buffer to be referenced by multiple jobs for different engines. Change the prototypes of host1x_bo_pin() and host1x_bo_unpin() to take a struct device *, specifying the device for which the buffer should be pinned. This is required in order to be able to properly construct the SG table. While at it, make host1x_bo_pin() return the SG table because that allows us to return an ERR_PTR()-encoded error code if we need to, or return NULL to signal that we don't need the SG table to be remapped and can simply use the DMA address as-is. At the same time, returning the DMA address is made optional because in the example of command buffers, host1x doesn't need to know the DMA address since it will have to create its own mapping anyway. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/gem.c | 34 ++++++++++++++++++++++++++++++---- drivers/gpu/host1x/job.c | 15 ++++++++++++--- include/linux/host1x.h | 17 ++++++++++------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index d2f88cc3134f..564ef60f67c2 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -27,17 +27,43 @@ static void tegra_bo_put(struct host1x_bo *bo) drm_gem_object_put_unlocked(&obj->gem); } -static dma_addr_t tegra_bo_pin(struct host1x_bo *bo, struct sg_table **sgt) +static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, + dma_addr_t *phys) { struct tegra_bo *obj = host1x_to_tegra_bo(bo); + struct sg_table *sgt; + int err; + + if (phys) + *phys = obj->iova; - *sgt = obj->sgt; + sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) + return ERR_PTR(-ENOMEM); - return obj->iova; + if (obj->pages) { + err = sg_alloc_table_from_pages(sgt, obj->pages, obj->num_pages, + 0, obj->gem.size, GFP_KERNEL); + if (err < 0) + goto free; + } else { + err = dma_get_sgtable(dev, sgt, obj->vaddr, obj->iova, + obj->gem.size); + if (err < 0) + goto free; + } + + return sgt; + +free: + kfree(sgt); + return ERR_PTR(err); } -static void tegra_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) +static void tegra_bo_unpin(struct device *dev, struct sg_table *sgt) { + sg_free_table(sgt); + kfree(sgt); } static void *tegra_bo_mmap(struct host1x_bo *bo) diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index eaa5c3352c13..90dd592fdfca 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -99,6 +99,7 @@ EXPORT_SYMBOL(host1x_job_add_gather); static unsigned int pin_job(struct host1x *host, struct host1x_job *job) { + struct device *dev = job->client->dev; unsigned int i; int err; @@ -115,7 +116,11 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto unpin; } - phys_addr = host1x_bo_pin(reloc->target.bo, &sgt); + sgt = host1x_bo_pin(dev, reloc->target.bo, &phys_addr); + if (IS_ERR(sgt)) { + err = PTR_ERR(sgt); + goto unpin; + } job->addr_phys[job->num_unpins] = phys_addr; job->unpins[job->num_unpins].bo = reloc->target.bo; @@ -139,7 +144,11 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto unpin; } - phys_addr = host1x_bo_pin(g->bo, &sgt); + sgt = host1x_bo_pin(host->dev, g->bo, &phys_addr); + if (IS_ERR(sgt)) { + err = PTR_ERR(sgt); + goto unpin; + } if (!IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL) && host->domain) { for_each_sg(sgt->sgl, sg, sgt->nents, j) @@ -566,7 +575,7 @@ void host1x_job_unpin(struct host1x_job *job) iova_pfn(&host->iova, job->addr_phys[i])); } - host1x_bo_unpin(unpin->bo, unpin->sgt); + host1x_bo_unpin(host->dev, unpin->bo, unpin->sgt); host1x_bo_put(unpin->bo); } diff --git a/include/linux/host1x.h b/include/linux/host1x.h index df6e613ba715..1ba23a6a2021 100644 --- a/include/linux/host1x.h +++ b/include/linux/host1x.h @@ -67,8 +67,9 @@ struct sg_table; struct host1x_bo_ops { struct host1x_bo *(*get)(struct host1x_bo *bo); void (*put)(struct host1x_bo *bo); - dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt); - void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt); + struct sg_table *(*pin)(struct device *dev, struct host1x_bo *bo, + dma_addr_t *phys); + void (*unpin)(struct device *dev, struct sg_table *sgt); void *(*mmap)(struct host1x_bo *bo); void (*munmap)(struct host1x_bo *bo, void *addr); void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum); @@ -95,15 +96,17 @@ static inline void host1x_bo_put(struct host1x_bo *bo) bo->ops->put(bo); } -static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo, - struct sg_table **sgt) +static inline struct sg_table *host1x_bo_pin(struct device *dev, + struct host1x_bo *bo, + dma_addr_t *phys) { - return bo->ops->pin(bo, sgt); + return bo->ops->pin(dev, bo, phys); } -static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) +static inline void host1x_bo_unpin(struct device *dev, struct host1x_bo *bo, + struct sg_table *sgt) { - bo->ops->unpin(bo, sgt); + bo->ops->unpin(dev, sgt); } static inline void *host1x_bo_mmap(struct host1x_bo *bo) From patchwork Mon Oct 28 12:37:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185347 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="uaeXfiXJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPS3xBgz9sPL for ; Mon, 28 Oct 2019 23:37:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727905AbfJ1Mhc (ORCPT ); Mon, 28 Oct 2019 08:37:32 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39907 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mhc (ORCPT ); Mon, 28 Oct 2019 08:37:32 -0400 Received: by mail-wm1-f68.google.com with SMTP id r141so8945691wme.4 for ; Mon, 28 Oct 2019 05:37:30 -0700 (PDT) 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=VncOp+mUljsufXJnBUWLSxNXn7g2AiBvDFJ0LnGPK3g=; b=uaeXfiXJ/j7C+zwGb61d7ibJLhREbj2cEPm/XJHipaZXsV38VifKgSdQmrtLCtUsDG Z+FaKqQqB3ahI45jyAIiUfl/rSZRpw7x06n0VxMt4Z0HA1r3RYze9eAR7a7YZe5Arjn8 +4x/SMpisS6zTV7iNKWjnVR8YqD8YJ+Xa7FbLwsOowpjNxnykaV3fyEPdoAJwynFx/yZ hR6AGbX+teXfwO31TmcBnoA0WPuWH7qaofu3ns9V9v1j1a/V9+a7JsacfBUtjLY/rnS2 HdoYqiOU6GXyorELDHXFyeiTdcYML4vRUcSWMGQF+LwvTGTmLdo3AO18zqtCL2z2OJ4T Fn6g== 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=VncOp+mUljsufXJnBUWLSxNXn7g2AiBvDFJ0LnGPK3g=; b=WwZdykcTvLJq53dWYcCEwtVitcBhgbiZ6W2CJ5JWVEDKkKn6KaZdpIA+fMqR6foZqA mddowcD+ibL+xYamdvE4iscYipRIgq3C5FG6Q2hyfZ4NFyWRP3AGpsN69fLbdh9iq/j7 mQJoaSsla8QJUwYr/ZvEpaPQL0oO6imdaf/32Wd4hPiZoR7AKsWYSDSVifBxRK8bKuoC MnOBo+YaEMTWnDWhnxsjTOXD4xt3qwNyM0kkkhoxf4IxW7c8Pzwa/yQDR/yNxWcEsMiG gF9yW1iu5gyfO25vPQlgCAMgRqfSECU9j/odIsk2vBxnzK5MDMehV7N62Ns3kWU1X8AB oA9w== X-Gm-Message-State: APjAAAWP++7EVV5+xrc+We8HNwhuprf7uxV7k7YSI9ud/yk1UHNZCBC4 A8wzK3tWqJ+v1r0Y2EuUukE= X-Google-Smtp-Source: APXvYqxOVy+bTCgBsSYJR12Xu8F14DGtiViRIFkjBwX5BaBhbTDniBwKyD+QOm+sSjn1NoeYuaxx/g== X-Received: by 2002:a1c:6146:: with SMTP id v67mr15687949wmb.102.1572266249852; Mon, 28 Oct 2019 05:37:29 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id u1sm15316861wru.90.2019.10.28.05.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:29 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 04/12] gpu: host1x: Clean up debugfs on removal Date: Mon, 28 Oct 2019 13:37:10 +0100 Message-Id: <20191028123718.3890217-5-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 The debugfs files created for host1x are never removed, causing these files to be left dangling in debugfs. This results in a crash when any of these files are accessed after the host1x driver has been removed, as well as a failure to create the debugfs entries when they are added again on driver probe. Signed-off-by: Thierry Reding --- drivers/gpu/host1x/dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 452ee5d64021..f30b8447a319 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -402,6 +402,7 @@ static int host1x_remove(struct platform_device *pdev) struct host1x *host = platform_get_drvdata(pdev); host1x_unregister(host); + host1x_debug_deinit(host); host1x_intr_deinit(host); host1x_syncpt_deinit(host); reset_control_assert(host->rst); From patchwork Mon Oct 28 12:37:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185348 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="isl9SFet"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPV4rMkz9sPL for ; Mon, 28 Oct 2019 23:37:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728076AbfJ1Mhe (ORCPT ); Mon, 28 Oct 2019 08:37:34 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40298 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mhe (ORCPT ); Mon, 28 Oct 2019 08:37:34 -0400 Received: by mail-wr1-f66.google.com with SMTP id o28so9701886wro.7 for ; Mon, 28 Oct 2019 05:37:32 -0700 (PDT) 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=eD/3jzkhTttili1L+hDnKUUTcpzreCksFu7kaZ3nllc=; b=isl9SFetQ6uOtfd80K61+4EPWD8j7L9JcGCZc82nzVQm6CPSIHQRI2yGIbG5E/6SBk yERgD2OTnpMMGK4/d827BFzOocROI6zzASDv4tieJxYqDbJW5LRs+M/T11kuTnYnXuav EKLJZwoCkDQHy7nXEMyPBxcg+OboLtPg8YG9DK0tWaFtkhD7lrPHYPHE5xHzXgXjjqHh xxzbmxwZD9OATZa41ioak2XZGX6lm8cYPRgw/TBS4ha8obH78XN/Saqbm06+0ZK8df8E VwFYnooU5ONhF0lBEy2KQKfcZyhrZoginl47EfbxrR/LSUyeV5Aus94gNHYGdj/xz/ER tfuQ== 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=eD/3jzkhTttili1L+hDnKUUTcpzreCksFu7kaZ3nllc=; b=XFpmMbMIdJ1CmxnXxUyb2GknzDNBo9M3CPRuy5F7d3Iq4oKr48emL5LFVPVRzz112m hU6JFpbNQM5gCXsU4L6TblLw72uORZXdFCoAO0HD9fLwM1XK+r2cdlEN6BLKjP1A9m/4 wI6a+llqIHjnUqkCEzrcmisgfxHUiaR+ZaOxVLAPZsdrcOpBY9XoqscVKsTjo10U5LHt Dqc8HGhWqadxoDYl7vxu0ANjexE0Q1lp0wInSa2EgmWQ3IYbYJUz6yQkHagCrvVBfLRs Gopxo/GYjlDFCfih9QTs3wfz/fwwdl6TII/m3jfmx1XJJRNqYxT3iFMi6+ZdRhHIQ13m TA2Q== X-Gm-Message-State: APjAAAWnMbaEu4DpSNsUJxDvOpTJ/wivVgB+kF+5cdw1vWKqk8ncg7Yi U7DOCgLXm+IAQ/6ewB5zezxXw2Kk X-Google-Smtp-Source: APXvYqxJ5QBDdZwav0OKxoV+O0v7Le3RgZKyUoXTyLkXOi/tNWCgpHygWnpuqOrodFLzq79/6dt0cQ== X-Received: by 2002:a5d:6b0e:: with SMTP id v14mr14576420wrw.280.1572266251823; Mon, 28 Oct 2019 05:37:31 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id 12sm12290850wmk.13.2019.10.28.05.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:30 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 05/12] gpu: host1x: Add direction flags to relocations Date: Mon, 28 Oct 2019 13:37:11 +0100 Message-Id: <20191028123718.3890217-6-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 Add direction flags to host1x relocations performed during job pinning. These flags indicate the kinds of accesses that hardware is allowed to perform on the relocated buffers. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/drm.c | 2 ++ include/linux/host1x.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 9a1c1694604a..efc8a27b9e6a 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -149,6 +149,8 @@ static int host1x_reloc_copy_from_user(struct host1x_reloc *dest, if (err < 0) return err; + dest->flags = HOST1X_RELOC_READ | HOST1X_RELOC_WRITE; + dest->cmdbuf.bo = host1x_bo_lookup(file, cmdbuf); if (!dest->cmdbuf.bo) return -ENOENT; diff --git a/include/linux/host1x.h b/include/linux/host1x.h index 1ba23a6a2021..6f8d772591ba 100644 --- a/include/linux/host1x.h +++ b/include/linux/host1x.h @@ -173,6 +173,9 @@ int host1x_job_submit(struct host1x_job *job); * host1x job */ +#define HOST1X_RELOC_READ (1 << 0) +#define HOST1X_RELOC_WRITE (1 << 1) + struct host1x_reloc { struct { struct host1x_bo *bo; @@ -183,6 +186,7 @@ struct host1x_reloc { unsigned long offset; } target; unsigned long shift; + unsigned long flags; }; struct host1x_job { From patchwork Mon Oct 28 12:37:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="J6T8Et3Q"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPY6xF8z9sPL for ; Mon, 28 Oct 2019 23:37:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389099AbfJ1Mhh (ORCPT ); Mon, 28 Oct 2019 08:37:37 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33895 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mhh (ORCPT ); Mon, 28 Oct 2019 08:37:37 -0400 Received: by mail-wr1-f65.google.com with SMTP id t16so9728987wrr.1 for ; Mon, 28 Oct 2019 05:37:34 -0700 (PDT) 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=YGu5TjyuaHf7D/YFViamxWFcAcwWPrmI9iCh49BU0qM=; b=J6T8Et3Q9OPbN2qUhiKDlDj4XkuDt/ejRzmA4Y+vOMYWTSHcAmlFNIDC9V9jAW4w+p 48GR6SvU7LTdX9aAiXbed/AX8rODJnC6qHCRM9qwMuVKohbGVxqnbmoCdKbSBjrbJhAj 6RqYc7u4Q4YrZGyrNliJFpbCmlI0Gm+W+126GLBIqEkC4yoTQir++QrqrSzgONFmd+cY TA7yFW0twfdoblb5IrT4oQO/jrCTT/Ds+fwh3Tp4Cx7CWl2bOWsurn2p/uaox4dNVBCY Er3trvhH2kF0ENxCN9pN7J1Ts/AFK4smzAbkpnZR0ptF+Ujj0sC66JBQgmvUNBL3xRb6 LSBg== 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=YGu5TjyuaHf7D/YFViamxWFcAcwWPrmI9iCh49BU0qM=; b=QmiOyK2PW7rfu4eRNc10l2S0AhonIFzJrJO7c+RkTI2oNnw3+Riuo1oGp3GGJuu46+ SxOp7B6B5K+B5EspdBRPvjv+81COTpdDXcBlNzBlTSRIodjRc0B9YO1zqKpQgSMz+IXl lBgla32j1JziEQGW7bM0bjYc6ZU9VCLMZmvr6ErwavU7Z8QhUg85XGrhEbDZ68lDlajU Uqt1pebRrG4CmdgFaDlLKofglBRqrfx4iUe9kPXJAaYRNZoG/Psr6QTkYHktWFsMdOQ3 niWNEkI53QtCtvU+se6pMK5Pdaee3rl/W3LUOdsXXO5CLKvlBpJEWKehxZtdT/UqOhWt R6og== X-Gm-Message-State: APjAAAXhlePyHsFNEazZby/CAb8U41e53Wixu8VlWjT6OOceFf1cQt3K VOd4XlGYrnitulkLxIbVvX4= X-Google-Smtp-Source: APXvYqz7QNZG6RSaXHUuYYcJVyTDml0KvIAScsBZprWSCdNBiGZVAoDWl7Flo6yTPY3bLHEYb3ebhw== X-Received: by 2002:a5d:4283:: with SMTP id k3mr14839241wrq.236.1572266253975; Mon, 28 Oct 2019 05:37:33 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id d16sm1542915wmb.27.2019.10.28.05.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:32 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 06/12] gpu: host1x: Allocate gather copy for host1x Date: Mon, 28 Oct 2019 13:37:12 +0100 Message-Id: <20191028123718.3890217-7-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 Currently when the gather buffers are copied, they are copied to a buffer that is allocated for the host1x client that wants to execute the command streams in the buffers. However, the gather buffers will be read by the host1x device, which causes SMMU faults if the DMA API is backed by an IOMMU. Fix this by allocating the gather buffer copy for the host1x device, which makes sure that it will be mapped into the host1x's IOVA space if the DMA API is backed by an IOMMU. Signed-off-by: Thierry Reding --- drivers/gpu/host1x/job.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index 90dd592fdfca..2e0c3e0ca1fa 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -445,7 +445,8 @@ static int validate(struct host1x_firewall *fw, struct host1x_job_gather *g) return err; } -static inline int copy_gathers(struct host1x_job *job, struct device *dev) +static inline int copy_gathers(struct device *host, struct host1x_job *job, + struct device *dev) { struct host1x_firewall fw; size_t size = 0; @@ -468,12 +469,12 @@ static inline int copy_gathers(struct host1x_job *job, struct device *dev) * Try a non-blocking allocation from a higher priority pools first, * as awaiting for the allocation here is a major performance hit. */ - job->gather_copy_mapped = dma_alloc_wc(dev, size, &job->gather_copy, + job->gather_copy_mapped = dma_alloc_wc(host, size, &job->gather_copy, GFP_NOWAIT); /* the higher priority allocation failed, try the generic-blocking */ if (!job->gather_copy_mapped) - job->gather_copy_mapped = dma_alloc_wc(dev, size, + job->gather_copy_mapped = dma_alloc_wc(host, size, &job->gather_copy, GFP_KERNEL); if (!job->gather_copy_mapped) @@ -521,7 +522,7 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev) goto out; if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL)) { - err = copy_gathers(job, dev); + err = copy_gathers(host->dev, job, dev); if (err) goto out; } @@ -582,7 +583,7 @@ void host1x_job_unpin(struct host1x_job *job) job->num_unpins = 0; if (job->gather_copy_size) - dma_free_wc(job->channel->dev, job->gather_copy_size, + dma_free_wc(host->dev, job->gather_copy_size, job->gather_copy_mapped, job->gather_copy); } EXPORT_SYMBOL(host1x_job_unpin); From patchwork Mon Oct 28 12:37:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="uBlDjD0N"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPc08LHz9sPK for ; Mon, 28 Oct 2019 23:37:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389116AbfJ1Mhj (ORCPT ); Mon, 28 Oct 2019 08:37:39 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50790 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389093AbfJ1Mhj (ORCPT ); Mon, 28 Oct 2019 08:37:39 -0400 Received: by mail-wm1-f68.google.com with SMTP id 11so9292449wmk.0 for ; Mon, 28 Oct 2019 05:37:36 -0700 (PDT) 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=E/UgrwgRQLjyCEevCXRu9Z+kxkO/MmTvvuOszdrefH0=; b=uBlDjD0NOHbZQoQnFny5KS7yvl6dLYmduoGNxk7iOlcSb+WzLIUdZY570FD5GgUcMw 94rUWCloxKl1L6oydW/Vougyavt7DyUtfAH87juHEbx5nPhtXkkEH0W4NCVKJEQAKqGp iwKm0d7KuIOuTZpwIGkC787h+3Opww6PA18Oqaxkef3W9rLrRglGz0XxSncKGNZk0hF1 S02aUoYRPuXA5K4HtX2pmbkrmUzbkrlNoSPWUj0j5m8VwEX6P7+RQUsyqAsX0v6rwQOF B8Pcj/IvEtNKZmVG4Wzfsis9iXlhleWR4EWMmSn1FRujNx/BVpHFY3g7jfe7Tg52M6ab 5JAg== 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=E/UgrwgRQLjyCEevCXRu9Z+kxkO/MmTvvuOszdrefH0=; b=QMLGp0EZtcTln9WyBPsnq8FYtqgUT43X55muiWKVA0mBy6yQY/JZUvfeDV9y+kvafx c72AmpXsgv6tTmT86U2nG9PFAmFmswjMZk50DvWtWm17019I2MkhWJVSYVoqAxU3+OhR xapjDV2imsxeZEw/EgTMRaST+ufCfZf//hk/eDuARYOPRqXBxYD2r3rWj0ST93o8ERvs 1xr/NDE/RViEDkFwSBrR1KpeqO+ir4M82p3i7mLje58smTae5OtG6IDWR+jGUdo9FbmI xm/O+unENg1sFshMflUNk10k02C4UImGgfeRWGLxKcjZZ6YV7ZqCKym2AOBH9HRKnefK bNfw== X-Gm-Message-State: APjAAAU6Y1UOGIhapTP8co2dbddPaikQeNQHB3qCrc1u86aHgKXBpIJS KmAocshHfj+DsLrYMskMjyY= X-Google-Smtp-Source: APXvYqyeRKg5k2Ef1ftZJv2yazvaKn/qdvlq67GEjLGiQEfnkKVmBiPD5813o6DyUzD5LAVPOTW6lA== X-Received: by 2002:a1c:1d41:: with SMTP id d62mr15282285wmd.32.1572266256156; Mon, 28 Oct 2019 05:37:36 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id 74sm13180791wrm.92.2019.10.28.05.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:35 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 07/12] gpu: host1x: Support DMA mapping of buffers Date: Mon, 28 Oct 2019 13:37:13 +0100 Message-Id: <20191028123718.3890217-8-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 host1x_bo_pin() returns an SG table, create a DMA mapping for the buffer. For buffers that the host1x client has already mapped itself, host1x_bo_pin() returns NULL and the existing DMA address is used. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/gem.c | 18 +++++++-- drivers/gpu/host1x/dev.c | 16 ++------ drivers/gpu/host1x/job.c | 73 ++++++++++++++++++++++++++++++++----- drivers/gpu/host1x/job.h | 4 ++ 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index 564ef60f67c2..746dae32c484 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -34,9 +34,19 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, struct sg_table *sgt; int err; - if (phys) + /* + * If we've manually mapped the buffer object through the IOMMU, make + * sure to return the IOVA address of our mapping. + */ + if (phys && obj->mm) { *phys = obj->iova; + return NULL; + } + /* + * If we don't have a mapping for this buffer yet, return an SG table + * so that host1x can do the mapping for us via the DMA API. + */ sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); if (!sgt) return ERR_PTR(-ENOMEM); @@ -62,8 +72,10 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, static void tegra_bo_unpin(struct device *dev, struct sg_table *sgt) { - sg_free_table(sgt); - kfree(sgt); + if (sgt) { + sg_free_table(sgt); + kfree(sgt); + } } static void *tegra_bo_mmap(struct host1x_bo *bo) diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index f30b8447a319..5bdc484398f4 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -18,10 +18,6 @@ #include #undef CREATE_TRACE_POINTS -#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) -#include -#endif - #include "bus.h" #include "channel.h" #include "debug.h" @@ -276,17 +272,13 @@ static int host1x_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to get reset: %d\n", err); return err; } -#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) - if (host->dev->archdata.mapping) { - struct dma_iommu_mapping *mapping = - to_dma_iommu_mapping(host->dev); - arm_iommu_detach_device(host->dev); - arm_iommu_release_mapping(mapping); - } -#endif + if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL)) goto skip_iommu; + if (iommu_get_domain_for_dev(&pdev->dev)) + goto skip_iommu; + host->group = iommu_group_get(&pdev->dev); if (host->group) { struct iommu_domain_geometry *geometry; diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index 2e0c3e0ca1fa..25ca54de8fc5 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -99,7 +99,8 @@ EXPORT_SYMBOL(host1x_job_add_gather); static unsigned int pin_job(struct host1x *host, struct host1x_job *job) { - struct device *dev = job->client->dev; + struct host1x_client *client = job->client; + struct device *dev = client->dev; unsigned int i; int err; @@ -107,8 +108,8 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) for (i = 0; i < job->num_relocs; i++) { struct host1x_reloc *reloc = &job->relocs[i]; + dma_addr_t phys_addr, *phys; struct sg_table *sgt; - dma_addr_t phys_addr; reloc->target.bo = host1x_bo_get(reloc->target.bo); if (!reloc->target.bo) { @@ -116,12 +117,51 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto unpin; } - sgt = host1x_bo_pin(dev, reloc->target.bo, &phys_addr); + if (client->group) + phys = &phys_addr; + else + phys = NULL; + + sgt = host1x_bo_pin(dev, reloc->target.bo, phys); if (IS_ERR(sgt)) { err = PTR_ERR(sgt); goto unpin; } + if (sgt) { + unsigned long mask = HOST1X_RELOC_READ | + HOST1X_RELOC_WRITE; + enum dma_data_direction dir; + + switch (reloc->flags & mask) { + case HOST1X_RELOC_READ: + dir = DMA_TO_DEVICE; + break; + + case HOST1X_RELOC_WRITE: + dir = DMA_FROM_DEVICE; + break; + + case HOST1X_RELOC_READ | HOST1X_RELOC_WRITE: + dir = DMA_BIDIRECTIONAL; + break; + + default: + err = -EINVAL; + goto unpin; + } + + err = dma_map_sg(dev, sgt->sgl, sgt->nents, dir); + if (!err) { + err = -ENOMEM; + goto unpin; + } + + job->unpins[job->num_unpins].dev = dev; + job->unpins[job->num_unpins].dir = dir; + phys_addr = sg_dma_address(sgt->sgl); + } + job->addr_phys[job->num_unpins] = phys_addr; job->unpins[job->num_unpins].bo = reloc->target.bo; job->unpins[job->num_unpins].sgt = sgt; @@ -144,7 +184,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto unpin; } - sgt = host1x_bo_pin(host->dev, g->bo, &phys_addr); + sgt = host1x_bo_pin(host->dev, g->bo, NULL); if (IS_ERR(sgt)) { err = PTR_ERR(sgt); goto unpin; @@ -172,15 +212,24 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto unpin; } - job->addr_phys[job->num_unpins] = - iova_dma_addr(&host->iova, alloc); job->unpins[job->num_unpins].size = gather_size; + phys_addr = iova_dma_addr(&host->iova, alloc); } else { - job->addr_phys[job->num_unpins] = phys_addr; + err = dma_map_sg(host->dev, sgt->sgl, sgt->nents, + DMA_TO_DEVICE); + if (!err) { + err = -ENOMEM; + goto unpin; + } + + job->unpins[job->num_unpins].dev = host->dev; + phys_addr = sg_dma_address(sgt->sgl); } - job->gather_addr_phys[i] = job->addr_phys[job->num_unpins]; + job->addr_phys[job->num_unpins] = phys_addr; + job->gather_addr_phys[i] = phys_addr; + job->unpins[job->num_unpins].dir = DMA_TO_DEVICE; job->unpins[job->num_unpins].bo = g->bo; job->unpins[job->num_unpins].sgt = sgt; job->num_unpins++; @@ -567,6 +616,8 @@ void host1x_job_unpin(struct host1x_job *job) for (i = 0; i < job->num_unpins; i++) { struct host1x_job_unpin_data *unpin = &job->unpins[i]; + struct device *dev = unpin->dev ?: host->dev; + struct sg_table *sgt = unpin->sgt; if (!IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL) && unpin->size && host->domain) { @@ -576,7 +627,11 @@ void host1x_job_unpin(struct host1x_job *job) iova_pfn(&host->iova, job->addr_phys[i])); } - host1x_bo_unpin(host->dev, unpin->bo, unpin->sgt); + if (unpin->dev && sgt) + dma_unmap_sg(unpin->dev, sgt->sgl, sgt->nents, + unpin->dir); + + host1x_bo_unpin(dev, unpin->bo, sgt); host1x_bo_put(unpin->bo); } diff --git a/drivers/gpu/host1x/job.h b/drivers/gpu/host1x/job.h index 62b8805e6b35..94bc2e4ae241 100644 --- a/drivers/gpu/host1x/job.h +++ b/drivers/gpu/host1x/job.h @@ -8,6 +8,8 @@ #ifndef __HOST1X_JOB_H #define __HOST1X_JOB_H +#include + struct host1x_job_gather { unsigned int words; dma_addr_t base; @@ -19,7 +21,9 @@ struct host1x_job_gather { struct host1x_job_unpin_data { struct host1x_bo *bo; struct sg_table *sgt; + struct device *dev; size_t size; + enum dma_data_direction dir; }; /* From patchwork Mon Oct 28 12:37:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="U2SFeajS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPf0lGkz9sPK for ; Mon, 28 Oct 2019 23:37:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389117AbfJ1Mhl (ORCPT ); Mon, 28 Oct 2019 08:37:41 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38323 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mhl (ORCPT ); Mon, 28 Oct 2019 08:37:41 -0400 Received: by mail-wm1-f68.google.com with SMTP id 22so8830667wms.3 for ; Mon, 28 Oct 2019 05:37:39 -0700 (PDT) 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=EsR2YxcBEI4MUl9EOXPu7+LeSq1Sp1B6X0bex2JGADQ=; b=U2SFeajSee2t0anmDd9kePHQiXKFxiXH4rhfm52UIKJi7EHFNGwMgqtgUVZqvE+l0V nOv95WPSjNiWmEkOINyCESL90QqzCccB80NTRRcXme3r7jv5Ww7TuZSKLPTV+re4QThU jE5V8qSIHQAdfd8bQFl9ql35pG5jMbZ2JPP3WMud3/75+yG7kvTkIIAXimyj/lgIOYo8 yPFkIuZOGaX9UjGIIwMprsCf1gcpKexM7W8zEWqeu+PiTVqktx5BIaUOdKfO+pqD4wzX P6pY7p3SRo7yu4dywv6QezRXb0SgZj6vmpAmu8R13iQN2yV85WVMULOmJEqv4VtNfKEu gsxg== 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=EsR2YxcBEI4MUl9EOXPu7+LeSq1Sp1B6X0bex2JGADQ=; b=qYJofkuqu4khS1bEbVeUEogS3jrJkrFIwmAzDs2Y0WiimYbg6J8TiTT64AtOcsCXkb JCc/pt0dKVkqaDwCx41pNiIv8+SLDopOi60Gpu/pS/NXvWqV0sqIcheECZEMtZIy+Nih l5wMYNOB6PG183aU1bm8/sVP1PcDXIT5bCIxFfnbbojaTc4Rb+3JTdtUnRBMJf60BFK7 buUfsnY9+SHIXuYM66k9j8Tzw1g+XeWVThqvNBitSIWbuU5xTRmJuCPMDsKqvFGrYt9j QZslzMs8ZdKlcNTafZ0/9gmNjLO6Vf+6aclXNL3SPSIlnD92r7ZVnnOIvMiGSu3SXs+B L9YQ== X-Gm-Message-State: APjAAAVvbqddmT85R0Sf8m0s/jJHqcyljCXj+n8HuImQzREu5nCu98R0 ARGmykdfeF/i7/tdBM3cBcM= X-Google-Smtp-Source: APXvYqzqKHG8EVopWt0rHUcXOAgn3Kztqk4T4Uj2Cl40VBfZKgpI7bwI3YESUAYitSoSEzrceUoHHA== X-Received: by 2002:a05:600c:c7:: with SMTP id u7mr16101501wmm.141.1572266258257; Mon, 28 Oct 2019 05:37:38 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id x8sm11768339wrr.43.2019.10.28.05.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:37 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 08/12] gpu: host1x: Set DMA mask based on IOMMU setup Date: Mon, 28 Oct 2019 13:37:14 +0100 Message-Id: <20191028123718.3890217-9-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 the Tegra DRM clients are backed by an IOMMU, push buffers are likely to be allocated beyond the 32-bit boundary if sufficient system memory is available. This is problematic on earlier generations of Tegra where host1x supports a maximum of 32 address bits for the GATHER opcode. More recent versions of Tegra (Tegra186 and later) have a wide variant of the GATHER opcode, which allows addressing up to 64 bits of memory. If host1x itself is behind an IOMMU as well this doesn't matter because the IOMMU's input address space is restricted to 32 bits on generations without support for wide GATHER opcodes. However, if host1x is not behind an IOMMU, it won't be able to process push buffers beyond the 32-bit boundary on Tegra generations that don't support wide GATHER opcodes. Restrict the DMA mask to 32 bits on these generations prevents buffers from being allocated from beyond the 32-bit boundary. Signed-off-by: Thierry Reding --- drivers/gpu/host1x/dev.c | 214 ++++++++++++++++++++++++--------------- drivers/gpu/host1x/dev.h | 1 + 2 files changed, 136 insertions(+), 79 deletions(-) diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 5bdc484398f4..a738ea55e407 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -73,6 +73,7 @@ static const struct host1x_info host1x01_info = { .init = host1x01_init, .sync_offset = 0x3000, .dma_mask = DMA_BIT_MASK(32), + .has_wide_gather = false, .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, @@ -86,6 +87,7 @@ static const struct host1x_info host1x02_info = { .init = host1x02_init, .sync_offset = 0x3000, .dma_mask = DMA_BIT_MASK(32), + .has_wide_gather = false, .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, @@ -99,6 +101,7 @@ static const struct host1x_info host1x04_info = { .init = host1x04_init, .sync_offset = 0x2100, .dma_mask = DMA_BIT_MASK(34), + .has_wide_gather = false, .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, @@ -112,6 +115,7 @@ static const struct host1x_info host1x05_info = { .init = host1x05_init, .sync_offset = 0x2100, .dma_mask = DMA_BIT_MASK(34), + .has_wide_gather = false, .has_hypervisor = false, .num_sid_entries = 0, .sid_table = NULL, @@ -134,6 +138,7 @@ static const struct host1x_info host1x06_info = { .init = host1x06_init, .sync_offset = 0x0, .dma_mask = DMA_BIT_MASK(40), + .has_wide_gather = true, .has_hypervisor = true, .num_sid_entries = ARRAY_SIZE(tegra186_sid_table), .sid_table = tegra186_sid_table, @@ -156,6 +161,7 @@ static const struct host1x_info host1x07_info = { .init = host1x07_init, .sync_offset = 0x0, .dma_mask = DMA_BIT_MASK(40), + .has_wide_gather = true, .has_hypervisor = true, .num_sid_entries = ARRAY_SIZE(tegra194_sid_table), .sid_table = tegra194_sid_table, @@ -186,6 +192,117 @@ static void host1x_setup_sid_table(struct host1x *host) } } +static struct iommu_domain *host1x_iommu_attach(struct host1x *host) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(host->dev); + int err; + + /* + * If the host1x firewall is enabled, there's no need to enable IOMMU + * support. Similarly, if host1x is already attached to an IOMMU (via + * the DMA API), don't try to attach again. + */ + if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL) || domain) + return domain; + + host->group = iommu_group_get(host->dev); + if (host->group) { + struct iommu_domain_geometry *geometry; + dma_addr_t start, end; + unsigned long order; + + err = iova_cache_get(); + if (err < 0) + goto put_group; + + host->domain = iommu_domain_alloc(&platform_bus_type); + if (!host->domain) { + err = -ENOMEM; + goto put_cache; + } + + err = iommu_attach_group(host->domain, host->group); + if (err) { + if (err == -ENODEV) + err = 0; + + goto free_domain; + } + + geometry = &host->domain->geometry; + start = geometry->aperture_start & host->info->dma_mask; + end = geometry->aperture_end & host->info->dma_mask; + + order = __ffs(host->domain->pgsize_bitmap); + init_iova_domain(&host->iova, 1UL << order, start >> order); + host->iova_end = end; + + domain = host->domain; + } + + return domain; + +free_domain: + iommu_domain_free(host->domain); + host->domain = NULL; +put_cache: + iova_cache_put(); +put_group: + iommu_group_put(host->group); + host->group = NULL; + + return ERR_PTR(err); +} + +static int host1x_iommu_init(struct host1x *host) +{ + u64 mask = host->info->dma_mask; + struct iommu_domain *domain; + int err; + + domain = host1x_iommu_attach(host); + if (IS_ERR(domain)) { + err = PTR_ERR(domain); + dev_err(host->dev, "failed to attach to IOMMU: %d\n", err); + return err; + } + + /* + * If we're not behind an IOMMU make sure we don't get push buffers + * that are allocated outside of the range addressable by the GATHER + * opcode. + * + * Newer generations of Tegra (Tegra186 and later) support a wide + * variant of the GATHER opcode that allows addressing more bits. + */ + if (!domain && !host->info->has_wide_gather) + mask = DMA_BIT_MASK(32); + + err = dma_coerce_mask_and_coherent(host->dev, mask); + if (err < 0) { + dev_err(host->dev, "failed to set DMA mask: %d\n", err); + return err; + } + + return 0; +} + +static void host1x_iommu_exit(struct host1x *host) +{ + if (host->domain) { + put_iova_domain(&host->iova); + iommu_detach_group(host->domain, host->group); + + iommu_domain_free(host->domain); + host->domain = NULL; + + iova_cache_put(); + + iommu_group_put(host->group); + host->group = NULL; + } +} + static int host1x_probe(struct platform_device *pdev) { struct host1x *host; @@ -248,8 +365,6 @@ static int host1x_probe(struct platform_device *pdev) host->dev->dma_parms = &host->dma_parms; dma_set_max_seg_size(host->dev, UINT_MAX); - dma_set_mask_and_coherent(host->dev, host->info->dma_mask); - if (host->info->init) { err = host->info->init(host); if (err) @@ -273,82 +388,41 @@ static int host1x_probe(struct platform_device *pdev) return err; } - if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL)) - goto skip_iommu; - - if (iommu_get_domain_for_dev(&pdev->dev)) - goto skip_iommu; - - host->group = iommu_group_get(&pdev->dev); - if (host->group) { - struct iommu_domain_geometry *geometry; - u64 mask = dma_get_mask(host->dev); - dma_addr_t start, end; - unsigned long order; - - err = iova_cache_get(); - if (err < 0) - goto put_group; - - host->domain = iommu_domain_alloc(&platform_bus_type); - if (!host->domain) { - err = -ENOMEM; - goto put_cache; - } - - err = iommu_attach_group(host->domain, host->group); - if (err) { - if (err == -ENODEV) { - iommu_domain_free(host->domain); - host->domain = NULL; - iova_cache_put(); - iommu_group_put(host->group); - host->group = NULL; - goto skip_iommu; - } - - goto fail_free_domain; - } - - geometry = &host->domain->geometry; - start = geometry->aperture_start & mask; - end = geometry->aperture_end & mask; - - order = __ffs(host->domain->pgsize_bitmap); - init_iova_domain(&host->iova, 1UL << order, start >> order); - host->iova_end = end; + err = host1x_iommu_init(host); + if (err < 0) { + dev_err(&pdev->dev, "failed to setup IOMMU: %d\n", err); + return err; } -skip_iommu: err = host1x_channel_list_init(&host->channel_list, host->info->nb_channels); if (err) { dev_err(&pdev->dev, "failed to initialize channel list\n"); - goto fail_detach_device; + goto iommu_exit; } err = clk_prepare_enable(host->clk); if (err < 0) { dev_err(&pdev->dev, "failed to enable clock\n"); - goto fail_free_channels; + goto free_channels; } err = reset_control_deassert(host->rst); if (err < 0) { dev_err(&pdev->dev, "failed to deassert reset: %d\n", err); - goto fail_unprepare_disable; + goto unprepare_disable; } err = host1x_syncpt_init(host); if (err) { dev_err(&pdev->dev, "failed to initialize syncpts\n"); - goto fail_reset_assert; + goto reset_assert; } err = host1x_intr_init(host, syncpt_irq); if (err) { dev_err(&pdev->dev, "failed to initialize interrupts\n"); - goto fail_deinit_syncpt; + goto deinit_syncpt; } host1x_debug_init(host); @@ -358,33 +432,22 @@ static int host1x_probe(struct platform_device *pdev) err = host1x_register(host); if (err < 0) - goto fail_deinit_intr; + goto deinit_intr; return 0; -fail_deinit_intr: +deinit_intr: host1x_intr_deinit(host); -fail_deinit_syncpt: +deinit_syncpt: host1x_syncpt_deinit(host); -fail_reset_assert: +reset_assert: reset_control_assert(host->rst); -fail_unprepare_disable: +unprepare_disable: clk_disable_unprepare(host->clk); -fail_free_channels: +free_channels: host1x_channel_list_free(&host->channel_list); -fail_detach_device: - if (host->group && host->domain) { - put_iova_domain(&host->iova); - iommu_detach_group(host->domain, host->group); - } -fail_free_domain: - if (host->domain) - iommu_domain_free(host->domain); -put_cache: - if (host->group) - iova_cache_put(); -put_group: - iommu_group_put(host->group); +iommu_exit: + host1x_iommu_exit(host); return err; } @@ -399,14 +462,7 @@ static int host1x_remove(struct platform_device *pdev) host1x_syncpt_deinit(host); reset_control_assert(host->rst); clk_disable_unprepare(host->clk); - - if (host->domain) { - put_iova_domain(&host->iova); - iommu_detach_group(host->domain, host->group); - iommu_domain_free(host->domain); - iova_cache_put(); - iommu_group_put(host->group); - } + host1x_iommu_exit(host); return 0; } diff --git a/drivers/gpu/host1x/dev.h b/drivers/gpu/host1x/dev.h index abafde7c665e..f781a9b0f39d 100644 --- a/drivers/gpu/host1x/dev.h +++ b/drivers/gpu/host1x/dev.h @@ -97,6 +97,7 @@ struct host1x_info { int (*init)(struct host1x *host1x); /* initialize per SoC ops */ unsigned int sync_offset; /* offset of syncpoint registers */ u64 dma_mask; /* mask of addressable memory */ + bool has_wide_gather; /* supports GATHER_W opcode */ bool has_hypervisor; /* has hypervisor registers */ unsigned int num_sid_entries; const struct host1x_sid_entry *sid_table; From patchwork Mon Oct 28 12:37:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185352 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="pTqgjxlP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPh036Tz9sPK for ; Mon, 28 Oct 2019 23:37:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389118AbfJ1Mhn (ORCPT ); Mon, 28 Oct 2019 08:37:43 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36433 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389093AbfJ1Mhn (ORCPT ); Mon, 28 Oct 2019 08:37:43 -0400 Received: by mail-wm1-f66.google.com with SMTP id c22so8966355wmd.1 for ; Mon, 28 Oct 2019 05:37:41 -0700 (PDT) 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=jILA6qDn53+J3zi0Jq6tX7gPyhs2Q6cSmssSkEQ8Rg8=; b=pTqgjxlPaLbkkIIY3USRXVKFeIKU0kFj4yLhGgFMcWSS2+R7Tjloj6LZvFhkoJmLsI P4WPklGcifu01lZp61tbFsIU+MorRmgYS8o0sLZxfmZKbdll6AT78Vvv+6nCe51ra1d7 OURxlshjvBoZXvZXqhb5kEmY7oIpJLdi4WC2tIExGEMIphjh1oFAKrBZMYsHAy2pceBh e990lodsL7SRb9COgkeqiUNnZf0W/1ADAeL0STxM6qm5oPhA8pEHSqkz/9oGQu5FTXdr RlJSTtWzpj/vEeNG/o2ILGjYlp2ACVY9hep24T686Qp2CAvcngLxyp7gV27j4dOHhBi2 /ghA== 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=jILA6qDn53+J3zi0Jq6tX7gPyhs2Q6cSmssSkEQ8Rg8=; b=DAtoDDQgI6Y1DS3/KJmpSXzdRvp/tvEv6wA/zIiWe18ltB7ahm6mEK77v4NmgfcOqp xev63L1TFozbxOYpzPFf8Yr3jRx8DGCFJeMHr4+n2PHIONy90AH70FCVo+O1UFNJ53mf 3zat7H2LIKmseWmi6CQqZE1opYMyT1R1q5rUowTsnWgkoJDb26ORVE//+i808c605mQa z+26Bo4RpiREyFYJ+lrbUmmmPAP6uFDWvJofNbzS+mCbup2VgyH3Y3vMt2oaOzMVv1b4 LHk+j3YH7Ss3oNFL1xw7DF3K7IN/w9UgaXoZVVeK8Cga1Lk20/VMsbdl9oxYkGMtooHJ yiTg== X-Gm-Message-State: APjAAAV9ulqX+txQGsEgeIygOcGkwhtmA+CqwBQc5wiKKyg96L+1yxWH p3qeWQVMlk1DU7uRtoNDp70= X-Google-Smtp-Source: APXvYqz5nj0j+hMGb1J6QUL5CWdJWKsffHNU30eDaEQ9ZXUdZx0im/kV2RPALLu6vB96WycvSSuxlQ== X-Received: by 2002:a05:600c:da:: with SMTP id u26mr16556164wmm.9.1572266260318; Mon, 28 Oct 2019 05:37:40 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id f18sm9962689wmh.43.2019.10.28.05.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:39 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 09/12] drm/tegra: Remove memory allocation from Falcon library Date: Mon, 28 Oct 2019 13:37:15 +0100 Message-Id: <20191028123718.3890217-10-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 Having to provide allocator hooks to the Falcon library is somewhat cumbersome and it doesn't give the users of the library a lot of flexibility to deal with allocations. Instead, remove the notion of Falcon "operations" and let drivers deal with the memory allocations themselves. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/falcon.c | 50 ++----------------- drivers/gpu/drm/tegra/falcon.h | 11 ---- drivers/gpu/drm/tegra/vic.c | 91 ++++++++++++++++++++++++---------- 3 files changed, 68 insertions(+), 84 deletions(-) diff --git a/drivers/gpu/drm/tegra/falcon.c b/drivers/gpu/drm/tegra/falcon.c index f49ad36e24db..a5b25e4ecbd2 100644 --- a/drivers/gpu/drm/tegra/falcon.c +++ b/drivers/gpu/drm/tegra/falcon.c @@ -59,26 +59,11 @@ static void falcon_copy_firmware_image(struct falcon *falcon, const struct firmware *firmware) { u32 *firmware_vaddr = falcon->firmware.vaddr; - dma_addr_t daddr; size_t i; - int err; /* copy the whole thing taking into account endianness */ for (i = 0; i < firmware->size / sizeof(u32); i++) firmware_vaddr[i] = le32_to_cpu(((u32 *)firmware->data)[i]); - - /* ensure that caches are flushed and falcon can see the firmware */ - daddr = dma_map_single(falcon->dev, firmware_vaddr, - falcon->firmware.size, DMA_TO_DEVICE); - err = dma_mapping_error(falcon->dev, daddr); - if (err) { - dev_err(falcon->dev, "failed to map firmware: %d\n", err); - return; - } - dma_sync_single_for_device(falcon->dev, daddr, - falcon->firmware.size, DMA_TO_DEVICE); - dma_unmap_single(falcon->dev, daddr, falcon->firmware.size, - DMA_TO_DEVICE); } static int falcon_parse_firmware_image(struct falcon *falcon) @@ -125,6 +110,8 @@ int falcon_read_firmware(struct falcon *falcon, const char *name) if (err < 0) return err; + falcon->firmware.size = falcon->firmware.firmware->size; + return 0; } @@ -133,16 +120,6 @@ int falcon_load_firmware(struct falcon *falcon) const struct firmware *firmware = falcon->firmware.firmware; int err; - falcon->firmware.size = firmware->size; - - /* allocate iova space for the firmware */ - falcon->firmware.vaddr = falcon->ops->alloc(falcon, firmware->size, - &falcon->firmware.paddr); - if (IS_ERR(falcon->firmware.vaddr)) { - dev_err(falcon->dev, "DMA memory mapping failed\n"); - return PTR_ERR(falcon->firmware.vaddr); - } - /* copy firmware image into local area. this also ensures endianness */ falcon_copy_firmware_image(falcon, firmware); @@ -150,27 +127,17 @@ int falcon_load_firmware(struct falcon *falcon) err = falcon_parse_firmware_image(falcon); if (err < 0) { dev_err(falcon->dev, "failed to parse firmware image\n"); - goto err_setup_firmware_image; + return err; } release_firmware(firmware); falcon->firmware.firmware = NULL; return 0; - -err_setup_firmware_image: - falcon->ops->free(falcon, falcon->firmware.size, - falcon->firmware.paddr, falcon->firmware.vaddr); - - return err; } int falcon_init(struct falcon *falcon) { - /* check mandatory ops */ - if (!falcon->ops || !falcon->ops->alloc || !falcon->ops->free) - return -EINVAL; - falcon->firmware.vaddr = NULL; return 0; @@ -178,17 +145,8 @@ int falcon_init(struct falcon *falcon) void falcon_exit(struct falcon *falcon) { - if (falcon->firmware.firmware) { + if (falcon->firmware.firmware) release_firmware(falcon->firmware.firmware); - falcon->firmware.firmware = NULL; - } - - if (falcon->firmware.vaddr) { - falcon->ops->free(falcon, falcon->firmware.size, - falcon->firmware.paddr, - falcon->firmware.vaddr); - falcon->firmware.vaddr = NULL; - } } int falcon_boot(struct falcon *falcon) diff --git a/drivers/gpu/drm/tegra/falcon.h b/drivers/gpu/drm/tegra/falcon.h index 3d1243217410..92491a1e90df 100644 --- a/drivers/gpu/drm/tegra/falcon.h +++ b/drivers/gpu/drm/tegra/falcon.h @@ -74,15 +74,6 @@ struct falcon_fw_os_header_v1 { u32 data_size; }; -struct falcon; - -struct falcon_ops { - void *(*alloc)(struct falcon *falcon, size_t size, - dma_addr_t *paddr); - void (*free)(struct falcon *falcon, size_t size, - dma_addr_t paddr, void *vaddr); -}; - struct falcon_firmware_section { unsigned long offset; size_t size; @@ -107,8 +98,6 @@ struct falcon { /* Set by falcon client */ struct device *dev; void __iomem *regs; - const struct falcon_ops *ops; - void *data; struct falcon_firmware firmware; }; diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index 603f41ed4b81..4345b8054617 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -158,27 +158,6 @@ static int vic_boot(struct vic *vic) return 0; } -static void *vic_falcon_alloc(struct falcon *falcon, size_t size, - dma_addr_t *iova) -{ - struct tegra_drm *tegra = falcon->data; - - return tegra_drm_alloc(tegra, size, iova); -} - -static void vic_falcon_free(struct falcon *falcon, size_t size, - dma_addr_t iova, void *va) -{ - struct tegra_drm *tegra = falcon->data; - - return tegra_drm_free(tegra, size, va, iova); -} - -static const struct falcon_ops vic_falcon_ops = { - .alloc = vic_falcon_alloc, - .free = vic_falcon_free -}; - static int vic_init(struct host1x_client *client) { struct tegra_drm_client *drm = host1x_to_drm_client(client); @@ -246,6 +225,15 @@ static int vic_exit(struct host1x_client *client) host1x_channel_put(vic->channel); host1x_client_iommu_detach(client); + if (client->group) + tegra_drm_free(tegra, vic->falcon.firmware.size, + vic->falcon.firmware.vaddr, + vic->falcon.firmware.paddr); + else + dma_free_coherent(vic->dev, vic->falcon.firmware.size, + vic->falcon.firmware.vaddr, + vic->falcon.firmware.paddr); + return 0; } @@ -256,25 +244,75 @@ static const struct host1x_client_ops vic_client_ops = { static int vic_load_firmware(struct vic *vic) { + struct host1x_client *client = &vic->client.base; + struct tegra_drm *tegra = vic->client.drm; + dma_addr_t phys; + size_t size; + void *virt; int err; - if (vic->falcon.data) + if (vic->falcon.firmware.vaddr) return 0; - vic->falcon.data = vic->client.drm; - err = falcon_read_firmware(&vic->falcon, vic->config->firmware); if (err < 0) - goto cleanup; + return err; + + size = vic->falcon.firmware.size; + + if (!client->group) { + virt = dma_alloc_coherent(vic->dev, size, &phys, GFP_KERNEL); + + err = dma_mapping_error(vic->dev, phys); + if (err < 0) + return err; + } else { + virt = tegra_drm_alloc(tegra, size, &phys); + } + + vic->falcon.firmware.vaddr = virt; + vic->falcon.firmware.paddr = phys; err = falcon_load_firmware(&vic->falcon); if (err < 0) goto cleanup; + /* + * In this case we have received an IOVA from the shared domain, so we + * need to make sure to get the physical address so that the DMA API + * knows what memory pages to flush the cache for. + */ + if (client->group) { + phys = dma_map_single(vic->dev, virt, size, DMA_TO_DEVICE); + + err = dma_mapping_error(vic->dev, phys); + if (err < 0) + goto cleanup; + + /* + * If the DMA API mapped this through a bounce buffer, the + * dma_sync_single_for_device() call below will not be able + * to flush the caches for the right memory pages. Output a + * big warning in that case so that the DMA mask can be set + * properly and the bounce buffer avoided. + */ + WARN(phys != vic->falcon.firmware.paddr, + "check DMA mask setting for %s\n", dev_name(vic->dev)); + } + + dma_sync_single_for_device(vic->dev, phys, size, DMA_TO_DEVICE); + + if (client->group) + dma_unmap_single(vic->dev, phys, size, DMA_TO_DEVICE); + return 0; cleanup: - vic->falcon.data = NULL; + if (!client->group) + dma_free_coherent(vic->dev, size, virt, phys); + else + tegra_drm_free(tegra, size, virt, phys); + return err; } @@ -415,7 +453,6 @@ static int vic_probe(struct platform_device *pdev) vic->falcon.dev = dev; vic->falcon.regs = vic->regs; - vic->falcon.ops = &vic_falcon_ops; err = falcon_init(&vic->falcon); if (err < 0) From patchwork Mon Oct 28 12:37:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="D+bqwQgu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPj6y4Nz9sPK for ; Mon, 28 Oct 2019 23:37:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389119AbfJ1Mhp (ORCPT ); Mon, 28 Oct 2019 08:37:45 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37692 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mhp (ORCPT ); Mon, 28 Oct 2019 08:37:45 -0400 Received: by mail-wm1-f67.google.com with SMTP id q130so8965742wme.2 for ; Mon, 28 Oct 2019 05:37:43 -0700 (PDT) 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=Vj6z8eCl5Er2CPWlhg0g4dEQkBmHi8mlQueCTrv8Xu8=; b=D+bqwQguJK0P3djt0F5KzpmvuingamK0L1C51W6AX4WTmR7psvfh2+8D9+b4Q3mRXP 07jJ4yu/EVL+RdFJRXObaVvfUl+r/W09FX1vYxPxpxCv+2WKMzBMc0cskAwdomUpOXhW Cg4NrJq8EK8+HpQbO9MY1rsjFkmuWeTuak+nvOufTMVc4qToYEd7tTQVJ8fzn4u9s623 jYA8YXpvE38eWKN77bzwH88j4IaHX6n6y/WG4B7np/7CnJ15j+/4fLestlabV0UkvJOn J6yXEoaunGkFO1qfQXUCcVKImArKrwBsV+3IdNpW2M0FXrPJZWxcI3G5+awWC/FLha9u JhHA== 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=Vj6z8eCl5Er2CPWlhg0g4dEQkBmHi8mlQueCTrv8Xu8=; b=PxZW8fLaw2uiEt3GrnSYgoLPmRVDz8pZg5LzXmYva4k7BqJX5u/vZg29UaZvXbP16d lzrFy5qqJGbz1V3GE5r43RS5nlj0mQYN2DTfWBTn2LlDLNDWjVfizdD+i5CbHWvaaLfI rlwoyl5Ic9hAtOi35nISNsNQTsXpUB9LV3OLlJKHo4iOhblJM2BGviTWVyj4SutfC3dp 6Nzz0oN9IRFE6877rsD4RhCYB/u8n4wzH4K6H/+dNrVimBzEdqcfyIW5p+GkKJ98sEnd j+ERNxBvJ2W/QRDiZwmbBaRXHvo8MP0SZExLi/qvBGzivj/yUfMzt2SXfN/mRDmFUlxe t2og== X-Gm-Message-State: APjAAAWABsjlxt1pCCO5iV+7LYoBrIpeCzfTqIsnA42igtDJC6X877gU JDgMQtSrujvzTiv/gUYCxPS0Yp7B X-Google-Smtp-Source: APXvYqwj4BsYGSwjizLoOl03s12BFG4yobYGi01ZqkUw2OleWZxXWluMuQUsf1QvMIShDGPR93JfFA== X-Received: by 2002:a7b:cd04:: with SMTP id f4mr15327911wmj.91.1572266262305; Mon, 28 Oct 2019 05:37:42 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id c16sm12551237wrw.32.2019.10.28.05.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:41 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 10/12] drm/tegra: falcon: Clarify address usage Date: Mon, 28 Oct 2019 13:37:16 +0100 Message-Id: <20191028123718.3890217-11-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 Rename paddr -> iova and vaddr -> virt to make it clearer how these addresses are used. This is important for a subsequent patch that makes a distinction between the physical address (physical address of the system memory from the CPU's point of view) and the IOVA (physical address of the system memory from the device's point of view). Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/falcon.c | 14 ++++----- drivers/gpu/drm/tegra/falcon.h | 5 +-- drivers/gpu/drm/tegra/vic.c | 56 +++++++++++++++------------------- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/tegra/falcon.c b/drivers/gpu/drm/tegra/falcon.c index a5b25e4ecbd2..56edef06c48e 100644 --- a/drivers/gpu/drm/tegra/falcon.c +++ b/drivers/gpu/drm/tegra/falcon.c @@ -58,17 +58,17 @@ static int falcon_copy_chunk(struct falcon *falcon, static void falcon_copy_firmware_image(struct falcon *falcon, const struct firmware *firmware) { - u32 *firmware_vaddr = falcon->firmware.vaddr; + u32 *virt = falcon->firmware.virt; size_t i; /* copy the whole thing taking into account endianness */ for (i = 0; i < firmware->size / sizeof(u32); i++) - firmware_vaddr[i] = le32_to_cpu(((u32 *)firmware->data)[i]); + virt[i] = le32_to_cpu(((u32 *)firmware->data)[i]); } static int falcon_parse_firmware_image(struct falcon *falcon) { - struct falcon_fw_bin_header_v1 *bin = (void *)falcon->firmware.vaddr; + struct falcon_fw_bin_header_v1 *bin = (void *)falcon->firmware.virt; struct falcon_fw_os_header_v1 *os; /* endian problems would show up right here */ @@ -89,7 +89,7 @@ static int falcon_parse_firmware_image(struct falcon *falcon) return -EINVAL; } - os = falcon->firmware.vaddr + bin->os_header_offset; + os = falcon->firmware.virt + bin->os_header_offset; falcon->firmware.bin_data.size = bin->os_size; falcon->firmware.bin_data.offset = bin->os_data_offset; @@ -138,7 +138,7 @@ int falcon_load_firmware(struct falcon *falcon) int falcon_init(struct falcon *falcon) { - falcon->firmware.vaddr = NULL; + falcon->firmware.virt = NULL; return 0; } @@ -155,7 +155,7 @@ int falcon_boot(struct falcon *falcon) u32 value; int err; - if (!falcon->firmware.vaddr) + if (!falcon->firmware.virt) return -EINVAL; err = readl_poll_timeout(falcon->regs + FALCON_DMACTL, value, @@ -168,7 +168,7 @@ int falcon_boot(struct falcon *falcon) falcon_writel(falcon, 0, FALCON_DMACTL); /* setup the address of the binary data so Falcon can access it later */ - falcon_writel(falcon, (falcon->firmware.paddr + + falcon_writel(falcon, (falcon->firmware.iova + falcon->firmware.bin_data.offset) >> 8, FALCON_DMATRFBASE); diff --git a/drivers/gpu/drm/tegra/falcon.h b/drivers/gpu/drm/tegra/falcon.h index 92491a1e90df..c56ee32d92ee 100644 --- a/drivers/gpu/drm/tegra/falcon.h +++ b/drivers/gpu/drm/tegra/falcon.h @@ -84,8 +84,9 @@ struct falcon_firmware { const struct firmware *firmware; /* Raw firmware data */ - dma_addr_t paddr; - void *vaddr; + dma_addr_t iova; + dma_addr_t phys; + void *virt; size_t size; /* Parsed firmware information */ diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index 4345b8054617..9444ba183990 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -133,9 +133,9 @@ static int vic_boot(struct vic *vic) if (err < 0) return err; - hdr = vic->falcon.firmware.vaddr; + hdr = vic->falcon.firmware.virt; fce_bin_data_offset = *(u32 *)(hdr + VIC_UCODE_FCE_DATA_OFFSET); - hdr = vic->falcon.firmware.vaddr + + hdr = vic->falcon.firmware.virt + *(u32 *)(hdr + VIC_UCODE_FCE_HEADER_OFFSET); fce_ucode_size = *(u32 *)(hdr + FCE_UCODE_SIZE_OFFSET); @@ -143,7 +143,7 @@ static int vic_boot(struct vic *vic) falcon_execute_method(&vic->falcon, VIC_SET_FCE_UCODE_SIZE, fce_ucode_size); falcon_execute_method(&vic->falcon, VIC_SET_FCE_UCODE_OFFSET, - (vic->falcon.firmware.paddr + fce_bin_data_offset) + (vic->falcon.firmware.iova + fce_bin_data_offset) >> 8); err = falcon_wait_idle(&vic->falcon); @@ -225,14 +225,17 @@ static int vic_exit(struct host1x_client *client) host1x_channel_put(vic->channel); host1x_client_iommu_detach(client); - if (client->group) + if (client->group) { + dma_unmap_single(vic->dev, vic->falcon.firmware.phys, + vic->falcon.firmware.size, DMA_TO_DEVICE); tegra_drm_free(tegra, vic->falcon.firmware.size, - vic->falcon.firmware.vaddr, - vic->falcon.firmware.paddr); - else + vic->falcon.firmware.virt, + vic->falcon.firmware.iova); + } else { dma_free_coherent(vic->dev, vic->falcon.firmware.size, - vic->falcon.firmware.vaddr, - vic->falcon.firmware.paddr); + vic->falcon.firmware.virt, + vic->falcon.firmware.iova); + } return 0; } @@ -246,12 +249,12 @@ static int vic_load_firmware(struct vic *vic) { struct host1x_client *client = &vic->client.base; struct tegra_drm *tegra = vic->client.drm; - dma_addr_t phys; + dma_addr_t iova; size_t size; void *virt; int err; - if (vic->falcon.firmware.vaddr) + if (vic->falcon.firmware.virt) return 0; err = falcon_read_firmware(&vic->falcon, vic->config->firmware); @@ -261,17 +264,17 @@ static int vic_load_firmware(struct vic *vic) size = vic->falcon.firmware.size; if (!client->group) { - virt = dma_alloc_coherent(vic->dev, size, &phys, GFP_KERNEL); + virt = dma_alloc_coherent(vic->dev, size, &iova, GFP_KERNEL); - err = dma_mapping_error(vic->dev, phys); + err = dma_mapping_error(vic->dev, iova); if (err < 0) return err; } else { - virt = tegra_drm_alloc(tegra, size, &phys); + virt = tegra_drm_alloc(tegra, size, &iova); } - vic->falcon.firmware.vaddr = virt; - vic->falcon.firmware.paddr = phys; + vic->falcon.firmware.virt = virt; + vic->falcon.firmware.iova = iova; err = falcon_load_firmware(&vic->falcon); if (err < 0) @@ -283,35 +286,24 @@ static int vic_load_firmware(struct vic *vic) * knows what memory pages to flush the cache for. */ if (client->group) { + dma_addr_t phys; + phys = dma_map_single(vic->dev, virt, size, DMA_TO_DEVICE); err = dma_mapping_error(vic->dev, phys); if (err < 0) goto cleanup; - /* - * If the DMA API mapped this through a bounce buffer, the - * dma_sync_single_for_device() call below will not be able - * to flush the caches for the right memory pages. Output a - * big warning in that case so that the DMA mask can be set - * properly and the bounce buffer avoided. - */ - WARN(phys != vic->falcon.firmware.paddr, - "check DMA mask setting for %s\n", dev_name(vic->dev)); + vic->falcon.firmware.phys = phys; } - dma_sync_single_for_device(vic->dev, phys, size, DMA_TO_DEVICE); - - if (client->group) - dma_unmap_single(vic->dev, phys, size, DMA_TO_DEVICE); - return 0; cleanup: if (!client->group) - dma_free_coherent(vic->dev, size, virt, phys); + dma_free_coherent(vic->dev, size, virt, iova); else - tegra_drm_free(tegra, size, virt, phys); + tegra_drm_free(tegra, size, virt, iova); return err; } From patchwork Mon Oct 28 12:37:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="giEOBhaq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPm1Zd0z9sPL for ; Mon, 28 Oct 2019 23:37:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389120AbfJ1Mhr (ORCPT ); Mon, 28 Oct 2019 08:37:47 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45644 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389093AbfJ1Mhr (ORCPT ); Mon, 28 Oct 2019 08:37:47 -0400 Received: by mail-wr1-f68.google.com with SMTP id q13so9675300wrs.12 for ; Mon, 28 Oct 2019 05:37:45 -0700 (PDT) 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=BVtc7jw7WhTJ+/y+/52Upjepj6jdz/+oV1yVXbshAuY=; b=giEOBhaqNlgnVww+O/bQbZJ5tR7V5vKEqHYMfYjDfp3lBZD5vgzQoR4i+gZSzuldP0 46lcvslmmwqEH8368q87YMedF5xn17EVoPQYrma78FNaViBxWgB4yxM72anAVst7fQo2 bxL1jxoRRYEpchccgU75GP4ad8STlzJ+0c/tvgnKxC48tiECZ8Air3L0E3VmChraHU6h HgexJiXJVRFDJYJ3FVNsPdAX45L3InQkNLzvVlBnznEbCEQuUYBybto0U+rHE+pJ1yAN EKwFU+wyNkUu8KzJ5ivx13pH281WwuWsPZGg1LAhghoNsWBd5QdmC9/QCjendF3wWZ7/ rK8w== 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=BVtc7jw7WhTJ+/y+/52Upjepj6jdz/+oV1yVXbshAuY=; b=cHmD9LBLoctvqGM83pyAAniqpZIqan0xt6g2IW0sVnaD1XddIPqvIfNksKWpKwJjVL ocKtmv6JkxMEqD6OLwUiHC21ou52+ESKjfk1GdU3boAov8gWU4xn3vGX5gcwc2xJ94wN 6aPD/suKUSNDWHq44tqWW30m20btbNjD2AIYFUld9YjwyJikEypWDvME/x5xP6B81rL0 X92NzUDh6TslQpYOIe576D5EpvKGblxRTzWWhav9v8oh1yOYRSFU6ONBzo7+ByElPpoq XSw8k9I1OlLtIAon8a44K3ap6lPbs3opeS1TBY6NWk4S29sX+zYPYZDAuc0fo5WRSWL3 KiXQ== X-Gm-Message-State: APjAAAUR+SAaygzPWYnlKrYRs43brmwoD3ja0GkRTSSP1Ai6wu6tIHJX EuieLOLk7oAy2ApPcXtWoJ6Dm0iU X-Google-Smtp-Source: APXvYqwbzd9LkRkDaiccU0sZZrjK1OVg8h6TPjnG6yblTCKSWqDwhT/AY+z45vrsTMW/AYBOKQ3sJw== X-Received: by 2002:a5d:4a81:: with SMTP id o1mr14642779wrq.225.1572266264388; Mon, 28 Oct 2019 05:37:44 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id t185sm15254147wmf.45.2019.10.28.05.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:43 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 11/12] drm/tegra: Support DMA API for display controllers Date: Mon, 28 Oct 2019 13:37:17 +0100 Message-Id: <20191028123718.3890217-12-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 a display controller is not attached to an explicit IOMMU domain, which usually means that it's connected to an IOMMU domain controlled by the DMA API, make sure to map the framebuffer to the display controller address space. This allows us to transparently handle setups where the display controller is attached to an IOMMU or setups where it isn't. It also allows the driver to work with a DMA API that is backed by an IOMMU. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/dc.c | 8 ++- drivers/gpu/drm/tegra/hub.c | 6 +- drivers/gpu/drm/tegra/plane.c | 104 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/plane.h | 8 +++ 4 files changed, 120 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 36c36b295ab1..5b1f9ff97576 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -715,9 +715,7 @@ static void tegra_plane_atomic_update(struct drm_plane *plane, window.swap = state->swap; for (i = 0; i < fb->format->num_planes; i++) { - struct tegra_bo *bo = tegra_fb_get_plane(fb, i); - - window.base[i] = bo->iova + fb->offsets[i]; + window.base[i] = state->iova[i] + fb->offsets[i]; /* * Tegra uses a shared stride for UV planes. Framebuffers are @@ -732,6 +730,8 @@ static void tegra_plane_atomic_update(struct drm_plane *plane, } static const struct drm_plane_helper_funcs tegra_plane_helper_funcs = { + .prepare_fb = tegra_plane_prepare_fb, + .cleanup_fb = tegra_plane_cleanup_fb, .atomic_check = tegra_plane_atomic_check, .atomic_disable = tegra_plane_atomic_disable, .atomic_update = tegra_plane_atomic_update, @@ -914,6 +914,8 @@ static void tegra_cursor_atomic_disable(struct drm_plane *plane, } static const struct drm_plane_helper_funcs tegra_cursor_plane_helper_funcs = { + .prepare_fb = tegra_plane_prepare_fb, + .cleanup_fb = tegra_plane_cleanup_fb, .atomic_check = tegra_cursor_atomic_check, .atomic_update = tegra_cursor_atomic_update, .atomic_disable = tegra_cursor_atomic_disable, diff --git a/drivers/gpu/drm/tegra/hub.c b/drivers/gpu/drm/tegra/hub.c index 104115e42190..2b4082d0bc9e 100644 --- a/drivers/gpu/drm/tegra/hub.c +++ b/drivers/gpu/drm/tegra/hub.c @@ -413,7 +413,6 @@ static void tegra_shared_plane_atomic_update(struct drm_plane *plane, unsigned int zpos = plane->state->normalized_zpos; struct drm_framebuffer *fb = plane->state->fb; struct tegra_plane *p = to_tegra_plane(plane); - struct tegra_bo *bo; dma_addr_t base; u32 value; @@ -456,8 +455,7 @@ static void tegra_shared_plane_atomic_update(struct drm_plane *plane, /* disable compression */ tegra_plane_writel(p, 0, DC_WINBUF_CDE_CONTROL); - bo = tegra_fb_get_plane(fb, 0); - base = bo->iova; + base = state->iova[0] + fb->offsets[0]; tegra_plane_writel(p, state->format, DC_WIN_COLOR_DEPTH); tegra_plane_writel(p, 0, DC_WIN_PRECOMP_WGRP_PARAMS); @@ -521,6 +519,8 @@ static void tegra_shared_plane_atomic_update(struct drm_plane *plane, } static const struct drm_plane_helper_funcs tegra_shared_plane_helper_funcs = { + .prepare_fb = tegra_plane_prepare_fb, + .cleanup_fb = tegra_plane_cleanup_fb, .atomic_check = tegra_shared_plane_atomic_check, .atomic_update = tegra_shared_plane_atomic_update, .atomic_disable = tegra_shared_plane_atomic_disable, diff --git a/drivers/gpu/drm/tegra/plane.c b/drivers/gpu/drm/tegra/plane.c index 6bab71d6e81d..163b590be224 100644 --- a/drivers/gpu/drm/tegra/plane.c +++ b/drivers/gpu/drm/tegra/plane.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "dc.h" @@ -23,6 +24,7 @@ static void tegra_plane_reset(struct drm_plane *plane) { struct tegra_plane *p = to_tegra_plane(plane); struct tegra_plane_state *state; + unsigned int i; if (plane->state) __drm_atomic_helper_plane_destroy_state(plane->state); @@ -36,6 +38,9 @@ static void tegra_plane_reset(struct drm_plane *plane) plane->state->plane = plane; plane->state->zpos = p->index; plane->state->normalized_zpos = p->index; + + for (i = 0; i < 3; i++) + state->iova[i] = DMA_MAPPING_ERROR; } } @@ -60,6 +65,11 @@ tegra_plane_atomic_duplicate_state(struct drm_plane *plane) for (i = 0; i < 2; i++) copy->blending[i] = state->blending[i]; + for (i = 0; i < 3; i++) { + copy->iova[i] = DMA_MAPPING_ERROR; + copy->sgt[i] = NULL; + } + return ©->base; } @@ -95,6 +105,100 @@ const struct drm_plane_funcs tegra_plane_funcs = { .format_mod_supported = tegra_plane_format_mod_supported, }; +static int tegra_dc_pin(struct tegra_dc *dc, struct tegra_plane_state *state) +{ + unsigned int i; + int err; + + for (i = 0; i < state->base.fb->format->num_planes; i++) { + struct tegra_bo *bo = tegra_fb_get_plane(state->base.fb, i); + + if (!dc->client.group) { + struct sg_table *sgt; + + sgt = host1x_bo_pin(dc->dev, &bo->base, NULL); + if (IS_ERR(sgt)) { + err = PTR_ERR(sgt); + goto unpin; + } + + err = dma_map_sg(dc->dev, sgt->sgl, sgt->nents, + DMA_TO_DEVICE); + if (err == 0) { + err = -ENOMEM; + goto unpin; + } + + state->iova[i] = sg_dma_address(sgt->sgl); + state->sgt[i] = sgt; + } else { + state->iova[i] = bo->iova; + } + } + + return 0; + +unpin: + dev_err(dc->dev, "failed to map plane %u: %d\n", i, err); + + while (i--) { + struct tegra_bo *bo = tegra_fb_get_plane(state->base.fb, i); + struct sg_table *sgt = state->sgt[i]; + + dma_unmap_sg(dc->dev, sgt->sgl, sgt->nents, DMA_TO_DEVICE); + host1x_bo_unpin(dc->dev, &bo->base, sgt); + + state->iova[i] = DMA_MAPPING_ERROR; + state->sgt[i] = NULL; + } + + return err; +} + +static void tegra_dc_unpin(struct tegra_dc *dc, struct tegra_plane_state *state) +{ + unsigned int i; + + for (i = 0; i < state->base.fb->format->num_planes; i++) { + struct tegra_bo *bo = tegra_fb_get_plane(state->base.fb, i); + + if (!dc->client.group) { + struct sg_table *sgt = state->sgt[i]; + + if (sgt) { + dma_unmap_sg(dc->dev, sgt->sgl, sgt->nents, + DMA_TO_DEVICE); + host1x_bo_unpin(dc->dev, &bo->base, sgt); + } + } + + state->iova[i] = DMA_MAPPING_ERROR; + state->sgt[i] = NULL; + } +} + +int tegra_plane_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct tegra_dc *dc = to_tegra_dc(state->crtc); + + if (!state->fb) + return 0; + + drm_gem_fb_prepare_fb(plane, state); + + return tegra_dc_pin(dc, to_tegra_plane_state(state)); +} + +void tegra_plane_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct tegra_dc *dc = to_tegra_dc(state->crtc); + + if (dc) + tegra_dc_unpin(dc, to_tegra_plane_state(state)); +} + int tegra_plane_state_add(struct tegra_plane *plane, struct drm_plane_state *state) { diff --git a/drivers/gpu/drm/tegra/plane.h b/drivers/gpu/drm/tegra/plane.h index 510c394e6d9a..a158a915109a 100644 --- a/drivers/gpu/drm/tegra/plane.h +++ b/drivers/gpu/drm/tegra/plane.h @@ -39,6 +39,9 @@ struct tegra_plane_legacy_blending_state { struct tegra_plane_state { struct drm_plane_state base; + struct sg_table *sgt[3]; + dma_addr_t iova[3]; + struct tegra_bo_tiling tiling; u32 format; u32 swap; @@ -61,6 +64,11 @@ to_tegra_plane_state(struct drm_plane_state *state) extern const struct drm_plane_funcs tegra_plane_funcs; +int tegra_plane_prepare_fb(struct drm_plane *plane, + struct drm_plane_state *state); +void tegra_plane_cleanup_fb(struct drm_plane *plane, + struct drm_plane_state *state); + int tegra_plane_state_add(struct tegra_plane *plane, struct drm_plane_state *state); From patchwork Mon Oct 28 12:37:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1185355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="icu0V3tx"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 471vPn66pMz9sPT for ; Mon, 28 Oct 2019 23:37:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbfJ1Mht (ORCPT ); Mon, 28 Oct 2019 08:37:49 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45648 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbfJ1Mht (ORCPT ); Mon, 28 Oct 2019 08:37:49 -0400 Received: by mail-wr1-f66.google.com with SMTP id q13so9675386wrs.12 for ; Mon, 28 Oct 2019 05:37:47 -0700 (PDT) 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=2ymWEbRHSElzNbuDgsTAxIt0SPIxRdOmiGeksusZlhM=; b=icu0V3tx03OmBkcca8Z6qPTM+g+WBsmLC62jDZV98LF03Gh01rH58bOG9foikmkKUz 6MT5u/4sIeF8UY/fLTarKdv0J2nV8CdFkarPd4Mq4rtFdkD67aaturmImUrpQcVIxOKo lExGlkiVqVKa2/SyBpt+W0lnl/HAN57+hft002CSldIT4+gKBKVDyt/OkUR5ZFXbJZS8 TaWqp+YlmflzVLR6jyXldqxhFlJFvJgxHMos+wQ5Q7RUTFp++jDBiQVrvQMTpahI+L/b +pxdNszHt/cf9ovJ6/x2vqvIl6KfBgVM4jHospbUtbIhTZEh9P887pbmjcAfg3P98mVB O/Mw== 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=2ymWEbRHSElzNbuDgsTAxIt0SPIxRdOmiGeksusZlhM=; b=sZuQXYB9+4qogzh2qzTFfM5cR3OSuqRD/2qWesxLxwp6BxK5F0ER4lhqthTrRvlxgX EeXL58OIdTD0Wjg0rGXiJmNr2ZCuqHFZc9BqWjLYeH30idF6GaCEBia8RGhRLka21pKN +4c5w7It9oYX+b7U2deiAAOgmfZY+JAS2keeEwibC37QMa/RIPuKgnJTlWARfvo7ydY6 hRhwnGN+4clagRvW1DCDc/oo02WpyX9NYz+lnD9CYxka+yoqmyxiWg9Q5Cu2Y60Rhyx9 xozfunrEeZ6qtf6iwpJC9cJQo3SE9pj4806cZ5zJZoCfGVNJQ6HYW5gpPsus+vy5yFXm ccrA== X-Gm-Message-State: APjAAAU8IWE7ltgFPgcp/Cngz1N6dop33pKINybKQUJZUVJrQ55r4Uwh oEI3s0Fj33j07JuBncZmwRU= X-Google-Smtp-Source: APXvYqz04kjsxEAcAdJD5HKV9ccsMeQdCvjWpQurQhV2rNL5tLBaD5O6xZzys65f9IqRDbRp1DOhLw== X-Received: by 2002:adf:fec3:: with SMTP id q3mr14812954wrs.343.1572266266222; Mon, 28 Oct 2019 05:37:46 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id s10sm13109089wrr.5.2019.10.28.05.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 05:37:45 -0700 (PDT) From: Thierry Reding To: Thierry Reding Cc: Sachin Nikam , Puneet Saxena , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 12/12] drm/tegra: Optionally attach clients to the IOMMU Date: Mon, 28 Oct 2019 13:37:18 +0100 Message-Id: <20191028123718.3890217-13-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028123718.3890217-1-thierry.reding@gmail.com> References: <20191028123718.3890217-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 a client is already attached to an IOMMU domain that is not the shared domain, don't try to attach it again. This allows using the IOMMU-backed DMA API. Since the IOMMU-backed DMA API is now supported and there's no way to detach from it on 64-bit ARM, don't bother to detach from it on 32-bit ARM either. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/drm.c | 66 +++++++++++++++++++++++++++---------- drivers/gpu/drm/tegra/drm.h | 1 + 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index efc8a27b9e6a..56e5e7a5c108 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -20,10 +20,6 @@ #include #include -#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) -#include -#endif - #include "drm.h" #include "gem.h" @@ -908,30 +904,27 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra, int host1x_client_iommu_attach(struct host1x_client *client) { + struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev); struct drm_device *drm = dev_get_drvdata(client->parent); struct tegra_drm *tegra = drm->dev_private; struct iommu_group *group = NULL; int err; - if (tegra->domain) { - struct iommu_domain *domain; + /* + * If the host1x client is already attached to an IOMMU domain that is + * not the shared IOMMU domain, don't try to attach it to a different + * domain. This allows using the IOMMU-backed DMA API. + */ + if (domain && domain != tegra->domain) + return 0; + if (tegra->domain) { group = iommu_group_get(client->dev); if (!group) { dev_err(client->dev, "failed to get IOMMU group\n"); return -ENODEV; } -#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) - if (client->dev->archdata.mapping) { - struct dma_iommu_mapping *mapping = - to_dma_iommu_mapping(client->dev); - arm_iommu_detach_device(client->dev); - arm_iommu_release_mapping(mapping); - } -#endif - - domain = iommu_get_domain_for_dev(client->dev); if (domain != tegra->domain) { err = iommu_attach_group(tegra->domain, group); if (err < 0) { @@ -939,6 +932,8 @@ int host1x_client_iommu_attach(struct host1x_client *client) return err; } } + + tegra->use_explicit_iommu = true; } client->group = group; @@ -963,6 +958,7 @@ void host1x_client_iommu_detach(struct host1x_client *client) iommu_detach_group(tegra->domain, client->group); iommu_group_put(client->group); + client->group = NULL; } } @@ -1046,6 +1042,7 @@ void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, static int host1x_drm_probe(struct host1x_device *dev) { struct drm_driver *driver = &tegra_drm_driver; + struct iommu_domain *domain; struct tegra_drm *tegra; struct drm_device *drm; int err; @@ -1060,7 +1057,36 @@ static int host1x_drm_probe(struct host1x_device *dev) goto put; } - if (iommu_present(&platform_bus_type)) { + /* + * If the Tegra DRM clients are backed by an IOMMU, push buffers are + * likely to be allocated beyond the 32-bit boundary if sufficient + * system memory is available. This is problematic on earlier Tegra + * generations where host1x supports a maximum of 32 address bits in + * the GATHER opcode. In this case, unless host1x is behind an IOMMU + * as well it won't be able to process buffers allocated beyond the + * 32-bit boundary. + * + * The DMA API will use bounce buffers in this case, so that could + * perhaps still be made to work, even if less efficient, but there + * is another catch: in order to perform cache maintenance on pages + * allocated for discontiguous buffers we need to map and unmap the + * SG table representing these buffers. This is fine for something + * small like a push buffer, but it exhausts the bounce buffer pool + * (typically on the order of a few MiB) for framebuffers (many MiB + * for any modern resolution). + * + * Work around this by making sure that Tegra DRM clients only use + * an IOMMU if the parent host1x also uses an IOMMU. + * + * Note that there's still a small gap here that we don't cover: if + * the DMA API is backed by an IOMMU there's no way to control which + * device is attached to an IOMMU and which isn't, except via wiring + * up the device tree appropriately. This is considered an problem + * of integration, so care must be taken for the DT to be consistent. + */ + domain = iommu_get_domain_for_dev(drm->dev->parent); + + if (domain && iommu_present(&platform_bus_type)) { tegra->domain = iommu_domain_alloc(&platform_bus_type); if (!tegra->domain) { err = -ENOMEM; @@ -1104,7 +1130,7 @@ static int host1x_drm_probe(struct host1x_device *dev) if (err < 0) goto fbdev; - if (tegra->domain) { + if (tegra->use_explicit_iommu) { u64 carveout_start, carveout_end, gem_start, gem_end; u64 dma_mask = dma_get_mask(&dev->dev); dma_addr_t start, end; @@ -1132,6 +1158,10 @@ static int host1x_drm_probe(struct host1x_device *dev) DRM_DEBUG_DRIVER(" GEM: %#llx-%#llx\n", gem_start, gem_end); DRM_DEBUG_DRIVER(" Carveout: %#llx-%#llx\n", carveout_start, carveout_end); + } else if (tegra->domain) { + iommu_domain_free(tegra->domain); + tegra->domain = NULL; + iova_cache_put(); } if (tegra->hub) { diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index 28f2820a7371..d941553f7a3d 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -36,6 +36,7 @@ struct tegra_drm { struct drm_device *drm; struct iommu_domain *domain; + bool use_explicit_iommu; struct mutex mm_lock; struct drm_mm mm;