Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp247707pxj; Thu, 10 Jun 2021 21:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySWE5J7h00BQR5MBnPdCI9+9zat6EVuwNTuqHz0HzeEwvNPwsBKzsc3p9vQ0j2ogeOmNKm X-Received: by 2002:a17:906:490:: with SMTP id f16mr1674386eja.541.1623384322251; Thu, 10 Jun 2021 21:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623384322; cv=none; d=google.com; s=arc-20160816; b=dW023nMIZmy8rizknjtvgLvsR7/F33ab3YVRwQfsWpnZUs7j/ZNxDaSUXfyrRKMsOB wxqs5mUH+OI3JpRjcy8QB3cIClExFGNMlU3cKdyYMQEG6PwJcDOKn/TqAdKr5j0IorRI 5imeVykd0yAZ3wg5+utX6Nxtil1hBKO/J+q+kqCTXwuoJlrIajPYajBEihrgSlTCru6+ pkAKM25w/GafeAXJ0No67JInHQpvUyU5VNygeHdau8jT5+ZYpoheropGgTCIgMvZtGf2 o9wZklYGc2h3sNl4bhv3PN4d5bsHTQu9t32OxkqlVfdfCDzIMQPFiz2cmTD2sPLHcbk1 ibNA== 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=lACjQG1o0nJMw/qqdJI0121HB32Gd9hhUmo902ISutw=; b=Z/MkaesXaw91EhlmCBRcvZG3f+nQbrAiS4nP1Rek+1rcekoYjXUvRXUIeltqszE6b9 nfNdW2ESr8uMQtG4vZyiVna/21xQeQ1HUmYDXuvlz9NiDvAryuCgobGHtuaRIbUMgQ0c OhLK0mj9qphG3NGNVwAZQxKBfRzXKE58M6l56OmqjuJaPX6mh9pm8Ncb6dtElZUQLZX+ oKqWPl5hqcTKpcamyH0bxcbV+eZjgGGUxasuwNJJeGc/J8WqYlOpQ8fhbj7Jr8i2zOja hfzhT2vvUvnXBUrBNNtsxyjva+rLGUTRkoBN/mm+TDTHLSHenNoOGmxdssBYIu3jVi4W AxGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V4v3zILA; 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 18si3662569ejr.397.2021.06.10.21.04.59; Thu, 10 Jun 2021 21:05:22 -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=V4v3zILA; 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 S231514AbhFKEEk (ORCPT + 99 others); Fri, 11 Jun 2021 00:04:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbhFKEEi (ORCPT ); Fri, 11 Jun 2021 00:04:38 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D314C0617AD for ; Thu, 10 Jun 2021 21:02:27 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id z1so1403707pgj.6 for ; Thu, 10 Jun 2021 21:02:27 -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=lACjQG1o0nJMw/qqdJI0121HB32Gd9hhUmo902ISutw=; b=V4v3zILAGo8uM5EF2tKjFX5ZJ4Azqxoq5NqTHSesXmA+4tyjd7EAbFL6Nh97Gt3Ehl GBsu/CYi60U6XAl/ZaK0Ypy3x01ygXhjkjY7laRKwUCQE3jXFh87v6VcMe/+qbjsKxBP hnBfhJhOPG9D2W5UYlBMjHAlag6//O4JuToco= 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=lACjQG1o0nJMw/qqdJI0121HB32Gd9hhUmo902ISutw=; b=UNgBzi6831Qw8HX9CVfdlHWYmnb1oj4/rgutCJVLUDvvuJVz0gHVebHRQOtfNxFYNr ILVSNoXjIwCYHn0IVUyu/0VhIhv1QhicyKlr/L/ZFAF/toW/BUCrUpPD54XyDvggS5ux 6bxtez6kmTQGlcIBFbd/uQiSHJJjYLlK9ZJW20hqzYKyj7a+ww/ARrJvvmaOqVcW8KS8 x8vkIGIPlKizdPt+IWjhHkqsoJVDDXV/MqxsnN7JN0PwMqgz5MufC4VYBiqSdqDut4Au w+CnSCWku7tv3RXE+zPsOayKteI4pJqZNoQ/cCIHuwHdAZcGHuM6ZU1u2+KmQMsdiP1D x4rg== X-Gm-Message-State: AOAM532L7ooqidmzHVLRP4Cjc4dE82ja2IDyvFWt1Y8McsnDC3xaU4aJ 7k3KiVvNTH+14UYeRNXUfz5eLbFy0x5mMdFC X-Received: by 2002:a63:e952:: with SMTP id q18mr1615665pgj.430.1623384146513; Thu, 10 Jun 2021 21:02:26 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:db52:e918:e5f9:9e14]) by smtp.gmail.com with UTF8SMTPSA id pi8sm3659848pjb.52.2021.06.10.21.02.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Jun 2021 21:02:26 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: houlong.wei@mediatek.com, enric.balletbo@collabora.com, yong.wu@mediatek.com, chunkuang.hu@kernel.org, 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 v2 3/8] media: mtk-mdp: don't pm_run_time_get/put for master comp in clock_on Date: Fri, 11 Jun 2021 14:01:40 +1000 Message-Id: <20210611140124.v2.3.Ifd87681955689a08cce4c65e72ee5e8c6d09af95@changeid> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210611040145.2085329-1-eizan@chromium.org> References: <20210611040145.2085329-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 8cebc3565826..9a12717ce416 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -53,15 +53,31 @@ 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; 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])) @@ -81,8 +97,6 @@ void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) continue; clk_disable_unprepare(comp->clk[i]); } - - 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 355e226d74fe..7ad9b06bb11b 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -21,6 +21,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 c55bcfe4cbb7..5e71496e2517 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -53,8 +53,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) @@ -62,7 +69,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) @@ -101,8 +115,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); @@ -124,8 +136,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; } @@ -136,7 +146,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.272.g935e593368-goog