From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linuxarm@huawei.com, mauro.chehab@huawei.com,
Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
John Stultz <john.stultz@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org
Subject: [PATCH 04/16] iommu: hisi_smmu_lpae: rebase it to work with upstream
Date: Mon, 17 Aug 2020 09:50:03 +0200 [thread overview]
Message-ID: <01f0e50095605755d105d5cbc3fc0ac7850e5906.1597650455.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1597650455.git.mchehab+huawei@kernel.org>
Currently, this driver OOPSes. It turns that this driver
needs to be updated in order to work with the current
iommu kAPI.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
drivers/staging/hikey9xx/hisi_smmu.h | 2 +
drivers/staging/hikey9xx/hisi_smmu_lpae.c | 81 ++++++++++++++++++++---
2 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/hikey9xx/hisi_smmu.h b/drivers/staging/hikey9xx/hisi_smmu.h
index 4637244dba6b..bd3ee53735bd 100644
--- a/drivers/staging/hikey9xx/hisi_smmu.h
+++ b/drivers/staging/hikey9xx/hisi_smmu.h
@@ -89,6 +89,8 @@ struct hisi_smmu_device_lpae {
unsigned long va_pgtable_addr;
phys_addr_t smmu_phy_pgtable_addr;
smmu_pgd_t *smmu_pgd;
+
+ struct iommu_device iommu;
};
struct hisi_map_tile_position_lpae {
diff --git a/drivers/staging/hikey9xx/hisi_smmu_lpae.c b/drivers/staging/hikey9xx/hisi_smmu_lpae.c
index b411ca97f2c2..5acde3ddbd99 100644
--- a/drivers/staging/hikey9xx/hisi_smmu_lpae.c
+++ b/drivers/staging/hikey9xx/hisi_smmu_lpae.c
@@ -724,30 +724,73 @@ static size_t hisi_smmu_unmap_tile_lpae(struct iommu_domain *domain,
return hisi_smmu_unmap_lpae(domain, iova, size, NULL);
}
+static bool hisi_smmu_capable(enum iommu_cap cap)
+{
+ return false;
+}
+
+static int hisi_smmu_add_device(struct device *dev)
+{
+ struct hisi_smmu_device_lpae *iommu = hisi_smmu_dev;
+ struct iommu_group *group;
+
+ if (iommu)
+ iommu_device_link(&iommu->iommu, dev);
+ else
+ return -ENODEV;
+
+ group = iommu_group_get_for_dev(dev);
+ if (IS_ERR(group))
+ return PTR_ERR(group);
+
+ iommu_group_put(group);
+
+ return 0;
+}
+
+static void hisi_smmu_remove_device(struct device *dev)
+{
+ struct hisi_smmu_device_lpae *iommu = hisi_smmu_dev;
+
+ if (iommu)
+ iommu_device_unlink(&iommu->iommu, dev);
+
+ iommu_group_remove_device(dev);
+}
+
static struct iommu_ops hisi_smmu_ops = {
+ .capable = hisi_smmu_capable,
.domain_alloc = hisi_smmu_domain_alloc_lpae,
.domain_free = hisi_smmu_domain_free_lpae,
+ .attach_dev = hisi_attach_dev_lpae,
+ .detach_dev = hisi_detach_dev_lpae,
.map = hisi_smmu_map_lpae,
.unmap = hisi_smmu_unmap_lpae,
- .attach_dev = hisi_attach_dev_lpae,
- .detach_dev = hisi_detach_dev_lpae,
.iova_to_phys = hisi_smmu_iova_to_phys_lpae,
+ .add_device = hisi_smmu_add_device,
+ .remove_device = hisi_smmu_remove_device,
+ .device_group = generic_device_group,
.pgsize_bitmap = SMMU_PAGE_SIZE,
- .map_tile = hisi_smmu_map_tile_lpae,
- .unmap_tile = hisi_smmu_unmap_tile_lpae,
+ .map_tile = hisi_smmu_map_tile_lpae,
+ .unmap_tile = hisi_smmu_unmap_tile_lpae,
};
static int hisi_smmu_probe_lpae(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ int ret;
dbg("enter %s\n", __func__);
hisi_smmu_dev = devm_kzalloc(dev,
sizeof(struct hisi_smmu_device_lpae), GFP_KERNEL);
- hisi_smmu_dev->smmu_pgd = devm_kzalloc(dev, SZ_64, GFP_KERNEL | __GFP_DMA);
- if (!hisi_smmu_dev)
+ hisi_smmu_dev->smmu_pgd = devm_kzalloc(dev, SZ_64,
+ GFP_KERNEL | __GFP_DMA);
+ if (!hisi_smmu_dev) {
+ ret = -ENOMEM;
goto smmu_device_error;
+ }
+
hisi_smmu_dev->dev = dev;
INIT_LIST_HEAD(&hisi_smmu_dev->domain_list);
spin_lock_init(&hisi_smmu_dev->lock);
@@ -756,18 +799,39 @@ static int hisi_smmu_probe_lpae(struct platform_device *pdev)
hisi_smmu_dev->smmu_phy_pgtable_addr =
virt_to_phys(hisi_smmu_dev->smmu_pgd);
- printk(KERN_ERR "%s, smmu_phy_pgtable_addr is = %llx\n", __func__, hisi_smmu_dev->smmu_phy_pgtable_addr);
+ dev_info(&pdev->dev, "%s, smmu_phy_pgtable_addr is = 0x%llx\n",
+ __func__, hisi_smmu_dev->smmu_phy_pgtable_addr);
hisi_smmu_dev->va_pgtable_addr = (unsigned long)(hisi_smmu_dev->smmu_pgd);
+
+ ret = iommu_device_sysfs_add(&hisi_smmu_dev->iommu, NULL, NULL,
+ "hisi-iommu");
+ if (ret)
+ goto fail_register;
+
+ iommu_device_set_ops(&hisi_smmu_dev->iommu, &hisi_smmu_ops);
+
+ ret = iommu_device_register(&hisi_smmu_dev->iommu);
+ if (ret) {
+ dev_info(&pdev->dev, "Could not register hisi-smmu\n");
+ goto fail_register;
+ }
+
bus_set_iommu(&platform_bus_type, &hisi_smmu_ops);
return 0;
+fail_register:
+ iommu_device_sysfs_remove(&hisi_smmu_dev->iommu);
+
smmu_device_error:
- return -ENOMEM;
+ return ret;
}
static int hisi_smmu_remove_lpae(struct platform_device *pdev)
{
+ iommu_device_unregister(&hisi_smmu_dev->iommu);
+ iommu_device_sysfs_remove(&hisi_smmu_dev->iommu);
+
return 0;
}
@@ -779,7 +843,6 @@ MODULE_DEVICE_TABLE(of, hisi_smmu_of_match_lpae);
static struct platform_driver hisi_smmu_driver_lpae = {
.driver = {
- .owner = THIS_MODULE,
.name = "hisi-smmu-lpae",
.of_match_table = of_match_ptr(hisi_smmu_of_match_lpae),
},
--
2.26.2
next prev parent reply other threads:[~2020-08-17 7:51 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 7:49 [PATCH 00/16] IOMMU driver for Kirin 960/970 Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 01/16] iommu: add support for HiSilicon Kirin 960/970 iommu Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 02/16] iommu: hisilicon: remove default iommu_map_sg handler Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 03/16] iommu: hisilicon: map and unmap ops gained new arguments Mauro Carvalho Chehab
2020-08-17 7:50 ` Mauro Carvalho Chehab [this message]
2020-08-17 7:50 ` [PATCH 05/16] iommu: hisi_smmu: remove linux/hisi/hisi-iommu.h Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 06/16] iommu: hisilicon: cleanup its code style Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 07/16] iommu: hisi_smmu_lpae: get rid of IOMMU_SEC and IOMMU_DEVICE Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 08/16] iommu: get rid of map/unmap tile functions Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 09/16] iommu: hisi_smmu_lpae: use the right code to get domain-priv data Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 10/16] iommu: hisi_smmu_lpae: convert it to probe_device Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 11/16] iommu: add Hisilicon Kirin970 iommu at the building system Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 12/16] iommu: hisi_smmu_lpae: cleanup printk macros Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 13/16] iommu: hisi_smmu_lpae: make OF compatible more standard Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 14/16] dt: add an spec for the Kirin36x0 SMMU Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 15/16] dt: hi3670-hikey970.dts: load the SMMU driver on Hikey970 Mauro Carvalho Chehab
2020-08-17 7:50 ` [PATCH 16/16] staging: hikey9xx: add an item about the iommu driver Mauro Carvalho Chehab
2020-08-17 8:21 ` [PATCH 00/16] IOMMU driver for Kirin 960/970 Christoph Hellwig
2020-08-17 9:27 ` Mauro Carvalho Chehab
2020-08-17 9:31 ` Christoph Hellwig
2020-08-17 9:37 ` Greg Kroah-Hartman
2020-08-17 10:46 ` Mauro Carvalho Chehab
2020-08-17 10:53 ` Greg Kroah-Hartman
2020-08-17 12:59 ` Joerg Roedel
2020-08-18 14:47 ` Robin Murphy
2020-08-18 15:29 ` Mauro Carvalho Chehab
2020-08-18 16:26 ` Robin Murphy
2020-08-18 22:02 ` John Stultz
2020-08-19 10:12 ` Robin Murphy
2020-08-19 10:28 ` Mauro Carvalho Chehab
2020-08-19 11:33 ` Robin Murphy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=01f0e50095605755d105d5cbc3fc0ac7850e5906.1597650455.git.mchehab+huawei@kernel.org \
--to=mchehab+huawei@kernel.org \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mani@kernel.org \
--cc=mauro.chehab@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).