From patchwork Fri Jul 28 00:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 707547 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp648295wru; Thu, 27 Jul 2023 17:34:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlGTdUxg7LrkpVNDbTztl3usg0qJWweSG+75kfwArvPIGzkKBTaKb8f7B2tIhj3L5HLICFA6 X-Received: by 2002:a7b:c5d6:0:b0:3f9:c82e:9d87 with SMTP id n22-20020a7bc5d6000000b003f9c82e9d87mr464022wmk.13.1690504492883; Thu, 27 Jul 2023 17:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690504492; cv=none; d=google.com; s=arc-20160816; b=cvyLi3ijlONY5hOW6MKHTup0zfvokZr0lrJKAz/Xo+j4iB5938JxrkMaOByMYn1FsT f9DxnSdYQZCmVfP+AePfZ3QtU9QcCUFI8V5dd29qjWENkWuBhi/PyA5llVxClnYoD4/D FlTFo/7G2HtUxo467384+2Tbnp8zG0djcMeIyjmRfzHxn+PYO2JOU62ta5CXm8P/zjTs KLJRcck3smfLhQidHDrvEVaKSKIPLg1/lz2zQfQMcfod3QwxYQb0ov/KKxjYNuQB04A8 PXrAcIzWgpsrYzRjoecCfjJM4BOC8WaXL6/g7u2E+qjt7F2xp6T6KsSz8iITbc4KADQ5 L3Sg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PzljctpNwsDwSDgwuLTnMzG71tkZzYH1C+lnk8CEWXg=; fh=RunEgwhbs7jBY7OMfHDvGK9UJp7q8al8FICtW1ZVXno=; b=R/e277gzi7w9P5ffCjKdTDTH6ifnsW1YShob7o/vrqcJ+Xr5s0uZ7NuBmQmRKIlEod /2Gb7YuZMh4bEExeazq+FWii8UTPd/lRxdx2th9zsB7IT8aK7UBGU79fbjmyPLGPsvuJ ZF6akKDUd5gAxBKQ09RAQCd7Kxyo8+FvKT77vOpMzIu7gE7cPP6GPVIPon7P6tKevHiw IcgxsHxGnWrEoPSH4MI+crR113/2oCplrCV+cfSf0nhl7RQNGwO6SG3hGsA+CLjfH4eu qe28lu+X0YAIgmKmRtRe3qFZu6JWUxtlzbnMBYh9HZ8FmWfYJre6u11LMWpp4yIX9EPR MBeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="mII/Fbyb"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id d16-20020adfe890000000b0031412be0110si1299470wrm.225.2023.07.27.17.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 17:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="mII/Fbyb"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 5BEBD86887; Fri, 28 Jul 2023 02:34:46 +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="mII/Fbyb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6EEA086885; Fri, 28 Jul 2023 02:34:12 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 87662863EE for ; Fri, 28 Jul 2023 02:33:59 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-55badd6d6feso258144a12.1 for ; Thu, 27 Jul 2023 17:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690504438; x=1691109238; 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=PzljctpNwsDwSDgwuLTnMzG71tkZzYH1C+lnk8CEWXg=; b=mII/Fbyb1Kl0AnZCw/MTSRtTATWOqpZ0Lvw/jsVQeTXTt43P6h+Ls4AmEZkW3aKJJR iHBinr/srdrQ4Zc7g2yDg47WNqfyGolbMeCzQJzaY/Pl2H/oAx3qIEpQ9o7btDG1a/I1 zMmTiJVP5/WxSn6wzUmlkCLf4NSVbqksZGbKdDWZbsWcBE7xIiO9M5RvK8TQJwNp2oUW pL+6mPnxSFhgMSqwCm+z0h9I3207atOu3mAY1Hqb+JQEW2Pw1czZSrDV3IshUFi9AOeP 2SBmHrSSDM4+Vu26gYEkBN5rL/G4ecO5KMA35IWKPRV+uy5ou1ZGqM4LkT7vcaLTaCsC YsRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690504438; x=1691109238; 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=PzljctpNwsDwSDgwuLTnMzG71tkZzYH1C+lnk8CEWXg=; b=H47d5ovOneQenTwV5NjODTIsCZfd4R2dOCdCji39/TZ2p1U2XmycLrkLXiZBCdykdv KQpsVUcPDSxpj/a/mHp3Ao//uWfeVU0qWdGWfyEh5wYQg94pxp3OmJcs7IadF1j/xvQO yOnFAWCO0KQzMzFmp7tVq9bifalrDfKLtdfQBCqc29uIp67Qfdc0PDDSlFsUG87MPykC zgrdMOGiQ5xWJJy6aSaO2WvRLTfQvBr34shtXRGZLWADxbGt0mH8fLbrKmuyAX/hOBYi SHhlEKlcPogtje7MDxohdbdVrawin2uq6FWd0i+7MK/dBKWDWj4WpJEIGSf+jCz3t+4r n/lw== X-Gm-Message-State: ABy/qLbqbhHjavMgBnprvl33TJQFbI9K4JbcoyeADmJnCnWquKa4LOK7 mYggCIfw1IoLfzd/WsqfQJ/hyQ== X-Received: by 2002:a17:902:eccc:b0:1b3:d8ac:8db3 with SMTP id a12-20020a170902eccc00b001b3d8ac8db3mr981853plh.6.1690504437593; Thu, 27 Jul 2023 17:33:57 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:25dd:d673:efea:dbcc]) by smtp.gmail.com with ESMTPSA id g14-20020a1709029f8e00b001b9dab0397bsm2228540plq.29.2023.07.27.17.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 17:33:57 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, lukma@denx.de, seanga2@gmail.com, jh80.chung@samsung.com Cc: sjg@chromium.org, etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 3/3] firmware: scmi: add a sanity check against protocol version Date: Fri, 28 Jul 2023 09:33:13 +0900 Message-ID: <20230728003313.10439-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728003313.10439-1-takahiro.akashi@linaro.org> References: <20230728003313.10439-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean SCMI_PROTOCOL_VERSION is a mandatory command for all the SCMI protocols. With this patch, this command is implemented on each protocol. Then, we can assure that the feature set implemented by SCMI Server (firmware) is compatible with U-Boot, that is, each protocol's version must be equal to or higher than the one that U-Boot's corresponding driver expects. Signed-off-by: AKASHI Takahiro --- drivers/clk/clk_scmi.c | 6 ++++++ drivers/power/regulator/scmi_regulator.c | 6 ++++++ drivers/reset/reset-scmi.c | 14 +++++++++++++- include/scmi_protocols.h | 6 ++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 34a49363a51a..3591acb6d3a9 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -138,12 +138,18 @@ static int scmi_clk_probe(struct udevice *dev) { struct clk *clk; size_t num_clocks, i; + u32 version; int ret; ret = devm_scmi_of_get_channel(dev); if (ret) return ret; + ret = scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_CLOCK, + &version); + if (ret || version < SCMI_CLOCK_PROTOCOL_VERSION) + return -EINVAL; + if (!CONFIG_IS_ENABLED(CLK_CCF)) return 0; diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c index 08918b20872c..936768d0eeeb 100644 --- a/drivers/power/regulator/scmi_regulator.c +++ b/drivers/power/regulator/scmi_regulator.c @@ -138,12 +138,18 @@ static int scmi_regulator_probe(struct udevice *dev) .out_msg = (u8 *)&out, .out_msg_sz = sizeof(out), }; + u32 version; int ret; ret = devm_scmi_of_get_channel(dev); if (ret) return ret; + ret = scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, + &version); + if (ret || version < SCMI_VOLTDOM_PROTOCOL_VERSION) + return -EINVAL; + /* Check voltage domain is known from SCMI server */ in.domain_id = pdata->domain_id; diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c index b76711f0a8fb..dbd98dbdbc4f 100644 --- a/drivers/reset/reset-scmi.c +++ b/drivers/reset/reset-scmi.c @@ -73,7 +73,19 @@ static const struct reset_ops scmi_reset_domain_ops = { static int scmi_reset_probe(struct udevice *dev) { - return devm_scmi_of_get_channel(dev); + u32 version; + int ret; + + ret = devm_scmi_of_get_channel(dev); + if (ret) + return ret; + + ret = scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_RESET_DOMAIN, + &version); + if (ret || version < SCMI_RESETDOM_PROTOCOL_VERSION) + return -EINVAL; + + return 0; } U_BOOT_DRIVER(scmi_reset_domain) = { diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index 64fd740472b5..6ab16efd49cc 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -398,6 +398,8 @@ int scmi_generic_protocol_version(struct udevice *dev, * SCMI Clock Protocol */ +#define SCMI_CLOCK_PROTOCOL_VERSION 0x20000 + enum scmi_clock_message_id { SCMI_CLOCK_ATTRIBUTES = 0x3, SCMI_CLOCK_RATE_SET = 0x5, @@ -509,6 +511,8 @@ struct scmi_clk_rate_set_out { * SCMI Reset Domain Protocol */ +#define SCMI_RESETDOM_PROTOCOL_VERSION 0x30000 + enum scmi_reset_domain_message_id { SCMI_RESET_DOMAIN_ATTRIBUTES = 0x3, SCMI_RESET_DOMAIN_RESET = 0x4, @@ -569,6 +573,8 @@ struct scmi_rd_reset_out { * SCMI Voltage Domain Protocol */ +#define SCMI_VOLTDOM_PROTOCOL_VERSION 0x20000 + enum scmi_voltage_domain_message_id { SCMI_VOLTAGE_DOMAIN_ATTRIBUTES = 0x3, SCMI_VOLTAGE_DOMAIN_CONFIG_SET = 0x5,