From patchwork Wed Jun 2 09:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 452485 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp417580jao; Wed, 2 Jun 2021 02:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBJEvr8bZkBDl3vMuYKNCK/4l31heCRvS1qMJu4TxH406TYLAEy2GKsPnZtEFGi1o1gsIr X-Received: by 2002:a05:6402:2789:: with SMTP id b9mr37735144ede.122.1622627777157; Wed, 02 Jun 2021 02:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622627777; cv=none; d=google.com; s=arc-20160816; b=bHL5SGzBGshUbcN1GRgUEqeyxh1KpLb2VzGOL+JErJrCCW3RvFEX5RDDvmeMDDDhy3 X1cX1OHmkIQwJ5NbQq7nuQDrLbK9qXrA3NjzXxgAIxj/JcspKgj2DZzQbarcv9limxPy mSvbSgWzafAhbcfDjGazLZUTpk+JZAu+IaW/ygGbA4WX78j4XgTutn9Y9Bw4B2vZ5cPl W8lOo3CikcAXcxXL+zHxcBLQDuYVCzh7l8GUN8ybYbuBsohPCD4dheYXk21PMjUDsbUe R9ihNKaE7zNyGSAAYrxbhtv7L6BoJBOc8JGJd7rOqOLXAkcsVbkD00dY+aUpIaXvF8Ld mfeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=jCpsWVaYz3wFBwyPazDwLv27RWORYE/qTqg3ZNFICRTVHUL3oAHwYirTcAsmRrUj2l 4mlr4opPaKOc4jVtOWyIqeIiKfnGGCle75LtZL9LNnKUfFtjeWSTdUHOyfoJ1vYcoicv RXE1NkuA4EaOrR+g8vuAF7BCVIbZvqHNrI81w4J1ss5ctgj/bvEa7yfO/lvOAJq2pDb/ XJSn7eWEXpuH2BTooeeTuA5s1NvvLb7FzUfO80EP5qTkxaKmdpF8eoDEyz8peLIxkxmZ qCRqhOQV3oniHCintphv2Sj9oRpQ/0rdGxHBp9T4SOdBpbOybdYPxkvJaR9Iuz0mHhVs EmFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9yqjdG+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a27si1920204edm.396.2021.06.02.02.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9yqjdG+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C18282F15; Wed, 2 Jun 2021 11:56:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="C9yqjdG+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 335C982ED6; Wed, 2 Jun 2021 11:56:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BB2F282F0C for ; Wed, 2 Jun 2021 11:56:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=etienne.carriere@linaro.org Received: by mail-wm1-x332.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso3374930wmh.4 for ; Wed, 02 Jun 2021 02:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=C9yqjdG++Y5R1+TcGcgVn2o293qcyjDS9w5b6KCSHT7tDXha1gsBTnq1/H03Pm8VtC tr2X+GjkZ6vICycDwELX2jOGmETpEwDpSf8rbBY1iAJPRmh91GL2++Sz04sR4IAwOmpl bO+Ylsn1If+5d36P0VVg8+vSjC1YyyGk6TjHs97gj0mKqlxxBJ9lkAziv+gtDVzj7X2I CQcSHM+HrXNMgugT6tpEyITjD5A3d1TR4QE3BChY2pZycDRAQK8YvcjhdrBP4s3fY3Nt LS4ceCWJpjyurHUgcJ1/YZ3ahaSQAebwhDizR7GN9dccrmY26oEyVzEkwt3dtSeY8lCZ bYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hQLoTKgQgXoe9tFAzqAnxCLmIqKBYdnQ6chjks0oxQI=; b=TyGmM078xrcCN+L+J9OPqHXG5kv2FOmwxWeXa6w2qltPFvt8/Ri36TA1SLZgjCZfYP /uAFDhVosADtnUEC/g3mWU9qtS+uYneWbWImzq00YL/+szOM1vxteSuuFZKHjvvZXY7N aIWQQYhfZUDFte5qtAVXHOLCKVkfT2XfS2d1tBJ+GIlk+rwe4WT0FWWlRR0t66CP/cCe rUEjhgowyeXSbirUUSeACBLf7vbifLQ7kFBcyzKZygQe1R72yHdsD0vL1WygpqYl8MJY c9OJ3XvRgroVJRFKhcE6Ipb7m7U+mjMOUAO4xAHAxySg3IKSPESFlrgnH0Ax7My6jO8y 3WIg== X-Gm-Message-State: AOAM533citgmZS3e5lpTNI/A2qSdOUYpOSP970xr258K/tZIrLp0N1eH ntghmITrLBGh2cdsvbZHXjS1fovgWtfphD2R X-Received: by 2002:a05:600c:2948:: with SMTP id n8mr4277251wmd.95.1622627761174; Wed, 02 Jun 2021 02:56:01 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:119f:e0e8:4829:7bc2:a82a:1daf]) by smtp.gmail.com with ESMTPSA id m23sm2581549wml.27.2021.06.02.02.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:56:00 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Simon Glass , Etienne Carriere Subject: [PATCH v2 2/2] firmware: scmi: fix sandbox and related test since clock discovery Date: Wed, 2 Jun 2021 11:54:46 +0200 Message-Id: <20210602095446.21947-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602095446.21947-1-etienne.carriere@linaro.org> References: <20210602095446.21947-1-etienne.carriere@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean Since SCMI clock are discovered because of integration in the CCF, update SCMI emulation in sandbox accordingly. Sandbox must emulate all clocks exposed by SCMI server since CCF clock discovery will query all of them even if some clocks have no consumer. This change adds clock discovery support in the sandbox and changes clock IDs so that less clock shall be managed as each SCMI clock ID is actually an index identifier. For consistency, update also sandbox SCMI reset controller test to conform with the IDs being also indices of exposed resources as per SCMI specification. Signed-off-by: Etienne Carriere Reviewed-by: Simon Glass --- Changes since v1: - Review tag applied --- arch/sandbox/dts/test.dts | 4 +- arch/sandbox/include/asm/scmi_test.h | 2 - drivers/firmware/scmi/sandbox-scmi_agent.c | 102 ++++++++++++++++++--- test/dm/scmi.c | 29 ++++-- 4 files changed, 113 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index fe26ced31d..91e488239b 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1346,8 +1346,8 @@ sandbox_scmi { compatible = "sandbox,scmi-devices"; - clocks = <&clk_scmi0 7>, <&clk_scmi0 3>, <&clk_scmi1 1>; - resets = <&reset_scmi0 3>; + clocks = <&clk_scmi0 2>, <&clk_scmi0 0>, <&clk_scmi1 0>; + resets = <&reset_scmi0 0>; regul0-supply = <®ul0_scmi0>; regul1-supply = <®ul1_scmi0>; }; diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index 2930e686d7..bce18deeea 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -17,7 +17,6 @@ struct sandbox_scmi_service; * @rate: Clock rate in Hertz */ struct sandbox_scmi_clk { - uint id; bool enabled; ulong rate; }; @@ -28,7 +27,6 @@ struct sandbox_scmi_clk { * @asserted: Reset control state: true if asserted, false if desasserted */ struct sandbox_scmi_reset { - uint id; bool asserted; }; diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index 4b968205c2..dee9e8fb58 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -27,7 +27,7 @@ * See IDs in scmi0_clk[]/scmi0_reset[] and "sandbox-scmi-agent@0" in test.dts. * * Agent #1 simulates 1 clock. - * See IDs in scmi1_clk[] and "sandbox-scmi-agent@1" in test.dts. + * See scmi1_clk[] and "sandbox-scmi-agent@1" in test.dts. * * All clocks and regulators are default disabled and reset controller down. * @@ -40,12 +40,13 @@ #define SANDBOX_SCMI_AGENT_COUNT 2 static struct sandbox_scmi_clk scmi0_clk[] = { - { .id = 7, .rate = 1000 }, - { .id = 3, .rate = 333 }, + { .rate = 333 }, + { .rate = 200 }, + { .rate = 1000 }, }; static struct sandbox_scmi_reset scmi0_reset[] = { - { .id = 3 }, + { .asserted = false }, }; static struct sandbox_scmi_voltd scmi0_voltd[] = { @@ -54,7 +55,7 @@ static struct sandbox_scmi_voltd scmi0_voltd[] = { }; static struct sandbox_scmi_clk scmi1_clk[] = { - { .id = 1, .rate = 44 }, + { .rate = 44 }, }; /* The list saves to simulted end devices references for test purpose */ @@ -102,7 +103,6 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) { struct sandbox_scmi_clk *target = NULL; size_t target_count = 0; - size_t n; switch (agent_id) { case 0: @@ -117,9 +117,8 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) return NULL; } - for (n = 0; n < target_count; n++) - if (target[n].id == clock_id) - return target + n; + if (clock_id < target_count) + return target + clock_id; return NULL; } @@ -127,14 +126,21 @@ static struct sandbox_scmi_clk *get_scmi_clk_state(uint agent_id, uint clock_id) static struct sandbox_scmi_reset *get_scmi_reset_state(uint agent_id, uint reset_id) { - size_t n; + struct sandbox_scmi_reset *target = NULL; + size_t target_count = 0; - if (agent_id == 0) { - for (n = 0; n < ARRAY_SIZE(scmi0_reset); n++) - if (scmi0_reset[n].id == reset_id) - return scmi0_reset + n; + switch (agent_id) { + case 0: + target = scmi0_reset; + target_count = ARRAY_SIZE(scmi0_reset); + break; + default: + return NULL; } + if (reset_id < target_count) + return target + reset_id; + return NULL; } @@ -156,6 +162,70 @@ static struct sandbox_scmi_voltd *get_scmi_voltd_state(uint agent_id, * Sandbox SCMI agent ops */ +static int sandbox_scmi_clock_protocol_attribs(struct udevice *dev, + struct scmi_msg *msg) +{ + struct sandbox_scmi_agent *agent = dev_get_priv(dev); + struct scmi_clk_protocol_attr_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_clk_protocol_attr_out *)msg->out_msg; + + switch (agent->idx) { + case 0: + out->attributes = ARRAY_SIZE(scmi0_clk); + out->status = SCMI_SUCCESS; + break; + case 1: + out->attributes = ARRAY_SIZE(scmi1_clk); + out->status = SCMI_SUCCESS; + break; + default: + out->status = SCMI_INVALID_PARAMETERS; + break; + } + + return 0; +} + +static int sandbox_scmi_clock_attribs(struct udevice *dev, struct scmi_msg *msg) +{ + struct sandbox_scmi_agent *agent = dev_get_priv(dev); + struct scmi_clk_attribute_in *in = NULL; + struct scmi_clk_attribute_out *out = NULL; + struct sandbox_scmi_clk *clk_state = NULL; + int ret; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(*in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + in = (struct scmi_clk_attribute_in *)msg->in_msg; + out = (struct scmi_clk_attribute_out *)msg->out_msg; + + clk_state = get_scmi_clk_state(agent->idx, in->clock_id); + if (!clk_state) { + dev_err(dev, "Unexpected clock ID %u\n", in->clock_id); + + out->status = SCMI_NOT_FOUND; + } else { + memset(out, 0, sizeof(*out)); + + if (clk_state->enabled) + out->attributes = 1; + + ret = snprintf(out->clock_name, sizeof(out->clock_name), + "clk%u", in->clock_id); + assert(ret > 0 && ret < sizeof(out->clock_name)); + + out->status = SCMI_SUCCESS; + } + + return 0; +} + static int sandbox_scmi_clock_rate_set(struct udevice *dev, struct scmi_msg *msg) { @@ -479,6 +549,10 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, switch (msg->protocol_id) { case SCMI_PROTOCOL_ID_CLOCK: switch (msg->message_id) { + case SCMI_PROTOCOL_ATTRIBUTES: + return sandbox_scmi_clock_protocol_attribs(dev, msg); + case SCMI_CLOCK_ATTRIBUTES: + return sandbox_scmi_clock_attribs(dev, msg); case SCMI_CLOCK_RATE_SET: return sandbox_scmi_clock_rate_set(dev, msg); case SCMI_CLOCK_RATE_GET: diff --git a/test/dm/scmi.c b/test/dm/scmi.c index c938e6d4fc..7d0a6799b7 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -58,7 +58,7 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, ut_asserteq(2, scmi_ctx->agent_count); ut_assertnonnull(agent0); - ut_asserteq(2, agent0->clk_count); + ut_asserteq(3, agent0->clk_count); ut_assertnonnull(agent0->clk); ut_asserteq(1, agent0->reset_count); ut_assertnonnull(agent0->reset); @@ -128,6 +128,15 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) if (ret) return ret; + /* + * As stated in sandbox test.dts: + * - Sandbox device clock #0 relates to SCMI server #0 clock #2 + * - Sandbox device clock #1 relates to SCMI server #0 clock #0 + * - Sandbox device clock #2 relates to SCMI server #1 clock #0 + * + * Note there exists a SCMI server #0 clock #1 but is it not + * used but the sandbox test device. + */ scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); agent0 = scmi_ctx->agent[0]; @@ -141,8 +150,9 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); ut_assert(!ret_dev || ret_dev == 1088); - ut_asserteq(1000, agent0->clk[0].rate); - ut_asserteq(1088, agent0->clk[1].rate); + ut_asserteq(1088, agent0->clk[0].rate); + ut_asserteq(200, agent0->clk[1].rate); + ut_asserteq(1000, agent0->clk[2 ].rate); ut_asserteq(44, agent1->clk[0].rate); ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); @@ -156,20 +166,23 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts) /* Test SCMI clocks gating manipulation */ ut_assert(!agent0->clk[0].enabled); ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent0->clk[2].enabled); ut_assert(!agent1->clk[0].enabled); - ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); + ut_asserteq(0, clk_enable(&scmi_devices->clk[0])); ut_asserteq(0, clk_enable(&scmi_devices->clk[2])); ut_assert(!agent0->clk[0].enabled); - ut_assert(agent0->clk[1].enabled); + ut_assert(!agent0->clk[1].enabled); + ut_assert(agent0->clk[2].enabled); ut_assert(agent1->clk[0].enabled); - ut_assertok(clk_disable(&scmi_devices->clk[1])); + ut_assertok(clk_disable(&scmi_devices->clk[0])); ut_assertok(clk_disable(&scmi_devices->clk[2])); ut_assert(!agent0->clk[0].enabled); ut_assert(!agent0->clk[1].enabled); + ut_assert(!agent0->clk[2].enabled); ut_assert(!agent1->clk[0].enabled); return release_sandbox_scmi_test_devices(uts, dev); @@ -188,6 +201,10 @@ static int dm_test_scmi_resets(struct unit_test_state *uts) if (ret) return ret; + /* + * As stated in sandbox test.dts: + * - Sandbox device reset ctrl #0 relates to SCMI #0 reset domain #0 + */ scmi_devices = sandbox_scmi_devices_ctx(dev); scmi_ctx = sandbox_scmi_service_ctx(); agent0 = scmi_ctx->agent[0];