From patchwork Wed Sep 12 08:28:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146513 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4546757ljw; Wed, 12 Sep 2018 01:29:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYtP3OFM8p6ic65Vvg6yCQepfWHQYiR9Vv/dsD+k7aOM0oOxhOnlylErC6DM6BucGE/cKVL X-Received: by 2002:a63:7d7:: with SMTP id 206-v6mr910109pgh.17.1536740996236; Wed, 12 Sep 2018 01:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536740996; cv=none; d=google.com; s=arc-20160816; b=CZxPbE3JLIzxxEpIXzukE/8wyozOBQT8ku1FYzi7Dp4uLw+wYF2t2cchgEVgt9GC/5 RzTiajaTQ6oQrXSWtbNRNfJynPa5bONmjWrNZ4vBlYbuJgneyjGNe6yFz8CEtQ2n8hLY CZsx/OBmsPz4+Hh8e8YqZhvlpVu2US+bWSZUUc7YcfYaE7S8DwR3vbofpneU2Y9S8E+l Ckp8YNt7CE/qrUwrJ1/Q9byeXv2YawT9bW83K+rh5sWKGpTxIGSKx4oDM9vLyKIKQsN7 +1ygHG9Wd0Lws7R5epJ9mTlz/FML89txvP0tc0D5FKqjTbnICSFI37SQRua17sk/oXdH qkpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5K1iJfqCM5hIrFK8wsKvsyblTx8byAQ2qMnGR+MYBnc=; b=VmIgCIUh+Y06AJ4RXsGbp2bStE64oUSdOJRv5tweNC4Em9zbTtRO3ztzcMow8fo8Lz yxwDYDiKZVmp17PNLpbY4jV7zdeloLEWHVke83sYXiZoL71ocjn93fJC50wDsUl+yh+a T3n7Ue0XPB8S3TB00TRIyJOSr6rxJqsA2R/YN59yffOsIW7pHh7HI7WSiJceWC80STif McGePyMYPZi0POtHF+J+HCwCgiZVRXc4CtdTcQ2CaDoRO0yGJQbkanta/NzPgSu3b8JR exqNIe9as6new4xzEjeaalwyHvQDieao2g/ROKM06G7MBmh/56DRat+SY7KFDAi+5aUp 50HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WWNP9+16; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4-v6si394131pgk.630.2018.09.12.01.29.55; Wed, 12 Sep 2018 01:29:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WWNP9+16; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727997AbeILNdV (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:21 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45483 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbeILNdU (ORCPT ); Wed, 12 Sep 2018 09:33:20 -0400 Received: by mail-pl1-f196.google.com with SMTP id j8-v6so612857pll.12 for ; Wed, 12 Sep 2018 01:29: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; bh=5K1iJfqCM5hIrFK8wsKvsyblTx8byAQ2qMnGR+MYBnc=; b=WWNP9+16Q6w6a9ObSV5yFXy4NZC8+D8pCNCf/EyLKZcePLCPJzMiT7hat05dplXjTU 92cSNpgtI3afDLSDD+H4AHKb7eRMK6I0OMgjoJNRlPb8O/5j1XEjL88ZK77BO1+Xl1yJ pya2C5Gxn5wHXUHiMVM396bZMjVmtV5X1UbIE= 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; bh=5K1iJfqCM5hIrFK8wsKvsyblTx8byAQ2qMnGR+MYBnc=; b=fE0pRqVWFLLRtIlTkyEOrkx1NsG120zywmCsK0YURjP/H14Lc7F4Ji5w5Gv9CLufSc PhGsnW7hA+4hDn97vW25pJTuvrK+zf3tG+/9EBpQ9HRGmq+9Nr4R6yPKWXTdpfN7BUba Cujucs29i/hiYM4rPYAWOswfErl9625/Qo8WfpZPJOsjV8CT5oQKQYEXU790vus1EYSO bCVSudULrRD018kPSpEdb7q7b7SwGXJ8Olof42nP3ntFZOAo5Efg0Itn85zjUQu+NxkO j5+viYdpVi6KGQGkRB1wAaHyIsCjmLAVJ9dm/ccI4vdXO2OP8HJSa38SXtVPXzkJhXK3 JWeQ== X-Gm-Message-State: APzg51CBSYEyGen8mvFjYBlhGjJ0axSNlIfaFwxZztpo4tYb7HPxEjeo 9iXgGKgpMrgIpCD6oRvYB9AN8A== X-Received: by 2002:a17:902:6ac5:: with SMTP id i5-v6mr904729plt.232.1536740993019; Wed, 12 Sep 2018 01:29:53 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id i7-v6sm601315pgs.17.2018.09.12.01.29.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:29:52 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 02/11] OPP: Protect dev_list with opp_table lock Date: Wed, 12 Sep 2018 13:58:41 +0530 Message-Id: <547f728dc5f4d9f27dae0a85517d5b2502b3b03d.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 0c0910709435..2868a022a040 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -222,8 +222,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 7c540fd063b2..e0866b1c1f1b 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 12 08:28:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146514 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4546805ljw; Wed, 12 Sep 2018 01:29:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbI3CXR2iDAESzEEutA41eIU6QIW4ooxqHORBPIWYxaYHD1t4dwYttLdr8aP1TSdxE8cyUW X-Received: by 2002:a62:8ad1:: with SMTP id o78-v6mr925100pfk.17.1536740999340; Wed, 12 Sep 2018 01:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536740999; cv=none; d=google.com; s=arc-20160816; b=vbPl5mCvK8JSZgC4N3FUdy6tq0H4J0eu6CMmMEY9EUbUcENR184nmgFZSaqEdoSNoq EIy1Tf2l8tntdCCXQRbmGSpIrc5CwZR/uvE/UlWp8u4MmCviac1RW55Euw8l8Lj5C7zf uSrqrzEQWHCQzu6wF+wxhZPFB2Y/SQ9AlMR0b8/y4dqzve27pUrV4lTXk0cmeSO+vqpf Ijf2SyaRmKEDdEZJuKnmuUFYy93UO9kK8bCsNsorvwqRGH5S3mNmiDIx4VLVSgKzSvHe JgwSZW8XhsNi5bQroKmQyANjhmPkt3BFKGOM8k2pmS/7B0o+SPcl4NuafKcoggzSrPgo lDPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=tDYkIscN1OCu/B3vv/mTFBv7y924obTrvpBhZ7BBUSs=; b=BVwvSKJosUl7KkSDr3lrMGBP5ON7OWW1KVCXbnxj0J+bG6esOsouXd3LNwscFNZVhm x2FWLN4Gjpjyh+lMCGS8Z0dFkS04TcflI4Fx1mN1dwPKgfS6s4++5uXrp6X8VV7Uc8XC WqMsOxeTEqJ+Zd0ZEj6YmdWcahiU89iR3rPl6wiVb2X6aikOd9zYnZe3D7lTLLRFLkmv GqLx/oXdIUR3KX6zgBHYhLRF5v+jLuYOh/xpRudT9Gb42gzxDKiRiW3j6tG3N8vdlfXh yq3hyVHzKXMAemK3AwhBMk2ajGe7458JALT1A0RLas11TyORnauTIftzyWBwOsMCeip2 7DqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GELEHqyp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4-v6si394131pgk.630.2018.09.12.01.29.59; Wed, 12 Sep 2018 01:29:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GELEHqyp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728029AbeILNdY (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:24 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39368 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbeILNdX (ORCPT ); Wed, 12 Sep 2018 09:33:23 -0400 Received: by mail-pf1-f196.google.com with SMTP id j8-v6so649688pff.6 for ; Wed, 12 Sep 2018 01:29:56 -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; bh=tDYkIscN1OCu/B3vv/mTFBv7y924obTrvpBhZ7BBUSs=; b=GELEHqypQ9xRec6OKHfUYHdRaXDz48QISqWD35Dr4vphPb786GJj/Zn9WqyAuNA3lL 9SdZdysUrMXkDnll5MTBtvwqwUnyZIalt7Lwv8+q7ZOPo4A5KYtSBqGJ7tFEKQqYl9zh Za3hRuOgLfc60SeQVZczL2AE0l0iROnQkkfms= 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; bh=tDYkIscN1OCu/B3vv/mTFBv7y924obTrvpBhZ7BBUSs=; b=LUENPkOU1pOeFMu78mMZPT7ZkK+ABjYpk7BqaHzJ6wFzFdTwAlHZMZa7e+HxTp09Co x8hSiYwczIz+AxrwlpWDmKeFyyh5vL2acRZNqCLR7+BXeSxQfMhebFDjeBwnThG5d7on usvBgzX+QGFtQv1whfHUrhTUo21m4FalzHN/SeEklBOJ6H40Jwp18qE6+UYoxSfFx+Qu dusioVk5j1a0iKqUa7S236hfglJ6XdbgUdJDk3IVlmGBM/5+FaQXIQXAeedH99g88sQb BUs/Cl4MI+QSzwdgfq6SBwVP9fu9FvsrQE1O4AHZDapwKVyl2iZ5ZZmHCnuZq51DJxNr HigA== X-Gm-Message-State: APzg51Dm3HJbOQW4Es9nTyM+df5/OaOgSZFX+ZseOy+yRjguey6aQQaX JNDyNTL+KRsoCnoqjXhmtnfzQA== X-Received: by 2002:a63:cf52:: with SMTP id b18-v6mr889480pgj.194.1536740996164; Wed, 12 Sep 2018 01:29:56 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id x2-v6sm905268pfi.166.2018.09.12.01.29.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:29:55 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 03/11] OPP: Pass index to _of_init_opp_table() Date: Wed, 12 Sep 2018 13:58:42 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). 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(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 20988c426650..a91857d163b2 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 e0866b1c1f1b..84aba19531b8 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); 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 12 08:28:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146515 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4546843ljw; Wed, 12 Sep 2018 01:30:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYLFoHWM+JeSW+WYcoDr3WCQ6xEN4Z4nsxTNS/7dxLn27B+E4vP3I3H7rp66iF1em8Q8Dx1 X-Received: by 2002:a63:91:: with SMTP id 139-v6mr873651pga.389.1536741003039; Wed, 12 Sep 2018 01:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741003; cv=none; d=google.com; s=arc-20160816; b=vV6PB6nlhStVRYMKdnm9bJe8e9JeihsoAq0xm8PTEnaP3ZDmRK5xXXAQrDQsP1IEwp EpBSehmnN/9SlsCUxzWz1STlVnHrHM7XjqoziNzHwVOLP2y9Tm17/3gH/lrcd5slbnLa oZpC/n6Vh9zAZGCgUsqTJM2QH16Q0DT01KQwIojQtHEjNXVj8pWDDGb67O2ETvB8KXj2 8oXQJ7WHhIH0tplgSwKKY+3yeV5btizNL+jspwunC65ui3Nf6u1dVjLj3oHpWLghEGL1 QqagXIuJmGBgnb/BxMY2RJIiaBypLjOqKqd+Rh4OmXfX4eaFPIX8CCVPJf+7gRdHYqyF SuJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=a64G58V8et84UbVCYe1qqjcYTUZTiK5vlPsAeWbwcVI=; b=AYKghAbSGcCSSts/EsHwGgOLqG9qUKJZF9w3OoT8SpUguIz81MDLy+K/vCLI+3AVeP CEi3byjScLbPtINVEKXTrdbUO9CvRhuopXN5F+Qxs+4/pa7PkdhWunLrJPRmfj9jEN6R pAHnX6Kn4yvJ2O8grEhfwGAv6K0r0rr+P99LE9CDNQVYFbrm9XroWwv4judJCjmyUGLd /JlSKuITsdqWo18AjWuf6uiOIu4giScgdrs/KXaKxnyQxMvbEwgSU6J40PdQGCW3lc2P 5yXzSvUoUIBJv4mq2Aiy8ePjKkbzj03urJTS5UUlpKtI5ppBHCnBCz7ksiqJ0GoprDKW mSuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XZ4mD9OP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s71-v6si363611pgs.499.2018.09.12.01.30.02; Wed, 12 Sep 2018 01:30:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XZ4mD9OP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728056AbeILNd2 (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:28 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41198 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbeILNd1 (ORCPT ); Wed, 12 Sep 2018 09:33:27 -0400 Received: by mail-pg1-f196.google.com with SMTP id s15-v6so665197pgv.8 for ; Wed, 12 Sep 2018 01:29:59 -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; bh=a64G58V8et84UbVCYe1qqjcYTUZTiK5vlPsAeWbwcVI=; b=XZ4mD9OPrI+JroMzHFWxIqIHmDNgkY8ABearv69nG5wQChTGC5Vn5ysiDsUmyYR1FC t4nGKvqw5HfRzckZ7RObiVZxrviux66ZcQEkV1A76xBS5He+RCBSBHABk2fhoX1GbMkg VCigB26LGdHcrAYZkTFQ32ie98xqSo1HmchjU= 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; bh=a64G58V8et84UbVCYe1qqjcYTUZTiK5vlPsAeWbwcVI=; b=IOmYTP8KsJsTjECNuosU1OUeQjrsLJdbyN2E83ND983zZevjJeXC0i421+c+hQasdF qQn/UHhdIBJ2q4/mLBYGoe+bGy1WS1VOM+af5FBmK+lYg19qOBrf5eWy/Qh95MXYXwoH 1cHY3AE2B03tom2QBPNyoDyCPSsMK9nC2+LY/7RAx3pXkMuUljad79Cipgw51qH4D9uL kAy+lmgVEi+GtuRFu5S9AfcCKNgiEoX63nrHfU16t+wiFYa2w/YHtKEGI4rqQ8TMUN2k Nb/2DgNsH3IUxcSfEqyucfJVyQew8pPYYyXTIj7+oA6CZDQNHzFO/7tZrpMI4SB63FJP 7Q3w== X-Gm-Message-State: APzg51DtDAeERO8cXsui6UCsWApKCKEqUC28tosymqDNTnN3HnRUDvaF ackVcvk1AFBiEHXjAdvDOkuVvQ== X-Received: by 2002:a65:6413:: with SMTP id a19-v6mr843673pgv.359.1536740999379; Wed, 12 Sep 2018 01:29:59 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id g21-v6sm916259pfe.41.2018.09.12.01.29.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:29:58 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 04/11] OPP: Parse OPP table's DT properties from _of_init_opp_table() Date: Wed, 12 Sep 2018 13:58:43 +0530 Message-Id: <9769f7f5b7772f0a96cf830209544cfb491d24f6.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 79 ++++++++++++++++++++++++++++------------------- drivers/opp/opp.h | 2 ++ 2 files changed, 50 insertions(+), 31 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index a91857d163b2..ebf467b4d99e 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 84aba19531b8..d218fc0a498d 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 12 08:28:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146516 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4546909ljw; Wed, 12 Sep 2018 01:30:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYiC7A7A5Cf5wva4M18MyxzE+bLOD94+r8uQY2trYjOoG52L8DgC8eHObOQhUJ2hvdMmT8a X-Received: by 2002:a63:5d4b:: with SMTP id o11-v6mr856251pgm.349.1536741006934; Wed, 12 Sep 2018 01:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741006; cv=none; d=google.com; s=arc-20160816; b=I5PfCSnA2ukyacxUcXyQmuTBppiwsPN6F9DjGAS/dMkhCzWr4HWr9ei8PMz/c/2HY4 X4PSvZ8UdgF5fqc+fO8oSl1qklTfgSSLJkyCQpBEA5xQAUHp0q+hZP0wGOdMTFM/2N9l II5+6pGT1joVRjxRzuBacqiISF2ucoZ3fgzBWwNRxjx7OVu18QkDidy3yMgSZ0Mf9SLS Eq7KPOx048JT+jDvfXQlhjAWDAaM9yX5eZEejiZgguYHVNPsoelRzE9/Pu2jwMx4tWeC Dh+S+TVZxiwxwCxz0PKRIgACt0KRVXXFOLeGgNmlkqEO5X0YaqVtqc3ct5PuBDD03v3K Uibg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=mzex9AgA9HFzEyzux2lL6WFaf/qX0dz9pPspaQPeB1KIT99KJAPpzmUf2JM4osyxUL u68QEJ+fpFpWHnupAWlH18OI4UJx9GHGt7ATLEv+DdMvReBINQifOp1ZpkV/ypD1BVKj glij7jlQ2Hio/QG9XbEKUARTuV+A9ZkmoQY+MeJXaZr/w9PqDKMBZ626id+h+okSIlYj IlCn1fzGiCuRAiEm7eWOf9gy77O+2OvZ3kPmXsuOm6N+TaTd0kBmpubfH8aCL8lxmiRz /1niHgNxJAzWiUlmrRkf3fzeVSUE6M0zseUP4y95uRwUIQUqUtQXj4vnEgUrdnO5Jntw TPig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdZ588XX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s71-v6si363611pgs.499.2018.09.12.01.30.05; Wed, 12 Sep 2018 01:30:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdZ588XX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728088AbeILNdb (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:31 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37386 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727789AbeILNda (ORCPT ); Wed, 12 Sep 2018 09:33:30 -0400 Received: by mail-pf1-f196.google.com with SMTP id h69-v6so652898pfd.4 for ; Wed, 12 Sep 2018 01:30:03 -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; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=MdZ588XXa/wpGdUAt4Ygq+BCWjnFwYVNL5v3gbPoGfNpZ10R8QGd1gS6l7AFo1hziz Am6Tm7Y9f9SpD319PLWMdd519oGNHaY5n1uNYr0Y291U6IFIuHvUT3rQJGxRH/eFYeR5 EgKbamcC9lN1n059MA6tx938cPi+3WYav74r4= 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; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=Vf+BJRnWotNN2YKfQK2/e3M/9Edtmiz3NowkE/gQrhiyJ9JthXuUaenHLbE0dV3hRR DM9ro0Y9fWujh3mVrlOTJgE1FmLdpfj+enxFj2/6j7K/++BXYo9zj05f/gunBUzJKdpJ Nuzb36vAkbEYuX0rSseHa3UKuQd8nzbrmv/mu/qYmN6rLTOThR8uI58waQBsnv2LNPjP 8RC8uUK2PDH2WPXxLP8uUoGxNhNcjsf3wesj6aWQB/r0sQe29ZUdYREwXfefhexoIior M4LiP4lZMp94pW3jp+NE168dWukOFf+Psmbtw7SoPqlvhX9d4C9lqtxQC6XFe3k6GzPR 2MZw== X-Gm-Message-State: APzg51Da5aFJK9cA+K41XRi9KT6ckscUY5q2DC8buOKLtzyY4GWEKYqa hmxulgkCa+45I69mMxqdhRp7Iw== X-Received: by 2002:a62:2744:: with SMTP id n65-v6mr920713pfn.125.1536741002527; Wed, 12 Sep 2018 01:30:02 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id g25-v6sm1079645pfd.23.2018.09.12.01.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:02 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 05/11] OPP: Don't take OPP table's kref for static OPPs Date: Wed, 12 Sep 2018 13:58:44 +0530 Message-Id: <08942a9ab06dd76034242cb70dd2446020a2efe0.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 12 08:28:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146518 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4546999ljw; Wed, 12 Sep 2018 01:30:13 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb0a2FlJhT5+0e6B8k7Xcj9gnuo3xHnQcp6VaVnVC9ACmKc6UoI9ZxX13T0JX3kQ8zWU5Gy X-Received: by 2002:a62:2f84:: with SMTP id v126-v6mr922614pfv.115.1536741013508; Wed, 12 Sep 2018 01:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741013; cv=none; d=google.com; s=arc-20160816; b=sunl01HAr8MsdENmheU9JblvmTvwYBPDO6DL+uGC8K3IvZ5Vd22wOwPsrfo197oPY2 sNsS96QRRxHCiHJcZWpL0oiXu3au7zzmucWApNr/Nkd6JCArpLV1SJTCl758o0fNlYyd Lhkik2V31JyiH6L5sydMtQ2Q5Q3MGDE9vrHPQ7GEouZ2X5hlO5naQAShoSJ9Bow5VgGO rOrkq89ciaCKFiBdpigzklG4dx5rdM+np2ilqjNTJiPV1pdrhNJ7bHmPXfjmuv1cN05o z9PvrcygaGi1mnzvozw/iEpFOzDA5I9pCk+b34YHbHaHzbiFuCmOpyXKos67DZiC4T6Y pYLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6pZdqzyNFzV9hoYXx9iwC3ap2vB1NU1hBlJF3aGozkE=; b=mu274G2gWSBwvkUyzRMGAM3pkqtLxj66sMUWcmTjjMC0vqSQubcFpgeeGsHbNgAE/2 59JtV8RqLB1rcoAqgGGim0fuztxVlvOkdyAOyCa544Mtl5jtNUjHtzWeqPw1GMBlJY9Y 4D+y5BHDCrG/xAP7xzy4go2yORUbl6pW4c/gmjgBoP2MqfJecSL03U5hVhLkdFk+n07x 2bpNjOaFmFkRGZi96uJvn3maWCgKFA9dlgLpxWGODLqyCP68KP5b2TToBZhs7uq8dpmQ 92riuuB9gv3MXTpRWiZZRmaRO08gpPdULwsR9pXOLFpLLwSwCDMz1Pw7uqJf7eo0o3sJ BSBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BnFj8fwJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4-v6si348600pfc.328.2018.09.12.01.30.13; Wed, 12 Sep 2018 01:30:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BnFj8fwJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728162AbeILNdi (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:38 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41589 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728122AbeILNdg (ORCPT ); Wed, 12 Sep 2018 09:33:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id h79-v6so643333pfk.8 for ; Wed, 12 Sep 2018 01:30:09 -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; bh=6pZdqzyNFzV9hoYXx9iwC3ap2vB1NU1hBlJF3aGozkE=; b=BnFj8fwJnhndXq1Pp4qGfFt1Rh5us1B1XFwLDGN6iRpdghqXxBb4SEtSEulWyWZi74 Uv7rCQrAqz6+ogMqmFwQShCcuIdOTJS9Jbm+QVqp62D8lgw4CLZ1sMC8gZQAM/RZvCdG c7sD4CSSgHMJxZz4yS9aDQgyVkPPiO1+Mo5JU= 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; bh=6pZdqzyNFzV9hoYXx9iwC3ap2vB1NU1hBlJF3aGozkE=; b=glTGQEriDgNHdDIEQkOgb0L7w+y9sTyYcldwbZSY6gKZ+qrfEQ1r+3LdC0okaECDAM Zo6gdVm7D3kA7T1bZ/dbyCaHQqq+tJGQ1BAQ2Wf857NYbzl2F6ZZO6635B4c9lPnlXUT +wCqgqQdRk3LEOL5sbiF8QF506RoONHYKBE4Z/3/8jZdHdWttCS9Qdqoo57PsiIQhoNI 9DucAs7T2uEwkqtszG/NJnSt7owrd0ze7Vi6cdWMabT26GAxMcaTGd1K3cGxyz+nO1WJ OksyGECs5dsV2PpKd04fAhMEE5+7cRkq31SdiLBCutE3XeqYEjsvWaOzMZKNzPDkIzhA pH2g== X-Gm-Message-State: APzg51DwxiTygIV0uw20RezBIS74ALxvYZHodY2as2M13dryErM6+hWZ kg2HF3LZtTEfZNhoMYLNRblDyg== X-Received: by 2002:a63:e949:: with SMTP id q9-v6mr914185pgj.4.1536741008837; Wed, 12 Sep 2018 01:30:08 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id w69-v6sm686923pgd.37.2018.09.12.01.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:08 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, 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 07/11] cpufreq: mvebu: Remove OPPs using dev_pm_opp_remove() Date: Wed, 12 Sep 2018 13:58:46 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). Signed-off-by: Viresh Kumar --- drivers/cpufreq/mvebu-cpufreq.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 12 08:28:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146519 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4547053ljw; Wed, 12 Sep 2018 01:30:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaIj25Qpn8P7lPM+txWPEvu5HXsVCCIw61gred66wdJpyxiOkHvFNh30xVMVeUGS+luP3qb X-Received: by 2002:a17:902:d881:: with SMTP id b1-v6mr889866plz.191.1536741016376; Wed, 12 Sep 2018 01:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741016; cv=none; d=google.com; s=arc-20160816; b=tLmok4q99+bTFrWul69rT3quQryRhJw6VJStvTIORkTNjjRXLm1zWnnVHcKa3AuSBl nh+e4XPZWQKarMNF01PZ8XxUm0B3igLyeQ60p0TQuLnHUu9gU6NFfM0uelVRnjxROhmq GKbKsqf/SvhAjyujOTpHMt0TvZCtgTQosTyMrmQNxLNXP4yhejMq5kFs0US8r1Gh1tf6 2QxU1hgP0QvLBTnLtfI/TXOwztAZosO9iPqvzsFy9B31fSPPrIV2t26PS0U/Exxy45T6 7//gL0ISH/sR1JS/f9u5/VsAL34L22CNHB8iz2DtXMD2r//pyap2B18DP6M2LshwuoyB KPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=72mpelPluGWAZTfEgSG4c7FeAVh+FKHnEDbIa+aT9Iw=; b=YyiqxtPOYQKYLy5zcIPpIev7GiJHy4hVbjRBQhiR8wGAAYpRcnf3v/VLe2X3VRxw9r B5DF7SlxiNoz2bG7EqbLYWAcfbK3xOkcnq08mBdVRX01slUYBTCHjnjPGOL1q/OgfFAl Mpc+cvOVvkFX3+fwtPg6nFipMRP4E6P6wsQPju0UJKG67c2PO9znv+312GvQ4DYtmEGw h0TeH5k2g2OvHV591EdTtq43MUKchYyUmZoRkdxKrrCZMfU8qx0wXY9QAZSrRdfoLZmD PCzDXJtnfQyDj8KM8ec5ZwyVtS60qdv61UOKpTISKbelVaI5VIbHLbgcH9ie+K8vfM5J KoIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W8CurDyO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s13-v6si366682pgo.505.2018.09.12.01.30.15; Wed, 12 Sep 2018 01:30:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W8CurDyO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728182AbeILNdl (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:41 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46470 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728166AbeILNdk (ORCPT ); Wed, 12 Sep 2018 09:33:40 -0400 Received: by mail-pf1-f196.google.com with SMTP id u24-v6so633447pfn.13 for ; Wed, 12 Sep 2018 01:30:12 -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; bh=72mpelPluGWAZTfEgSG4c7FeAVh+FKHnEDbIa+aT9Iw=; b=W8CurDyOSrdu5Jx55Z7SyRskyd+RGAImYa7B4muSn4jkcvv/8dyq2/iLjdDRXirr3f mncOA7TdK+pZHUzFLVmL+lMPofjUuhUOZIiHpxxvHbU8tJkMWjRs/7xvnmVjiymH+A+2 GvnDmN6eTcRmZ4tFyMDfOVdtX3aws/sPgEqbE= 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; bh=72mpelPluGWAZTfEgSG4c7FeAVh+FKHnEDbIa+aT9Iw=; b=M67fULgcwMhFDk2tyqj3UtA05ahOGt1oP+EQYaZfldSbtuO/AFyIuEfY/Ei2D4NU8c NFvCM5y9ihOpQTKNtmDG/cNVu6TNcUU7obySN4WdMa0Uv9uFB3n7HUz/QZnyowfcEJc4 aHAJ7NYOuM3F36qu6m9otG6afq9Y5zjzjfVA5rS4rXU1alV03OSU54x7WL0XmyGiTTP0 UQfv/rouMO1nhW7idPz+uo+yRmNAYJHsV44juF/tgEGuAypWyk/W3+ftvWeJLz7rOzKC QJfKjsNOdOOmMjFwa46vGmwJJ0tRDpYXc83V8F7H0bX23qD24SPygmUBIJzJTiwG2+/Z lJ+g== X-Gm-Message-State: APzg51CduxCesfyfzUfj3lID45hR9gWkVFrus8hhU/cPvTdiBoBD5hoR rDLaGjdL9Fb2JowIZlyQhsVrBg== X-Received: by 2002:a65:560a:: with SMTP id l10-v6mr919201pgs.130.1536741012097; Wed, 12 Sep 2018 01:30:12 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id u9-v6sm729814pfi.104.2018.09.12.01.30.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:11 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 08/11] OPP: Don't remove dynamic OPPs from _dev_pm_opp_remove_table() Date: Wed, 12 Sep 2018 13:58:47 +0530 Message-Id: <4d433fbb463a5a66a5576e37173dac9a55f48b82.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 20 +++++--------------- drivers/opp/cpu.c | 9 +++------ drivers/opp/of.c | 10 +++++----- drivers/opp/opp.h | 6 +++--- 4 files changed, 16 insertions(+), 29 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 2868a022a040..2d4505ea34d2 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) { struct device *cpu_dev; int cpu; @@ -123,10 +123,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); } } @@ -140,7 +137,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); } EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 892d17069f05..9c98682af374 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); + _dev_pm_opp_cpumask_remove_table(cpumask); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 783428fa9c33..3b1d94748a4d 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); +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); struct opp_table *_add_opp_table(struct device *dev); void _put_opp_list_kref(struct opp_table *opp_table); From patchwork Wed Sep 12 08:28:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146521 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4547175ljw; Wed, 12 Sep 2018 01:30:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYg35kDgLnGb4+/iGPAQ1hzy5A2d9fH3y05xV3bdcmj7y9gPuAM6txADv3fGGniJkjlCejJ X-Received: by 2002:a17:902:158b:: with SMTP id m11-v6mr918707pla.102.1536741022820; Wed, 12 Sep 2018 01:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741022; cv=none; d=google.com; s=arc-20160816; b=sX5RlVEBL5Cv6x8tM+J/sCVO8kJeJRrcsLvxnibbVPtuYu9APNIRMHszM2Ghta9+6U qM4mvBqA3T6++ADzD6cGlFhH8kRfWfsMnoL38cvjXLHZ43nkoaQrS1uvmcCKSXlHinl2 J6tybYp8B+4vNWI6SKzytVMs0OAxj29CO7tPesJoZO/5j+VTQcG0iMvG4B62nN+H42c8 o5esRQKYqZtIlCtXsLfN1BHoFDFdpC+urSqPZJ0QtmkRmq41bILCJh1if1S50we8qbcc Hcg+HG1zAB3dPsDXpCYdvvpp2GSf9mZiQ4yuclqloZVjPrTuJglWuI+66kHPSffn0S0a LdqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Stjj/H9G3aXswDY/tKzqdma60cnAtlbZCxqe7sSqXuo=; b=u8+F1EB5GPIt3tTgrt/smhCDiwymvtRLuZ9e3glZ5KZNxdDbWzgDVBio691MBT56Cq cZNuIkUE85cgrXZyc1oZMb1wc+r95nf1V0Z03AfEdlGARJLkHEzwrrrk5gi+iQiFfU+T ZP59uf6HaP1lYKcosXwP0Bc7wLI61bNE82wTPFZN7MjJLVX+te4jL6FPWELo0G661t6K IDMbGF0w76tjF4cfF8BfP0kkRAZ4khd687NWN/jFTOPMUr7NuY5DhWxncaQ9dFm+uZev oekzrKEZ6YuSHM6z5uF7WOLmfH6vc1VZTfBkWr088XgpkwRRCBl6a+UjgrQZQJlOg+OC DO0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h26DAAA1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17-v6si478136pgu.79.2018.09.12.01.30.22; Wed, 12 Sep 2018 01:30:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h26DAAA1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728229AbeILNdr (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:47 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45010 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728211AbeILNdq (ORCPT ); Wed, 12 Sep 2018 09:33:46 -0400 Received: by mail-pf1-f196.google.com with SMTP id k21-v6so637464pff.11 for ; Wed, 12 Sep 2018 01:30:19 -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; bh=Stjj/H9G3aXswDY/tKzqdma60cnAtlbZCxqe7sSqXuo=; b=h26DAAA1KuZS4qxlQp1c06/J7D11gwkLjpO5IZ+V47qLkzzVGGg/NtOqBBPF3/XAu0 TkJXAnD6TDDlIC+fhtatYNezOH36RyotbwbhFKCb60Cbn5zkM2mKZuzBvr9wKZPoPUVc 92Hj8ROTApXI8drMzT1AVbgMYX9mGqB6XrLow= 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; bh=Stjj/H9G3aXswDY/tKzqdma60cnAtlbZCxqe7sSqXuo=; b=TD+2GtGcj6xyuNMgRRyo7VDt41drkOtkEITyXxOmjA5guNP8N3z0VfMhsI8x1QMD07 ItxOBhiBuY80gR8iDefrub6q+NpBeEjc8gwDz+KPhJH5KzF5E56zzaBUqok3if8dm+cg CYg9d8T38bKpe9XKtyaRzKyLF4oKfVMA9tABvU5KJ9oEyMzuKAJGJmzMUH+4L4fNaYSJ t29f0JLhtN2FnVsAgeqOLVo9JXqcVuO8BygrS2e4KLTwme0YG5LyyaAcB8dnu7EhFtzT hrUq2htVFLr7P1LCIjvIgFPivw+hY4cxKtLkQTmIX/lIOiZS9awpfBjhLShoA27TwoMx Hoew== X-Gm-Message-State: APzg51AQmnUvcWffMgHniso7S4Ml33lDkgIv1LGQXpr5dOc+u68n2wcU RnGWF72vNxhV8nuuum9J60ixvA== X-Received: by 2002:a63:352:: with SMTP id 79-v6mr922441pgd.112.1536741018546; Wed, 12 Sep 2018 01:30:18 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id x82-v6sm1688726pfe.129.2018.09.12.01.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:18 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 10/11] OPP: Prevent creating multiple OPP tables for devices sharing OPP nodes Date: Wed, 12 Sep 2018 13:58:49 +0530 Message-Id: <79af9cf4c4e8e4d6dd8288d013900939ab4d5855.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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(-) -- 2.18.0.rc1.242.g61856ae69a2c 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 a5cba0234220..db3e4d2b969e 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 b260fb7b307a..a7e9adab4cd3 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 12 08:28:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146522 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4547242ljw; Wed, 12 Sep 2018 01:30:26 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbu5e2AtAY7PX9M8GhSNK0yP7FuU6UgTbo3HNYPywWEt1WrQIiPy1jYn/Yn8uxrti3m1wLL X-Received: by 2002:a17:902:9f90:: with SMTP id g16-v6mr925721plq.34.1536741026247; Wed, 12 Sep 2018 01:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741026; cv=none; d=google.com; s=arc-20160816; b=LSFZILLxQ3KUgtVL3RcRH0ob8wwR4gXdnSdcKIcewkpGzIePwPUSW9704HuvaJVWFZ /RTbDR3fbDJqJMBK7h7QpGhLROkDUiztOkNPbcKrHUcQEb5461vfbeieOX72bsY4QqfP rToG1H0LzxjgxlDxpUHtLBQ3qGSe+xs+G5o406VBm2qhBJk3ZTaza5yT/J8gv1sxyP+4 H4nV76i4Y5/kjxYpz++VrgxiLq30aIEWRjSXPKpuD7ayCoYLuu5qYlSPsDOXsiPREox1 zwiWvxLFcuwzSM+PGG0SkCbDOYNJQlR/I7Xzw/+yYTMYamIZyMKLE8+sGxzSv3MUrXXN NOLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=LabDs4Ag3cbs9EteFoJpElF2B1erqsIywk8ijeAcC58Idczxn2TXCHEdaWKqBdnE5X 2DIF+6Li2Zy1slsbeB5WzvaWHvp2cLJlFqZuiHcWWuS5S3PGs4M7XXYBkvQUZUHCtcAO N37t+fBz9Oxs9KeDW5SCAPry+dCLR8cpQ4d9mNBJPRRhM6LIRsztpokipGim6ixt2bME Ud8pxN/W84x0/Pa+Jpb/lRMf4Xq3KRgrKNnAfv/Lxaje9DarrXrFe+B6LoK3XbENY0xo nACgvv/gcvYN963lnJ7IbPJ3tqwcPw2MR9H9FzbjajPi/J/XSc/67MaRZwm4Vz1ZXpl8 66hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZYIYY7ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si415051pgg.341.2018.09.12.01.30.25; Wed, 12 Sep 2018 01:30:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZYIYY7ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728245AbeILNdv (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:51 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33415 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727720AbeILNdt (ORCPT ); Wed, 12 Sep 2018 09:33:49 -0400 Received: by mail-pg1-f194.google.com with SMTP id s7-v6so684954pgc.0 for ; Wed, 12 Sep 2018 01:30:22 -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; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=ZYIYY7ieWLdGVt4I6F0vJJS1u98pbm9AeIcLAbPEPv3NM6n6GzgEK0fO8XgqG3RjSH XlHtqBe8jU1G75F/nuFVayA16G6n+IIfEJQucSjZU4V+MAHRXxm1ThBVAw8GblqaCYfr +0jlr9QbEoX2NodKbHqhcIZhHeZwxn5QMkTKI= 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; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=Npz5Pm7/kItoBE1iXRbUJLaN8o6VWUWmugQGR0Ka/YXplpTXMaz62MykF8aOyG43wq uRpDxcuKGN0SLDddiudx8aNCbGMnbyJUxUp8XNKRuzWOVV0BfYc7CJObzU8X+XSj08Y9 0PyxrZHR4HMoETzx01GcfvSSUmsnpPz4TiuzqLpNiiAdfQCkbQbYLcBC8GojwjSzsQot dbjhjuEfDZy/Jo3YpEFVfSOpqk9Wq5Lk7SpTBG/OjitFnhXaHz69X3oKQY6GKzfazoMY ZZZXaLN4RXtOq6uptmh+DhDryuE1h6ML02C5QAAqs00wS+Llmd47JXDKenftOzWigqwl J1HA== X-Gm-Message-State: APzg51DLavFMq8jdtCA7+aUB/qnSG7QtsnL9ORJawdFQlXKMV4GpZmnu Z8HkoJ/NiWYgZt5YHKxhTwSL1A== X-Received: by 2002:a63:fb07:: with SMTP id o7-v6mr877509pgh.333.1536741021653; Wed, 12 Sep 2018 01:30:21 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id 187-v6sm924302pfu.184.2018.09.12.01.30.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:21 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 11/11] OPP: Pass OPP table to _of_add_opp_table_v{1|2}() Date: Wed, 12 Sep 2018 13:58:50 +0530 Message-Id: <5e869c96ac9fca2986dd7d82669b0593dc15c5c6.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 68 ++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index db3e4d2b969e..c410ecc2c53d 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; }