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: 11215293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37B8C13B1 for ; Mon, 28 Oct 2019 12:37:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 201E5208C0 for ; Mon, 28 Oct 2019 12:37:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 201E5208C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCCB26E827; Mon, 28 Oct 2019 12:37:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0E7266E821 for ; Mon, 28 Oct 2019 12:37:27 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id w9so8950869wmm.5 for ; Mon, 28 Oct 2019 05:37:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oCHEmXXyh53/Om/kiUXuXh86NdIS0vexI4+H1W2Xp5I=; b=F6mL2p5bvg9VnQXdURDsh0Snmnf6eFN9C6C0YNjOprDscIgDbE/D57UzlFAhbCk+Ma Z+7WDIMOSkzCedMsyzhfAhCbIcd1UT3/cELfW2HTN89VSbBbKDVdslzOqxlE/YGbUK71 UnpMrd0e/vb2lUToWjPsx2NTPBel9bZAPsre+AAlrjR7ob1sxDCX5/+Q8OxtfsJHdKC2 BPEYhLFq9Zj2N99m8/e+vyPEkCMsDVStGjF1tdjvIFTjy3dGV3e2K0MS4q1FbsNb+/Ve qgyNVALnyBNEvfz+Oz1BP/Nglx0MVAECiRv3Mp0B8xNNuA42ExyGq1nXoilKcdNhrRGN cvJw== X-Gm-Message-State: APjAAAX0JWkUgisXIfm/hhs2J6udlZTgZyZsl/6NwDfXYpPN/kH7jd03 ccANDeJAfkyrl1kmFEApslU= 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 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 X-Mailman-Original-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-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-tegra@vger.kernel.org, Sachin Nikam , dri-devel@lists.freedesktop.org, Puneet Saxena Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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;