Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp257330pxu; Wed, 25 Nov 2020 02:16:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmcHUs6pU+wBQMVU11YRN2kjkM5r15LVszwj1My6yDeKqCBYzUnoZQ8DwNKiWsTu7BKx4j X-Received: by 2002:aa7:d601:: with SMTP id c1mr2673787edr.323.1606299388784; Wed, 25 Nov 2020 02:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606299388; cv=none; d=google.com; s=arc-20160816; b=xd/9hTYHxzCaSFNsiT6twaUycISSxThrviLMcsWlLvgl5WiBiUncu+MOxylm07Mb4j skfy94YTUzeRfFh7VJ+MkjmPWnAj9gfwRDntM67U87CTZPjTB78wCf0eajwNbawJ2zmY yo1rGfSndzXb7uBZWKZQ64dxQmivb2P0HTKREyapyISVl202IO9poG7jmooNWV34hgT8 V4wloipaY3YO29vNDIyhPlnncmo2Nb7qXw12j/2GY+rlZNOTS5i4jBY2FqVu07p4eXOV XefcGEeAJNZzxeNyT+ln8opIAwe0BI/mMmGcyP8PTsZSE7Fgx7LomgoxzESCTN0yAzfH dYww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=HoasHv3y6th/yvEKkLA5l4WpDaFfWmVWvaf3/EksU3s=; b=h16PWLoS+iGPCS4OHsZkFCik2MdkOEwXS0b+UhM78DcMLojRGFMFNdh8S0vCqzf7B/ hjFA6H2AIA1cAAzRU6P5FQ2HJdA0pwkXOCaBkkOaGzp4crfVs3kpsUMtrrYdDDsuq1i/ SzuWwuVwcTjiTdIg7dvRTVMUa+vSzrQ9NwwUSjMVnQ0gtrgpXwFYFomTfZNkkV+GYYix k1cUhGwUqKFRW3juDdNQC+CCZCz7DD6OwF3cWbgoly155CzC1GYu23g+PzhVSemBtgjb 0RLlbPsjJXlIeaPFJRpSD/YxhXBOtt/OUgncE9AIk4vCdiqWjkRIYMPqxjKYGYGf/xxq qCDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EvMPkn9i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si1001421ejv.10.2020.11.25.02.16.06; Wed, 25 Nov 2020 02:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EvMPkn9i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729004AbgKYKL4 (ORCPT + 99 others); Wed, 25 Nov 2020 05:11:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728953AbgKYKLz (ORCPT ); Wed, 25 Nov 2020 05:11:55 -0500 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABBE2C0613D6; Wed, 25 Nov 2020 02:11:55 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id l1so878134pld.5; Wed, 25 Nov 2020 02:11:55 -0800 (PST) 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; bh=HoasHv3y6th/yvEKkLA5l4WpDaFfWmVWvaf3/EksU3s=; b=EvMPkn9iIXJjwCLoEKVFo7ymURGwzfJq3//6UucjvYZMhdT94vVL3PaXw5KMgtH2HG uagBLZTSmlFHKunUzHtH9QcFYVUU05ey9owWvW1hvNv7fkBImHGzgaSSwbWy0yLtMxfc N2+uhaUtRnvdgY2GqZ+hBHbezztseKyK+1ovIHrdUBPxS73skE92iEQyekAVXkC5+7gV OvwhIyFE6b6LL15TZxIXwgxpy0Qeg5b52qzI2jvUKTfCxK8iVBwtPQcQjsvy2p08YLzT GDxTbOFGldJO1Z8z/6VX//56QIOWV1vY56ZPlRHbDUyNXvUJ1kwLeOG8HxBiSErd08E7 XRuA== 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; bh=HoasHv3y6th/yvEKkLA5l4WpDaFfWmVWvaf3/EksU3s=; b=Q8/5yNjuwVa3J3FuadsidkOt9nhi9ac7FoSEYvpqEwKCSXHB/46HPZpaj/A+znWnvx YJeYS1sELVQvaWoaQ+VdtOkxDXz9G7BWKn4k8NkaXd8Sd6FdYpwIMg/NRh0WpbO80jTG DF3+d0fT194WwVEVrvH2gdhwoOL7ny7dcYpIGA2ApBWmjaNVDVTWAEG4xXWWGsD6YjKT wiyZWXplj+B6P3ni95e1HgZQAzWh8MZh1oSTeDZJLK7fyFRzdcbMbYaMWDDSN9DjaIrz N72kX/hiDsPZ5XMpaOe1zMdy+ptLaOjiEjxXfWTlsRMmaYXm0fxr4THN4S1jDgRYRg6p V5aw== X-Gm-Message-State: AOAM530scYzrVoNuSz4fSWZNN9M4B7bdrNzJGAUMYYWOVEo2DRn/yw+M DMrmxbMUWA0wlhqH7xQj0a4= X-Received: by 2002:a17:902:26a:b029:d6:caca:620a with SMTP id 97-20020a170902026ab02900d6caca620amr2527900plc.46.1606299115271; Wed, 25 Nov 2020 02:11:55 -0800 (PST) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id r130sm1599496pfc.41.2020.11.25.02.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 02:11:54 -0800 (PST) From: Nicolin Chen To: will@kernel.org Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-tegra@vger.kernel.org, jonathanh@nvidia.com, vdumpa@nvidia.com, thierry.reding@gmail.com, joro@8bytes.org Subject: [PATCH RESEND v2 5/5] iommu/tegra-smmu: Add PCI support Date: Wed, 25 Nov 2020 02:10:13 -0800 Message-Id: <20201125101013.14953-6-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201125101013.14953-1-nicoleotsuka@gmail.com> References: <20201125101013.14953-1-nicoleotsuka@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch simply adds support for PCI devices. Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko Acked-by: Thierry Reding Signed-off-by: Nicolin Chen --- drivers/iommu/tegra-smmu.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index f45ed43cf8db..4a3f095a1c26 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -865,7 +866,11 @@ static struct iommu_group *tegra_smmu_device_group(struct device *dev) group->smmu = smmu; group->soc = soc; - group->group = iommu_group_alloc(); + if (dev_is_pci(dev)) + group->group = pci_device_group(dev); + else + group->group = generic_device_group(dev); + if (IS_ERR(group->group)) { devm_kfree(smmu->dev, group); mutex_unlock(&smmu->lock); @@ -1075,22 +1080,32 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev, iommu_device_set_fwnode(&smmu->iommu, dev->fwnode); err = iommu_device_register(&smmu->iommu); - if (err) { - iommu_device_sysfs_remove(&smmu->iommu); - return ERR_PTR(err); - } + if (err) + goto remove_sysfs; err = bus_set_iommu(&platform_bus_type, &tegra_smmu_ops); - if (err < 0) { - iommu_device_unregister(&smmu->iommu); - iommu_device_sysfs_remove(&smmu->iommu); - return ERR_PTR(err); - } + if (err < 0) + goto unregister; + +#ifdef CONFIG_PCI + err = bus_set_iommu(&pci_bus_type, &tegra_smmu_ops); + if (err < 0) + goto unset_platform_bus; +#endif if (IS_ENABLED(CONFIG_DEBUG_FS)) tegra_smmu_debugfs_init(smmu); return smmu; + +unset_platform_bus: __maybe_unused; + bus_set_iommu(&platform_bus_type, NULL); +unregister: + iommu_device_unregister(&smmu->iommu); +remove_sysfs: + iommu_device_sysfs_remove(&smmu->iommu); + + return ERR_PTR(err); } void tegra_smmu_remove(struct tegra_smmu *smmu) -- 2.17.1