Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1388499lqj; Mon, 3 Jun 2024 22:51:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzB9n/Bu9QM8FPK0W2hDNkCb74ru0aHfMOgglfwNKevyIRz0GYh3iq5+KbfYDCLI5M6kMEdSalP4DNAwXfrreNJ8YwedlBLYmII3aZ0w== X-Google-Smtp-Source: AGHT+IHOeWpVSN6QVSjJ5ynMMrCady+eJHn11RwRXdnujDsOl5Hdd+ApwlNKG35WfUTNbq672mgh X-Received: by 2002:a05:6a00:4388:b0:702:33a4:53a5 with SMTP id d2e1a72fcca58-7024789cccamr12211323b3a.27.1717480294267; Mon, 03 Jun 2024 22:51:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717480294; cv=pass; d=google.com; s=arc-20160816; b=qt8xBCWceaQxxAsgYYL+Jx8BYD49FAV3SGdsgWF5oAIFPRGVW9XaV40iEjTmACLXBv B9N2/JcIkfzYZ709yx4QgwfjlRLS1uhLXgxQkndeaWe9M6g+Z50bnT+2UdgL3hrJhZhV FRrKHzwnHhqX3S2Zd2IUZbfNGkNNq4NeDS68LVAdVyA+OVqcojbhsxDq168UE6raD03j a6U6gzSPs+Za8LM3y2eKhVqQUDwnQbHhXfrqyLKSm4L5Dqx4RVAGlBAc0+7G0xr7XL6L bv2H17pXTKHk0QS+Df5jSD7Vkn1n32jdWDfiZINnFCsX7RuRbMn/nHbtV5q3/a+7xKOB VvhA== 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=u7VIfotmvhCnFPKh0R845OAh004BwcT1TGiZ1dQEGzo=; b=QUas4TlVRwtrGc22AjUAjA1FPOeRnwkk1aPDU4/PX3i8y4jIKY8ITCNchnG1GfqLS3 W7v+nJqAWmnRnrmxJ8gozgCAEoHPM/Zx+S/40zZm35srmmnAbrX6YlIqBgHTI/TV9FHO a2jD8yAvhlIVGnd7r+P6610BJaC75l+UWdprkJGs8zSLEyCE+J1mKhO0kd3+LHda1uaz +HrLWYrsfvZCl6VXg3Q332i8r6SZek+bT69uF4SK/nGgVbxH9DSYoQ7QGYmpEQvlMEuD acEOzqfjGAxuxRABam462Nx40XvKSlW5VE2x5SbGOktQtqRvNWCflQjqYP0ewVUE4M9o y+kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H9g6H+yi; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-199937-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199937-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35c552765si7521642a12.685.2024.06.03.22.51.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 22:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199937-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H9g6H+yi; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-199937-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199937-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 98D4528D72A for ; Tue, 4 Jun 2024 01:58:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8105E142903; Tue, 4 Jun 2024 01:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="H9g6H+yi" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 668B513D62A for ; Tue, 4 Jun 2024 01:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466136; cv=none; b=tb1mioFb/VQMuVqTSCAnCsCy4f+/IedOvOXYXhmpvW6PtLBVv6AN/XJKOVomVfOd0XF2j/uKJy0Zoy/Cc3GI2yBzG0w6gPT3GzbEdvPCZ2nIyeAl2fSs1UFe1GudIWu5cQ7MUeQHUOIvMYACXmc0Z1by3ZPbvzuhzqMDmUCl/jQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466136; c=relaxed/simple; bh=I56l8aUrWEsOdJKWYfI6TJlpnl4t+tX3NQmfYGnyV7M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kpmqPYaiQgdlnNxTG25aODF6YCNqLzD+g3I/FURSVQo9jGG3aeeIaQsTjTbsAyKqxLAmbpzIPQXFaXhzPXyi/JA0Egn5qEJNhhQPe9U6vt8AFjCmnrOZkJHMUTl6yNg7XYQO2DpvGDlLyaabLpO5WQoak2d5H08v0r2N8ofVeSQ= 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=H9g6H+yi; arc=none smtp.client-ip=192.198.163.10 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=1717466135; x=1749002135; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I56l8aUrWEsOdJKWYfI6TJlpnl4t+tX3NQmfYGnyV7M=; b=H9g6H+yiPOB+1V2jTkmFFiAiqZ1HzZjoDyd2PhjIe/JuqavYVZ0GBhu2 JsmIY03EuEpCHVbo6AJTitWDqaWaiUgRl3oVy7lT00cGj6v1Z+ilmn5Ip XKfLU/BdQaOxu8qlQI8xDsi1gNnX/4RX9LbYmiGQjQQoSDL86uHamN8ti HaX6rVNghyK4O/oBJgzVU67jQw6Z5BgBjyLENLutHMXU/mMjKnVVKpTCB TSNRMLZX50Ujeb/6/xvkKPHZkrkwzJ2vWMCW4J1Bi2afCZq+35Sj6MP4G jxM2QBOkndyH0gnHyI003e55hC0olphoPqqrRS8Z4yIA58jbuTbwzFG3r Q==; X-CSE-ConnectionGUID: Rl5XRdtuQe6Gg0rZu6FJSg== X-CSE-MsgGUID: S0nU5liwTuKMTdv3NDztmw== X-IronPort-AV: E=McAfee;i="6600,9927,11092"; a="25385189" X-IronPort-AV: E=Sophos;i="6.08,212,1712646000"; d="scan'208";a="25385189" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2024 18:55:35 -0700 X-CSE-ConnectionGUID: iy5Ha6XGSomqRxRqbU9xMQ== X-CSE-MsgGUID: 0J02TVC8Qyu9oAdvu9xQyg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,212,1712646000"; d="scan'208";a="37662052" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by orviesa008.jf.intel.com with ESMTP; 03 Jun 2024 18:55:31 -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 , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 20/22] drm/tegra: Remove call to iommu_domain_alloc() Date: Tue, 4 Jun 2024 09:51:32 +0800 Message-Id: <20240604015134.164206-21-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240604015134.164206-1-baolu.lu@linux.intel.com> References: <20240604015134.164206-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