Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1734456ybe; Tue, 3 Sep 2019 02:41:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzguTmzZxRI5PIhf1zoPddgObMuRLbEhPGURTffBBfxfKFv1n5S5PULciBgr0yZUJ0y0H46 X-Received: by 2002:a17:902:346:: with SMTP id 64mr34448470pld.151.1567503691054; Tue, 03 Sep 2019 02:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567503691; cv=none; d=google.com; s=arc-20160816; b=shDYNQhVoNru302rWS57kEk2Q2IsL8mQ30qDuwgeFO/in5IHCCY1myWJwTjVmJt6So 7C8jgiP3tBq8NbB1wYIIV+EdNI6FOkakd1lVfMN7HLz9NgaVWO94yde6dpoPlJE3iE+6 rFiEwKbi/FgSGjJfl46pZ/13kmvNG9X4KcY3DC/XKYqD/7p+LVig4BGkBqggEKr6QAQn AO8ErgUB/mrqZ9LfoGxLXqwpHITe4bM/LQwtZ8B+jiN0ovg3sGwVmJ//i9UxRgU2bi4C tJ788g99fSuljP5Oiov/dGon77013DFahT1yAuAypzay8FwLgAvmQKu1vS9/rpSu05IR tXYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=keEu6GJq0r5g1jMWvaCBqCiH+hzFMmklJ1aWgc4735A=; b=KPG+wJu/XUdjtS+WLwXt3WUaQl3nM5t4fIfug1skcXrRbMJldIlB6F1Ppqd1BGqA+1 flSdzPHecN1obz1Cjpv0nFCJo747Tega4/d9T85+NKbf9B0lPg1mpdXIKgCSe7WojHRU hmLmGi4BO02gKXoIjZdIL/ZD1oCnmsZaEVagXeoZfjIjvBVs+Ro432qh/CooLjhmZOHO pRif6cSXVlUe+aRkWSuB2zvbiBtWWNaFHoa6xtAEcPzowf7cj8TBZAA1W4MfGIa0OdNW D51mFCzrKqzUdhGyhbIef/jzNiJZaGBLbmb/MLhNHud+s4fKcD9SgahXooaODk5NRuo3 w+Fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si4479954pfd.59.2019.09.03.02.41.15; Tue, 03 Sep 2019 02:41:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728807AbfICJil (ORCPT + 99 others); Tue, 3 Sep 2019 05:38:41 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:64166 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726946AbfICJil (ORCPT ); Tue, 3 Sep 2019 05:38:41 -0400 X-UUID: 0b746e19303b4e6b91bce88b3538ff3d-20190903 X-UUID: 0b746e19303b4e6b91bce88b3538ff3d-20190903 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1697110160; Tue, 03 Sep 2019 17:38:37 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 3 Sep 2019 17:38:36 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 3 Sep 2019 17:38:35 +0800 From: Yong Wu To: Matthias Brugger , Joerg Roedel , Rob Herring CC: Evan Green , Robin Murphy , Tomasz Figa , Will Deacon , , , , , , , , , Nicolas Boichat , Matthias Kaehlcke , , , , Subject: [PATCH v3 03/14] iommu/mediatek: Add device_link between the consumer and the larb devices Date: Tue, 3 Sep 2019 17:37:25 +0800 Message-ID: <1567503456-24725-4-git-send-email-yong.wu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1567503456-24725-1-git-send-email-yong.wu@mediatek.com> References: <1567503456-24725-1-git-send-email-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org MediaTek IOMMU don't have its power-domain. all the consumer connect with smi-larb, then connect with smi-common. M4U | smi-common | ------------- | | ... | | larb1 larb2 | | vdec venc When the consumer works, it should enable the smi-larb's power which also need enable the smi-common's power firstly. Thus, First of all, use the device link connect the consumer and the smi-larbs. then add device link between the smi-larb and smi-common. This patch adds device_link between the consumer and the larbs. When device_link_add, I add the flag DL_FLAG_STATELESS to avoid calling pm_runtime_xx to keep the original status of clocks. It can avoid two issues: 1) Display HW show fastlogo abnormally reported in [1]. At the beggining, all the clocks are enabled before entering kernel, but the clocks for display HW(always in larb0) will be gated after clk_enable and clk_disable called from device_link_add(->pm_runtime_resume) and rpm_idle. The clock operation happened before display driver probe. At that time, the display HW will be abnormal. 2) A deadlock issue reported in [2]. Use DL_FLAG_STATELESS to skip pm_runtime_xx to avoid the deadlock. Corresponding, DL_FLAG_AUTOREMOVE_CONSUMER can't be added, then device_link_removed should be added explicitly. [1] http://lists.infradead.org/pipermail/linux-mediatek/2019-July/ 021500.html [2] https://lore.kernel.org/patchwork/patch/1086569/ Suggested-by: Tomasz Figa Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 17 +++++++++++++++++ drivers/iommu/mtk_iommu_v1.c | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index b138b94..2511b3c 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -450,6 +450,9 @@ static int mtk_iommu_add_device(struct device *dev) struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct mtk_iommu_data *data; struct iommu_group *group; + struct device_link *link; + struct device *larbdev; + unsigned int larbid; if (!fwspec || fwspec->ops != &mtk_iommu_ops) return -ENODEV; /* Not a iommu client device */ @@ -461,6 +464,14 @@ static int mtk_iommu_add_device(struct device *dev) if (IS_ERR(group)) return PTR_ERR(group); + /* Link the consumer device with the smi-larb device(supplier) */ + larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); + larbdev = data->larb_imu[larbid].dev; + link = device_link_add(dev, larbdev, + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); + if (!link) + dev_err(dev, "Unable to link %s\n", dev_name(larbdev)); + iommu_group_put(group); return 0; } @@ -469,6 +480,8 @@ static void mtk_iommu_remove_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct mtk_iommu_data *data; + struct device *larbdev; + unsigned int larbid; if (!fwspec || fwspec->ops != &mtk_iommu_ops) return; @@ -476,6 +489,10 @@ static void mtk_iommu_remove_device(struct device *dev) data = fwspec->iommu_priv; iommu_device_unlink(&data->iommu, dev); + larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); + larbdev = data->larb_imu[larbid].dev; + device_link_remove(dev, larbdev); + iommu_group_remove_device(dev); iommu_fwspec_free(dev); } diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 2034d72..a7f22a2 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -423,7 +423,9 @@ static int mtk_iommu_add_device(struct device *dev) struct of_phandle_iterator it; struct mtk_iommu_data *data; struct iommu_group *group; - int err; + struct device_link *link; + struct device *larbdev; + int err, larbid; of_for_each_phandle(&it, err, dev->of_node, "iommus", "#iommu-cells", 0) { @@ -466,6 +468,14 @@ static int mtk_iommu_add_device(struct device *dev) return err; } + /* Link the consumer device with the smi-larb device(supplier) */ + larbid = mt2701_m4u_to_larb(fwspec->ids[0]); + larbdev = data->larb_imu[larbid].dev; + link = device_link_add(dev, larbdev, + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); + if (!link) + dev_err(dev, "Unable to link %s\n", dev_name(larbdev)); + return iommu_device_link(&data->iommu, dev); } @@ -473,6 +483,8 @@ static void mtk_iommu_remove_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct mtk_iommu_data *data; + struct device *larbdev; + unsigned int larbid; if (!fwspec || fwspec->ops != &mtk_iommu_ops) return; @@ -480,6 +492,10 @@ static void mtk_iommu_remove_device(struct device *dev) data = fwspec->iommu_priv; iommu_device_unlink(&data->iommu, dev); + larbid = mt2701_m4u_to_larb(fwspec->ids[0]); + larbdev = data->larb_imu[larbid].dev; + device_link_remove(dev, larbdev); + iommu_group_remove_device(dev); iommu_fwspec_free(dev); } -- 1.9.1