From patchwork Wed Feb 22 11:06:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 60466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp511984wrd; Wed, 22 Feb 2023 03:12:47 -0800 (PST) X-Google-Smtp-Source: AK7set9h4q+sf5k2BiyxCc2BlEExstFw1KVZuKczEb9JNHCge5oppfVJKgYcEQb0E8UjmAfWwgeW X-Received: by 2002:a05:6a00:9b:b0:5a8:a263:7f4d with SMTP id c27-20020a056a00009b00b005a8a2637f4dmr6589738pfj.15.1677064366951; Wed, 22 Feb 2023 03:12:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677064366; cv=none; d=google.com; s=arc-20160816; b=lKS8B6suY5La35YG23wG6swnS9umdhddHTNdoVFdOtLZxEYkfzW2oHRMMU47p3Fasl qumVexeowFvkYm/GW4lrjzr3LjIN+fWaygrR/CkbJZLlPpnlB9UcZgQQj7W+Y3MCJpy/ wxMvQZEM/o6sbRkJyahGsV1vCumj6ziX/B3LGqf30tWpyaXA4qwlqtrZoWPu5FpNWN3e lrPXC3YUeppo8q5Rr02TnZdJo4Nx8vyaqMeZM9kO4BABKOBlAtfV9XBrJHeZPIEv2t7n e5zwrtQYx4KBk2FH82ULg9ukxphI4ZK6DoJiNZB+CAMUZAQGGNmADtecjlbVDaK/LmR2 36Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pKF4g3sJY4F36hMtcM0eHUIlxzL76BJwo9OlrmTuaXo=; b=L7lHbMKdGQ0tV9wuGOZtp4xPbM6yLl3T2D35bUijl0pALoO4/KlMCK8DLBwG12A9uW nD6kl5GDc0vQ/5tpoRQqAtoXnUAWEKCzbw5Jdn6LtJuIyRI5kmb6Sps9NtxN5QvMHX5Q XF5TJPAXS05CC2R9ORLClbr32mQ5PulbFns5GWuutXE0jsT4bq0oEvMVYSz8eCAQG9mV fWPiGM0WpbNW0NbZJth7tpTL3LQnsHZya1w2z54z4h31xql8KJKmjLMtNlc2rIRtDo+G Xmdu2YTos94Bx2OskL2urITu9cd3LzntSL3oINqyhi+5M8djB22tJ0P/WwAn2qnsCPsU pL5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1QtHTdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o12-20020aa7978c000000b0058bb0834688si7879479pfp.157.2023.02.22.03.12.34; Wed, 22 Feb 2023 03:12:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1QtHTdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231654AbjBVLHB (ORCPT + 99 others); Wed, 22 Feb 2023 06:07:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjBVLG5 (ORCPT ); Wed, 22 Feb 2023 06:06:57 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D648C38E8E for ; Wed, 22 Feb 2023 03:06:55 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id z2so8481227plf.12 for ; Wed, 22 Feb 2023 03:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pKF4g3sJY4F36hMtcM0eHUIlxzL76BJwo9OlrmTuaXo=; b=r1QtHTdmuiRplIZ5BlnOJSnSr9AfM12vU5yV8seTDhtwDfAwQVVrchPoLYEtimSeSO fZcOjLk2nkQ4BNkACOsmfYIXAurwqq1Wcp1/8R447NRr9t/UwAwiK4ReoOoKg8fMz61B NzblmUIez8fpvNadarTg5ogp8sv3C6SBBsUiAuHC/3V6DbSw/L42g5bneQ4b2MtrHTsv sTs7V9J11iejVjby1kcY+SPupy/b+vy3wM6W0mLZe9sgFJr2hD26X8aWk4K8YILU4Qns DluNjWyWME9jDCYpOFtKWAImOytgUD1JN11Vdpbiw72JWSd1Bj/xkYth2KyB6VcR8mrk up7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pKF4g3sJY4F36hMtcM0eHUIlxzL76BJwo9OlrmTuaXo=; b=NWdurBxGwlIVJxEg4o5xg7tYMOTfEpNN8XU8YokIu49/iH4bS1kXyMCqrtdclZTQnj SZP1G3nwE/+CFM57MqUxAEuHrGrM/iE8jAhnF3r2/RTdXCNptKCXL6BgIJRgScpIBLPC aK2kY/8QOitHTh2AfWDamCPPQL9qyPc8D8dZsjueuXOiUkaZCJ6NkPQKXag46KuxJfcd tr9sBJ2Usi2P81cXO1SN+FMhUUMloeqhEyAC/kydBQD5MNB4N8Va1RruxiN5+GH2mkwG dTt+uLeVcj7McZYbuJ2CXr+h8A9fnrUihzzXEY1F2RlV4YjZSgLi7WAoMjWtOBneykDX 8YIg== X-Gm-Message-State: AO0yUKV/6IBVMIVwUI8397Xk0zktF4kOLJy+8XklzQEAOcSGljPsK8ru tG8u3rXqSv6J77qdgTbskKtrIw== X-Received: by 2002:a17:902:cf48:b0:19a:80c2:4396 with SMTP id e8-20020a170902cf4800b0019a80c24396mr8138522plg.68.1677064015575; Wed, 22 Feb 2023 03:06:55 -0800 (PST) Received: from localhost ([122.172.83.155]) by smtp.gmail.com with ESMTPSA id 12-20020a170902c14c00b001949f21e1d2sm4579999plj.308.2023.02.22.03.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 03:06:55 -0800 (PST) From: Viresh Kumar To: Jun Nie , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Manivannan Sadhasivam , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] OPP: Handle all genpd cases together in _set_required_opps() Date: Wed, 22 Feb 2023 16:36:37 +0530 Message-Id: <8f9fba47f91ef04fa2cf0c3adba9299a23d5280a.1677063656.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758529445322245293?= X-GMAIL-MSGID: =?utf-8?q?1758529445322245293?= There is no real need of keeping separate code for single genpd case, it can be made to work with a simple change. Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson --- drivers/opp/core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index e87567dbe99f..6d7016ce8c53 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -959,7 +959,8 @@ static int _set_required_opps(struct device *dev, struct dev_pm_opp *opp, bool up) { struct opp_table **required_opp_tables = opp_table->required_opp_tables; - struct device **genpd_virt_devs = opp_table->genpd_virt_devs; + struct device **genpd_virt_devs = + opp_table->genpd_virt_devs ? opp_table->genpd_virt_devs : &dev; int i, ret = 0; if (!required_opp_tables) @@ -979,12 +980,6 @@ static int _set_required_opps(struct device *dev, return -ENOENT; } - /* Single genpd case */ - if (!genpd_virt_devs) - return _set_required_opp(dev, dev, opp, 0); - - /* Multiple genpd case */ - /* * Acquire genpd_virt_dev_lock to make sure we don't use a genpd_dev * after it is freed from another thread. From patchwork Wed Feb 22 11:06:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 60467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp512007wrd; Wed, 22 Feb 2023 03:12:49 -0800 (PST) X-Google-Smtp-Source: AK7set/IiirkmFR8H1/Wt7/TPsNnnqcZdq9hdFlyrtM4rkH51RqXNbXmn2AX6VcM3VwnaVL4rPPc X-Received: by 2002:a17:90a:341:b0:236:75d3:fedc with SMTP id 1-20020a17090a034100b0023675d3fedcmr8367144pjf.8.1677064368779; Wed, 22 Feb 2023 03:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677064368; cv=none; d=google.com; s=arc-20160816; b=zEvZKDVspBZoSV8g/3d9VpaAgjbsm5HdHsCYEGcKYInYAGr494YbWQFpw3o5wPoIZz K2U6VDHeBBaT7oc7mSMrhLR5Q9GQYr7qjq9ZrzaUiDhAKJJuXzTdGuQtG6h9P9S1JTkj kRC+YkFLvdvxdqkSar8nD9fTnKTVAU+oDQcd1r0jmGD9kciPwzCwNsyGPl+A+8+Jx9ph 9mgLQYBkQAGkD5ekwd8RcrtHigmsKHrVDKFIxXubOe79FuLSDHY/zHX8/NWXPy8EXXfN tANhfTgQUL8vb6HZAg4jUViQLsrHV8FtybH4181FCPN/+hVoX7rKfAHic1I7WQh1YTtp lnXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VTFmQMiqtUc7pwcWMY+qhhF7WdtAyTRbIisqm76H6qE=; b=aXrs+yMyupNGOCJDKzLbDrNDhMJnaxpsDeY/v9VVmRBIPBTgJwOxvdicbb7woe65mS AMzTkiQknjZrBYfMXNfFWyxiGgddy9QhjxjScciPwWVpJ/lVNupdlEFo2tyDKv1YtfrB gEWe+NxjcG1H4bmH7s2FlXFyHSXNIAs1w5qk8TAq9YKgZf3N5bDl/+1iF5Q6W+gAEnSu 0ljkBNy5ORNVD9O0RB11XhJLz9ZXheQlw33lFQPpu1lvRoF57gK1QlPtC6gVyHdK9uVp iFzS5R/TKAvjnIZZtfDRsM9EECyk2lq+JM0//FHyYPZIJSK4mRaxVPDX5ZQAR49uN6Yn jH1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r4ALaOW2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a65414c000000b004fbc5c96d03si5500835pgp.696.2023.02.22.03.12.36; Wed, 22 Feb 2023 03:12:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r4ALaOW2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231669AbjBVLHE (ORCPT + 99 others); Wed, 22 Feb 2023 06:07:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbjBVLHB (ORCPT ); Wed, 22 Feb 2023 06:07:01 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7988838E8E for ; Wed, 22 Feb 2023 03:06:59 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id y2so4158399pjg.3 for ; Wed, 22 Feb 2023 03:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VTFmQMiqtUc7pwcWMY+qhhF7WdtAyTRbIisqm76H6qE=; b=r4ALaOW2f7Akg1Mdcn3iw8u74rUnAqIkuefrRsyXjT1f3JQ1f8o9Cf+sRlMGMndhue yt94gDP2i6As0UHAEILftMnAljUNFXdm7bhl4O0LRdzjOyw3EN3aT2hhhGJi6k0PTpYM onDUTZzr/QJufxfzro5YS4CdKgNn/rou3baC6xS4Vkpj5NOU8VOjfLU8QS+jvsmAhD+V o3WCZSipVs0jl+kVlVvq955378NoTUxuE/ycQvW0JxYpCYbn+xUFZDJvqZVKRmYF5QgD 9TK8vuwABItOoVsnMuxaSzHx5HPUrLxSALbFAXdeVOl8usZ06aMaSJHtbZ2YMX+9bXO8 Z8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VTFmQMiqtUc7pwcWMY+qhhF7WdtAyTRbIisqm76H6qE=; b=piHLIlyQvBvMKTiYIqxLatpNssZbWUIRZCMFopo+99vwJZLDTkOI1/0t7uFDH1YgxN rExiQzNEU0Xv7hEPACUpSJ7MsawSGJotU4bUXXtky2FWVniu45Ultd02Oeqd9+qzuhys mllif27rYLNLYfnn6ODqxiMXfRO5sKqSBT+DlLJ880kogFxQCyOF95EwKj/EPa4IHF2F 5KDQKznCoAtPCXeXrxr3xGbaaveZXbK/ppv4YAv24h531PyIcBHZx4Jy6/zF8y0/QIim NnsNCXHf4VisYbH2UUk/GxunzoddUNS9T2R8AFvUzzjeRpVH+HHXIkFYUBLwAFKTAp1N zMFw== X-Gm-Message-State: AO0yUKWpz7MoKCMkwyaqJrJO+BW4kkxYdsF23Aky/Q0pV5KvDzgpXSTn xUlY8qx+NszQndQNIfq6GayhMQ== X-Received: by 2002:a17:902:f908:b0:19a:a2e7:64cf with SMTP id kw8-20020a170902f90800b0019aa2e764cfmr6332392plb.69.1677064018883; Wed, 22 Feb 2023 03:06:58 -0800 (PST) Received: from localhost ([122.172.83.155]) by smtp.gmail.com with ESMTPSA id y7-20020a170902d64700b0019926c7757asm4956737plh.289.2023.02.22.03.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 03:06:58 -0800 (PST) From: Viresh Kumar To: Jun Nie , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Manivannan Sadhasivam , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] OPP: Move required opps configuration to specialized callback Date: Wed, 22 Feb 2023 16:36:38 +0530 Message-Id: <56b9926836652e9dbf56ca6b7628e836cddca351.1677063656.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758529447581791872?= X-GMAIL-MSGID: =?utf-8?q?1758529447581791872?= The required-opps configuration is closely tied to genpd and performance states at the moment and it is not very obvious that required-opps can live without genpds. Though we don't support configuring required-opps for non-genpd cases currently. This commit aims at separating these parts, where configuring genpds would be a special case of configuring the required-opps. Add a specialized callback, set_required_opps(), to the opp table and set it to different callbacks accordingly. This shouldn't result in any functional changes for now. Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson --- drivers/opp/core.c | 69 ++++++++++++++++++++++++++++------------------ drivers/opp/of.c | 3 ++ drivers/opp/opp.h | 4 +++ 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 6d7016ce8c53..954c94865cf5 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -935,8 +935,8 @@ static int _set_opp_bw(const struct opp_table *opp_table, return 0; } -static int _set_required_opp(struct device *dev, struct device *pd_dev, - struct dev_pm_opp *opp, int i) +static int _set_performance_state(struct device *dev, struct device *pd_dev, + struct dev_pm_opp *opp, int i) { unsigned int pstate = likely(opp) ? opp->required_opps[i]->pstate : 0; int ret; @@ -953,33 +953,20 @@ static int _set_required_opp(struct device *dev, struct device *pd_dev, return ret; } -/* This is only called for PM domain for now */ -static int _set_required_opps(struct device *dev, - struct opp_table *opp_table, - struct dev_pm_opp *opp, bool up) +static int _opp_set_required_opps_generic(struct device *dev, + struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down) +{ + dev_err(dev, "setting required-opps isn't supported for non-genpd devices\n"); + return -ENOENT; +} + +static int _opp_set_required_opps_genpd(struct device *dev, + struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down) { - struct opp_table **required_opp_tables = opp_table->required_opp_tables; struct device **genpd_virt_devs = opp_table->genpd_virt_devs ? opp_table->genpd_virt_devs : &dev; int i, ret = 0; - if (!required_opp_tables) - return 0; - - /* required-opps not fully initialized yet */ - if (lazy_linking_pending(opp_table)) - return -EBUSY; - - /* - * We only support genpd's OPPs in the "required-opps" for now, as we - * don't know much about other use cases. Error out if the required OPP - * doesn't belong to a genpd. - */ - if (unlikely(!required_opp_tables[0]->is_genpd)) { - dev_err(dev, "required-opps don't belong to a genpd\n"); - return -ENOENT; - } - /* * Acquire genpd_virt_dev_lock to make sure we don't use a genpd_dev * after it is freed from another thread. @@ -987,15 +974,15 @@ static int _set_required_opps(struct device *dev, mutex_lock(&opp_table->genpd_virt_dev_lock); /* Scaling up? Set required OPPs in normal order, else reverse */ - if (up) { + if (!scaling_down) { for (i = 0; i < opp_table->required_opp_count; i++) { - ret = _set_required_opp(dev, genpd_virt_devs[i], opp, i); + ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i); if (ret) break; } } else { for (i = opp_table->required_opp_count - 1; i >= 0; i--) { - ret = _set_required_opp(dev, genpd_virt_devs[i], opp, i); + ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i); if (ret) break; } @@ -1006,6 +993,34 @@ static int _set_required_opps(struct device *dev, return ret; } +/* This is only called for PM domain for now */ +static int _set_required_opps(struct device *dev, struct opp_table *opp_table, + struct dev_pm_opp *opp, bool up) +{ + /* required-opps not fully initialized yet */ + if (lazy_linking_pending(opp_table)) + return -EBUSY; + + if (opp_table->set_required_opps) + return opp_table->set_required_opps(dev, opp_table, opp, up); + + return 0; +} + +/* Update set_required_opps handler */ +void _update_set_required_opps(struct opp_table *opp_table) +{ + /* Already set */ + if (opp_table->set_required_opps) + return; + + /* All required OPPs will belong to genpd or none */ + if (opp_table->required_opp_tables[0]->is_genpd) + opp_table->set_required_opps = _opp_set_required_opps_genpd; + else + opp_table->set_required_opps = _opp_set_required_opps_generic; +} + static void _find_current_opp(struct device *dev, struct opp_table *opp_table) { struct dev_pm_opp *opp = ERR_PTR(-ENODEV); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index e55c6095adf0..93da3c797afc 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -196,6 +196,8 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, /* Let's do the linking later on */ if (lazy) list_add(&opp_table->lazy, &lazy_opp_tables); + else + _update_set_required_opps(opp_table); goto put_np; @@ -411,6 +413,7 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) /* All required opp-tables found, remove from lazy list */ if (!lazy) { + _update_set_required_opps(opp_table); list_del_init(&opp_table->lazy); list_for_each_entry(opp, &opp_table->opp_list, node) diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 3a6e077df386..2a057c42ddf4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -184,6 +184,7 @@ enum opp_table_access { * @enabled: Set to true if the device's resources are enabled/configured. * @genpd_performance_state: Device's power domain support performance state. * @is_genpd: Marks if the OPP table belongs to a genpd. + * @set_required_opps: Helper responsible to set required OPPs. * @dentry: debugfs dentry pointer of the real device directory (not links). * @dentry_name: Name of the real dentry. * @@ -234,6 +235,8 @@ struct opp_table { bool enabled; bool genpd_performance_state; bool is_genpd; + int (*set_required_opps)(struct device *dev, + struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down); #ifdef CONFIG_DEBUG_FS struct dentry *dentry; @@ -257,6 +260,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cp struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk); void _put_opp_list_kref(struct opp_table *opp_table); void _required_opps_available(struct dev_pm_opp *opp, int count); +void _update_set_required_opps(struct opp_table *opp_table); static inline bool lazy_linking_pending(struct opp_table *opp_table) { From patchwork Wed Feb 22 11:06:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 60468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp512074wrd; Wed, 22 Feb 2023 03:12:59 -0800 (PST) X-Google-Smtp-Source: AK7set9WXr5v91KnwnJ6xpPmhKvPxcLUKsCfVFJpFZDX+Yhy2J6kKMLhA7ZyVMsXelS7LI1PAU5M X-Received: by 2002:a17:903:803:b0:19a:e462:3e70 with SMTP id kr3-20020a170903080300b0019ae4623e70mr6559996plb.10.1677064379039; Wed, 22 Feb 2023 03:12:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677064379; cv=none; d=google.com; s=arc-20160816; b=LzE0hKFwJuyv/eE7qYL1oOdOiHAPe4mvFbLREof+vowaS0ag1akC02h6s8bBwrENq+ LbX2mptASDAQQhHBdKvH0e31p6i73+KWBr+r441EsfV073j6qtFrvrsbQFwl4raLvhyj g0/vi8PhbZYSj9I38Z2NFUfIxmre28bwxffkjY8kV64Uh03TOoZGxhKOBMszIkF/ybCs En6V2ZOQ4cs6B/lNdh9+32JGPrZgq6fccroAZigj+zi7H4lb1Ide/1U5NhKr2jCQpLBR W96LX5TRtpCSqnY2YfCswpls9WjJyBJndYKZ81GywMdsaAbuYWw/8FWZBh4eA56qO3vO rZmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pDg7lq2x44X37ra1GNdaDrKzjiETRuIzGhmCMqpU5cE=; b=aryHM1W2WjqcEoFWmjxNOL3hrsz8fptclJyPKFRSCOC9NM+xn/vgE+dG/xLg1xSziA tQjz8AiFpjsaCE6/4bftxLbjc0AwqyfHX/vt4NPxy2FaxPzMHNK7HuO0WaSJuewYzawf qnRFjrCMsjaERPeGNelxhaMMWmZOhr3UkmSZdtXvmKJajpOuW/1rXYjHFyZZfK1wz71C v+O2fI/zE7rfZADDlLdOaGha6iBN8wSw1j5Iu1vjKbJxWe31M2aStReoUy0VLq5sr8uX RB2IuCdfNBnT74RX4Xmv8109b8pkWyLI3AZV5ySdJoTCELanw2hZTpu7ePw9dzRHolGw 6vEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1B1OjeR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020a63cc0d000000b005023dfa3c69si14766479pgf.405.2023.02.22.03.12.46; Wed, 22 Feb 2023 03:12:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1B1OjeR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231512AbjBVLHS (ORCPT + 99 others); Wed, 22 Feb 2023 06:07:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231717AbjBVLHL (ORCPT ); Wed, 22 Feb 2023 06:07:11 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93A6392B9 for ; Wed, 22 Feb 2023 03:07:03 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id q189so3858307pga.9 for ; Wed, 22 Feb 2023 03:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pDg7lq2x44X37ra1GNdaDrKzjiETRuIzGhmCMqpU5cE=; b=r1B1OjeRgYE2hqrawLKj4xpLJVqD/NOJn2YO5tpvGrJoVa63RKypdjpj7HIRczRaRq 4EJSObe8KfRHFxJGyQ/5jOv5SajH0HE7OCEeJuBmMwMUwQjgw96J13XWoBgSvhs68U4u oMFV2k0JCMxS0aFax7sI1VqIq1Blgx2Z9M9xJAR3b5/N1z699TcZHAcRIYFDq5vzfm4E oMRdVlhqbsVRnpS7qVtEJuDP0ffT/nlbbiryV/2HEPVWlknxa0uNTpfuQ2rDBjfyUdt3 wEgbEl7QURSywxkwf3cxQGTzx1qsPwfjyqxd5P+yeUUHcI1fZJ6eyAiJhDxzat3cRYM6 yz7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pDg7lq2x44X37ra1GNdaDrKzjiETRuIzGhmCMqpU5cE=; b=pRA51AyvKzlyNXXXg4dyH7k9Fpwt2j9wHnFXyv4PciIOYWZZ/1s5auRcp6m7DyUmbv YwC4+yzRbrHlmy4d5E7xdtx3i+6EmRVWrhi644sdryEISL4QBnhzftdJcq2mVN+MLZXX vMfCJQOAtz7YN4ycYDrxL8OpfFExuYDnynmP08kX55VlZ38vm6KMeX/2+NhL+MkzgJ5l xg/DQei+jpN0pr9PNk0nB/Pw/l0KyISefK2p47pdKToVGLjqGIkp72rk6DkMDs1ZIGdp 4eQJkqZ2IXCLV2QvkYgw82SJXOPZrZAM7itijtK1O6QBsrHCk3q1R0VNzofFaKpk+Lqh ozfQ== X-Gm-Message-State: AO0yUKUiyQ6jXxUpP2UPgFoq7hqob4gsqwDjHCNVn+/NqAa6PxgwvjdT XJXggLQMOHa4USVaP0DY+HUmZw== X-Received: by 2002:a62:52d5:0:b0:5a8:ad9d:83f with SMTP id g204-20020a6252d5000000b005a8ad9d083fmr6289573pfb.24.1677064023416; Wed, 22 Feb 2023 03:07:03 -0800 (PST) Received: from localhost ([122.172.83.155]) by smtp.gmail.com with ESMTPSA id f15-20020aa78b0f000000b005ac419804d3sm4822377pfd.186.2023.02.22.03.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 03:07:02 -0800 (PST) From: Viresh Kumar To: Jun Nie , Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Manivannan Sadhasivam , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] OPP: Allow platforms to add a set_required_opps() callback Date: Wed, 22 Feb 2023 16:36:39 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758529458211705461?= X-GMAIL-MSGID: =?utf-8?q?1758529458211705461?= We currently configure required-opps only for genpds, as we aren't really sure what's required of the other use cases. This patch allows platforms to add their own set_required_opps() helper. Signed-off-by: Viresh Kumar --- Jun, I think this can replace the cpufreq notification from the devfreq driver (get_target_freq_with_cpufreq()), which is used currently only by mtk-cci-devfreq.c. Instead of the notification, the aggregation of the requests for the devfreq device can be done within this callback. What do you say ? --- drivers/opp/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 4 ++-- include/linux/pm_opp.h | 5 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 954c94865cf5..22985ad7af79 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2421,8 +2421,35 @@ static void _opp_detach_genpd(struct opp_table *opp_table) mutex_unlock(&opp_table->genpd_virt_dev_lock); } +/** + * _opp_set_required_opps_helper() - Register custom set required opps helper. + * @dev: Device for which the helper is getting registered. + * @set_required_opps: Custom set required opps helper. + * + * This must be called before any OPPs are initialized for the device. + */ +static void _opp_set_required_opps_helper(struct opp_table *opp_table, + set_required_opps_t set_required_opps) +{ + opp_table->set_required_opps = set_required_opps; +} + +/** + * _opp_put_required_opps_helper() - Releases resources blocked for + * required opps helper. + * @opp_table: OPP table returned from _opp_set_required_opps_helper(). + * + * Release resources blocked for platform specific required opps helper. + */ +static void _opp_put_required_opps_helper(struct opp_table *opp_table) +{ + opp_table->set_required_opps = NULL; +} + static void _opp_clear_config(struct opp_config_data *data) { + if (data->flags & OPP_CONFIG_REQUIRED_OPPS) + _opp_put_required_opps_helper(data->opp_table); if (data->flags & OPP_CONFIG_GENPD) _opp_detach_genpd(data->opp_table); if (data->flags & OPP_CONFIG_REGULATOR) @@ -2546,6 +2573,14 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) data->flags |= OPP_CONFIG_GENPD; } + /* Required opps helper */ + if (config->set_required_opps) { + _opp_set_required_opps_helper(opp_table, + config->set_required_opps); + + data->flags |= OPP_CONFIG_REQUIRED_OPPS; + } + ret = xa_alloc(&opp_configs, &id, data, XA_LIMIT(1, INT_MAX), GFP_KERNEL); if (ret) diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 2a057c42ddf4..54cfeb894f5d 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -35,6 +35,7 @@ extern struct list_head opp_tables, lazy_opp_tables; #define OPP_CONFIG_PROP_NAME BIT(3) #define OPP_CONFIG_SUPPORTED_HW BIT(4) #define OPP_CONFIG_GENPD BIT(5) +#define OPP_CONFIG_REQUIRED_OPPS BIT(6) /** * struct opp_config_data - data for set config operations @@ -235,8 +236,7 @@ struct opp_table { bool enabled; bool genpd_performance_state; bool is_genpd; - int (*set_required_opps)(struct device *dev, - struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down); + set_required_opps_t set_required_opps; #ifdef CONFIG_DEBUG_FS struct dentry *dentry; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index dc1fb5890792..5a8c0cc50c96 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -64,6 +64,9 @@ typedef int (*config_regulators_t)(struct device *dev, typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, bool scaling_down); +typedef int (*set_required_opps_t)(struct device *dev, struct opp_table *opp_table, + struct dev_pm_opp *opp, bool scaling_down); + /** * struct dev_pm_opp_config - Device OPP configuration values * @clk_names: Clk names, NULL terminated array. @@ -76,6 +79,7 @@ typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table, * @genpd_names: Null terminated array of pointers containing names of genpd to * attach. * @virt_devs: Pointer to return the array of virtual devices. + * @set_required_opps: Custom set required opps helper. * * This structure contains platform specific OPP configurations for the device. */ @@ -90,6 +94,7 @@ struct dev_pm_opp_config { const char * const *regulator_names; const char * const *genpd_names; struct device ***virt_devs; + set_required_opps_t set_required_opps; }; #if defined(CONFIG_PM_OPP)