From patchwork Mon Aug 12 07:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13760250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC719C3DA7F for ; Mon, 12 Aug 2024 07:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=meC3v3SMbWghdUSWZfuvi30wu7qYUGsDueeLPF+5edg=; b=M2bm29AW1b+ica X5Tl691PsOrGnv10FKyGFfEnnvHnuJpb2BEX0Ta9ig1fRemlJ+o91JSJSsk/qF393vaG11F5Z9XUJ 9hC1lvlR/C1JhLCOKJGJSwh6kHpLBQFmwjCcNMIj+wshFc4Oa4Rqa8CsyHHvxT+nBeHvjI7lSGql7 I9REFAe9wI8SWVI7pj3EOE2j2e7p8axfATr9e4fCgSFWHOYAXacjabX6rsnpfUhoWpmZ7H8CcsAYC q3UKHGvpLgR5BROwLJlsEAMAfLMIW5o5sTtSfzSw35hYPP+A0qceo8WDAHFy317V7hd+9k7efEW5m Vd+Qn3LwbKrLcWqvyx1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdPHt-0000000H8CX-2URk; Mon, 12 Aug 2024 07:16:17 +0000 Received: from mgamail.intel.com ([192.198.163.14]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdPG3-0000000H7fP-3JYk; Mon, 12 Aug 2024 07:14:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723446863; x=1754982863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nLYeFCmV2sqj4+yCU6U1t0LxOTa1hw9jyckG6WHjQvg=; b=OSwn7sTvj2cTlQXSgkSAPekLJO14m+80E5oIqCtbM7ki3M9EKWfmDEL9 PNTzWIdgGucBjmHpodY2bUMfUBBW3twurMliPbm2bupTPYCDesc2/Lyus tINuH15t/1jjYYSlJwwt3lw9dH1+Kdda8i9OXMYCwfcFjFI6VlN9RVD0k YHgkTKwpaza2K9gEB5tfwXOYNpieEB1qOdTn7LFAOVEMTFEmyVm19M1Mw XjcR5L3qjY5f1MwMPrYsSY8c++reGHur8taGyg9Jz0ldcxp2q3GKvAueH Ad6H1o8WcQiLMB2RiKcN54aRhPsZ+8WZK1MeVAonhNDxr1C3HcLTU5Xj9 w==; X-CSE-ConnectionGUID: 0r7D1gRSTxWL1u2LoYIhsw== X-CSE-MsgGUID: kWoO//WyQzybLa1Fn35rgQ== X-IronPort-AV: E=McAfee;i="6700,10204,11161"; a="21711588" X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="21711588" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2024 00:14:23 -0700 X-CSE-ConnectionGUID: gDxvwbtUQGqyr6hrki+oVA== X-CSE-MsgGUID: EJqZOrj4S8WKg9ArWC+AEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="57823841" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 12 Aug 2024 00:14:17 -0700 From: Lu Baolu To: Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Daniel Vetter , Thierry Reding , Jonathan Hunter , Sandy Huang , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Mikko Perttunen , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-media@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 3/3] drm/tegra: Remove call to iommu_domain_alloc() Date: Mon, 12 Aug 2024 15:10:34 +0800 Message-Id: <20240812071034.9443-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812071034.9443-1-baolu.lu@linux.intel.com> References: <20240812071034.9443-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_001423_869104_2F07A694 X-CRM114-Status: GOOD ( 16.30 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Commit <17de3f5fdd35> ("iommu: Retire bus ops") removes iommu ops from the bus structure. The iommu subsystem no longer relies on bus for operations. So iommu_domain_alloc() interface is no longer relevant. Normally, iommu_paging_domain_alloc() could be a replacement for iommu_domain_alloc() if the caller has the right device for IOMMU API use. Unfortunately, this is not the case for this driver. Iterate the devices on the platform bus and find a suitable device whose device DMA is translated by an IOMMU. Then use this device to allocate an iommu domain. The iommu subsystem prevents domains allocated by one iommu driver from being attached to devices managed by any different iommu driver. Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20240610085555.88197-20-baolu.lu@linux.intel.com --- drivers/gpu/drm/tegra/drm.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 03d1c76aec2d..ee391f859992 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -1133,6 +1133,17 @@ static bool host1x_drm_wants_iommu(struct host1x_device *dev) return domain != NULL; } +static int iommu_mapped_device(struct device *dev, void *data) +{ + struct device **iommu_dev = data; + + if (!device_iommu_mapped(dev)) + return 0; + + *iommu_dev = dev; + return 1; +} + static int host1x_drm_probe(struct host1x_device *dev) { struct tegra_drm *tegra; @@ -1149,16 +1160,21 @@ static int host1x_drm_probe(struct host1x_device *dev) goto put; } - if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { - tegra->domain = iommu_domain_alloc(&platform_bus_type); - if (!tegra->domain) { - err = -ENOMEM; - goto free; + if (host1x_drm_wants_iommu(dev)) { + struct device *iommu_dev = NULL; + + bus_for_each_dev(&platform_bus_type, NULL, &iommu_dev, iommu_mapped_device); + if (iommu_dev) { + tegra->domain = iommu_paging_domain_alloc(iommu_dev); + if (IS_ERR(tegra->domain)) { + err = PTR_ERR(tegra->domain); + goto free; + } + + err = iova_cache_get(); + if (err < 0) + goto domain; } - - err = iova_cache_get(); - if (err < 0) - goto domain; } mutex_init(&tegra->clients_lock);