From patchwork Wed Sep 19 22:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5E0A14BD for ; Wed, 19 Sep 2018 22:21:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C64342C9BC for ; Wed, 19 Sep 2018 22:21:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B86112CC9A; Wed, 19 Sep 2018 22:21:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DDE12C9BC for ; Wed, 19 Sep 2018 22:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726013AbeITEAp (ORCPT ); Thu, 20 Sep 2018 00:00:45 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34450 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726003AbeITEAp (ORCPT ); Thu, 20 Sep 2018 00:00:45 -0400 Received: by mail-pf1-f193.google.com with SMTP id k19-v6so3357857pfi.1 for ; Wed, 19 Sep 2018 15:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=/7A+jgDIUZCGxGLhoGYTieLMUMpj5eaMcqaxJhDr4YA=; b=BXitjeAafq8N0RjL/QUGy9m5AifOy3d1uuIkG/hOfeQrnNf1WzTljTy2lUbyaBJPfO KWqpu6n98jyuWmA6R4w0PI0OnZNlmgjAe6EbRFKFcFfc9UYON/AX0QI+KcTeF2k123a9 dNbuUEn9RMaKtaFqrXV+FqWr/1kr/Im2EfI5Q= 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:in-reply-to:references; bh=/7A+jgDIUZCGxGLhoGYTieLMUMpj5eaMcqaxJhDr4YA=; b=F4RL7wMsUCvp41Fuaw2G3qKCKYdgpOZQEsvoEfuO8sIC3Ck/Y9dgA1ztktAk6c3YH4 bAd00yCenKEsspbtiU8gWDYW+A4jyOnPCENJZ9kmBkujofLrXcJhF4d+JL4bxb9HlzsT pSPASXo9j2yWMdYIlZYnSI+fXO02Cxhvr9sAp2V9m4rfH2C3+JNv66yZKp+LkiRw1+BY Lecs9m+8d1IIAi93+4js3+3Nzg5m3XfH4AYNo1abm/Y7Ht+G/oVOCnAEd8espeXbXb53 6nih2pG/RsYBH9TeQ5Tg+5nUEw3CrR93Ns6T5m0rf0HTPZlgXIMnHHSadjF5pFmiQqBx z/Bg== X-Gm-Message-State: APzg51ATkQsst85S7T6zR0/4IBPmBRb2y1Z4yysNy9QIuOKiaTuJ8l8n 17i86lFsAlZKyyKhx4s0sRgjTg== X-Google-Smtp-Source: ANB0VdYoOb/IDfKIIbejCcQMN92UlhOUzEVXI/WLLAFIsZoi93FrFweNXjnxTo7Y0Njtsls2q1pGhw== X-Received: by 2002:a65:5284:: with SMTP id y4-v6mr32790902pgp.283.1537395644376; Wed, 19 Sep 2018 15:20:44 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id f13-v6sm21489306pgq.63.2018.09.19.15.20.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:43 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , "4 . 18" , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 01/12] OPP: Free OPP table properly on performance state irregularities Date: Wed, 19 Sep 2018 15:20:20 -0700 Message-Id: <2fbb8670b4ff4454f1c0de510f788d737edc4b90.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The OPP table was freed, but not the individual OPPs which is done from _dev_pm_opp_remove_table(). Fix it by calling _dev_pm_opp_remove_table() as well. Cc: 4.18 # v4.18 Fixes: 3ba98324e81a ("PM / OPP: Get performance state using genpd helper") Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 7af0ddec936b..20988c426650 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -425,6 +425,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) dev_err(dev, "Not all nodes have performance state set (%d: %d)\n", count, pstate_count); ret = -ENOENT; + _dev_pm_opp_remove_table(opp_table, dev, false); goto put_opp_table; } From patchwork Wed Sep 19 22:20:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A46D6913 for ; Wed, 19 Sep 2018 22:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92C9B2C9BC for ; Wed, 19 Sep 2018 22:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 864F42CC9A; Wed, 19 Sep 2018 22:20:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18DE52C9BC for ; Wed, 19 Sep 2018 22:20:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725784AbeITEAr (ORCPT ); Thu, 20 Sep 2018 00:00:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34051 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726123AbeITEAr (ORCPT ); Thu, 20 Sep 2018 00:00:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id d19-v6so3409722pgv.1 for ; Wed, 19 Sep 2018 15:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=eozK+qk21bu6C0o4GTQGviL35NBsR1qUdySDKI0vP2I=; b=SwuaU0eMFXWnHwJhPlvOyv1Ga8JLS7+7VSsRo3kxfYuFSx+xD06mKbdqANxh0D6aTu yLH7qygik4fIlLze/wJlcC5Jp2Y8uuYOFSS9qnG2Ec1Z4KM/QmhRNrRZfrZjs0N9C6oK mghgYTt71zKhka1NiY4O/UJ9fQUBja1hRVG7c= 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:in-reply-to:references; bh=eozK+qk21bu6C0o4GTQGviL35NBsR1qUdySDKI0vP2I=; b=VcWnfvTb1SaGAwHT9VBOmjXBJA5iCqEGAiaywL6af0u7uw8qLJ+mSj5o4eKO+l1p0l 5EqFNVtXWOIXpXlOBQoQ0M3TkoInquCNYfXSfmCzmX1IRSatCY2xr1KdpjVrvq8KfQIf RNaKWL8g7fgwqwH1IeIjOCfgpmGV1vsaMSxqkbUF74c2h9Z5jbpv9bKqCMf+V7Cgn72b RADyrBPgVlM8v3MHyp/q9U3o3I/2ZkCdtfQBURwfU+ix63kjcOEyN8d8qTYkSyrHXqVT widCQ958LGSMStPz6V+nMoNh7aONe/fxHBB/LAJIaCi0V9K8L/rY7EA80xsEBAh+PaHX ZRlA== X-Gm-Message-State: APzg51CLz9Gmcx+gbKOuZpu2omTjEuI53dEi6DwNXEmGageRmeWxW0nb t9jWgsmUEfAIAAXUW99vkMthnw== X-Google-Smtp-Source: ANB0VdYiF7rqZS1Mv5+Ge9lYSY73jpKTdzsiNjN4ilcRmn+P2v8UF6/zWvOCzUBqoNaESoDs1IdfTg== X-Received: by 2002:a62:6690:: with SMTP id s16-v6mr38022974pfj.152.1537395645964; Wed, 19 Sep 2018 15:20:45 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id e190-v6sm45557047pfc.81.2018.09.19.15.20.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:45 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 02/12] OPP: Don't try to remove all OPP tables on failure Date: Wed, 19 Sep 2018 15:20:21 -0700 Message-Id: <404b1369ea26f598b96ae4d3183262a879703cfe.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP dev_pm_opp_of_cpumask_add_table() creates the OPP table for all CPUs present in the cpumask and on errors it should revert all changes it has done. It actually is doing a bit more than that. On errors, it tries to free all the OPP tables, even the one it hasn't created yet. This may also end up freeing the OPP tables which were created from separate path, like dev_pm_opp_set_supported_hw(). Reported-and-tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/cpu.c | 8 ++++++-- drivers/opp/of.c | 4 ++-- drivers/opp/opp.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 0c0910709435..2eb5e2e7ff66 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -108,7 +108,8 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table); #endif /* CONFIG_CPU_FREQ */ -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, + int last_cpu) { struct device *cpu_dev; int cpu; @@ -116,6 +117,9 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) WARN_ON(cpumask_empty(cpumask)); for_each_cpu(cpu, cpumask) { + if (cpu == last_cpu) + break; + cpu_dev = get_cpu_device(cpu); if (!cpu_dev) { pr_err("%s: failed to get cpu%d device\n", __func__, @@ -140,7 +144,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) */ void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, false); + _dev_pm_opp_cpumask_remove_table(cpumask, false, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 20988c426650..86222586f27b 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -592,7 +592,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); */ void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, true); + _dev_pm_opp_cpumask_remove_table(cpumask, true, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); @@ -627,7 +627,7 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) __func__, cpu, ret); /* Free all other OPPs */ - dev_pm_opp_of_cpumask_remove_table(cpumask); + _dev_pm_opp_cpumask_remove_table(cpumask, true, cpu); break; } } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 7c540fd063b2..a9d22aa534c3 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -196,7 +196,7 @@ struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of); +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, int last_cpu); struct opp_table *_add_opp_table(struct device *dev); #ifdef CONFIG_OF From patchwork Wed Sep 19 22:20:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF41114BD for ; Wed, 19 Sep 2018 22:21:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEB792C9BC for ; Wed, 19 Sep 2018 22:21:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1A122CC9A; Wed, 19 Sep 2018 22:21:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FECF2C9BC for ; Wed, 19 Sep 2018 22:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725993AbeITEAs (ORCPT ); Thu, 20 Sep 2018 00:00:48 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34907 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbeITEAs (ORCPT ); Thu, 20 Sep 2018 00:00:48 -0400 Received: by mail-pl1-f195.google.com with SMTP id g2-v6so3307027plo.2 for ; Wed, 19 Sep 2018 15:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=KNbb/GBRT5l235B0JCuUrzsEESNrHyS5fTToF34GITM=; b=kb0LyyBAoMOdq8BVQnvoGN9iZbuEZTsvI+BGU1C2Nbd4tVxnR4nkW+xpV48FIidvwW V9fAIAsXEWiLB5gKDmOybT339oXK8ne+05ELmx7mTffsLEes7801R35UJB+176ZVj9r7 bQJrjdt8aL4wZOPVcT0HKAIvA0ueZm7rAT3fs= 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:in-reply-to:references; bh=KNbb/GBRT5l235B0JCuUrzsEESNrHyS5fTToF34GITM=; b=ZXRxAMgNFJG/kQvd/nFBOZW/Ju6pAtfLjyHX/SYs21eU4x9kHBFuoIAlqQC20EZAvN klCI41t+ckXzYr0ZWpeNeiLj18BhmA5kvnC1kpWQoARNd1xsO8NFs2e3nA7Y0fUyLDP6 vA/eGFb6tlwQsB1piZt/0HNqKI4jwqmAJLRqi6EBXYrQfb43wdRB0hWo1H81XCvL86Vx jiUosOQ8B3BinLUBm7XSr/yUapVhZgA24pcnoNkIsJvJwK5ALUcV6qsiEERKt1qeDgyY hlrDDL5tGoDtDbtZoFiAfZ/lQS/TSWVODcS9Ge1ac/ugpX0xl5BHo/ilIllrz+GXDMUr MmiQ== X-Gm-Message-State: APzg51AEuR++vYOOyL74xR3jk0ZsTC12vTBxrD69ZW0/Fq9pZjHyg4HX OVMvCxTitX16uDdrNi+UZUMMIw== X-Google-Smtp-Source: ANB0VdZdF3S9vkGNAsHagBLJa4qZHb27TNpH8o7jiOBFVg8zDFFppbC/jesQKGyjDyj8z4QdlHc4JQ== X-Received: by 2002:a17:902:286a:: with SMTP id e97-v6mr36378195plb.340.1537395647452; Wed, 19 Sep 2018 15:20:47 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id a20-v6sm52014829pfc.14.2018.09.19.15.20.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:46 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 03/12] OPP: Protect dev_list with opp_table lock Date: Wed, 19 Sep 2018 15:20:22 -0700 Message-Id: <3d2556992a878a2210d3be498416aee39e0c32aa.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The dev_list needs to be protected with a lock, else we may have simultaneous access (addition/removal) to it and that would be racy. Extend scope of the opp_table lock to protect dev_list as well. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 21 +++++++++++++++++++-- drivers/opp/cpu.c | 2 ++ drivers/opp/opp.h | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 31ff03dbeb83..9f8aa31265fe 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -48,9 +48,14 @@ static struct opp_device *_find_opp_dev(const struct device *dev, static struct opp_table *_find_opp_table_unlocked(struct device *dev) { struct opp_table *opp_table; + bool found; list_for_each_entry(opp_table, &opp_tables, node) { - if (_find_opp_dev(dev, opp_table)) { + mutex_lock(&opp_table->lock); + found = !!_find_opp_dev(dev, opp_table); + mutex_unlock(&opp_table->lock); + + if (found) { _get_opp_table_kref(opp_table); return opp_table; @@ -766,6 +771,8 @@ struct opp_device *_add_opp_dev(const struct device *dev, /* Initialize opp-dev */ opp_dev->dev = dev; + + mutex_lock(&opp_table->lock); list_add(&opp_dev->node, &opp_table->dev_list); /* Create debugfs entries for the opp_table */ @@ -773,6 +780,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, if (ret) dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", __func__, ret); + mutex_unlock(&opp_table->lock); return opp_dev; } @@ -791,6 +799,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev) if (!opp_table) return NULL; + mutex_init(&opp_table->lock); INIT_LIST_HEAD(&opp_table->dev_list); opp_dev = _add_opp_dev(dev, opp_table); @@ -812,7 +821,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev) BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); INIT_LIST_HEAD(&opp_table->opp_list); - mutex_init(&opp_table->lock); kref_init(&opp_table->kref); /* Secure the device table modification */ @@ -854,6 +862,10 @@ static void _opp_table_kref_release(struct kref *kref) if (!IS_ERR(opp_table->clk)) clk_put(opp_table->clk); + /* + * No need to take opp_table->lock here as we are guaranteed that no + * references to the OPP table are taken at this point. + */ opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, node); @@ -1716,6 +1728,9 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, { struct dev_pm_opp *opp, *tmp; + /* Protect dev_list */ + mutex_lock(&opp_table->lock); + /* Find if opp_table manages a single device */ if (list_is_singular(&opp_table->dev_list)) { /* Free static OPPs */ @@ -1733,6 +1748,8 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, } else { _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); } + + mutex_unlock(&opp_table->lock); } void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 2eb5e2e7ff66..36586f66cd83 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -226,8 +226,10 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) cpumask_clear(cpumask); if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { + mutex_lock(&opp_table->lock); list_for_each_entry(opp_dev, &opp_table->dev_list, node) cpumask_set_cpu(opp_dev->dev->id, cpumask); + mutex_unlock(&opp_table->lock); } else { cpumask_set_cpu(cpu_dev->id, cpumask); } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index a9d22aa534c3..88e9f47aadf1 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -126,7 +126,7 @@ enum opp_table_access { * @dev_list: list of devices that share these OPPs * @opp_list: table of opps * @kref: for reference count of the table. - * @lock: mutex protecting the opp_list. + * @lock: mutex protecting the opp_list and dev_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. * @shared_opp: OPP is shared between multiple devices. From patchwork Wed Sep 19 22:20:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34D6714BD for ; Wed, 19 Sep 2018 22:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24DE82C9BC for ; Wed, 19 Sep 2018 22:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1935A2CC9A; Wed, 19 Sep 2018 22:21:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 912492C9BC for ; Wed, 19 Sep 2018 22:21:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732381AbeITEAv (ORCPT ); Thu, 20 Sep 2018 00:00:51 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40398 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726142AbeITEAu (ORCPT ); Thu, 20 Sep 2018 00:00:50 -0400 Received: by mail-pl1-f193.google.com with SMTP id s17-v6so3299442plp.7 for ; Wed, 19 Sep 2018 15:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+qw1WHdkun9NT16a0EkMQe8eVOqrEPq24qtM3EnA0WM=; b=N7qKUtGRcs8B8Xx/g9uYzFVy1r8dhJsiLpibsY278uGTZ/Argo3cU52+D0Tu52336f 9P5KRj/dchx8/qRWJ9lhmvRj/SqI/QJaF19LpniElgWN472BjJwdMSor+5GDMNK9RH6v VoQzaSlIL7MZK1v3CR48y8VppWW3aOnAbqctk= 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:in-reply-to:references; bh=+qw1WHdkun9NT16a0EkMQe8eVOqrEPq24qtM3EnA0WM=; b=DndvnGJiSobhZCM43momKO9g9BQl97JnjuaLxsX6CbH3Tbt47qURFy3bEzu+E16aP6 q5clnq/cp4v9CSr+4/v28Up+/ke688AG0WJ5F0q8P6yhfKRZsDg3SQ20D+n3Xz7axbgv N0iUrnPc7PlTFk5A6QtuyWsezg3uo4Yhotb45dUIUbaFswH75usdRqFcFDABvpb0F1wZ bjWVNJ8HiAMqfKzofC9m+A8qKoLOc9i7aPqgyTb/ebIOfl0pdsPQbOk5GHgoxBvTE1d3 qDSwZhvVOTyPQTO+X1NMtfnK6g0ZH+zk9gthrsTpjCaMEGr6SSKjo/WKEhntmWRm7LzL N4+w== X-Gm-Message-State: APzg51DKD5l1I5Uldi/MA1JrkSqZfY96lKd/5sJseqsr8DeNS66O7weP oomCF7Cv3x45WkHOMkJcyz89pQ== X-Google-Smtp-Source: ANB0Vdba+XwunvS/cMsWShRUrMLXr7dovJbWGEbPeNUgfaUgnqugcQFUjt/NfBx/WOVibMBGduknhQ== X-Received: by 2002:a17:902:2f43:: with SMTP id s61-v6mr35459595plb.176.1537395649068; Wed, 19 Sep 2018 15:20:49 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k26-v6sm39170825pfb.167.2018.09.19.15.20.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:48 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 04/12] OPP: Pass index to _of_init_opp_table() Date: Wed, 19 Sep 2018 15:20:23 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preparatory patch required for the next commit which will start using OPP table's node pointer in _of_init_opp_table(), which requires the index in order to read the OPP table's phandle. This commit adds the index argument in the call chains in order to get it delivered to _of_init_opp_table(). Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 19 +++++++++++++++---- drivers/opp/of.c | 12 +++++++----- drivers/opp/opp.h | 4 ++-- include/linux/pm_opp.h | 6 ++++++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 9f8aa31265fe..332748adc262 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -785,7 +785,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, return opp_dev; } -static struct opp_table *_allocate_opp_table(struct device *dev) +static struct opp_table *_allocate_opp_table(struct device *dev, int index) { struct opp_table *opp_table; struct opp_device *opp_dev; @@ -808,7 +808,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev) return NULL; } - _of_init_opp_table(opp_table, dev); + _of_init_opp_table(opp_table, dev, index); /* Find clk for the device */ opp_table->clk = clk_get(dev, NULL); @@ -833,7 +833,7 @@ void _get_opp_table_kref(struct opp_table *opp_table) kref_get(&opp_table->kref); } -struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) +static struct opp_table *_opp_get_opp_table(struct device *dev, int index) { struct opp_table *opp_table; @@ -844,15 +844,26 @@ struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) if (!IS_ERR(opp_table)) goto unlock; - opp_table = _allocate_opp_table(dev); + opp_table = _allocate_opp_table(dev, index); unlock: mutex_unlock(&opp_table_lock); return opp_table; } + +struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) +{ + return _opp_get_opp_table(dev, 0); +} EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table); +struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, + int index) +{ + return _opp_get_opp_table(dev, index); +} + static void _opp_table_kref_release(struct kref *kref) { struct opp_table *opp_table = container_of(kref, struct opp_table, kref); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 86222586f27b..1a9e1242a2a7 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -52,7 +52,8 @@ static struct opp_table *_managed_opp(const struct device_node *np) return managed_table; } -void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) +void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, + int index) { struct device_node *np; @@ -378,7 +379,8 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, } /* Initializes OPP tables based on new bindings */ -static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) +static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, + int index) { struct device_node *np; struct opp_table *opp_table; @@ -393,7 +395,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) goto put_opp_table; } - opp_table = dev_pm_opp_get_opp_table(dev); + opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); if (!opp_table) return -ENOMEM; @@ -526,7 +528,7 @@ int dev_pm_opp_of_add_table(struct device *dev) return _of_add_opp_table_v1(dev); } - ret = _of_add_opp_table_v2(dev, opp_np); + ret = _of_add_opp_table_v2(dev, opp_np, 0); of_node_put(opp_np); return ret; @@ -574,7 +576,7 @@ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) return -ENODEV; } - ret = _of_add_opp_table_v2(dev, opp_np); + ret = _of_add_opp_table_v2(dev, opp_np, index); of_node_put(opp_np); return ret; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 88e9f47aadf1..b235e76fc8cc 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -200,9 +200,9 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, in struct opp_table *_add_opp_table(struct device *dev); #ifdef CONFIG_OF -void _of_init_opp_table(struct opp_table *opp_table, struct device *dev); +void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); #else -static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {} +static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} #endif #ifdef CONFIG_DEBUG_FS diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 099b31960dec..5d399eeef172 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -79,6 +79,7 @@ struct dev_pm_set_opp_data { #if defined(CONFIG_PM_OPP) struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); +struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index); void dev_pm_opp_put_opp_table(struct opp_table *opp_table); unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); @@ -136,6 +137,11 @@ static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) return ERR_PTR(-ENOTSUPP); } +static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) From patchwork Wed Sep 19 22:20:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3BC5913 for ; Wed, 19 Sep 2018 22:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1EBD2CC86 for ; Wed, 19 Sep 2018 22:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3F1A2CC9B; Wed, 19 Sep 2018 22:21:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56C312CC86 for ; Wed, 19 Sep 2018 22:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728124AbeITEAw (ORCPT ); Thu, 20 Sep 2018 00:00:52 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39653 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731348AbeITEAv (ORCPT ); Thu, 20 Sep 2018 00:00:51 -0400 Received: by mail-pg1-f193.google.com with SMTP id 85-v6so327627pge.6 for ; Wed, 19 Sep 2018 15:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6ebVYraCbWvrsnGm3xtUNzVrcWRfL2zqlZLpD6LOi2s=; b=dxjJqa1vvwPFcHa03u/ywqzWZVjSAg+zQ0FUfhWhg+CmV6zWPXiDg3FTuIg/a0YyKI 4YVIOIxjGAif2hAns3p6bTfCickHn0wwirtX58hXnPGGb1t/6shCyxGqOmSI8z+8eZVK dmbmYz3dZ2xnncmMbnMPyAifJLoOg2CG1zSzs= 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:in-reply-to:references; bh=6ebVYraCbWvrsnGm3xtUNzVrcWRfL2zqlZLpD6LOi2s=; b=QHdflQLuDOD/nNzmja+OeD6mlF0cIXf4JfDvwfNKazniDOlwme600EjeSMoSrERUoi IAOtjqaG82NVXaq/REfb73H6tAg9OAnJ+M4MOGkZxvDnkyYRFdLXcNXhDhZY1mpexrMO RCafWYB0NQYVAbUz3e2AszCZFQlJOJenVqa6YFPCmJ/l2UkoqtsJv7YtTdu1xPWul7RE 1LpFevsqBmB20wZPGRFgvdkdWQZM4j4+pXmZxs4RXBMkhywOEt5R2IeuWV0t09yucJ3p 79Ja1nGFxkAJEsyqukKNx2cyAYYkSTkbZzBXiNxR5xrFkEWUEpk8cqI+Dex17DjhZd5Z 2C8A== X-Gm-Message-State: APzg51Di8r2F2lo2FB2tjjfvmrjQUdkS0RbdDKwlzFKK7QfsiXLVV/fJ N+LzkO4J07g2WW3Y9T60iV6ICA== X-Google-Smtp-Source: ANB0VdaEj/eLZDr/amGlqwY/1hmlKGRwTKBTzK6zP/15g6546upj42Yc4ps0qiPIJmkXUuJYRhYZig== X-Received: by 2002:a62:438f:: with SMTP id l15-v6mr38615178pfi.196.1537395650494; Wed, 19 Sep 2018 15:20:50 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id u184-v6sm41809554pgd.46.2018.09.19.15.20.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:49 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 05/12] OPP: Parse OPP table's DT properties from _of_init_opp_table() Date: Wed, 19 Sep 2018 15:20:24 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parse the DT properties present in the OPP table from _of_init_opp_table(), which is a dedicated routine for DT parsing. Minor relocation of helpers is required for this. It is possible now for _managed_opp() to return a partially initialized OPP table if the OPP table is created via the helpers like dev_pm_opp_set_supported_hw() and we need another flag to indicate if the static OPP are already parsed or not to make sure we don't incorrectly skip initializing the static OPPs. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 79 +++++++++++++++++++++++++++++++++---------------------- drivers/opp/opp.h | 2 ++ 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 1a9e1242a2a7..4a19f76880d3 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -23,6 +23,24 @@ #include "opp.h" +/* + * Returns opp descriptor node for a device node, caller must + * do of_node_put(). + */ +static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np, + int index) +{ + /* "operating-points-v2" can be an array for power domain providers */ + return of_parse_phandle(np, "operating-points-v2", index); +} + +/* Returns opp descriptor node for a device, caller must do of_node_put() */ +struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) +{ + return _opp_of_get_opp_desc_node(dev->of_node, 0); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); + static struct opp_table *_managed_opp(const struct device_node *np) { struct opp_table *opp_table, *managed_table = NULL; @@ -55,22 +73,37 @@ static struct opp_table *_managed_opp(const struct device_node *np) void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) { - struct device_node *np; + struct device_node *np, *opp_np; + u32 val; /* * Only required for backward compatibility with v1 bindings, but isn't * harmful for other cases. And so we do it unconditionally. */ np = of_node_get(dev->of_node); - if (np) { - u32 val; - - if (!of_property_read_u32(np, "clock-latency", &val)) - opp_table->clock_latency_ns_max = val; - of_property_read_u32(np, "voltage-tolerance", - &opp_table->voltage_tolerance_v1); - of_node_put(np); - } + if (!np) + return; + + if (!of_property_read_u32(np, "clock-latency", &val)) + opp_table->clock_latency_ns_max = val; + of_property_read_u32(np, "voltage-tolerance", + &opp_table->voltage_tolerance_v1); + + /* Get OPP table node */ + opp_np = _opp_of_get_opp_desc_node(np, index); + of_node_put(np); + + if (!opp_np) + return; + + if (of_property_read_bool(opp_np, "opp-shared")) + opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; + else + opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; + + opp_table->np = opp_np; + + of_node_put(opp_np); } static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, @@ -250,22 +283,6 @@ void dev_pm_opp_of_remove_table(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); -/* Returns opp descriptor node for a device node, caller must - * do of_node_put() */ -static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np, - int index) -{ - /* "operating-points-v2" can be an array for power domain providers */ - return of_parse_phandle(np, "operating-points-v2", index); -} - -/* Returns opp descriptor node for a device, caller must do of_node_put() */ -struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) -{ - return _opp_of_get_opp_desc_node(dev->of_node, 0); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); - /** * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings) * @opp_table: OPP table @@ -392,6 +409,9 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, /* OPPs are already managed */ if (!_add_opp_dev(dev, opp_table)) ret = -ENOMEM; + else if (!opp_table->parsed_static_opps) + goto initialize_static_opps; + goto put_opp_table; } @@ -399,6 +419,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (!opp_table) return -ENOMEM; +initialize_static_opps: /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_np, np) { count++; @@ -434,11 +455,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (pstate_count) opp_table->genpd_performance_state = true; - opp_table->np = opp_np; - if (of_property_read_bool(opp_np, "opp-shared")) - opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; - else - opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; + opp_table->parsed_static_opps = true; put_opp_table: dev_pm_opp_put_opp_table(opp_table); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index b235e76fc8cc..b04c2b511c4d 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -129,6 +129,7 @@ enum opp_table_access { * @lock: mutex protecting the opp_list and dev_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. + * @parsed_static_opps: True if OPPs are initialized from DT. * @shared_opp: OPP is shared between multiple devices. * @suspend_opp: Pointer to OPP to be used during device suspend. * @supported_hw: Array of version number to support. @@ -164,6 +165,7 @@ struct opp_table { /* For backward compatibility with v1 bindings */ unsigned int voltage_tolerance_v1; + bool parsed_static_opps; enum opp_table_access shared_opp; struct dev_pm_opp *suspend_opp; From patchwork Wed Sep 19 22:20:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E022913 for ; Wed, 19 Sep 2018 22:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EFF82C9BC for ; Wed, 19 Sep 2018 22:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126552CC9A; Wed, 19 Sep 2018 22:21:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEDAD2C9BC for ; Wed, 19 Sep 2018 22:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbeITEBa (ORCPT ); Thu, 20 Sep 2018 00:01:30 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43716 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733258AbeITEAw (ORCPT ); Thu, 20 Sep 2018 00:00:52 -0400 Received: by mail-pf1-f195.google.com with SMTP id j26-v6so3339364pfi.10 for ; Wed, 19 Sep 2018 15:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WirGS/aOSjVS/D7R/G1/ncvS7OJ05Sy4IF/d4iCNwD8=; b=fha9ep2Y2vw9rRqF09AyZZ8ZlWVXYyqZM5Q1h0q2YhrXNxungj8Mdm1ZHZySaVzJhc J+Ri+e9fLBrHNL2/yyYo0LthjssGM3j1zS4ucn4QdKyXKt7VlCj9ciQV4SZYwySjCJsA HGSoI8N3t286OoUVhOaHKirL8HjtFU3cDhem4= 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:in-reply-to:references; bh=WirGS/aOSjVS/D7R/G1/ncvS7OJ05Sy4IF/d4iCNwD8=; b=G47l19H7NgeRynOLWnabPKxlqGvaP8l+ZXpHMxKrVqA8bOiu82U9g1z/FPn/40y3Zd R44DpgX77luEhM96Ii7j0FVtaCw8LIz4HfdL0eNQvMpZCqYRTn26kyp47bdpUllZUjZf KKwa4M1I4YOURQny47EpBVmkb1YI0EZLgNmgYCsK8mom/wAL+ZarL+qDgtCeAF0inqpa rPc31In2vY9Znvtek+NODQsURoAbLysT+aP7AGqbzRPK+3RzodVCBhPrMFkO6+ymLzK9 6RsN2IUk6Irc79MKnBoGzA1qmEHJlCu0ZFSCDDK+3YLE4JsG706rbQapJrQU6q8kKPyA myyw== X-Gm-Message-State: APzg51C0fdgakmdFDPtXxzQDjjIqO4b5LHmnmggqxuTiLG5+OtmuODKJ zxZp3Qd+P0DkduV7uM+JXAjlTQ== X-Google-Smtp-Source: ANB0VdYBlfUiAgO95AoyLc7rDgHGLPz2TRMUsI9I8ldKBN8RuVJtEU0WvP6A1zPXW4WEFouZExmthg== X-Received: by 2002:a63:5204:: with SMTP id g4-v6mr33813789pgb.274.1537395651939; Wed, 19 Sep 2018 15:20:51 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id w16-v6sm53798471pfi.101.2018.09.19.15.20.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:51 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 06/12] OPP: Don't take OPP table's kref for static OPPs Date: Wed, 19 Sep 2018 15:20:25 -0700 Message-Id: <0ad8c623907c27f4b8572d36c4ba73ea103e3108.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The reference count is only required to be incremented for every call that may lead to adding the OPP table. For static OPPs the same should be done from the parent routine which adds all static OPPs together and so only one refcount for all static OPPs. Update code to reflect that. The refcount is incremented every time a dynamic OPP is created (as that can lead to creating the OPP table) and the same is dropped when the OPP is removed. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 332748adc262..2a6976265580 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -919,7 +919,6 @@ static void _opp_kref_release(struct kref *kref) kfree(opp); mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); } void dev_pm_opp_get(struct dev_pm_opp *opp) @@ -963,11 +962,15 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) if (found) { dev_pm_opp_put(opp); + + /* Drop the reference taken by dev_pm_opp_add() */ + dev_pm_opp_put_opp_table(opp_table); } else { dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", __func__, freq); } + /* Drop the reference taken by _find_opp_table() */ dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove); @@ -1085,9 +1088,6 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->opp_table = opp_table; kref_init(&new_opp->kref); - /* Get a reference to the OPP table */ - _get_opp_table_kref(opp_table); - ret = opp_debug_create_one(new_opp, opp_table); if (ret) dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", @@ -1566,8 +1566,9 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) return -ENOMEM; ret = _opp_add_v1(opp_table, dev, freq, u_volt, true); + if (ret) + dev_pm_opp_put_opp_table(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_add); From patchwork Wed Sep 19 22:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1E3714BD for ; Wed, 19 Sep 2018 22:21:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A22262C9BC for ; Wed, 19 Sep 2018 22:21:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967702CC9A; Wed, 19 Sep 2018 22:21:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1530A2C9BC for ; Wed, 19 Sep 2018 22:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387405AbeITEAz (ORCPT ); Thu, 20 Sep 2018 00:00:55 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38306 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733245AbeITEAy (ORCPT ); Thu, 20 Sep 2018 00:00:54 -0400 Received: by mail-pl1-f195.google.com with SMTP id u11-v6so3309238plq.5 for ; Wed, 19 Sep 2018 15:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=HX5eDqLq6MnZX9E6B4v/vOFT0a/x+hzpVnpPDmao/5Y=; b=iVliWPLgAZaeCvinWz/oXkCKCEBJw1rChrOeNhddY1LOHXqe/CHuwAQXYj44J7S12i 25l3DV1zAWvCPZDDN2CY767iL2caYnqVIbfSnFHr2mi9KdLXlxPYhe3FgFRarJGxxYIf F4zcVTyNjt0kBVeOH86pNmt/0oVYwvXw5XY0Q= 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:in-reply-to:references; bh=HX5eDqLq6MnZX9E6B4v/vOFT0a/x+hzpVnpPDmao/5Y=; b=hsohGDMbPyJh11qGixLv/x9joPd5tdZeoCfeBJXf12hFa8LuXUg55HGebZYUckr2XG SJ7Y/uaDWBizGyz1MhIC0SbX9hG3gPy766Yf8nNpPTBtAYwGL5OoXwkRSgAtpydMUZhp yXTI09AOuqNL5DbzOv1Si21Qn76cfzk9rmRBPvDA2DWftKsxFp24j/x3cYa1a6x26mnw lGtmoHJGzzhRBpgPmykUzN8nYyIcw94LT+e1llCsyXc4rSb9ze5GygpiJvsXk6iMnOHt a6l0Yut4M072N0fy6QK2rGowTDpP1IV4dRbtCCpfxb0ddpEvcCJy7cfZWiTaUbqy/EfI +DlQ== X-Gm-Message-State: APzg51CuDBYz9jWyjTCNjcfykbpxO9aEV6Ot4ojA4EOV9Q16MkulNKKf 0T6M0vUnvZdqQaMtav1CgSZhlQ== X-Google-Smtp-Source: ANB0VdaMzdZ9LY/xeffQPA75Z+yo0kf4CNQySawO/f+ejIe+5cFIcLO87WkvQwHghoOSuTg5GbeNRQ== X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr36276933plb.86.1537395653568; Wed, 19 Sep 2018 15:20:53 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id x9-v6sm33824822pfd.31.2018.09.19.15.20.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:52 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 07/12] OPP: Create separate kref for static OPPs list Date: Wed, 19 Sep 2018 15:20:26 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The static OPPs don't always get freed with the OPP table, it can happen before that as well. For example, if the OPP table is first created using helpers like dev_pm_opp_set_supported_hw() and the OPPs are created at a later point. Now when the OPPs are removed, the OPP table stays until the time dev_pm_opp_put_supported_hw() is called. Later patches will streamline the freeing of OPP table and that requires the static OPPs to get freed with help of a separate kernel reference. This patch prepares for that by creating a separate kref for static OPPs list. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 33 ++++++++++++++++++++++++++++++++- drivers/opp/of.c | 7 +++++++ drivers/opp/opp.h | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2a6976265580..b555121b878b 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -892,6 +892,33 @@ static void _opp_table_kref_release(struct kref *kref) mutex_unlock(&opp_table_lock); } +void _opp_remove_all_static(struct opp_table *opp_table) +{ + struct dev_pm_opp *opp, *tmp; + + list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { + if (!opp->dynamic) + dev_pm_opp_put(opp); + } + + opp_table->parsed_static_opps = false; +} + +static void _opp_table_list_kref_release(struct kref *kref) +{ + struct opp_table *opp_table = container_of(kref, struct opp_table, + list_kref); + + _opp_remove_all_static(opp_table); + mutex_unlock(&opp_table_lock); +} + +void _put_opp_list_kref(struct opp_table *opp_table) +{ + kref_put_mutex(&opp_table->list_kref, _opp_table_list_kref_release, + &opp_table_lock); +} + void dev_pm_opp_put_opp_table(struct opp_table *opp_table) { kref_put_mutex(&opp_table->kref, _opp_table_kref_release, @@ -1746,8 +1773,11 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, /* Find if opp_table manages a single device */ if (list_is_singular(&opp_table->dev_list)) { /* Free static OPPs */ + _put_opp_list_kref(opp_table); + + /* Free dynamic OPPs */ list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { - if (remove_all || !opp->dynamic) + if (remove_all) dev_pm_opp_put(opp); } @@ -1758,6 +1788,7 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, if (opp_table->genpd_performance_state) dev_pm_genpd_set_performance_state(dev, 0); } else { + _put_opp_list_kref(opp_table); _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 4a19f76880d3..aaa4bab69846 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -411,6 +411,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, ret = -ENOMEM; else if (!opp_table->parsed_static_opps) goto initialize_static_opps; + else + kref_get(&opp_table->list_kref); goto put_opp_table; } @@ -420,6 +422,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, return -ENOMEM; initialize_static_opps: + kref_init(&opp_table->list_kref); + /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_np, np) { count++; @@ -437,6 +441,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, /* There should be one of more OPP defined */ if (WARN_ON(!count)) { ret = -ENOENT; + _put_opp_list_kref(opp_table); goto put_opp_table; } @@ -491,6 +496,8 @@ static int _of_add_opp_table_v1(struct device *dev) if (!opp_table) return -ENOMEM; + kref_init(&opp_table->list_kref); + val = prop->value; while (nr) { unsigned long freq = be32_to_cpup(val++) * 1000; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index b04c2b511c4d..9274116c90e4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -126,6 +126,7 @@ enum opp_table_access { * @dev_list: list of devices that share these OPPs * @opp_list: table of opps * @kref: for reference count of the table. + * @list_kref: for reference count of the OPP list. * @lock: mutex protecting the opp_list and dev_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. @@ -157,6 +158,7 @@ struct opp_table { struct list_head dev_list; struct list_head opp_list; struct kref kref; + struct kref list_kref; struct mutex lock; struct device_node *np; @@ -200,6 +202,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *o int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, int last_cpu); struct opp_table *_add_opp_table(struct device *dev); +void _put_opp_list_kref(struct opp_table *opp_table); #ifdef CONFIG_OF void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); From patchwork Wed Sep 19 22:20:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C342D14BD for ; Wed, 19 Sep 2018 22:21:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3AE62C9BC for ; Wed, 19 Sep 2018 22:21:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7DFF2CC9A; Wed, 19 Sep 2018 22:21:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 554B02C9BC for ; Wed, 19 Sep 2018 22:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732702AbeITEBX (ORCPT ); Thu, 20 Sep 2018 00:01:23 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39443 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387404AbeITEA4 (ORCPT ); Thu, 20 Sep 2018 00:00:56 -0400 Received: by mail-pf1-f193.google.com with SMTP id j8-v6so3347669pff.6 for ; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=25gV/yr+DQaieOUd7LXdpHMVharUDBC9tXEOJxeQeO8=; b=Djc6bI6BMMVojfSs9W39ToJZ753bA6PsqPD81ey1/C6zHiIfxmZW6YnXtHhub/fUNm 7HMSwb/5oxeFPv89MelgsJ76rIoRbPpkKQjuQSkDhXcmrMVXJXFvLri/s5j7QEj5CvVv Y5Tty7RqTw+A7oAp+29XLZVaByP+2HFlecf5c= 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:in-reply-to:references; bh=25gV/yr+DQaieOUd7LXdpHMVharUDBC9tXEOJxeQeO8=; b=FCBf0VZH7PX8zsTs7Sr45mL0r2ulGg71TH194iN7dA7v80gVoxdWh1fY334V1anqrK f+D2+40Qgic/TgUApmfDwpGDR/kEjuYfw8hseKo1fk4kW9IvRRYFPHF2AcqUfmlSr/TR 4TQFuOOSi2ok7s8uN34zxe217D7Z6ensh2ex+0H1IKWFrha4BfGx/+Wkwy/xdesWNwoY 7FCa+3Vwv/4JI5oVITCXkRhZ/rPdHd78rEzBKG4qw6UjlIh36tKDs/KgrGZlbTZOhuyb ohctlNXTXMJDgP1hFWUKhKHSJtjTz6Loplj/AKINzawL1ws+SCHaAGRZR063coiG45y7 ujRw== X-Gm-Message-State: APzg51C8di9spJARY5gLiA5X9Cxr6jO0hl+h7PmSUeiSLXExYjGYyhWq ioxLptZULiO4KAUVjaIFmNoiZQ== X-Google-Smtp-Source: ANB0VdbnIvHZfHKwjt12/ZMC4gDh+MnJZSinZAWMt77a/ti42fjrtALCbyoQD6ymS14FPdNT8bPyeg== X-Received: by 2002:a63:26c6:: with SMTP id m189-v6mr33939143pgm.70.1537395655114; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k23-v6sm23996094pgl.42.2018.09.19.15.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:54 -0700 (PDT) From: Viresh Kumar To: Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Stephen Boyd , Nishanth Menon , Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 08/12] cpufreq: mvebu: Remove OPPs using dev_pm_opp_remove() Date: Wed, 19 Sep 2018 15:20:27 -0700 Message-Id: <883071c4bd9a6e45bf0b5e45575d110eaeb2e6d0.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP dev_pm_opp_cpumask_remove_table() is going to change in the next commit and will not remove dynamic OPPs automatically. They must be removed with a call to dev_pm_opp_remove(). Reviewed-by: Gregory CLEMENT Signed-off-by: Viresh Kumar --- drivers/cpufreq/mvebu-cpufreq.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/mvebu-cpufreq.c b/drivers/cpufreq/mvebu-cpufreq.c index 31513bd42705..6d33a639f902 100644 --- a/drivers/cpufreq/mvebu-cpufreq.c +++ b/drivers/cpufreq/mvebu-cpufreq.c @@ -84,9 +84,10 @@ static int __init armada_xp_pmsu_cpufreq_init(void) ret = dev_pm_opp_add(cpu_dev, clk_get_rate(clk) / 2, 0); if (ret) { + dev_pm_opp_remove(cpu_dev, clk_get_rate(clk)); clk_put(clk); dev_err(cpu_dev, "Failed to register OPPs\n"); - goto opp_register_failed; + return ret; } ret = dev_pm_opp_set_sharing_cpus(cpu_dev, @@ -99,11 +100,5 @@ static int __init armada_xp_pmsu_cpufreq_init(void) platform_device_register_simple("cpufreq-dt", -1, NULL, 0); return 0; - -opp_register_failed: - /* As registering has failed remove all the opp for all cpus */ - dev_pm_opp_cpumask_remove_table(cpu_possible_mask); - - return ret; } device_initcall(armada_xp_pmsu_cpufreq_init); From patchwork Wed Sep 19 22:20:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A978913 for ; Wed, 19 Sep 2018 22:21:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B78D2C9BC for ; Wed, 19 Sep 2018 22:21:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EE5B2CC9A; Wed, 19 Sep 2018 22:21:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80BF82C9BC for ; Wed, 19 Sep 2018 22:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732890AbeITEBB (ORCPT ); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43302 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387458AbeITEA5 (ORCPT ); Thu, 20 Sep 2018 00:00:57 -0400 Received: by mail-pg1-f195.google.com with SMTP id q19-v6so2534151pgn.10 for ; Wed, 19 Sep 2018 15:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=lOCO4EDC8Q7oDBzPlggldAfccotE1FhuTN71HpuLTTI=; b=dxzQxtXOMt24gp9Kdm/pMZ4LveTazVeLqdhF0qSrKiMNHtcJ44NVLQzl9NBf+hGERr JhaKkEzKDIC4UUM4N51wTgrXmUhXBu5rFIbe7nDqq/HjP0dKHAXUBMbLAquaY8pySmiy itRyPU2Xdg6pKq0p+JcgiptMxGSHBVQbyWTsE= 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:in-reply-to:references; bh=lOCO4EDC8Q7oDBzPlggldAfccotE1FhuTN71HpuLTTI=; b=prZEF+Doog1ybaXc33x0a0cpSCcqUYVKshc80goxpXnjALF2l4B84NWrp7HxPA0aTO KzV3+TB/DCahoMktygZ7x5B+hEaZr12m46EKBI6fBH8rBxb/+N1JTwAnbUQHKJJ4QkZh qmCZP/uPDlWzvDIpi2EE8FCvbtuoEnxZbLSZV/lTTIIjU3dZPkBLTCKCaeNt6lo0P/RT tLB1IVQs5MyxAWQx0q7JCASPIGsARpjIynV+dvwhCp2cxsbMVp1tdjx9BfSgVBf0sPC3 g5RYzEJMM66SFvzUr5C8LPXInFiOYnhuMT0UReZXJn1VyHjB3Bwlg//D4jmsrcvsARsD HAVw== X-Gm-Message-State: APzg51AEWOI1Hr86GXJ5holdRbExE3wySG/zZgMVMT+kL7Ss5U5EdqUD U/40o014zWM7SZmgKFtZeztpkA== X-Google-Smtp-Source: ANB0VdaL1SAy6f+k+QqxgnNOtaMzq9r0+V5SBrXriQSGTNP4raT39QMHeqYwfQq/s0SG59BTbXBKeA== X-Received: by 2002:a62:225d:: with SMTP id i90-v6mr37923089pfi.246.1537395656692; Wed, 19 Sep 2018 15:20:56 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id f11-v6sm32580232pfa.131.2018.09.19.15.20.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:56 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 09/12] OPP: Don't remove dynamic OPPs from _dev_pm_opp_remove_table() Date: Wed, 19 Sep 2018 15:20:28 -0700 Message-Id: <2a4eb7358aba6beff7fa23f028c733310756e525.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Only one platform was depending on this feature and it is already updated now. Stop removing dynamic OPPs from _dev_pm_opp_remove_table(). This simplifies lot of paths and removes unnecessary parameters. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 20 +++++--------------- drivers/opp/cpu.c | 9 +++------ drivers/opp/of.c | 12 ++++++------ drivers/opp/opp.h | 6 +++--- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index b555121b878b..2319ad4a0177 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1759,14 +1759,10 @@ int dev_pm_opp_unregister_notifier(struct device *dev, EXPORT_SYMBOL(dev_pm_opp_unregister_notifier); /* - * Free OPPs either created using static entries present in DT or even the - * dynamically added entries based on remove_all param. + * Free OPPs either created using static entries present in DT. */ -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, - bool remove_all) +void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev) { - struct dev_pm_opp *opp, *tmp; - /* Protect dev_list */ mutex_lock(&opp_table->lock); @@ -1775,12 +1771,6 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, /* Free static OPPs */ _put_opp_list_kref(opp_table); - /* Free dynamic OPPs */ - list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { - if (remove_all) - dev_pm_opp_put(opp); - } - /* * The OPP table is getting removed, drop the performance state * constraints. @@ -1795,7 +1785,7 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, mutex_unlock(&opp_table->lock); } -void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) +void _dev_pm_opp_find_and_remove_table(struct device *dev) { struct opp_table *opp_table; @@ -1812,7 +1802,7 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) return; } - _dev_pm_opp_remove_table(opp_table, dev, remove_all); + _dev_pm_opp_remove_table(opp_table, dev); dev_pm_opp_put_opp_table(opp_table); } @@ -1826,6 +1816,6 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) */ void dev_pm_opp_remove_table(struct device *dev) { - _dev_pm_opp_find_and_remove_table(dev, true); + _dev_pm_opp_find_and_remove_table(dev); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 36586f66cd83..ab6d07e78945 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -108,7 +108,7 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table); #endif /* CONFIG_CPU_FREQ */ -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu) { struct device *cpu_dev; @@ -127,10 +127,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, continue; } - if (of) - dev_pm_opp_of_remove_table(cpu_dev); - else - dev_pm_opp_remove_table(cpu_dev); + _dev_pm_opp_find_and_remove_table(cpu_dev); } } @@ -144,7 +141,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, */ void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, false, -1); + _dev_pm_opp_cpumask_remove_table(cpumask, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index aaa4bab69846..861cc75de329 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -279,7 +279,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, */ void dev_pm_opp_of_remove_table(struct device *dev) { - _dev_pm_opp_find_and_remove_table(dev, false); + _dev_pm_opp_find_and_remove_table(dev); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); @@ -432,7 +432,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); - _dev_pm_opp_remove_table(opp_table, dev, false); + _dev_pm_opp_remove_table(opp_table, dev); of_node_put(np); goto put_opp_table; } @@ -453,7 +453,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, dev_err(dev, "Not all nodes have performance state set (%d: %d)\n", count, pstate_count); ret = -ENOENT; - _dev_pm_opp_remove_table(opp_table, dev, false); + _dev_pm_opp_remove_table(opp_table, dev); goto put_opp_table; } @@ -507,7 +507,7 @@ static int _of_add_opp_table_v1(struct device *dev) if (ret) { dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); - _dev_pm_opp_remove_table(opp_table, dev, false); + _dev_pm_opp_remove_table(opp_table, dev); break; } nr -= 2; @@ -618,7 +618,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); */ void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, true, -1); + _dev_pm_opp_cpumask_remove_table(cpumask, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); @@ -653,7 +653,7 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) __func__, cpu, ret); /* Free all other OPPs */ - _dev_pm_opp_cpumask_remove_table(cpumask, true, cpu); + _dev_pm_opp_cpumask_remove_table(cpumask, cpu); break; } } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 9274116c90e4..98dd7d39e1ad 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -194,13 +194,13 @@ void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all); -void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all); +void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev); +void _dev_pm_opp_find_and_remove_table(struct device *dev); struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, int last_cpu); +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu); struct opp_table *_add_opp_table(struct device *dev); void _put_opp_list_kref(struct opp_table *opp_table); From patchwork Wed Sep 19 22:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A183D913 for ; Wed, 19 Sep 2018 22:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F4FE2C9BC for ; Wed, 19 Sep 2018 22:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8319B2CC9A; Wed, 19 Sep 2018 22:21:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D85BF2C9BC for ; Wed, 19 Sep 2018 22:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387471AbeITEBB (ORCPT ); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43725 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387459AbeITEA7 (ORCPT ); Thu, 20 Sep 2018 00:00:59 -0400 Received: by mail-pf1-f194.google.com with SMTP id j26-v6so3339484pfi.10 for ; Wed, 19 Sep 2018 15:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FGjzVhkQGPOODLqAXRdoaHZm4n2l5c0zwlvyqWMhwuw=; b=a3osEZ3sHowHWjU78Z2zkw3YpuUItl/Yoh4wmulmmJDKNHQ3lp3Dbe2TntakK96VCQ DhSc6Zkvb5Pgo8QlXVP/JW0mum/05dyz13mMThJVeKiSbRnZbv9wa//6BenKqDIQcdEI MLX3cNzrrg51ZD9vTtSY70F1UuFfmJKQ9b59Y= 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:in-reply-to:references; bh=FGjzVhkQGPOODLqAXRdoaHZm4n2l5c0zwlvyqWMhwuw=; b=dvaPIPx+XcgFl5uGjpDdMMNssC83+xCGuh4hDWzk6maLqTBOZ+ffEwoEOX/3HIvcFj TS5xjvIRK052Yt/jmI0ezBWjWRxtzRTpjSetcC9s6vVA+fAnQUnbf0CC1qJvKMpqUWtC BJiVdZJEFIMwmY4mhs0+pjhWoXXsAtjUORLSLd1ntE2Jm/1CGPQm5lvdUYY9lnq3J8C6 0SG4YpVxnQkgbogpzHmjHSvO51jZYvbnkVycEHVyCw6UH1NCPS4DpD7aiepQ7l9GB1mW 0dgAdS5dYdPh3CbxIdHLSIrbApW7yZH6zyQ081waenb2mWS+fJOtE8zRwAVcDWFvIzvX Outw== X-Gm-Message-State: APzg51CJZ/PMbL4F0Ic8i80/iBR+gFAvgQbEYJrzre6IEoKUImbb3+39 AO3OJyhb1n1LljPmnX0C4caBow== X-Google-Smtp-Source: ANB0VdYr4472Fk9sjTEL+bGEBu5U0/cqXD+U0GdhXLXBcq1nrQdmD9YZeAvNJkaMit7RnSoyOfD5ew== X-Received: by 2002:a63:7a50:: with SMTP id j16-v6mr97237pgn.112.1537395658493; Wed, 19 Sep 2018 15:20:58 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id v26-v6sm30312412pfe.57.2018.09.19.15.20.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:57 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 10/12] OPP: Use a single mechanism to free the OPP table Date: Wed, 19 Sep 2018 15:20:29 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently there are two separate ways to free the OPP table based on how it is created in the first place. We call _dev_pm_opp_remove_table() to free the static and/or dynamic OPP, OPP list devices, etc. This is done for the case where the OPP table is added while initializing the OPPs, like via the path dev_pm_opp_of_add_table(). We also call dev_pm_opp_put_opp_table() in some cases which eventually frees the OPP table structure once the reference count reaches 0. This is used by the first case as well as other cases like dev_pm_opp_set_regulators() where the OPPs aren't necessarily initialized at this point. This whole thing is a bit unclear and messy and obstruct any further cleanup/fixup of OPP core. This patch tries to streamline this by keeping a single path for OPP table destruction, i.e. dev_pm_opp_put_opp_table(). All the cleanup happens in _opp_table_kref_release() now after the reference count reaches 0. _dev_pm_opp_remove_table() is removed as it isn't required anymore. We don't drop the reference to the OPP table after creating it from _of_add_opp_table_v{1|2}() anymore and the same is dropped only when we try to remove them. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 54 ++++++++++++++++-------------------------------------- drivers/opp/of.c | 32 ++++++++++++++++++-------------- drivers/opp/opp.h | 2 +- 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2319ad4a0177..d3e33fd32694 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -867,23 +867,24 @@ struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, static void _opp_table_kref_release(struct kref *kref) { struct opp_table *opp_table = container_of(kref, struct opp_table, kref); - struct opp_device *opp_dev; + struct opp_device *opp_dev, *temp; /* Release clk */ if (!IS_ERR(opp_table->clk)) clk_put(opp_table->clk); - /* - * No need to take opp_table->lock here as we are guaranteed that no - * references to the OPP table are taken at this point. - */ - opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, - node); + WARN_ON(!list_empty(&opp_table->opp_list)); - _remove_opp_dev(opp_dev, opp_table); + list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) { + /* + * The OPP table is getting removed, drop the performance state + * constraints. + */ + if (opp_table->genpd_performance_state) + dev_pm_genpd_set_performance_state((struct device *)(opp_dev->dev), 0); - /* dev_list must be empty now */ - WARN_ON(!list_empty(&opp_table->dev_list)); + _remove_opp_dev(opp_dev, opp_table); + } mutex_destroy(&opp_table->lock); list_del(&opp_table->node); @@ -1758,33 +1759,6 @@ int dev_pm_opp_unregister_notifier(struct device *dev, } EXPORT_SYMBOL(dev_pm_opp_unregister_notifier); -/* - * Free OPPs either created using static entries present in DT. - */ -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev) -{ - /* Protect dev_list */ - mutex_lock(&opp_table->lock); - - /* Find if opp_table manages a single device */ - if (list_is_singular(&opp_table->dev_list)) { - /* Free static OPPs */ - _put_opp_list_kref(opp_table); - - /* - * The OPP table is getting removed, drop the performance state - * constraints. - */ - if (opp_table->genpd_performance_state) - dev_pm_genpd_set_performance_state(dev, 0); - } else { - _put_opp_list_kref(opp_table); - _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); - } - - mutex_unlock(&opp_table->lock); -} - void _dev_pm_opp_find_and_remove_table(struct device *dev) { struct opp_table *opp_table; @@ -1802,8 +1776,12 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev) return; } - _dev_pm_opp_remove_table(opp_table, dev); + _put_opp_list_kref(opp_table); + + /* Drop reference taken by _find_opp_table() */ + dev_pm_opp_put_opp_table(opp_table); + /* Drop reference taken while the OPP table was added */ dev_pm_opp_put_opp_table(opp_table); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 861cc75de329..ae0436eaa911 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -407,14 +407,17 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, opp_table = _managed_opp(opp_np); if (opp_table) { /* OPPs are already managed */ - if (!_add_opp_dev(dev, opp_table)) + if (!_add_opp_dev(dev, opp_table)) { ret = -ENOMEM; - else if (!opp_table->parsed_static_opps) - goto initialize_static_opps; - else + goto put_opp_table; + } + + if (opp_table->parsed_static_opps) { kref_get(&opp_table->list_kref); + return 0; + } - goto put_opp_table; + goto initialize_static_opps; } opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); @@ -432,17 +435,15 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); - _dev_pm_opp_remove_table(opp_table, dev); of_node_put(np); - goto put_opp_table; + goto put_list_kref; } } /* There should be one of more OPP defined */ if (WARN_ON(!count)) { ret = -ENOENT; - _put_opp_list_kref(opp_table); - goto put_opp_table; + goto put_list_kref; } list_for_each_entry(opp, &opp_table->opp_list, node) @@ -453,8 +454,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, dev_err(dev, "Not all nodes have performance state set (%d: %d)\n", count, pstate_count); ret = -ENOENT; - _dev_pm_opp_remove_table(opp_table, dev); - goto put_opp_table; + goto put_list_kref; } if (pstate_count) @@ -462,6 +462,10 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, opp_table->parsed_static_opps = true; + return 0; + +put_list_kref: + _put_opp_list_kref(opp_table); put_opp_table: dev_pm_opp_put_opp_table(opp_table); @@ -507,13 +511,13 @@ static int _of_add_opp_table_v1(struct device *dev) if (ret) { dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); - _dev_pm_opp_remove_table(opp_table, dev); - break; + _put_opp_list_kref(opp_table); + dev_pm_opp_put_opp_table(opp_table); + return ret; } nr -= 2; } - dev_pm_opp_put_opp_table(opp_table); return ret; } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 98dd7d39e1ad..f9fbb7553fc4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -190,11 +190,11 @@ struct opp_table { /* Routines internal to opp core */ void dev_pm_opp_get(struct dev_pm_opp *opp); +void _opp_remove_all_static(struct opp_table *opp_table); void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev); void _dev_pm_opp_find_and_remove_table(struct device *dev); struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp); From patchwork Wed Sep 19 22:20:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9E1C913 for ; Wed, 19 Sep 2018 22:21:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA3232C9BC for ; Wed, 19 Sep 2018 22:21:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B70F2CC9A; Wed, 19 Sep 2018 22:21:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 137C72C9BC for ; Wed, 19 Sep 2018 22:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387504AbeITEBB (ORCPT ); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34567 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387462AbeITEBB (ORCPT ); Thu, 20 Sep 2018 00:01:01 -0400 Received: by mail-pl1-f193.google.com with SMTP id f6-v6so3310601plo.1 for ; Wed, 19 Sep 2018 15:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rxiJu/KT0VOL6VfChRrYVDga8+0QfxrCXpVuzdXnBO4=; b=ikzmAEGB42Zj3XDq48lFhnbEIA+c4LuNJVaQsujEHiXSx6BS3+oapROn/ZkNBKiMsm wL4GwkY2G66JLWmNNyTaeOCduCVoUZmepJKZnaevA7P+ckL6+5JviKqvH9Zx+I9CsaJi hdOJHWpo9kSX+XGRMIkbSJyIAzaYlAjN9Ktm0= 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:in-reply-to:references; bh=rxiJu/KT0VOL6VfChRrYVDga8+0QfxrCXpVuzdXnBO4=; b=Wb9RG+B1i7LYxb3bo+obCDkXRYT1/Laowe2Ad2Zrv0oRN7DpVEU5ax/Qvb0955EXb6 85mJROgR2Q4M5qRsgMkl2d9zef/4VQD8eSFoXxj3aew67qEwCCW/1qw6UAbVZ1lubNbf YAQDGw4YlMtxTPtz/zBC+IKO8b6FQbGn9YQWqScJi8hmFvnHriCrCIlz+nBX2Zj31sj9 8bWkflWtLXeNqAnqVU2UzVjGXGRMerbd1KVmXtLqdnr48djac7MeiwyvFsuNZWLStssO 1oBIgJD0sfnRYrcZK5tTPZrVAC+Z3C2fvsm6YYFIRJWSkqDIyrbgUYPbxo2By6sjuQO/ rwNQ== X-Gm-Message-State: APzg51B6/mOChFXFJqzhzkVMRGQt8xflgNX3XSirKVAF6rTey2Q2v9GI neUql14BJpUeW2k6/ccRPJrOVA== X-Google-Smtp-Source: ANB0Vdb1TvlsFQtZY6IiAI98YjFGq2CzW61mBkfyyMzKE/e+pYkZ2uKkBNe+evlmoAZbtbSHpHLPkg== X-Received: by 2002:a17:902:8a92:: with SMTP id p18-v6mr36016518plo.148.1537395660158; Wed, 19 Sep 2018 15:21:00 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id w81-v6sm41086185pfk.92.2018.09.19.15.20.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:59 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 11/12] OPP: Prevent creating multiple OPP tables for devices sharing OPP nodes Date: Wed, 19 Sep 2018 15:20:30 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When two or more devices are sharing their clock and voltage rails, they share the same OPP table. But there are some corner cases where the OPP core incorrectly creates separate OPP tables for them. For example, CPU 0 and 1 share clock/voltage rails. The platform specific code calls dev_pm_opp_set_regulators() for CPU0 and the OPP core creates an OPP table for it (the individual OPPs aren't initialized as of now). The same is repeated for CPU1 then. Because _opp_get_opp_table() doesn't compare DT node pointers currently, it fails to find the link between CPU0 and CPU1 and so creates a new OPP table. Fix this by calling _managed_opp() from _opp_get_opp_table(). _managed_opp() gain an additional argument (index) to get the right node pointer. This resulted in simplifying code in _of_add_opp_table_v2() as well. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 25 ++++++++++++++++++++++--- drivers/opp/of.c | 35 +++++++++++++---------------------- drivers/opp/opp.h | 2 ++ 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index d3e33fd32694..aaef20cf4df2 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -759,8 +759,8 @@ static void _remove_opp_dev(struct opp_device *opp_dev, kfree(opp_dev); } -struct opp_device *_add_opp_dev(const struct device *dev, - struct opp_table *opp_table) +struct opp_device *_add_opp_dev_unlocked(const struct device *dev, + struct opp_table *opp_table) { struct opp_device *opp_dev; int ret; @@ -772,7 +772,6 @@ struct opp_device *_add_opp_dev(const struct device *dev, /* Initialize opp-dev */ opp_dev->dev = dev; - mutex_lock(&opp_table->lock); list_add(&opp_dev->node, &opp_table->dev_list); /* Create debugfs entries for the opp_table */ @@ -780,6 +779,17 @@ struct opp_device *_add_opp_dev(const struct device *dev, if (ret) dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", __func__, ret); + + return opp_dev; +} + +struct opp_device *_add_opp_dev(const struct device *dev, + struct opp_table *opp_table) +{ + struct opp_device *opp_dev; + + mutex_lock(&opp_table->lock); + opp_dev = _add_opp_dev_unlocked(dev, opp_table); mutex_unlock(&opp_table->lock); return opp_dev; @@ -844,6 +854,15 @@ static struct opp_table *_opp_get_opp_table(struct device *dev, int index) if (!IS_ERR(opp_table)) goto unlock; + opp_table = _managed_opp(dev, index); + if (opp_table) { + if (!_add_opp_dev_unlocked(dev, opp_table)) { + dev_pm_opp_put_opp_table(opp_table); + opp_table = NULL; + } + goto unlock; + } + opp_table = _allocate_opp_table(dev, index); unlock: diff --git a/drivers/opp/of.c b/drivers/opp/of.c index ae0436eaa911..1ddef52c27fd 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -41,11 +41,14 @@ struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); -static struct opp_table *_managed_opp(const struct device_node *np) +struct opp_table *_managed_opp(struct device *dev, int index) { struct opp_table *opp_table, *managed_table = NULL; + struct device_node *np; - mutex_lock(&opp_table_lock); + np = _opp_of_get_opp_desc_node(dev->of_node, index); + if (!np) + return NULL; list_for_each_entry(opp_table, &opp_tables, node) { if (opp_table->np == np) { @@ -65,7 +68,7 @@ static struct opp_table *_managed_opp(const struct device_node *np) } } - mutex_unlock(&opp_table_lock); + of_node_put(np); return managed_table; } @@ -401,30 +404,19 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, { struct device_node *np; struct opp_table *opp_table; - int ret = 0, count = 0, pstate_count = 0; + int ret, count = 0, pstate_count = 0; struct dev_pm_opp *opp; - opp_table = _managed_opp(opp_np); - if (opp_table) { - /* OPPs are already managed */ - if (!_add_opp_dev(dev, opp_table)) { - ret = -ENOMEM; - goto put_opp_table; - } - - if (opp_table->parsed_static_opps) { - kref_get(&opp_table->list_kref); - return 0; - } - - goto initialize_static_opps; - } - opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); if (!opp_table) return -ENOMEM; -initialize_static_opps: + /* OPP table is already initialized for the device */ + if (opp_table->parsed_static_opps) { + kref_get(&opp_table->list_kref); + return 0; + } + kref_init(&opp_table->list_kref); /* We have opp-table node now, iterate over it and add OPPs */ @@ -466,7 +458,6 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, put_list_kref: _put_opp_list_kref(opp_table); -put_opp_table: dev_pm_opp_put_opp_table(opp_table); return ret; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index f9fbb7553fc4..9c6544b4f4f9 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -206,8 +206,10 @@ void _put_opp_list_kref(struct opp_table *opp_table); #ifdef CONFIG_OF void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); +struct opp_table *_managed_opp(struct device *dev, int index); #else static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} +static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; } #endif #ifdef CONFIG_DEBUG_FS From patchwork Wed Sep 19 22:20:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10606613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C618314BD for ; Wed, 19 Sep 2018 22:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2D1A2C9BC for ; Wed, 19 Sep 2018 22:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A299D2CC9A; Wed, 19 Sep 2018 22:21:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29F822C9BC for ; Wed, 19 Sep 2018 22:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387546AbeITEBC (ORCPT ); Thu, 20 Sep 2018 00:01:02 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38693 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387400AbeITEBC (ORCPT ); Thu, 20 Sep 2018 00:01:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id t84-v6so3394264pgb.5 for ; Wed, 19 Sep 2018 15:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=hhjieuyCFF5O3dZJ7hBHeN+t4o6LV6wzvk0nAfJBO0tOBLRhitxoGt/uNlyTwgFAuj kiEIPcaxjMAEuTNiHupwpORBRBSIM7YeX/KHhHiOdiowaviDkLmFjis0/ewTbtRkZHdz B12lgvkMKp8upAfDAPVWxk8hzgd7wJ8l19sXg= 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:in-reply-to:references; bh=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=i6FPanH4fsscoFl3RcE0dFDbQt+DI9fpNA7Alv91huc49OTqIK02kIlBpo5C12cARd Fr4zRAhcLU9cE4ZDriZfdA49lOXF6hDAkzwU5yp5JM1Su/dsfRkUz6M9W+Y0diGdReLl LNb5EMXGsKSpHZpi3I+RHWjmTwVczidPzoAWhTiY6ouuFiagqzGmlNvx48qbWUggBIuf C5AEzqVFE5JhDS+7UBIwXbRsWd3nUvVy/O2GafaYGhmaIGH+sfn3ps2rhhI4SS7/945R Krgu6RmwuTWnLVY2/90ofxYsCDo0zvWLdtkl53TvfL++4kYT1aRcI7FQKDaKpQuc2mlS t8wg== X-Gm-Message-State: APzg51CQ7Wc/NSnZyacvPZJ+QcRjJ1mw/b4o0IPHS1kYLaS1F9DQq2za ESxzWa3u0KV0VWZW04Pmt1phLQ== X-Google-Smtp-Source: ANB0VdbjJ9xAe5zBsb00IxYeJqEf6204GfVsA0SNWBo269V/4sNaY1PSco7MQreU5cge9kqf/KAHsg== X-Received: by 2002:a63:8648:: with SMTP id x69-v6mr32605489pgd.268.1537395661604; Wed, 19 Sep 2018 15:21:01 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id h130-v6sm27647724pgc.88.2018.09.19.15.21.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:21:00 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 12/12] OPP: Pass OPP table to _of_add_opp_table_v{1|2}() Date: Wed, 19 Sep 2018 15:20:31 -0700 Message-Id: <9ea47a1cc5f08797e6c854c234acbe269b98405a.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both _of_add_opp_table_v1() and _of_add_opp_table_v2() contain similar code to get the OPP table and their parent routine also parses the DT to find the OPP table's node pointer. This can be simplified by getting the OPP table in advance and then passing it as argument to these routines. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 68 +++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 1ddef52c27fd..a71ff3acca0f 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -399,18 +399,12 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, } /* Initializes OPP tables based on new bindings */ -static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, - int index) +static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table) { struct device_node *np; - struct opp_table *opp_table; int ret, count = 0, pstate_count = 0; struct dev_pm_opp *opp; - opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); - if (!opp_table) - return -ENOMEM; - /* OPP table is already initialized for the device */ if (opp_table->parsed_static_opps) { kref_get(&opp_table->list_kref); @@ -420,7 +414,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, kref_init(&opp_table->list_kref); /* We have opp-table node now, iterate over it and add OPPs */ - for_each_available_child_of_node(opp_np, np) { + for_each_available_child_of_node(opp_table->np, np) { count++; ret = _opp_add_static_v2(opp_table, dev, np); @@ -458,15 +452,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, put_list_kref: _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } /* Initializes OPP tables based on old-deprecated bindings */ -static int _of_add_opp_table_v1(struct device *dev) +static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) { - struct opp_table *opp_table; const struct property *prop; const __be32 *val; int nr, ret = 0; @@ -487,10 +479,6 @@ static int _of_add_opp_table_v1(struct device *dev) return -EINVAL; } - opp_table = dev_pm_opp_get_opp_table(dev); - if (!opp_table) - return -ENOMEM; - kref_init(&opp_table->list_kref); val = prop->value; @@ -503,7 +491,6 @@ static int _of_add_opp_table_v1(struct device *dev) dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } nr -= 2; @@ -531,24 +518,24 @@ static int _of_add_opp_table_v1(struct device *dev) */ int dev_pm_opp_of_add_table(struct device *dev) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret; + opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0); + if (!opp_table) + return -ENOMEM; + /* - * OPPs have two version of bindings now. The older one is deprecated, - * try for the new binding first. + * OPPs have two version of bindings now. Also try the old (v1) + * bindings for backward compatibility with older dtbs. */ - opp_np = dev_pm_opp_of_get_opp_desc_node(dev); - if (!opp_np) { - /* - * Try old-deprecated bindings for backward compatibility with - * older dtbs. - */ - return _of_add_opp_table_v1(dev); - } + if (opp_table->np) + ret = _of_add_opp_table_v2(dev, opp_table); + else + ret = _of_add_opp_table_v1(dev, opp_table); - ret = _of_add_opp_table_v2(dev, opp_np, 0); - of_node_put(opp_np); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; } @@ -575,28 +562,29 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); */ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret, count; -again: - opp_np = _opp_of_get_opp_desc_node(dev->of_node, index); - if (!opp_np) { + if (index) { /* * If only one phandle is present, then the same OPP table * applies for all index requests. */ count = of_count_phandle_with_args(dev->of_node, "operating-points-v2", NULL); - if (count == 1 && index) { - index = 0; - goto again; - } + if (count != 1) + return -ENODEV; - return -ENODEV; + index = 0; } - ret = _of_add_opp_table_v2(dev, opp_np, index); - of_node_put(opp_np); + opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); + if (!opp_table) + return -ENOMEM; + + ret = _of_add_opp_table_v2(dev, opp_table); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; }