From nobody Sun Apr 19 07:16:06 2026 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 79857C433EF for ; Tue, 5 Jul 2022 06:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbiGEGhx (ORCPT ); Tue, 5 Jul 2022 02:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiGEGhu (ORCPT ); Tue, 5 Jul 2022 02:37:50 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A98D610FEE for ; Mon, 4 Jul 2022 23:37:49 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id n10so10245059plp.0 for ; Mon, 04 Jul 2022 23:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zcbMmvHbvVMpZvOTILkaolJLorfaQM+g9wQsZMC+FTE=; b=g0bprKe6UgQxC7q+zKqSxMLjOwv+3yRMZlfrMw1EgUwyP8SDkEwAeCs/bJYayUtvnW 19u4tZ/iyydAJ7QjsxfvYAuT/VlpL5oAGF6DSuwz5Q0Bv1IF7qHYiARtoM9knRoMY+v7 iKPX/Mcx1bjA38/7ewO4vcQWQ+jV6XuYnAvz+XyJ1gs5laJZwx5cXsMPP2tCiLYTsrAO 05DaCYfWpkua89iCVEWUAxW/acA0XQgmWpgjF8Rtk1PyHsdgpXd5M6B/XTHvkBD46e+J FDywfa1vAHUhY1Pu/agPHghVESqhmKu7I+J68IYl4S7xF4gZWVbAtccx8yB4Oo0xVOLi Kgzg== 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=zcbMmvHbvVMpZvOTILkaolJLorfaQM+g9wQsZMC+FTE=; b=jV/MIZ0LhRIcc2oxOnfXXnxgQpMX+qSZNvZl5Ng0QJ10/Olbh+wUS58C5N2Z4V5jbs u9Fo6KBdKrInUWVxBI+jwGlHRUCj6e969bA5T06LO77ZVNC2eX4MSKYyvMyi7FWv+fXX 1pTc7m3Inqklg06AnshranFe+kGKq+LCzNWQTLbavQztGRaOVBHJjksRs2DxvhZIvznB Wt8p3iehZ/8lN7L5sDnN/AggAuAajhsY9qbqaRL/39AIWP6sbCIWRSqh8QA+E+FIT5dQ qiY0Kmca1W+pOXNidHHXDN0g8wDmwcOHpf3nOgCOHz5+MWPya9G0+GV2WfSylrJKzJNd BE+g== X-Gm-Message-State: AJIora+AoVxXexCGrp4mRPT+ATgt4wpa+IHvnN79SuL2ojdoK+uN4Eb1 /lKDh/rpiepmxYPa6lqajAovXg== X-Google-Smtp-Source: AGRyM1uz18gDPJhA64KqvLCW7ypIfE0r8nA3ehySpmm8TrHVMpZGnoqNWf719nS7QCronhFKOxNFKw== X-Received: by 2002:a17:90b:278e:b0:1ee:f086:9c9d with SMTP id pw14-20020a17090b278e00b001eef0869c9dmr40729090pjb.182.1657003069210; Mon, 04 Jul 2022 23:37:49 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id u2-20020a170902714200b00168b4b550f2sm22535425plm.54.2022.07.04.23.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 23:37:48 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/4] OPP: Remove dev_pm_opp_find_freq_ceil_by_volt() Date: Tue, 5 Jul 2022 12:07:37 +0530 Message-Id: <63de4a326ceb5b8836c46c6ee347d443e4068eb4.1657002904.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This was added few years back, but the code that was supposed to use it never got merged. Remove the unused helper. Tested-by: Dmitry Osipenko 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 e74bdc134c5a..fc0232f695c6 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -607,60 +607,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct d= evice *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); =20 -/** - * dev_pm_opp_find_freq_ceil_by_volt() - Find OPP with highest frequency f= or - * target voltage. - * @dev: Device for which we do this operation. - * @u_volt: Target voltage. - * - * Search for OPP with highest (ceil) frequency and has voltage <=3D u_vol= t. - * - * Return: matching *opp, else returns ERR_PTR in case of error which shou= ld 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 =3D ERR_PTR(-ERANGE); - - if (!dev || !u_volt) { - dev_err(dev, "%s: Invalid argument volt=3D%lu\n", __func__, - u_volt); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _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 =3D 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 9d59aedc2be3..50cbc75bef71 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -118,8 +118,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct de= vice *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); =20 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigned int level); @@ -265,12 +263,6 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_= floor(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } =20 -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) { --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 07:16:06 2026 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 DA462C433EF for ; Tue, 5 Jul 2022 06:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbiGEGiB (ORCPT ); Tue, 5 Jul 2022 02:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiGEGhx (ORCPT ); Tue, 5 Jul 2022 02:37:53 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777C61116C for ; Mon, 4 Jul 2022 23:37:52 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id z1so4411225plb.1 for ; Mon, 04 Jul 2022 23:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=squH0g0ZyU7acyau8EuY18KsACXTY7LGnn7ZEWB58Lg=; b=Y4sqp8vcqK0ALA7AZ9P2jYTozrprGqlIqpn3QMeikjM434aKeOFJjtSOQemje8qnn1 t+8B4RYTSsgxEsPO5qMnKpf7FwPhNVSSBod+4rHYCbvJmb1mFtLqLptxPYT/8gop3g7c aWw8jOjQuTKNBTN+7t7NTgm+gkdEgZcOTtEXkKa7CnjUkJgx1O1MrVF3JNfRRwoLf6Uw YOyWlhv5y9YbHkH2XdugJeiuvkSVLnwBbhNcqCWfIA05GvPi4lFJiz/76mdMS76mouv4 xgXU0F5rZrMbIdCt5LELNyJfQ1lI9HSenLZ3u6slBBOJsYTQRZRIqzVrLHqf8G6tSVRr Zhnw== 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=squH0g0ZyU7acyau8EuY18KsACXTY7LGnn7ZEWB58Lg=; b=lPHLcuEJUX9w4eOFoNocIDZke1zAyj5irXBajGwdDh1L8wb6yAjsY1Uo+ryU3xRY7U hG/XVWe76QyG5dYOXXQFWRVkGAb5K0J0JfT6NY7llocqVSpSb7gbqKcLfShcANpy/A4N C4WjPfDlyvb1wBWpyiBA3H2Wqc+EtN7oVkPL7XR6TM3hVHUjH2JtgA5VmFE74hnJ75pJ WLLqjhuRNN7Ragh3st3QdFpO7x6512sh1vp5U1bCchzOnuiCErRZjjp6BVUC/PQsRqKG 2V9Kujd4Ga0YEbvSCOVT3JtptE3acN+Mq3WiLV5ZQhjYKj6iSlshN2vwMcokDaSznt3t 9oQw== X-Gm-Message-State: AJIora8sngDcICYFudwtFSTEs5X1wqbCGaihLozC9+QnWFQbf7Ny6fbs T/B0hIjzl5alAaiTyzNxFnY2rg== X-Google-Smtp-Source: AGRyM1vIrbOyKhZN37oEO47IfDs25UzM+FR08FROKrVikQXrvi4krROTDiK3WgvfWn0UZf3yFokTIw== X-Received: by 2002:a17:902:d701:b0:16a:2206:9ba8 with SMTP id w1-20020a170902d70100b0016a22069ba8mr39319081ply.168.1657003071996; Mon, 04 Jul 2022 23:37:51 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id x12-20020a17090a1f8c00b001ef307e1deesm11522008pja.18.2022.07.04.23.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 23:37:51 -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" , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 2/4] OPP: Add generic key finding helpers and use them for freq APIs Date: Tue, 5 Jul 2022 12:07:38 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Also update the freq finder helpers to use the new infrastructure. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 229 +++++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 99 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index fc0232f695c6..c850b8691ee6 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -427,6 +427,131 @@ int dev_pm_opp_get_opp_count(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); =20 +/* Helpers to read keys */ +static unsigned long _read_freq(struct dev_pm_opp *opp, int index) +{ + return opp->rate; +} + +/* Generic comparison helpers */ +static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *tem= p_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key =3D=3D key) { + *opp =3D 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 >=3D key) { + *opp =3D temp_opp; + return true; + } + + return false; +} + +static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *tem= p_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key > key) + return true; + + *opp =3D 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 =3D ERR_PTR(-ERANGE); + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->available =3D=3D available) { + if (compare(&opp, temp_opp, read(temp_opp, index), *key)) + break; + } + } + + /* Increment the reference count of OPP */ + if (!IS_ERR(opp)) { + *key =3D 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 availabl= e, + 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 =3D _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 =3D _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_t= able, + 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 @@ -451,61 +576,16 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); * use. */ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, - unsigned long freq, - bool available) + unsigned long freq, bool available) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D 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 =3D=3D available && - temp_opp->rate =3D=3D freq) { - opp =3D 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); =20 static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_t= able, unsigned long *freq) { - struct dev_pm_opp *temp_opp, *opp =3D 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 >=3D *freq) { - opp =3D temp_opp; - *freq =3D 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); } =20 /** @@ -529,23 +609,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(str= uct opp_table *opp_table, 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=3D%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - opp =3D _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); =20 @@ -570,40 +634,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); 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 =3D ERR_PTR(-ERANGE); - - if (!dev || !freq) { - dev_err(dev, "%s: Invalid argument freq=3D%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _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 =3D 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 =3D opp->rate; - - return opp; + return _find_key_floor(dev, freq, 0, true, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 07:16:06 2026 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 B1371C433EF for ; Tue, 5 Jul 2022 06:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbiGEGiF (ORCPT ); Tue, 5 Jul 2022 02:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiGEGh4 (ORCPT ); Tue, 5 Jul 2022 02:37:56 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAB5E11478 for ; Mon, 4 Jul 2022 23:37:55 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id y18so2196591plb.2 for ; Mon, 04 Jul 2022 23:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mgVrobRjRVVckOe4+13ub+Rh2vX8SJDm/0tKekQBc40=; b=b3lGdME5GHaIYu+2f81jtoPrZGLSIn/R2Rp23ERfIY/OsM6YR0qJLY1Wtvjn2Q2PZP ylN3AL7hjz++KNzVTk+pUmIt7h/WT1yMxxbD8zT2MK2sJcmKuM0RzSgBfSbSe2E5Nuj9 8CkNOqHeh3s1FPKpHoCRrEz2vgxZDWDh33QlexqCqjz9I3BosBOvg3oA0/UiLzIMosDP hud3azSEAmzL+6BoUMM8gHYza9r8Ra7Ef0WPHUmi9sdoWaBu8FIfvbur5S4oh/TZ2mBN YOl09mxPYHqZavMUAM7thK5JAvmInxlKYsXyzP2rn38Ol9j7MnpvtQFmkgsfMLYGlmI5 +T/A== 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=mgVrobRjRVVckOe4+13ub+Rh2vX8SJDm/0tKekQBc40=; b=jTjvUTIOTpLuGNEKbhWT1c1QaD17Skkviu3GLB+fyWpqPFKq8PqnwCw8ZO26uAHuOw nBGl1mmrM8nYV0xhiIT+Q9Ok3u+593O7YXm48ovFIDS2moGTsQ1kDONDJEk8uo8hV7ap 3iCxNusFHLyay7afhFMdMTulNeyRPY/P50gZOy4ZT5a/++f/jrH3ny8gHDriR5YKp/wT EfkB6LNsd/PT3aFgfpvpTP1h/EhuA0TNULA+MQaoWyVG8dgLwMcC+l5YgFOtt45FwIhi JxnwaMK+ViWihugBAYBIkQkZuTVyyrChs5eoDivV8DY9JDs17Q4+t028h6wrLnCzvN47 kx+Q== X-Gm-Message-State: AJIora9tohOG1SGEYSlR6c9FL/Kdxm3Jcb0b9+S6H9xfBroEY+Azzh+E OckOzTnsq2BmxPOhkpZUZqZgKg== X-Google-Smtp-Source: AGRyM1u8awKUnXFqpuo/32okx5J1EnxHusVCBX85KZo+aIV8d2QuurrG6XfMic89cMVtCZNyUq3qOQ== X-Received: by 2002:a17:902:d4c3:b0:16a:7696:971a with SMTP id o3-20020a170902d4c300b0016a7696971amr38957197plg.142.1657003074925; Mon, 04 Jul 2022 23:37:54 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id c6-20020a63ef46000000b0040ca00cd318sm21368116pgk.40.2022.07.04.23.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 23:37:54 -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" , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 3/4] OPP: Use generic key finding helpers for level key Date: Tue, 5 Jul 2022 12:07:39 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the recently added generic key findings helpers to find level key values. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 63 ++++++++-------------------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index c850b8691ee6..968fdbbc0693 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -433,6 +433,11 @@ static unsigned long _read_freq(struct dev_pm_opp *opp= , int index) return opp->rate; } =20 +static unsigned long _read_level(struct dev_pm_opp *opp, int index) +{ + return opp->level; +} + /* Generic comparison helpers */ static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *tem= p_opp, unsigned long opp_key, unsigned long key) @@ -656,33 +661,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); 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 =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D 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 =3D=3D level) { - opp =3D 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); =20 @@ -704,33 +683,11 @@ 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 =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D 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 >=3D *level) { - opp =3D temp_opp; - *level =3D 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); + unsigned long temp =3D *level; + struct dev_pm_opp *opp; =20 + opp =3D _find_key_ceil(dev, &temp, 0, true, _read_level); + *level =3D temp; return opp; } EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil); --=20 2.31.1.272.g89b43f80a514 From nobody Sun Apr 19 07:16:06 2026 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 2D683C43334 for ; Tue, 5 Jul 2022 06:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiGEGiH (ORCPT ); Tue, 5 Jul 2022 02:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiGEGh7 (ORCPT ); Tue, 5 Jul 2022 02:37:59 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D8911A1E for ; Mon, 4 Jul 2022 23:37:58 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id t5-20020a17090a6a0500b001ef965b262eso1315787pjj.5 for ; Mon, 04 Jul 2022 23:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mcN5aWF/+F7X9Dd6NAzqDokTXFgMVn5D4Bvd5NBE264=; b=VJGq5G0/CDZRAMAODM6TfM4aIIch7aVu0lmqTWD4KxBuCoZ3DtXshzKbGvH0pTJCkk kqOPW/s0S3SstmRjP5V7qA1hI0jhELXOGvgmzo7ueKs7DgvgDtYl8hfd8xmXjRbZL4hB qx+xXyuh4PHs/3EZuM5T382nVrxnyBuewtQJ9aFNq53Jym+SYUY4EEfiJGi5fCEewGyZ Etm10IzQX44BALDRFy4ygoxAdgpQm2Z3WfZI1RURwKzKMq5BkQD0InTarsSRbC9+SRgi Nlv4O36UZuuxbgADmoIAQofXtqho+3p2KD0CwI4cw0KdbxYShx4ARrsIYu1JyhHlYoKe AIcg== 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=mcN5aWF/+F7X9Dd6NAzqDokTXFgMVn5D4Bvd5NBE264=; b=Q73xL+hYFh5BuragO2jm1XYQhxQNWbyNPE18m60Gqg7tZ6Vr42P2XPEz5r3KxIFZFO pXULa/QwaKTfMbg6EM59+pa7HZap8UKLBPzNEEqjg8EeStIWEqPGDhtxAhQ/Divn6y/d UxXElj1OyUp/mJ5tNim0oVAsi50vjp3zrIrOlY8j1kkj/vS0PqRx1EHCr1FcxpCg+zRh w0HfX6dhwi1q8O4DBq/egCGWNJQwIPqp8Agrdyd1jebJMgpvXYU06GzidEH+zxRPkj+k HjjRgHD1/PctyeUWy3Mm2lwvUaGNpqaiAQdQ9li5mTC3jE7rcpRpycr5BDsiHUQbr3v6 5VQg== X-Gm-Message-State: AJIora+2MWLVov2vEO2foBzfbwLCtprGXV5FzfCUfsYouvKco1Dm/yAh ZywgcFTIZO+G5Mav7cofqjYycw== X-Google-Smtp-Source: AGRyM1s6eL8w4tjHdNsJxvPP4VeAZaAPooYVPfK1Mk2uaInhFxM7fBf4tBdImNj41uKdR3Yv7hf81w== X-Received: by 2002:a17:90b:4c49:b0:1ec:e8a2:b5f0 with SMTP id np9-20020a17090b4c4900b001ece8a2b5f0mr40764256pjb.21.1657003077666; Mon, 04 Jul 2022 23:37:57 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id p6-20020a170902780600b0016a4db13429sm22464251pll.192.2022.07.04.23.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 23:37:57 -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" , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 4/4] OPP: Use generic key finding helpers for bandwidth key Date: Tue, 5 Jul 2022 12:07:40 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the recently added generic key findings helpers to find bandwidth key values. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 83 +++++++++------------------------------------- 1 file changed, 15 insertions(+), 68 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 968fdbbc0693..5ad43dbfd87f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -438,6 +438,11 @@ static unsigned long _read_level(struct dev_pm_opp *op= p, int index) return opp->level; } =20 +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 *tem= p_opp, unsigned long opp_key, unsigned long key) @@ -711,42 +716,14 @@ 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 in= t *bw, + int index) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=3D%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >=3D 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 >=3D *bw) { - opp =3D temp_opp; - *bw =3D 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); + unsigned long temp =3D *bw; + struct dev_pm_opp *opp; =20 + opp =3D _find_key_ceil(dev, &temp, index, true, _read_bw); + *bw =3D temp; return opp; } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); @@ -773,41 +750,11 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); 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 =3D ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=3D%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >=3D 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 =3D 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 =3D opp->bandwidth[index].peak; + unsigned long temp =3D *bw; + struct dev_pm_opp *opp; =20 + opp =3D _find_key_floor(dev, &temp, index, true, _read_bw); + *bw =3D temp; return opp; } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_floor); --=20 2.31.1.272.g89b43f80a514