From patchwork Tue Sep 12 17:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 138344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp582896vqx; Tue, 12 Sep 2023 10:59:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHC3AJLpfIHqEsDCXMOAXDFRF9ApR959Q1DKju6ULlrIJVc6RbsGnU0CdY5+XX+JkS6XW/e X-Received: by 2002:a17:903:188:b0:1c3:21ae:7a4a with SMTP id z8-20020a170903018800b001c321ae7a4amr599816plg.38.1694541582981; Tue, 12 Sep 2023 10:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694541582; cv=none; d=google.com; s=arc-20160816; b=HqiAmkh+DRo+g9pWeRFUcc8wPstLTSbtuo3lCIJjylY+0drAESqaqpeONLPQtpVqGu sXfevdNG0gokavnxdDMmANxac7fFXKwimws4l3Hgww1hS0o4XLDFO4uS2nmh3Y1sYEzC bybu8rM+YhoftkhoUFoeS9W4JpGReBJTZ24wRPHCP6E3n7NrTiKCQDjrr7Ic1Klj0iPW 7ue/UZg+Zf8ZiinO+HJxAeS4T0xoTQu5rVNukWXDNLU5FAo/meD8YXT1DrW3A/48jr5S Hu3gm/DRDpJBgS6NUnWI7b8O3tN20J5Tmk1o3GTVcuAMGWBXE4e4Qvd0yI4nfYgUPbzZ eEnQ== 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=wICgjCnrV6U4LumHZx8L8HTrMNcCINMp6EY9quaNYZM=; fh=ncZ9FZxYDSVz/grCh/WR+Eul+N2DK5wZHP60jyIas4A=; b=jEiPD/i5wxizoxNECP+0wcc0mq004Y8bW4EkmOTVmhZ3oDnoUy7NQ9jtuZbhiGmjmu H5SeVEC0qRQ057cMX/hgeN0hAxeUllG4vPhNh0SB7pMTppRAjXND88zFmmtfg3TjzFAT 7chcYJ8gEk5Hb3MlscePB4ZqiRtyn6lYxMqDXWlmf/enknUl5hdx7nPpvhP/WBIIyKyF ZC2AqqEQXPlZrWUfTsn5i52LR2XZTsM085tpBgY3aDypFSuG8OeoImbYPJZJwAi4Ghf+ I69zJgNYyTGod4jrVKhrmKum4PeBMXhqeY21WoXpJirjmskRJA2v224bjYgilenYpbI1 BqPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Er1pbDCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u8-20020a17090341c800b001bbfbe6bf3esi8450664ple.504.2023.09.12.10.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 10:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Er1pbDCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D084B801B8B9; Tue, 12 Sep 2023 10:55:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237050AbjILRzm (ORCPT + 36 others); Tue, 12 Sep 2023 13:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236893AbjILRzk (ORCPT ); Tue, 12 Sep 2023 13:55:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85EEFC1; Tue, 12 Sep 2023 10:55:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC82FC433C9; Tue, 12 Sep 2023 17:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694541336; bh=Ko4/UwcgT3eF+DcCLkqCyN0KFTjfLGv5nyGKHZQ9hcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Er1pbDCrPsgoljrMA7EZu4PaPiK4QM/q0W5JqbtXFV8FolVzjwN/rrjYK+mg/2dnZ LIo+HwBY3cQ8yBBeBDM57UPLKJ+nZBzmWGz1+NFeojsx9LKFJfxjoubXUPwHGG7jDs O0IAOqRu6N12saJD9lDjBrgUDFulU69nztdX2n2yr+dej312vxW9Dfe3GfcLlxgaz1 2MCg6w7STeRELdeErgKDnrD2bb7y32OHCi6EgAM1uc2YbOl4Qc9ZZCgT4nbnLB5WSa 6W7hnodZ3RrtE+GWm8+nLjFfmfmMVe4f4j/jc1idaoaI7WWqPj/dIPyIC2UM8YqsBo gQYDj7fPGq53Q== From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, Guenter Roeck , Maxime Ripard Subject: [PATCH 2/2] clk: Parameterize clk_leaf_mux_set_rate_parent Date: Tue, 12 Sep 2023 10:55:31 -0700 Message-ID: <20230912175534.2427862-3-sboyd@kernel.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230912175534.2427862-1-sboyd@kernel.org> References: <20230912175534.2427862-1-sboyd@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 10:55:56 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776855635135632288 X-GMAIL-MSGID: 1776855635135632288 Transform the existing clk_leaf_mux_set_rate_parent test into a parameterized test that calls the various determine rate APIs that exist for clk providers. This ensures that whatever determine rate API is used by a clk provider will return the correct parent in the best_parent_hw pointer of the clk_rate_request because clk_rate_requests are forwarded properly. Cc: Guenter Roeck Cc: Maxime Ripard Signed-off-by: Stephen Boyd --- drivers/clk/clk_test.c | 81 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index 43e85fc0b025..39e2b5ff4f51 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -2159,6 +2159,7 @@ struct clk_leaf_mux_ctx { struct clk_hw hw; struct clk_hw parent; struct clk_rate_request *req; + int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req); }; static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) @@ -2168,7 +2169,7 @@ static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_reques struct clk_rate_request *parent_req = ctx->req; clk_hw_forward_rate_request(hw, req, req->best_parent_hw, parent_req, req->rate); - ret = __clk_determine_rate(req->best_parent_hw, parent_req); + ret = ctx->determine_rate_func(req->best_parent_hw, parent_req); if (ret) return ret; @@ -2246,20 +2247,83 @@ static void clk_leaf_mux_set_rate_parent_test_exit(struct kunit *test) clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw); } +struct clk_leaf_mux_set_rate_parent_determine_rate_test_case { + const char *desc; + int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req); +}; + +static void +clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc( + const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *t, char *desc) +{ + strcpy(desc, t->desc); +} + +static const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case +clk_leaf_mux_set_rate_parent_determine_rate_test_cases[] = { + { + /* + * Test that __clk_determine_rate() on the parent that can't + * change rate doesn't return a clk_rate_request structure with + * the best_parent_hw pointer pointing to the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent", + .determine_rate_func = __clk_determine_rate, + }, + { + /* + * Test that __clk_mux_determine_rate() on the parent that + * can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_proper_parent", + .determine_rate_func = __clk_mux_determine_rate, + }, + { + /* + * Test that __clk_mux_determine_rate_closest() on the parent + * that can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_closest_proper_parent", + .determine_rate_func = __clk_mux_determine_rate_closest, + }, + { + /* + * Test that clk_hw_determine_rate_no_reparent() on the parent + * that can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent_clk_hw_determine_rate_no_reparent_proper_parent", + .determine_rate_func = clk_hw_determine_rate_no_reparent, + }, +}; + +KUNIT_ARRAY_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test, + clk_leaf_mux_set_rate_parent_determine_rate_test_cases, + clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc) + /* - * Test that, for a clock that will forward any rate request to its parent, the - * rate request structure returned by __clk_determine_rate() is sane and - * doesn't have the clk_rate_request's best_parent_hw pointer point to the - * clk_hw passed into __clk_determine_rate(). See commit 262ca38f4b6e ("clk: - * Stop forwarding clk_rate_requests to the parent") for more background. + * Test that when a clk that can't change rate itself calls a function like + * __clk_determine_rate() on its parent it doesn't get back a clk_rate_request + * structure that has the best_parent_hw pointer point to the clk_hw passed + * into the determine rate function. See commit 262ca38f4b6e ("clk: Stop + * forwarding clk_rate_requests to the parent") for more background. */ -static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struct kunit *test) +static void clk_leaf_mux_set_rate_parent_determine_rate_test(struct kunit *test) { struct clk_leaf_mux_ctx *ctx = test->priv; struct clk_hw *hw = &ctx->hw; struct clk *clk = clk_hw_get_clk(hw, NULL); struct clk_rate_request req; unsigned long rate; + const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *test_param; + + test_param = test->param_value; + ctx->determine_rate_func = test_param->determine_rate_func; ctx->req = &req; rate = clk_get_rate(clk); @@ -2274,7 +2338,8 @@ static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struc } static struct kunit_case clk_leaf_mux_set_rate_parent_test_cases[] = { - KUNIT_CASE(clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent), + KUNIT_CASE_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test, + clk_leaf_mux_set_rate_parent_determine_rate_test_gen_params), {} };