[PATCH v3 02/14] iommu/mediatek: Add probe_defer for smi-larb

From: Yong Wu
Date: Tue Sep 03 2019 - 05:38:32 EST


The iommu consumer should use device_link to connect with the
smi-larb(supplier). then the smi-larb should run before the iommu
consumer. Here we delay the iommu driver until the smi driver is
ready, then all the iommu consumer always is after the smi driver.

When there is no this patch, if some consumer drivers run before
smi-larb, the supplier link_status is DL_DEV_NO_DRIVER(0) in the
device_link_add, then device_links_driver_bound will use WARN_ON
to complain that the link_status of supplier is not right.

This is a preparing patch for adding device_link.

Signed-off-by: Yong Wu <yong.wu@xxxxxxxxxxxx>
---
drivers/iommu/mtk_iommu.c | 8 +++++++-
drivers/iommu/mtk_iommu_v1.c | 7 ++++++-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 400066d..b138b94 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -660,6 +660,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
for (i = 0; i < larb_nr; i++) {
struct device_node *larbnode;
struct platform_device *plarbdev;
+ bool larbdev_is_bound = false;
u32 id;

larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
@@ -676,7 +677,12 @@ static int mtk_iommu_probe(struct platform_device *pdev)
id = i;

plarbdev = of_find_device_by_node(larbnode);
- if (!plarbdev) {
+ if (plarbdev) {
+ device_lock(&plarbdev->dev);
+ larbdev_is_bound = device_is_bound(&plarbdev->dev);
+ device_unlock(&plarbdev->dev);
+ }
+ if (!plarbdev || !larbdev_is_bound) {
of_node_put(larbnode);
return -EPROBE_DEFER;
}
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 860926c..2034d72 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -601,10 +601,15 @@ static int mtk_iommu_probe(struct platform_device *pdev)

plarbdev = of_find_device_by_node(larb_spec.np);
if (!plarbdev) {
+ bool larbdev_is_bound;
+
plarbdev = of_platform_device_create(
larb_spec.np, NULL,
platform_bus_type.dev_root);
- if (!plarbdev) {
+ device_lock(&plarbdev->dev);
+ larbdev_is_bound = device_is_bound(&plarbdev->dev);
+ device_unlock(&plarbdev->dev);
+ if (!plarbdev || !larbdev_is_bound) {
of_node_put(larb_spec.np);
return -EPROBE_DEFER;
}
--
1.9.1