From patchwork Mon Aug 12 07:10:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 819044 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 CD82514C5BA; Mon, 12 Aug 2024 07:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446854; cv=none; b=tczw5ZT99zaEdfS2l9xrA1oEl4EcPvN09x4XBmBAHpSLxnM6x9+wL6fBUkRbfBlWZGYauEstQHmieSvim3TqFMC8I+qpCB0BuPZNLpOev2YeQcn3Uet83Z5uhISDN1m+L8d9ESp2UNP1qjvQCArn5fPYJvD0sx8TeDyOkEJaI6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446854; c=relaxed/simple; bh=2W/be8VISRZC7fVoJ9VGu3iMrIsNaD0YF4i34a1dFE4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Hi1jiEp482Y8fczYkru+oS53uT45E9M0clsiPrzeHgcB9Zv9Md52v8KcEGcC5NUFvM0loIA9M14dYhijbEQdfz82dS3/jBF+BVbin9VM/6l7vkgDHyaZwpp4pPfeuBmM3K/0inovoLjBYCXRHdPI4Nx7KT5B2UOB1VYLbasMIQM= 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=R56Zd5iG; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="R56Zd5iG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723446853; x=1754982853; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2W/be8VISRZC7fVoJ9VGu3iMrIsNaD0YF4i34a1dFE4=; b=R56Zd5iGKYcoDTzZpVbxZJRuAhRSHaMpGDDN01Na6WgPSaRoYAPmvlQZ hp1gmqFluhh4EgSio8eXNYSy0eViq1dCJVVZtI1/nRcdgSCj0PI7nxfSx OWGm8F0FXJ75cFLdtgPYzAYBFMqpA/tchRfDGGFrFFZnNVbUz8ls+SYqj F3k/pLWMgXCUgMAqF3i9p9nNTl8LM+NcK7daxTQVcmjceXMF6sFe8LzQT DClw8M4qlW6sWjY8xiy9fsyf2HuvMym+CdxLsX3I5fQsVCwq1jdzO2285 RWUtZRlRu1z5bbCRpTIKQSMYYPGiw7YGyujqKBTzZzbFK/t6NsBil4tY4 A==; X-CSE-ConnectionGUID: BrTaaed6Sm6RLhOkk3hKHA== X-CSE-MsgGUID: 4oz61V0CSPK3EtY/FlRQ3g== X-IronPort-AV: E=McAfee;i="6700,10204,11161"; a="21711537" X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="21711537" 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:11 -0700 X-CSE-ConnectionGUID: OLEmc47wRB6veAq2mjcdLw== X-CSE-MsgGUID: r/FxCR4NT760l1EVOg/r5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="57823793" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 12 Aug 2024 00:14:06 -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 1/3] drm/nouveau/tegra: Use iommu_paging_domain_alloc() Date: Mon, 12 Aug 2024 15:10:32 +0800 Message-Id: <20240812071034.9443-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In nvkm_device_tegra_probe_iommu(), a paging domain is allocated for @dev and attached to it on success. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20240610085555.88197-7-baolu.lu@linux.intel.com --- drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c index 87caa4a72921..763c4c2925f9 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c @@ -120,8 +120,8 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev) mutex_init(&tdev->iommu.mutex); if (device_iommu_mapped(dev)) { - tdev->iommu.domain = iommu_domain_alloc(&platform_bus_type); - if (!tdev->iommu.domain) + tdev->iommu.domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(tdev->iommu.domain)) goto error; /* From patchwork Mon Aug 12 07:10:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 818720 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 923BE1607B8; Mon, 12 Aug 2024 07:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446859; cv=none; b=EtSMqBulaeMiQQlQ1aUTs+NrF2LvSpuL/63BPDvDLKkjeEm2Hmt/dOEfCgXX3SGPqHqWS8A+tM66VLcH4F7r6KsMDd9sbgdecOtzuVgY9FmOP3f8LPqxHgYBMTBPT1SZK20RdwJaw89mulPvXfiFHvZ8vHQUnr5trf4syly7HjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446859; c=relaxed/simple; bh=ugPZI6M1TvdJVOqkCaWpsQPcKmLp14vmdPpzyb0jTXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PwY6NSpRTbxeEy1F12nw+TiGeH3jojY+5GFWfLX+zVKUTr5595vokanD1DX9CKcexJKDfIfhw4x1BK8bago8tjrOXjYeKl785pr1uz9sFhkAO+JniLZ7kXkGiYTZAsH60zvzRsmSpIDyI3H6xe37aXAra1Wx25OsQEmZwYlRpQM= 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=fEtQoajw; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fEtQoajw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723446857; x=1754982857; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ugPZI6M1TvdJVOqkCaWpsQPcKmLp14vmdPpzyb0jTXA=; b=fEtQoajwEwEBBPvt9JNuAolVRFSpRZBXjBQtobHiiJMGmykqBBmUb8Ji dUU3DlKZQYsKoEJHFTQyVSvaht0chuDNuvzNN3B88gQUgJcxlxUdy6TVV YHdMElkJ7mOzoQP6Q3llcwXsnRzEKRrUj1mN2ACfSbzpMYyN5cJSC/KN0 VOGMYLlDrrzsrsY4Pi5ZKteK54Hkd8t/fmIaNH9OspWjL60ZMFpWyqhVw 5OanrckripR/V6eOnc6LepHYkxgIkfpPY0QXkpH/BJfWxmKXVrQYUZxKD utlqtTCuEJnw1/nYH6PtBeP1YJVPJmnv3qGieZIC2AfdNRh07ZRupPGXx g==; X-CSE-ConnectionGUID: vQkOPWYhRl6ca9NwzWwZvw== X-CSE-MsgGUID: nSEio8ORQzGsrxlf9qBDoQ== X-IronPort-AV: E=McAfee;i="6700,10204,11161"; a="21711559" X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="21711559" 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:17 -0700 X-CSE-ConnectionGUID: 20gV+VxOTN66vkWjO4j+TA== X-CSE-MsgGUID: j+8tsWuwRpO5z66lvcz4BQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="57823816" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 12 Aug 2024 00:14:11 -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 , Jason Gunthorpe Subject: [PATCH 2/3] drm/rockchip: Use iommu_paging_domain_alloc() Date: Mon, 12 Aug 2024 15:10:33 +0800 Message-Id: <20240812071034.9443-2-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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit <421be3ee36a4> ("drm/rockchip: Refactor IOMMU initialisation") has refactored rockchip_drm_init_iommu() to pass a device that the domain is allocated for. Replace iommu_domain_alloc() with iommu_paging_domain_alloc() to retire the former. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20240610085555.88197-19-baolu.lu@linux.intel.com --- drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 44d769d9234d..11e5d10de4d7 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -103,13 +103,17 @@ static int rockchip_drm_init_iommu(struct drm_device *drm_dev) struct rockchip_drm_private *private = drm_dev->dev_private; struct iommu_domain_geometry *geometry; u64 start, end; + int ret; if (IS_ERR_OR_NULL(private->iommu_dev)) return 0; - private->domain = iommu_domain_alloc(private->iommu_dev->bus); - if (!private->domain) - return -ENOMEM; + private->domain = iommu_paging_domain_alloc(private->iommu_dev); + if (IS_ERR(private->domain)) { + ret = PTR_ERR(private->domain); + private->domain = NULL; + return ret; + } geometry = &private->domain->geometry; start = geometry->aperture_start; 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: 819043 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 DD2881547CB; Mon, 12 Aug 2024 07:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446865; cv=none; b=LnzMjv4AA+2dsP0v4aAtTKE29Yh8jmIGZiq4+U62XCjhoZVw8hPWbXyNOooWLBI3haPzNh330Uvko9N2B+9/s+XAk0evNZj0uXVGRXOx2EIQixErHuPrHSyMI0y1gJyGrGE8p/u0Yl6H2XOxLovEsBWVZVzgywBiGEWVM+Rrd8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723446865; c=relaxed/simple; bh=nLYeFCmV2sqj4+yCU6U1t0LxOTa1hw9jyckG6WHjQvg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xc4jkIBXInVVbS7QhqwnR9PAZ9GiYS5mbQM7G7JvF3BJDemjCQ1y2MmWCG0r9hIWdAi2nMKZ3VHpjHbfhQrRE/8IyGnrHZ2q7zDP5NNuaVpg/HMD9BKgCtL6tYMKj5j6YJN8fmyamsNqgzhEjpkzck5nFfeNTt81Wh063ohEahU= 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=DqvqL9c7; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DqvqL9c7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723446864; x=1754982864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nLYeFCmV2sqj4+yCU6U1t0LxOTa1hw9jyckG6WHjQvg=; b=DqvqL9c7bVT8n41u/UjrSOHj79S6IxA4cMPa2HVxKv8yRZsS1DCYKA0t vc8ferCqGO1qzNCBQ+dhVBkeiAbs6Lfs5PEZPTKc/KPA4JMg3trJj4Yg6 t9VXlsi6NTXaNc1RmsL47o94FmlQE92LM+YijjZHQKqk8Xf5r8iEkk6SZ 98rKSIXrv72sptOAJf2HulgmjzrOa2BCqWPFFQzM3JxLBRGXkh/+qod0J LLLgrVQRrsCa7Lio9xwx8AyLT8xlDLfL6XFNj651TSNg18lCFRIMnQ8Lj IZbCJrtYdiJGz1fthUI1LWYz3QDuIbmBrICUx3rI1rFoEbSqPH6WQ96/I Q==; X-CSE-ConnectionGUID: XH9ypoG1RGqNmYiGxoaPfQ== X-CSE-MsgGUID: AHCAIQ1XTKO74/OPm3SbLw== X-IronPort-AV: E=McAfee;i="6700,10204,11161"; a="21711590" X-IronPort-AV: E=Sophos;i="6.09,282,1716274800"; d="scan'208";a="21711590" 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);