Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp345994lqp; Mon, 10 Jun 2024 06:09:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWPrIp6ZnQTzAn8H7+lN8TByDlwKoIyjrKmie+ubIWFZ5ggm8Yw94j8OYNw7ldD2+ylfeKP1fqL70r2w84fHqzpgh7MZQPsCf/PXGd7kg== X-Google-Smtp-Source: AGHT+IFX88pWTGB/dIXcdBvnyFGm0E9RUjfLXWBH8PgY2XzljAprBa5wYAUb4beqMdCoL9jj8i/h X-Received: by 2002:a17:90a:940e:b0:2c2:4109:9466 with SMTP id 98e67ed59e1d1-2c299985790mr17228592a91.8.1718024956165; Mon, 10 Jun 2024 06:09:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718024956; cv=pass; d=google.com; s=arc-20160816; b=A7ojj1VlGLQhkAEpOCjCD18GuXLBkEF3cp3UxV0ZNbgck2TEPOyNKaURC8qRgRc6yQ qHNCzT/wjEtV64tZfSXItkR1Cr0MuKNR2iRIgUDrXExSBNNKwoNGlSR8kHL5IQtbbbYR h/MPiW97pEud4V01hv4tpWBHq6I3O2kxfIYNjuDJefpsf9vO1Kp4cfAWRHoRxq+VSE9K gf2CxtnePdyKKhD7OVbQiGaTpkTv9evYb3K6CXSow83IsLRIWf4Z9PSa3LFaG1T9IPv5 N0ur/T3E1KkiPrFqjvf7UaIrIGE7AU9dVLb8jqoy3C4BJj47KqGeM6MhFw96XhZeGeMM iZzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5ek3WjndrkPVVqVs+Khkx9kCDyWrz8uFyDTMb2PwVXo=; fh=oMfgzkEw/ooUXqvARCgNaSZrpwGw5y27+DEhhPidNdU=; b=K1tj27CZk5gc4FW61LODJlcDxxBJNKcF9ByZUkorAbE1EGAb68EMfJkaVzjBNM+8a4 Sd2GqxpKwtUTsWFz+k8D0w3txQBzheZL6iT9WLsS9oQ/741aniOJ443Ct1AW50wrlbHG b2tHfu9SUHaTo68uqbiRBkoKzt1xW8A7RiHBTy/iU73IEZ5AEUlT3yLbpb+/yMrDsCNc AiqWbko0epvrYHuLuXa1LjkH4XquWhtgvRxo3VX6pPvQbTlyWByzyXO/j6WqiWjYi1nI 0Bbd+0jV8EhF8knPk/g0y24e6aNZO4OauCyHhddG3juRwjb6djRW6PMbyy/pLvTERTjU PeKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GwWZ25QR; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-207910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2c4de19bfsi4510863a91.105.2024.06.10.06.09.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GwWZ25QR; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-207910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 02FCBB2537B for ; Mon, 10 Jun 2024 09:05:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62242137C35; Mon, 10 Jun 2024 08:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GwWZ25QR" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 511B17C09E for ; Mon, 10 Jun 2024 08:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718009998; cv=none; b=S+ItXFBxR0ALjt76hLOy5jr+ZKKBlnrTAuROEBbeVEf2KBL8HRbD6CoWkNc9+nMIXiIC6cvZx8Xc3sFsmt5IqIMTBnQAVoI8OBTDj9C45cvjuX/ht5vsjdIioCKyXOLt8EF75pK4uQ1RaCQfkNww/SvAnTCZlhGG6QF5a5tO1nA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718009998; c=relaxed/simple; bh=I56l8aUrWEsOdJKWYfI6TJlpnl4t+tX3NQmfYGnyV7M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BeDWnhf1pujv5Dvy8rjWBUFUWOVxQz+sv7i2j2dCk62jsQIIJq+GCkpXGrhVnjIQl795DKLklBbbK+jAbEj/977+c/V1TH9xyMi/zeIycqdLCAJNDR+x63ODJIcGQ9incBVanUO05q3iUG6n8T0g9UV2sX+M496apoFAhXV+Apo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GwWZ25QR; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718009997; x=1749545997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I56l8aUrWEsOdJKWYfI6TJlpnl4t+tX3NQmfYGnyV7M=; b=GwWZ25QRKt38SZPrBw59wJMufvbOz2Wu90Bh+6iPI/li6jb6f+/K6ZHp lnQwn7dhazxM+ieIkO/TkYEegRvlG4uvGiCIOxUzD8IJuxzxy4skF5flD Ok50pwaSetJvrv3uQApPrFXx3ls5VXL3Ie8I+LyLQjSuEiP5woD+F8SB3 LMMhP7hplCN+l65AoAhVdBBZysf57Qu4tbcdVxN28GtQKTi2nyePUr5iV VPoqmKX/vNKp7zceUyuS4PcmM5Xu1wmlmmyV4tYlEF51+U8s9F+LHA6vR vblB5soDUY9KVRhpXUcxUKfLrEuhmDAx5NWRuW4BNPxEV79MynMW91ykB w==; X-CSE-ConnectionGUID: bH587zMWQNOziq7gB7Gpiw== X-CSE-MsgGUID: NMKR1Ws3TWCa+GVUi+x1YA== X-IronPort-AV: E=McAfee;i="6600,9927,11098"; a="17581990" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="17581990" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 01:59:56 -0700 X-CSE-ConnectionGUID: dSiXcWhERE2aZC+rbkMwCw== X-CSE-MsgGUID: zTw8PCNRSvSb9YRaNVvOxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="43433094" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa003.fm.intel.com with ESMTP; 10 Jun 2024 01:59:50 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Jeff Johnson , ath10k@lists.infradead.org, ath11k@lists.infradead.org, iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v3 19/21] drm/tegra: Remove call to iommu_domain_alloc() Date: Mon, 10 Jun 2024 16:55:53 +0800 Message-Id: <20240610085555.88197-20-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610085555.88197-1-baolu.lu@linux.intel.com> References: <20240610085555.88197-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.34.1