Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp221097pxv; Thu, 8 Jul 2021 19:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQPh1musPrGeUbd0MYsnMWqBSzYQ38oGxT6WzJnPgz5/oSEAxzog6dzndZ1Hl9wIR0S0dT X-Received: by 2002:a05:6402:6:: with SMTP id d6mr30447870edu.236.1625797533847; Thu, 08 Jul 2021 19:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625797533; cv=none; d=google.com; s=arc-20160816; b=UrfHoAG/Spq5sr1ZC7TJ+XbKG/jd08le2KaNOtI7IzTgEUpOw52oSTH8Xnmv6wwGx+ nXgxtpcTY3xT7t/Fn/KGhHZ8MafUXbBhZksDYlGW37TYYofHStyzWkDwQ2baQfquM+KM FbDR7yDUmIgfUPtK4Ob5uokWaGn32IGVMtFirDAGfEEkPMDU9kYpSbzgNDdksFPZ4yrQ bzy7L+FHASsfCKa1LDt3wIO+o+Ur+ca4ZLXKpr++F9UDF7gEZnVYiVCRNZo+N7F5qA0N 519zCOKW2e1ZpTnUBIdxLQu3n+Dlsx2h86hFg1hchnwiFIu93zcZ6dL640nHqJOzgTOc m6DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yyRKuMpZOVLMa4ikk2b2WHtFLwi/HwkthLMsBTXY13A=; b=ML1v9GJALleGfx0b6mD9R/J9XoCeB2a8TfcheY0Br4nlNWckxWjZNy2/6BPLkm+LVt yo01zJ/kf1aufNzvT796EnEL5BuMfr/TzDbrsQn8jtg32wFzuIojtOjYOxh5skfp9wIg dcHrOyv9C59EpUgZ8bYxPoWKPZ1lt3LdZHt4uLTkkaOjuRE8CTFO8J73YT52HouZVpfl dhGcZuU0KCf8EWp2hHhGzlUSJXhA+7RqB5k4k+duR9iATBtDGb3xSBHR9WPT6LPd3MKA R4gBuYz5HG6r1n2CPEeSOThSpG39t8pOXyx7f7PVFFfeSNFWLqbFkWxqiEGCSsVD1GuN dd9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IWtpsGTS; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz43si5237960ejc.422.2021.07.08.19.25.11; Thu, 08 Jul 2021 19:25:33 -0700 (PDT) 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=@chromium.org header.s=google header.b=IWtpsGTS; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbhGIC0n (ORCPT + 99 others); Thu, 8 Jul 2021 22:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbhGIC0m (ORCPT ); Thu, 8 Jul 2021 22:26:42 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8986C06175F for ; Thu, 8 Jul 2021 19:23:59 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id n11so4940764pjo.1 for ; Thu, 08 Jul 2021 19:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yyRKuMpZOVLMa4ikk2b2WHtFLwi/HwkthLMsBTXY13A=; b=IWtpsGTSq/C4xSGZlvADlPwHO6G6Ww/eiJiJPBh/CdQ3OSpkm2/Qc8qzIhH8VCI/k2 4g6VY55My77QLcxx0jrz/pQZsYOiQccuAJpf8Ue86AMV0y9vxD/8AWv2e4HONrMXHwCn 5rQ9+jdcrYBDVjjp+ys1/6sb85HzZhdJ6pXao= 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:mime-version:content-transfer-encoding; bh=yyRKuMpZOVLMa4ikk2b2WHtFLwi/HwkthLMsBTXY13A=; b=aphLy0ajl51dfc0hb1lS3hkQD7HKblPgZLkUYnOAkjR4oaIAWlVY8pPUEXj4Abq6ws uVzq2YJvySayAzEFNYhRdrKQ3a8jmQbyM9dGGZIE84yTfj7uBUDE9ZKhcqlo85UWpYLv 5m6Bh7YUc324g8V1lOERPqqqbdEMYJSPsI0xJr7olYmiOYdkn6fVEMzMvhXnQ49+Ehw5 TlY0jerqOZPCt4NtwnAQ6pJ93O5TCuS39qS0TMvFskzbwJL4l5WxwaOX3ElSJ/1Eo1Np /8DPRPoEBe1QeRH3wutph5gXFSNyNFLSwgnFJf8BprMtGsy7h0JkPyOM0ZglrFcSNM/7 O9Pg== X-Gm-Message-State: AOAM533x0Z6CDCSwFnIfrI2vIxdLGXVrl8xKq7YWXl0fmOc6sALwATTa aKdtwwJ5gTYIDUWtFZiDnlaqDfSOPvLc9Q== X-Received: by 2002:a17:90a:b110:: with SMTP id z16mr35021291pjq.170.1625797439023; Thu, 08 Jul 2021 19:23:59 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:d956:2966:7910:2bd2]) by smtp.gmail.com with UTF8SMTPSA id g4sm5037932pgn.45.2021.07.08.19.23.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Jul 2021 19:23:58 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: wenst@chromium.org, chunkuang.hu@kernel.org, yong.wu@mediatek.com, enric.balletbo@collabora.com, houlong.wei@mediatek.com, Eizan Miyamoto , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Minghsiu Tsai , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v5 3/8] media: mtk-mdp: don't pm_run_time_get/put for master comp in clock_on Date: Fri, 9 Jul 2021 12:23:19 +1000 Message-Id: <20210709122040.v5.3.Ifd87681955689a08cce4c65e72ee5e8c6d09af95@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210709022324.1607884-1-eizan@chromium.org> References: <20210709022324.1607884-1-eizan@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The original intent of commit 86698b9505bbc ("media: mtk-mdp: convert mtk_mdp_dev.comp array to list") was to create a list to track all the MDP components that needed to have their clocks enabled/disabled when calling mtk_mdp_comp_clock_on/off. However, there was a bug inside mtk_mdp_register_component where the args to a call to list_add were swapped. The result is that only one component was added to mtk_mdp_dev.comp_list because comp_list was instead being repeatedly added to the single element lists headed by each mtk_mdp_comp. The order of the args to list_add in mtk_mdp_register_component was fixed in https://patchwork.kernel.org/patch/11742895/ (Fix Null pointer dereference when calling list_add). Then, as a result of https://patchwork.kernel.org/patch/11530769/ (mtk-mdp: use pm_runtime in MDP component driver) if all the components are added to the component list, the mdp "master" / rdma0 component ends up having pm_runtime_get_sync() called on it twice recursively: rpm_resume+0x694/0x8f8 __pm_runtime_resume+0x7c/0xa0 ***NOTE*** mtk_mdp_comp_clock_on+0x48/0x104 [mtk_mdp] mtk_mdp_pm_resume+0x2c/0x44 [mtk_mdp] pm_generic_runtime_resume+0x34/0x48 __genpd_runtime_resume+0x6c/0x80 genpd_runtime_resume+0x104/0x1ac __rpm_callback+0x120/0x238 rpm_callback+0x34/0x8c rpm_resume+0x7a0/0x8f8 __pm_runtime_resume+0x7c/0xa0 ***NOTE*** mtk_mdp_m2m_start_streaming+0x2c/0x3c [mtk_mdp] (The calls to pm_runtime_get_sync are inlined and correspond to the calls to __pm_runtime_resume). It is not correct to have pm_runtime_get_sync called recursively and the second call will block indefinitely. As a result of all that, this change factors mtk_mdp_comp_clock_on/off into mtk_mdp_comp_power_on/off and moves the calls to pm_runtime_get/put into the power_on/off functions. This change then special-cases the master/rdma0 MDP component and does these things: - the master/rdma0 component is not added to mtk_mdp_dev.comp_list - the master/rdma0 component has its clocks (*but not power*) toggled by mtk_mpd_comp_clock_on/off inside mtk_mdp_clock_on/off. - the other components have their clocks *and* power toggled with mtk_mdp_comp_power_on/off. This change introduces the assumption that mtk_mdp_pm_resume will always be called though a callback from pm_runtime_get_sync made on the master / rdma0 component. Signed-off-by: Eizan Miyamoto --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 28 ++++++++++++++----- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 3 ++ drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 23 ++++++++++----- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 8b6158379f41..ce54863c24ce 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -53,9 +53,9 @@ static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match); -void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) +void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp) { - int i, err; + int err; if (comp->larb_dev) { err = mtk_smi_larb_get(comp->larb_dev); @@ -66,9 +66,25 @@ void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) err = pm_runtime_get_sync(comp->dev); if (err < 0) - dev_err(comp->dev, - "failed to runtime get, err %d.\n", - err); + dev_err(comp->dev, "failed to runtime get, err %d.\n", err); + + mtk_mdp_comp_clock_on(comp); +} + +void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp) +{ + int err; + + mtk_mdp_comp_clock_off(comp); + + err = pm_runtime_put_sync(comp->dev); + if (err < 0) + dev_err(comp->dev, "failed to runtime put, err %d.\n", err); +} + +void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) +{ + int i, err; for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { if (IS_ERR(comp->clk[i])) @@ -91,8 +107,6 @@ void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) if (comp->larb_dev) mtk_smi_larb_put(comp->larb_dev); - - pm_runtime_put_sync(comp->dev); } static int mtk_mdp_comp_bind(struct device *dev, struct device *master, diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index 5e2ee94a1b37..15ef9539a5a7 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -23,6 +23,9 @@ struct mtk_mdp_comp { int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev); +void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp); +void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp); + void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp); void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp); diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 78c40a61df1d..3558a6587f51 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -54,8 +54,15 @@ static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) { struct mtk_mdp_comp *comp_node; + /* + * The master / rdma0 component will have pm_runtime_get_sync called + * on it through mtk_mdp_m2m_start_streaming, making it unnecessary to + * have mtk_mdp_comp_power_on called on it. + */ + mtk_mdp_comp_clock_on(&mdp->comp_self); + list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_on(comp_node); + mtk_mdp_comp_power_on(comp_node); } static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) @@ -63,7 +70,14 @@ static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) struct mtk_mdp_comp *comp_node; list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_off(comp_node); + mtk_mdp_comp_power_off(comp_node); + + /* + * The master / rdma0 component will have pm_runtime_put called + * on it through mtk_mdp_m2m_stop_streaming, making it unnecessary to + * have mtk_mdp_comp_power_off called on it. + */ + mtk_mdp_comp_clock_off(&mdp->comp_self); } static void mtk_mdp_wdt_worker(struct work_struct *work) @@ -102,8 +116,6 @@ static int mtk_mdp_master_bind(struct device *dev) int status; struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); - mtk_mdp_register_component(mdp, &mdp->comp_self); - status = component_bind_all(dev, mdp); if (status) { dev_err(dev, "Failed to bind all components: %d\n", status); @@ -125,8 +137,6 @@ static int mtk_mdp_master_bind(struct device *dev) component_unbind_all(dev, mdp); err_component_bind_all: - mtk_mdp_unregister_component(mdp, &mdp->comp_self); - return status; } @@ -137,7 +147,6 @@ static void mtk_mdp_master_unbind(struct device *dev) pm_runtime_disable(dev); mtk_mdp_unregister_m2m_device(mdp); component_unbind_all(dev, mdp); - mtk_mdp_unregister_component(mdp, &mdp->comp_self); } static const struct component_master_ops mtk_mdp_com_ops = { -- 2.32.0.93.g670b81a890-goog