From patchwork Fri Jun 3 06:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12868611 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F72FC43334 for ; Fri, 3 Jun 2022 06:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241385AbiFCGUc (ORCPT ); Fri, 3 Jun 2022 02:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiFCGUa (ORCPT ); Fri, 3 Jun 2022 02:20:30 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71F3D31DCA for ; Thu, 2 Jun 2022 23:20:29 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id g205so6478387pfb.11 for ; Thu, 02 Jun 2022 23:20:29 -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 :mime-version:content-transfer-encoding; bh=FtqSGSpcTYMhqEhiOK8deMmsDpT+y77WgcKMAx0xXi0=; b=x561OUt53M0UXGNsOFsZ+zaKCUzTGqTkew0UeDthOgHX3JQ4WVtTCji+ahD8BPJRso 7k39vcNQsWRwp3SCRX1nLP+zQvs4ymDVI0pJz+sqIaSotC+vJFJf9JWo6XbokVZoeW1q NvcCSgVRTH9krggLTZ/XvBABxZnWGrUxphO6kOj1Sl78xovk+Xfd7U/7QUCLYfvdFXMq U8TvBcc+5WSM8WTuWZ5iN9Z+H+evmAqJQ4ihAinRyb2xTpXa7Tkc7xJlavZ+jEskurs3 fPbvotzmPQXfk/cmqpzOJk2KfDO0arubZRS4C2jHFjUTdO4gcspkn99IxWNDVW/EThDs 5MIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FtqSGSpcTYMhqEhiOK8deMmsDpT+y77WgcKMAx0xXi0=; b=fxKwjGBAf7e+EE03FAAw7bYkFmc76FaxiTXR+ImbwBM4BJqLAl8h80e4X/IFm2U1O8 sKf9E3t407cUTa0haKD3oZ4FQv2SYwgMfa+Vcbm8PEFxhVZ1N1Bw56arhmNcaCONA5mX AMDCGT1M3ZK+kjek0AIXjByCz2mANZH98L5ojR+nRrRcQJ39OGu+vGRsGiCl8rNApAUX FRq9307xOQATkXeb2gZ5mpJzaC1phe58ui2aUOnPDgieBP/lPaggN60AmxGU1OZO63vs akVA6Z/AJXfDvn2vOetyFTGCdB6NLLRzmcEHGAf4/3681kJxOiUmccisQkVrSXlgl8ek Fs/Q== X-Gm-Message-State: AOAM533YMpHnL4StcVdCKeAPcfICAA6g81NRpHZ3bo2x7Eu+EfYiVWGh xw/qToLvN3h4yBlJhEg9wND5Kg== X-Google-Smtp-Source: ABdhPJxXOUS7EM/9384o4OYGzgHKDDVyzIFQnrK0vG1J1No1ZfoxjwGOqMi3WjHSf8PDzrED76RTRQ== X-Received: by 2002:a63:85c8:0:b0:3fd:1851:3d67 with SMTP id u191-20020a6385c8000000b003fd18513d67mr2440586pgd.520.1654237227929; Thu, 02 Jun 2022 23:20:27 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id d19-20020a17090ac25300b001cd4989feebsm6815158pjx.55.2022.06.02.23.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:27 -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 , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] OPP: Remove dev_pm_opp_find_freq_ceil_by_volt() Date: Fri, 3 Jun 2022 11:50:15 +0530 Message-Id: <7b1d7a692f91e52da49b93f280ccba7014c139ba.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This was added few years back, but the code that was supposed to use it never got merged. Remove the unused helper. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 54 ------------------------------------------ include/linux/pm_opp.h | 8 ------- 2 files changed, 62 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 554a043bc225..1ee218dcb0b9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -600,60 +600,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); -/** - * dev_pm_opp_find_freq_ceil_by_volt() - Find OPP with highest frequency for - * target voltage. - * @dev: Device for which we do this operation. - * @u_volt: Target voltage. - * - * Search for OPP with highest (ceil) frequency and has voltage <= u_volt. - * - * Return: matching *opp, else returns ERR_PTR in case of error which should be - * handled using IS_ERR. - * - * Error return values can be: - * EINVAL: bad parameters - * - * The callers are required to call dev_pm_opp_put() for the returned OPP after - * use. - */ -struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, - unsigned long u_volt) -{ - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - if (!dev || !u_volt) { - dev_err(dev, "%s: Invalid argument volt=%lu\n", __func__, - u_volt); - return ERR_PTR(-EINVAL); - } - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available) { - if (temp_opp->supplies[0].u_volt > u_volt) - break; - opp = temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; -} -EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_by_volt); - /** * dev_pm_opp_find_level_exact() - search for an exact level * @dev: device for which we do this operation diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index c6d8f01ef9fd..fde202b1f5a7 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -117,8 +117,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, bool available); struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq); -struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, - unsigned long u_volt); struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigned int level); @@ -264,12 +262,6 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } -static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, - unsigned long u_volt) -{ - return ERR_PTR(-EOPNOTSUPP); -} - static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned long *freq) { From patchwork Fri Jun 3 06:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12868612 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94DD4C433EF for ; Fri, 3 Jun 2022 06:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241414AbiFCGUj (ORCPT ); Fri, 3 Jun 2022 02:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241391AbiFCGUd (ORCPT ); Fri, 3 Jun 2022 02:20:33 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEA1E2ED59 for ; Thu, 2 Jun 2022 23:20:31 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id 187so6496905pfu.9 for ; Thu, 02 Jun 2022 23:20:31 -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 :mime-version:content-transfer-encoding; bh=h1P/A46rz0jqr+k+LHINMkdY2BqpjbSfON2jDhuttCk=; b=bRZbRb0c6vbM3h5BD8ZwiJVDiaraTaM+flEivzgjZibK0703ajhsQiA8SeXBzTeQ1P 46URkWniAu7UOdd0g5z18mB6RKn8Pl+vNRONvHyOQecR9ML6/X/pPE6fwFrRKLJo0oa+ C2IgTYWwxQKmoD4u35TwTBCoFjh4cFWtJ3rmBoUmGqWBJK813JfzuUer5YoTeWP827EZ 9Vs/UuOC9ESJ14R1Ej/3XMqgIRA9WFWuL3ND0z7t3SOsHkCGkqfwSrYrSkxA/XS60QIb l/0Ehy1R919k5a8HA37sEv6333fwbsejHKjQZNgARebERYHCUvytBq8iKFxxQM0rFRVE 4sUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h1P/A46rz0jqr+k+LHINMkdY2BqpjbSfON2jDhuttCk=; b=dEKsvjuOyj2qVRxo7H/1WnbDsNtkjjVp1Rx0jGTKptfbTM6INS2dcoaIU08FS0pRki rPh20ivTV1S2PGFXZwW/8pS2zA+OsOkh2UiRWotbmjoZ+tuxkMsYZCEbV4k7Sn+/cqb7 gwxnSIYrAamm/coXu+qtqL3DoQx3TqJGPyVBJFH4YONtYs11T/c3OO8GWT0KtmJy5aP9 B/UGZJA/mFn0B4YpOyuQ2ewmb110YT37jqsLk2zBOZT2DD/siOhMKP9ypOFUawg3I06e Dp/HOoBTQfj/Pk0ZvelaAYQDxJjNNihX30V5ZK7j0oBcnxkwvN0/FCnwJymHYP+i4CAk F5EA== X-Gm-Message-State: AOAM531/WB5Z2ICC10foQ1d3E2kMXJ6nBkItlVBjEADAlnJFDM0v3u4E F269Robp6qW4eoBwxodH6SqCgQ== X-Google-Smtp-Source: ABdhPJxY4oWi3mOzIZS/bc0MEnpzrXKxSgYmAb7SDcvCmYxl2hJuyDWFqwYtZZ4Gx+IVApZ9JlK5RQ== X-Received: by 2002:a05:6a00:10cc:b0:505:ada6:e03e with SMTP id d12-20020a056a0010cc00b00505ada6e03emr8905928pfu.45.1654237231271; Thu, 02 Jun 2022 23:20:31 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id y20-20020a170902d65400b00163cc9d6a04sm4606486plh.299.2022.06.02.23.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:30 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] OPP: Add generic key finding helpers Date: Fri, 3 Jun 2022 11:50:16 +0530 Message-Id: <015602dc3313be081ce2b5b2057361dab95d55b9.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There are three type of helpers, to find exact, ceil, and floor values, replicated for multiple key types, freq, level, bw. And all of these helpers share a lot of boilerplate code. Add generic key finding helpers to reduce code redundancy. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 1ee218dcb0b9..7ef6eafc7946 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -420,6 +420,138 @@ int dev_pm_opp_get_opp_count(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); +/* Helpers to read keys */ +static unsigned long _read_freq(struct dev_pm_opp *opp, int index) +{ + return opp->rate; +} + +static unsigned long _read_level(struct dev_pm_opp *opp, int index) +{ + return opp->level; +} + +static unsigned long _read_bw(struct dev_pm_opp *opp, int index) +{ + return opp->bandwidth[index].peak; +} + +/* Generic comparison helpers */ +static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key == key) { + *opp = temp_opp; + return true; + } + + return false; +} + +static bool _compare_ceil(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key >= key) { + *opp = temp_opp; + return true; + } + + return false; +} + +static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key > key) + return true; + + *opp = temp_opp; + return false; +} + +/* Generic key finding helpers */ +static struct dev_pm_opp * +_opp_table_find_key(struct opp_table *opp_table, unsigned long *key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index), + bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key)) +{ + struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->available == available) { + if (compare(&opp, temp_opp, read(temp_opp, index), *key)) + break; + } + } + + /* Increment the reference count of OPP */ + if (!IS_ERR(opp)) { + *key = read(opp, index); + dev_pm_opp_get(opp); + } + + mutex_unlock(&opp_table->lock); + + return opp; +} + +static struct dev_pm_opp * +_find_key(struct device *dev, unsigned long *key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index), + bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key)) +{ + struct opp_table *opp_table; + struct dev_pm_opp *opp; + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) { + dev_err(dev, "%s: OPP table not found (%ld)\n", __func__, PTR_ERR(opp_table)); + return ERR_CAST(opp_table); + } + + opp = _opp_table_find_key(opp_table, key, index, available, read, compare); + + dev_pm_opp_put_opp_table(opp_table); + + return opp; +} + +static struct dev_pm_opp * +_find_key_exact(struct device *dev, unsigned long key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + /* + * The value of key will be updated here, but will be ignored as the + * caller doesn't need it. + */ + return _find_key(dev, &key, index, available, read, _compare_exact); +} + +static struct dev_pm_opp * +_opp_table_find_key_ceil(struct opp_table *opp_table, unsigned long *key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _opp_table_find_key(opp_table, key, index, available, read, _compare_ceil); +} + +static struct dev_pm_opp * +_find_key_ceil(struct device *dev, unsigned long *key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _find_key(dev, key, index, available, read, _compare_ceil); +} + +static struct dev_pm_opp * +_find_key_floor(struct device *dev, unsigned long *key, int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _find_key(dev, key, index, available, read, _compare_floor); +} + /** * dev_pm_opp_find_freq_exact() - search for an exact frequency * @dev: device for which we do this operation From patchwork Fri Jun 3 06:20:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12868613 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFECACCA473 for ; Fri, 3 Jun 2022 06:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbiFCGUk (ORCPT ); Fri, 3 Jun 2022 02:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241397AbiFCGUh (ORCPT ); Fri, 3 Jun 2022 02:20:37 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1CA637035 for ; Thu, 2 Jun 2022 23:20:34 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id o6so1117392plg.2 for ; Thu, 02 Jun 2022 23:20:34 -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 :mime-version:content-transfer-encoding; bh=AJWbZrhYBBK/nZwEp8oEDzNVeqkUQnXH1sic0IKz15o=; b=FYJXrijbSyRV9DxoEDjyD5K0VwHrFPs2Rxn229GB700FpcNUBGlnxk/4+4TUtNVXTs EFykN0qpLNv4lF0FHxHrVyKOCkp4oe4UbnbRR9/X0CMmPhS4DDKsGO+dpFn1ZG3o9PS5 1uDP0ePVuxajD0juj1+hWAR+JjeUm25WCnRdEr83g5g+kOG40UKKZ94YRoTcaUucAbBU ewE+Fvz4B6TpBOq8OwgaGUcTFgA6Cvgt+xfZ9wy7zhMztaGUUV2awuWnykBWGFJ13HOt qSkUtbilU1K7oM4WKjgwp2ZX8Y00mqlg9VqSmBTzJo7HBkul5J5NYTHCvALlNns6ci7l pjxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AJWbZrhYBBK/nZwEp8oEDzNVeqkUQnXH1sic0IKz15o=; b=hhZL7fkPD8hLSZn/8BQm0iyOlkMhO026ydSYx8vMucUyGZWIerdlHC5eofqQbyaBG1 K4I1eGiadaVEFGkv37MXzMZhMSvUov5zvDbcbjbhlqEztsNlpAmsIWhm8xtniitCvwTA 6OtVMunaMxiL+0e75qKSh0rVz75mPgsX0tsp++1382s+XHTMDJgTl/qZv1u6tKMgmXV1 R/+dCe331GyXj4m6otGjm+JVwMntr0fdPUSHmzTx32UO+XKxwXiouPV2tcLkdTsKGVZh dSeY6mqPYAfAE4mVexm95tNBpL8LSBM5ANWmxpuS+JzX7vUGW9IQXASpR7WUU2gf3OLv 7Q8w== X-Gm-Message-State: AOAM5307zMGuenExKKQUHsaE7tpp1NligeEaxefZAMqmCgUzbtexT/HF uyg3WROJ/e85zQ9CdkX0xlGozw== X-Google-Smtp-Source: ABdhPJx6Fes6DwkCQHCVRV+H/LydnWY82HwtV8Rol5UHgNxnFTNnHK9lxTrRfSlmwBiUM6XO+kBz6g== X-Received: by 2002:a17:902:db0a:b0:167:466e:b72c with SMTP id m10-20020a170902db0a00b00167466eb72cmr2387021plx.172.1654237234341; Thu, 02 Jun 2022 23:20:34 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id r14-20020a63ec4e000000b003fb0354c43asm4387425pgj.32.2022.06.02.23.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:33 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] OPP: Use generic key finding helpers for freq key Date: Fri, 3 Jun 2022 11:50:17 +0530 Message-Id: <7bbf461f918b62867305f7ede05ee6691246f3e9.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use the recently added generic key findings helpers to find frequency key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 113 ++++----------------------------------------- 1 file changed, 8 insertions(+), 105 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 7ef6eafc7946..2e6cb2abf0b9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -575,62 +575,16 @@ _find_key_floor(struct device *dev, unsigned long *key, int index, bool availabl * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, - unsigned long freq, +struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r = PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available == available && - temp_opp->rate == freq) { - opp = temp_opp; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_exact(dev, freq, 0, available, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact); -static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, - unsigned long *freq) +static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, unsigned long *freq) { - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->rate >= *freq) { - opp = temp_opp; - *freq = opp->rate; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - - return opp; + return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq); } /** @@ -651,26 +605,9 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, - unsigned long *freq) +struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned long *freq) { - struct opp_table *opp_table; - struct dev_pm_opp *opp; - - if (!dev || !freq) { - dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - opp = _find_freq_ceil(opp_table, freq); - - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, freq, 0, true, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); @@ -692,43 +629,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, - unsigned long *freq) +struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - if (!dev || !freq) { - dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available) { - /* go to the next node, before choosing prev */ - if (temp_opp->rate > *freq) - break; - else - opp = temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - if (!IS_ERR(opp)) - *freq = opp->rate; - - return opp; + return _find_key_floor(dev, freq, 0, true, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); From patchwork Fri Jun 3 06:20:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12868614 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0310C433EF for ; Fri, 3 Jun 2022 06:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241408AbiFCGUk (ORCPT ); Fri, 3 Jun 2022 02:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241390AbiFCGUj (ORCPT ); Fri, 3 Jun 2022 02:20:39 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2CAC31DF4 for ; Thu, 2 Jun 2022 23:20:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so11373098pju.1 for ; Thu, 02 Jun 2022 23:20:37 -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 :mime-version:content-transfer-encoding; bh=4vGD8xeygMuouGJmhsw5Y0o7g11kgBD47l9iHV0atlE=; b=PAIEVagjF87QEZSuJ46V1NbanKyWVzHu2P+0TaPHRFAhFD/E10fEZcstdDjH5aHwc6 kYXteNBdgV0t6hCyV9o1IWNvNeDQ2I3GL1ssgEnfy8XeQFNt0QwiEqFJ0dO06GqdsC0A WcavoNLbur3qNEUc1rlZ3GUBcu9xZiwLJoW4sXZpE7t28EUtZduSTYd8C8HZg/WNzrGj MiePq5i06UBmBWqxw8jqWEjn3bjsyIeA/1NmH+Xwk/g3CU63Hsw6oRpUFTW15Uh5XEDw twHqF6GuAhuZOkSWVKp+MdXXyhHJ0EvVV1cCFWnMO3BGHAcWLzSv5xGqJTDrYsNTrwet dijg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4vGD8xeygMuouGJmhsw5Y0o7g11kgBD47l9iHV0atlE=; b=IO8DpfAZ8o1H6RRyEp8HCN3cGAqs/MD1t/BVn6QJpao38AEGHGApS9bbgokcdZxJUL XfiLbEfipSovhuirVnb5qtNdsxrBp+UONlS648u9qHLPjLi50Sm5q06g7E4ncu3yiHGk iwFn0aWzG4UBTwjR7DDsbdOv4omc5tHdZnBr+ITqgMQEBPHqCIvEFuwcIXyxnDZQlxB4 pIjqH7JjYEtt6G6X1MsDe+PXlxIzwaWbfYT74WHgDKmeBC4GoBccgP1E0+zz59mOVb0L x5eYRQYA3FEs/0F256yMa6EZPm7VnivkIuP6q9F09GMnXwgIpUF1LsNvpNGH5w9q3k2+ XjNw== X-Gm-Message-State: AOAM530reK/aQsTWJ51Ini0Q+9+yMezK6O8SkqEopAWBlf8WGS8dl32D s4qbtf0alMYcVtUoGKb/BiwitQ== X-Google-Smtp-Source: ABdhPJx3v0WTCiUSqEVf4ES8VFLb1f6/DrsOqENUN5DKirn9hteNSryYlnTTzGPxvH8DKzLFQxTAiw== X-Received: by 2002:a17:902:cf06:b0:163:62cb:250e with SMTP id i6-20020a170902cf0600b0016362cb250emr8720003plg.171.1654237237301; Thu, 02 Jun 2022 23:20:37 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id fh6-20020a17090b034600b001cd4989fec6sm6837272pjb.18.2022.06.02.23.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:36 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] OPP: Use generic key finding helpers for level key Date: Fri, 3 Jun 2022 11:50:18 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use the recently added generic key findings helpers to find level key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 60 +++------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2e6cb2abf0b9..d8a91900d8a9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -650,36 +650,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, - unsigned int level) +struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigned int level) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r = PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->level == level) { - opp = temp_opp; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_exact(dev, level, 0, true, _read_level); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact); @@ -701,34 +674,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact); struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, unsigned int *level) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r = PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->level >= *level) { - opp = temp_opp; - *level = opp->level; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, (unsigned long *)level, 0, true, _read_level); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil); From patchwork Fri Jun 3 06:20:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12868615 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 679C3C43334 for ; Fri, 3 Jun 2022 06:20:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241390AbiFCGUp (ORCPT ); Fri, 3 Jun 2022 02:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241428AbiFCGUn (ORCPT ); Fri, 3 Jun 2022 02:20:43 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89E637037 for ; Thu, 2 Jun 2022 23:20:40 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id w21so6550521pfc.0 for ; Thu, 02 Jun 2022 23:20:40 -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 :mime-version:content-transfer-encoding; bh=gbNLNoNUtLpmvXGtkruf34xAYHi/j4E55WSdSx4bUmU=; b=JYxSDO1g1tQSMHpPKKPMY2RVHLSYsZM4Akn7PtJlzCFV7ZBIWYNnG/MH4qSb/Z962J p/Rlz7u3eTr0pn258InQjm1G49vXSF5ZtywFATcuk86gmi89yiVoEU0P8uYAC0iMeu0+ 83L3xO5tQG/YrMiPjMNtnJjIATeKT2bggZ4aj31Agl0IPbkNBzopWEGddpxO2kk9AKUt brS6x5cvldkh9cfyMeWy+LEmF682U99ZcZLq2VP5/VRTfTjGsqTVxkBYDiAqAlSHPX4+ K/NahCHpDS62o7bQBnFqIBKNd6L4jrN+Vw7I9rGqy0ea7Q7Ki22JoEkiLKovFBdZfzVc DHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gbNLNoNUtLpmvXGtkruf34xAYHi/j4E55WSdSx4bUmU=; b=40vV6oBALvCjWs83uUyi6tO3H1fp/Wv++vzVQyxoCm6OnxcsOV2YcKkKqjcuqeYmV3 8GClPapIT4ECHRlyC2UpB38aQaH9eiOev+jhb1FdyKcVp6Hs4rPDUeMlW2P9GUkmrNHS y0lUwGPeCi6CcKigfVk2NZ6z2sWEX7/7ybBivu43TMXZX91qb1MVOE8N5+EerHAAIZY9 IMLY64teyJI/BZKG6wBmuH7KEvihUM7Gc8FswMwujr9Ixq/Qt0uKLeg2qCuWtnL0QcH8 kcsJKp2/EkXNvpZGzQYsSTr20ayKxnxejs3bCPXerWSbjsb8PDsM9uVFShkNm37OqOq8 TUfw== X-Gm-Message-State: AOAM532PQNq7su8Ht7SxFTXk14FHkwLWJWLg5g0Q50tSQejWafN/WVVo vg6Hi1OJfjZ4NsN3KVpmF1exVA== X-Google-Smtp-Source: ABdhPJztO9aPd48ZSjjD4aY9lShRgqdRU7Zs47AgfKXEdv0GxvFhUwP8Z+mcxJuzKx4yAUM+L2AMrA== X-Received: by 2002:a63:305:0:b0:3fc:7f18:8d7 with SMTP id 5-20020a630305000000b003fc7f1808d7mr7469116pgd.186.1654237240030; Thu, 02 Jun 2022 23:20:40 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id a6-20020a170902710600b00163a6e1416dsm4575155pll.32.2022.06.02.23.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:39 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] OPP: Use generic key finding helpers for bandwidth key Date: Fri, 3 Jun 2022 11:50:19 +0530 Message-Id: <07c76851ac311d704522aef1d8712550ef1ac7ca.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use the recently added generic key findings helpers to find bandwidth key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 78 +++------------------------------------------- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index d8a91900d8a9..f17e19872769 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -697,43 +697,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, - unsigned int *bw, int index) +struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw, int index) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >= opp_table->path_count) - return ERR_PTR(-EINVAL); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->bandwidth) { - if (temp_opp->bandwidth[index].peak >= *bw) { - opp = temp_opp; - *bw = opp->bandwidth[index].peak; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, (unsigned long *)bw, index, true, _read_bw); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); @@ -756,45 +722,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ -struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, - unsigned int *bw, int index) +struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned int *bw, int index) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >= opp_table->path_count) - return ERR_PTR(-EINVAL); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->bandwidth) { - /* go to the next node, before choosing prev */ - if (temp_opp->bandwidth[index].peak > *bw) - break; - opp = temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - if (!IS_ERR(opp)) - *bw = opp->bandwidth[index].peak; - - return opp; + return _find_key_floor(dev, (unsigned long *)bw, index, true, _read_bw); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_floor);