From patchwork Tue Sep 26 07:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726396 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2781128wrm; Tue, 26 Sep 2023 00:01:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFknHTgaNUS4jB+0nIUzys7crljHVXQ4UOvVINj9eKYPVd2VG3azUZi72yGC3nxQAHnWSq X-Received: by 2002:adf:ffc4:0:b0:321:71be:3484 with SMTP id x4-20020adfffc4000000b0032171be3484mr8154757wrs.21.1695711701273; Tue, 26 Sep 2023 00:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711701; cv=none; d=google.com; s=arc-20160816; b=Flq01FcTXSVxW0ctzO1Jyv5E9lrhEcIk34hZBJx6+xQNQRJxpX9m5oSjRKMhudQHZy +L0xVK/zIuxebnem9+k5DJulsCrdRTWaMKjCgeZ93/ehpZnu7aMqhTzp9VKQmJ26JhrE KopJBZKEBsk3HwOLeDBPjwhjJVk5/fA6BgS75+nKX5m3bKihBpnRkvxtsB6QDy6sIFt6 8QPJqOOCao8oQUbNa3VPVsh1OIp+iKFD0BRq2jyrZmz0VwhUSyzBtQEveKd6pW6nr376 8KxmvOIXwoBKfNTw0d8txyO0vDLdEJiLXxhhxaR/uEFPwVsw+SkbHYwokNSpvJN6GUPD FIqQ== 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=01wfWo6U8HLTHAg24OdY6ODw0XQDBEVowfapOuQgWQE=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=vhMkhLev4VsM6iHrX5say5fVB8/tG9uDxddpnTx95XjImHsEbT0UbufYyaIEhT7GnT W8go2SoggUKWr7YIWfqQAQNMIkyDI3l4R2/ciumzzC4Z9URbK2ksuKcOo4p2U2dNQ+Qc 1qkVWlvW1AN60bGrJNI6pXTg7TsnDho4NNWEd0+oN0tIohFAQX7d5aA2eCIHYSleWFGw 3Tq1LmatWzQMAeD2P7sf5YNbZk4DErRzP1C8Op8ltoIuLu2/81dwh4wTuQDKyya8Yw8n xQgGBHTpaJSOg3uwufCT+AImQbGXmeYvahmH+F3q02Noc8CZ94cgm5DVkBqmBdsrGArz KlHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i8MjxFnR; 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 y13-20020adff14d000000b00319771cee30si6006464wro.285.2023.09.26.00.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:41 -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=i8MjxFnR; 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 6D9C886D92; Tue, 26 Sep 2023 09:01:09 +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="i8MjxFnR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 82DF886D90; Tue, 26 Sep 2023 09:01:08 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 0258286D86 for ; Tue, 26 Sep 2023 09:01:06 +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-x52d.google.com with SMTP id 41be03b00d2f7-578e174660dso453901a12.1 for ; Tue, 26 Sep 2023 00:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711664; x=1696316464; darn=lists.denx.de; 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=01wfWo6U8HLTHAg24OdY6ODw0XQDBEVowfapOuQgWQE=; b=i8MjxFnRPzmMQc+nSK7JtX9i3poXjQbZPLD/odNrDNuYZfnbhxRaDPyPPseQ6NFBfC 4SlDvMAYxVrB+Ouvn3IcqvTEOpPb6JM2B70aX+Nodz47OibUJxo94DQeo6UzWuIVRBp6 kIMOUj3uMvrEW0O8MEYLSnJ3GAXflKgXQ8kmoHYEZxrrXZC5A2gbXSNP4cG36+Wx2ejK i3lzttCUSgeW5RzB+4bsKqflrzrmVis8ZM7Jhwrojy/1Ze/AU05Pgw7o7WAt0vfdJSTk DdJZGJDZCgcYy4NK97H33HqVll85lIhqb2rJvrhvFG0HGSUrhj7yGfUiaBBe8IjcturH OqBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711664; x=1696316464; 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=01wfWo6U8HLTHAg24OdY6ODw0XQDBEVowfapOuQgWQE=; b=kHnEIvcmhWxTdwE5qycRdaqeI0ZPE0dziRiwhMePzay4Q8O9CkBt5vJdaYW9+x8f4Q y8cT5EmMPHF8NhlFcyVIz+CGCEIMn7aiZ3bEx8Ipe8VDMrIMGhzuvKX8U4cJq8Ivtg4r clwvq/tt6N5YMzjNPKJzWOxx+dv2RxEMGzz0KnljwNd18jVI6pkdjcgi79CQEuFwXFbe EEyzTgP9lneMbApfY887rQp2qSjBFx6q54KqWCUCdTJejIpG9bF80T9zqIDog9SE+dRP 8HsGFiPtkT0ckGvvwKrGAM3Lf7fjc0ZLvX32YV3vCtxcR4/3COArREynKygR1bNyTOoj /Jvg== X-Gm-Message-State: AOJu0Yyi0VzkDOAhUhm5JYN34nYQWwrwpTQmHuGWDKI8VJ6HNZVHRhoH F0hxBTlowMYTUMqy/95BaFGzkQ== X-Received: by 2002:a17:90a:bc9:b0:268:38a7:842e with SMTP id x9-20020a17090a0bc900b0026838a7842emr7876157pjd.2.1695711664253; Tue, 26 Sep 2023 00:01:04 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id ge13-20020a17090b0e0d00b0027758c7f585sm3178480pjb.52.2023.09.26.00.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:03 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 1/4] firmware: scmi: add power domain protocol support Date: Tue, 26 Sep 2023 16:00:40 +0900 Message-Id: <20230926070043.738340-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926070043.738340-1-takahiro.akashi@linaro.org> References: <20230926070043.738340-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 In this patch, added are helper functions to directly manipulate SCMI power domain management protocol. DM compliant power domain driver will be implemented on top of those interfaces in a succeeding patch. Signed-off-by: AKASHI Takahiro --- drivers/firmware/scmi/Makefile | 1 + drivers/firmware/scmi/pwdom.c | 189 +++++++++++++++++++++++++++++++++ include/scmi_protocols.h | 178 +++++++++++++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 drivers/firmware/scmi/pwdom.c diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile index 1a23d4981709..dae42863589a 100644 --- a/drivers/firmware/scmi/Makefile +++ b/drivers/firmware/scmi/Makefile @@ -4,4 +4,5 @@ obj-y += smt.o obj-$(CONFIG_SCMI_AGENT_SMCCC) += smccc_agent.o obj-$(CONFIG_SCMI_AGENT_MAILBOX) += mailbox_agent.o obj-$(CONFIG_SCMI_AGENT_OPTEE) += optee_agent.o +obj-$(CONFIG_SCMI_POWER_DOMAIN) += pwdom.o obj-$(CONFIG_SANDBOX) += sandbox-scmi_agent.o sandbox-scmi_devices.o diff --git a/drivers/firmware/scmi/pwdom.c b/drivers/firmware/scmi/pwdom.c new file mode 100644 index 000000000000..61b4338663de --- /dev/null +++ b/drivers/firmware/scmi/pwdom.c @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SCMI Power domain management protocol + * + * Copyright (C) 2023 Linaro Limited + * author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include + +int scmi_pwd_protocol_attrs(struct udevice *dev, int *num_pwdoms, + u64 *stats_addr, size_t *stats_len) +{ + struct scmi_pwd_protocol_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PROTOCOL_ATTRIBUTES, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!dev || !num_pwdoms || !stats_addr || !stats_len) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *num_pwdoms = SCMI_PWD_PROTO_ATTRS_NUM_PWD(out.attributes); + *stats_addr = ((u64)out.stats_addr_high << 32) + out.stats_addr_low; + *stats_len = out.stats_len; + + return 0; +} + +int scmi_pwd_protocol_message_attrs(struct udevice *dev, s32 message_id, + u32 *attributes) +{ + struct scmi_pwd_protocol_msg_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PROTOCOL_MESSAGE_ATTRIBUTES, + .in_msg = (u8 *)&message_id, + .in_msg_sz = sizeof(message_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!dev || !attributes) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *attributes = out.attributes; + + return 0; +} + +int scmi_pwd_attrs(struct udevice *dev, u32 domain_id, u32 *attributes, + u8 **name) +{ + struct scmi_pwd_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PWD_ATTRIBUTES, + .in_msg = (u8 *)&domain_id, + .in_msg_sz = sizeof(domain_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!dev || !attributes || !name) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *name = strdup(out.name); + if (!*name) + return -ENOMEM; + + *attributes = out.attributes; + + return 0; +} + +int scmi_pwd_state_set(struct udevice *dev, u32 flags, u32 domain_id, + u32 pstate) +{ + struct scmi_pwd_state_set_in in; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PWD_STATE_SET, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + if (!dev) + return -EINVAL; + + in.flags = flags; + in.domain_id = domain_id; + in.pstate = pstate; + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +int scmi_pwd_state_get(struct udevice *dev, u32 domain_id, u32 *pstate) +{ + struct scmi_pwd_state_get_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PWD_STATE_GET, + .in_msg = (u8 *)&domain_id, + .in_msg_sz = sizeof(domain_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!dev || !pstate) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *pstate = out.pstate; + + return 0; +} + +int scmi_pwd_name_get(struct udevice *dev, u32 domain_id, u8 **name) +{ + struct scmi_pwd_name_get_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_POWER_DOMAIN, + .message_id = SCMI_PWD_NAME_GET, + .in_msg = (u8 *)&domain_id, + .in_msg_sz = sizeof(domain_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + if (!dev || !name) + return -EINVAL; + + ret = devm_scmi_process_msg(dev, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *name = strdup(out.extended_name); + if (!*name) + return -ENOMEM; + + return 0; +} diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index ee551b38deb4..9e0ba26f8632 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -400,6 +400,184 @@ int scmi_base_reset_agent_configuration(struct udevice *dev, u32 agent_id, int scmi_generic_protocol_version(struct udevice *dev, enum scmi_std_protocol id, u32 *version); +/* + * SCMI Power Domain Management Protocol + */ + +#define SCMI_PWD_PROTOCOL_VERSION 0x30000 +#define SCMI_PWD_PSTATE_TYPE_LOST BIT(30) +#define SCMI_PWD_PSTATE_ID GENMASK(27, 0) + +enum scmi_power_domain_message_id { + SCMI_PWD_ATTRIBUTES = 0x3, + SCMI_PWD_STATE_SET = 0x4, + SCMI_PWD_STATE_GET = 0x5, + SCMI_PWD_STATE_NOTIFY = 0x6, + SCMI_PWD_STATE_CHANGE_REQUESTED_NOTIFY = 0x7, + SCMI_PWD_NAME_GET = 0x8, +}; + +/** + * struct scmi_pwd_protocol_attrs_out + * @status: SCMI command status + * @attributes: Protocol attributes + * @stats_addr_low: Lower 32 bits of address of statistics memory region + * @stats_addr_high: Higher 32 bits of address of statistics memory region + * @stats_len: Length of statistics memory region + */ +struct scmi_pwd_protocol_attrs_out { + s32 status; + u32 attributes; + u32 stats_addr_low; + u32 stats_addr_high; + u32 stats_len; +}; + +#define SCMI_PWD_PROTO_ATTRS_NUM_PWD(attributes) ((attributes) & GENMASK(15, 0)) + +/** + * struct scmi_pwd_protocol_msg_attrs_out + * @status: SCMI command status + * @attributes: Message-specific attributes + */ +struct scmi_pwd_protocol_msg_attrs_out { + s32 status; + u32 attributes; +}; + +#define SCMI_PWD_NAME_LENGTH_MAX 16 + +/** + * struct scmi_pwd_attrs_out + * @status: SCMI command status + * @attributes: Power domain attributes + * @name: Name of power domain + */ +struct scmi_pwd_attrs_out { + s32 status; + u32 attributes; + u8 name[SCMI_PWD_NAME_LENGTH_MAX]; +}; + +#define SCMI_PWD_ATTR_PSTATE_CHANGE_NOTIFY BIT(31) +#define SCMI_PWD_ATTR_PSTATE_ASYNC BIT(30) +#define SCMI_PWD_ATTR_PSTATE_SYNC BIT(29) +#define SCMI_PWD_ATTR_PSTATE_CHANGE_RQ_NOTIFY BIT(28) +#define SCMI_PWD_ATTR_EXTENDED_NAME BIT(27) + +/** + * struct scmi_pwd_state_set_in + * @flags: Flags + * @domain_id: Identifier of power domain + * @pstate: Power state of the domain + */ +struct scmi_pwd_state_set_in { + u32 flags; + u32 domain_id; + u32 pstate; +}; + +#define SCMI_PWD_SET_FLAGS_ASYNC BIT(0) + +/** + * struct scmi_pwd_state_get_out + * @status: SCMI command status + * @pstate: Power state of the domain + */ +struct scmi_pwd_state_get_out { + s32 status; + u32 pstate; +}; + +#define SCMI_PWD_EXTENDED_NAME_MAX 64 +/** + * struct scmi_pwd_name_get_out + * @status: SCMI command status + * @flags: Parameter flags + * @extended_name: Extended name of power domain + */ +struct scmi_pwd_name_get_out { + s32 status; + u32 flags; + u8 extended_name[SCMI_PWD_EXTENDED_NAME_MAX]; +}; + +/** + * scmi_pwd_protocol_attrs - get protocol attributes + * @dev: SCMI protocol device + * @num_pwdoms: Number of power domains + * @stats_addr: Address of statistics memory region + * @stats_len: Length of statistics memory region + * + * Obtain the protocol attributes, the number of power domains and + * the information of statistics memory region. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_protocol_attrs(struct udevice *dev, int *num_pwdoms, + u64 *stats_addr, size_t *stats_len); +/** + * scmi_pwd_protocol_message_attrs - get message-specific attributes + * @dev: SCMI protocol device + * @message_id: SCMI message ID + * @attributes: Message-specific attributes + * + * Obtain the message-specific attributes in @attributes. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_protocol_message_attrs(struct udevice *dev, s32 message_id, + u32 *attributes); +/** + * scmi_pwd_attrs - get power domain attributes + * @dev: SCMI protocol device + * @domain_id: Identifier of power domain + * @attributes: Power domain attributes + * @name: Name of power domain + * + * Obtain the attributes of the given power domain, @domain_id, in @attributes + * as well as its name in @name. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_attrs(struct udevice *dev, u32 message_id, u32 *attributes, + u8 **name); +/** + * scmi_pwd_state_set - set power state + * @dev: SCMI protocol device + * @flags: Parameter flags + * @domain_id: Identifier of power domain + * @pstate: Power state + * + * Change the power state of the given power domain, @domain_id. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_state_set(struct udevice *dev, u32 flags, u32 domain_id, + u32 pstate); +/** + * scmi_pwd_state_get - get power state + * @dev: SCMI protocol device + * @domain_id: Identifier of power domain + * @pstate: Power state + * + * Obtain the power state of the given power domain, @domain_id. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_state_get(struct udevice *dev, u32 domain_id, u32 *pstate); +/** + * scmi_pwd_name_get - get extended name + * @dev: SCMI protocol device + * @domain_id: Identifier of power domain + * @name: Extended name of the domain + * + * Obtain the extended name of the given power domain, @domain_id, in @name. + * + * Return: 0 on success, error code on failure + */ +int scmi_pwd_name_get(struct udevice *dev, u32 domain_id, u8 **name); + /* * SCMI Clock Protocol */ From patchwork Tue Sep 26 07:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726397 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2781221wrm; Tue, 26 Sep 2023 00:01:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy5hfuxRCRtmckPTQTWXE/KlfdMycnRB5hGuWeyaYQMwxzqzlss8rx2PupAkY49uZyo6p6 X-Received: by 2002:a7b:c8ce:0:b0:3fd:2e89:31bd with SMTP id f14-20020a7bc8ce000000b003fd2e8931bdmr7582152wml.14.1695711713797; Tue, 26 Sep 2023 00:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711713; cv=none; d=google.com; s=arc-20160816; b=p/5JOHhUa940D2IguTtbE9OIV/4nelAixg060h/67UGoePn/Sh1Utjwm5LNvZ4Kjnc /P+fQeX7QKZWlrDOsfUI4kaC8IT5DkBDKKTMs8EUI3KVY+xBTAD8oy5QYehU72qEcne7 e7qlimPHR6i/lZuxYUran2htAgW5NH1t2VCy+M3V/wdZDpZly3q0iu+phr+5aoQVuhZC mLVLQQntzz94wktc9NTsp7nTkTnNrpgI8yYg/t+nXxQyk1zWq03Cx1S+Pe5bvn2mpZ+Q /omSGC/8PppD1+I15aOrFbxvtj6nEFMC4XiA/4OwkElbP2gJZMxX+ONj3pP3msYMkmRd g1Nw== 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=sSDEfXbx1Ru9WjEtbD0zE1/a/iAr+2GqyYt7YedDTOw=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=iweeBY4VzCZ99QceUEbGocJf11pm8QiPra2Xk9qN3FsBD73bBLcUGHG/A/i1muWmAB QgLZg1adrqC5bMsny1vOqWv50g9+DohaldK2eXerAcxMJ2cu2fCE8ukj/ge7hTLgNhy+ PasEkR0IswHuM4fffVVX8kI84a+XuWynrCJ6A8OlaYewWjasrQebyNmzRVHQsdn6wG6/ SjN8/qlNBD2yg+5hw3KoCHUs2zSKYvyVW6nB3PFcJl44othmLO9YC/l47A8Mdd2oium3 HWlVugmplu+3QtRYiMl/vaDQKYtML95C12YPBuEcFTNEH5ylnH1N1NPf4TVZXZzmmSNg geVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LijeBl25; 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 i22-20020a05600c355600b004063e3cdf17si11980wmq.150.2023.09.26.00.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:53 -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=LijeBl25; 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 C658486D8B; Tue, 26 Sep 2023 09:01: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="LijeBl25"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A4B0086D9A; Tue, 26 Sep 2023 09:01: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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 5178886D8E for ; Tue, 26 Sep 2023 09:01:08 +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-pf1-x433.google.com with SMTP id d2e1a72fcca58-68cc1b70e05so1941547b3a.1 for ; Tue, 26 Sep 2023 00:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711667; x=1696316467; darn=lists.denx.de; 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=sSDEfXbx1Ru9WjEtbD0zE1/a/iAr+2GqyYt7YedDTOw=; b=LijeBl25YkiBEW9nLoL2oQ2ZAsb/X8oQAYSKerClbLY2Pjq/KARtwYFkmT54EbZcgC a4iKh3GjexEehXWBHvBhjLvehKBYWAivMjifWaF6h0JTNtAjN7Yune0oteQioBNF6EkF mMSWnFTDWzHXaks1hP+7SG5v015gCJfe4OyMBRTZ5rLs5BA0dJvCtjQfIhy0CwghiBre bp/SamhwaYO1buqPqhaYgH5prl9jsO2CFsfUljxvoCPmC0kBcHTXpwXVxDbfcpy551NF efND8UmVZ3RZwHQdmlpePIoYjfcCRh0C+V1lODOb1gpxbIc/dBjKLZnW7hIh3tSspKs1 Q0gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711667; x=1696316467; 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=sSDEfXbx1Ru9WjEtbD0zE1/a/iAr+2GqyYt7YedDTOw=; b=hUeH+h3fZX73gwKMv4ThiwElmJaPxUAGrSz3DBqk9yMdFSZ43/X91RxaT4Ry6/ET65 sVySWGu4c60gI2T9l+QyqG5bS7EfMILcdlZNdyLPexDIWULXJXDWlKBlZlwD5ZBGzUh+ KtM92N8KxNwaNIy4h1hUJYDCKDjr3aUn6BKt8j+BnOC2xntw3u2YBYdmzZtdzJxZvuEV 5w3fABQHf7Ldb2vwBZ/Ec7gz2j0+G/m+Z7+AWT+74sMsnjl6Q0DHBsg2yG9+qtpv1HeH rwfevfBQcBnnQ2WDmka2JZWzIuwVufO1hcDgPaoTpEwZ78p4tnhE7ECoN3FbDMSM423N GmYA== X-Gm-Message-State: AOJu0Yy9gfd4Smh+YIFezYwUB9AO7c8B8kF572CjHNMsjj6+tPcZFEI4 RtECtVR6KsvUsbhXHihXMqHq+A== X-Received: by 2002:a05:6a20:394c:b0:13d:fff1:c672 with SMTP id r12-20020a056a20394c00b0013dfff1c672mr8342037pzg.4.1695711666577; Tue, 26 Sep 2023 00:01:06 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id ge13-20020a17090b0e0d00b0027758c7f585sm3178480pjb.52.2023.09.26.00.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:06 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 2/4] power: domain: add SCMI driver Date: Tue, 26 Sep 2023 16:00:41 +0900 Message-Id: <20230926070043.738340-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926070043.738340-1-takahiro.akashi@linaro.org> References: <20230926070043.738340-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 Add power domain driver based on SCMI power domain management protocol. Signed-off-by: AKASHI Takahiro --- drivers/firmware/scmi/scmi_agent-uclass.c | 11 ++ drivers/power/domain/Kconfig | 7 + drivers/power/domain/Makefile | 1 + drivers/power/domain/scmi-power-domain.c | 197 ++++++++++++++++++++++ include/scmi_agent-uclass.h | 2 + 5 files changed, 218 insertions(+) create mode 100644 drivers/power/domain/scmi-power-domain.c diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 6f585b96f740..0f1003e167e6 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -86,6 +86,9 @@ struct udevice *scmi_get_protocol(struct udevice *dev, case SCMI_PROTOCOL_ID_BASE: proto = priv->base_dev; break; + case SCMI_PROTOCOL_ID_POWER_DOMAIN: + proto = priv->pwdom_dev; + break; case SCMI_PROTOCOL_ID_CLOCK: proto = priv->clock_dev; break; @@ -133,6 +136,9 @@ static int scmi_add_protocol(struct udevice *dev, case SCMI_PROTOCOL_ID_BASE: priv->base_dev = proto; break; + case SCMI_PROTOCOL_ID_POWER_DOMAIN: + priv->pwdom_dev = proto; + break; case SCMI_PROTOCOL_ID_CLOCK: priv->clock_dev = proto; break; @@ -405,6 +411,11 @@ static int scmi_bind_protocols(struct udevice *dev) drv = NULL; name = ofnode_get_name(node); switch (protocol_id) { + case SCMI_PROTOCOL_ID_POWER_DOMAIN: + if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN) && + scmi_protocol_is_supported(dev, protocol_id)) + drv = DM_DRIVER_GET(scmi_power_domain); + break; case SCMI_PROTOCOL_ID_CLOCK: if (CONFIG_IS_ENABLED(CLK_SCMI) && scmi_protocol_is_supported(dev, protocol_id)) diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig index 411c210756a3..bd82d2f7044b 100644 --- a/drivers/power/domain/Kconfig +++ b/drivers/power/domain/Kconfig @@ -83,6 +83,13 @@ config SANDBOX_POWER_DOMAIN simply accepts requests to power on/off various HW modules without actually doing anything beyond a little error checking. +config SCMI_POWER_DOMAIN + bool "Enable SCMI power domain driver" + depends on POWER_DOMAIN && SCMI_FIRMWARE + help + Enable power domain implementation based on SCMI power domain + management protocol. + config TEGRA186_POWER_DOMAIN bool "Enable Tegra186 BPMP-based power domain driver" depends on TEGRA186_BPMP diff --git a/drivers/power/domain/Makefile b/drivers/power/domain/Makefile index aa5a4ba57cd8..2daab73eb758 100644 --- a/drivers/power/domain/Makefile +++ b/drivers/power/domain/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_MESON_EE_POWER_DOMAIN) += meson-ee-pwrc.o obj-$(CONFIG_MESON_SECURE_POWER_DOMAIN) += meson-secure-pwrc.o obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain.o obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain-test.o +obj-$(CONFIG_SCMI_POWER_DOMAIN) += scmi-power-domain.o obj-$(CONFIG_TEGRA186_POWER_DOMAIN) += tegra186-power-domain.o obj-$(CONFIG_TI_SCI_POWER_DOMAIN) += ti-sci-power-domain.o obj-$(CONFIG_TI_POWER_DOMAIN) += ti-power-domain.o diff --git a/drivers/power/domain/scmi-power-domain.c b/drivers/power/domain/scmi-power-domain.c new file mode 100644 index 000000000000..5ea9ff889231 --- /dev/null +++ b/drivers/power/domain/scmi-power-domain.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SCMI Power domain driver + * + * Copyright (C) 2023 Linaro Limited + * author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * struct scmi_pwd_properties + * @attributes: Power domain attributes + * @name: Name of the domain + */ +struct scmi_pwd_properties { + u32 attributes; + u8 *name; /* not used now */ +}; + +/** + * struct scmi_power_domain_priv + * @num_pwdoms: Number of power domains + * @prop: Pointer to domain's properties + * @stats_addr: Address of statistics memory region + * @stats_len: Length of statistics memory region + */ +struct scmi_power_domain_priv { + int num_pwdoms; + struct scmi_pwd_properties *prop; + u64 stats_addr; + size_t stats_len; +}; + +/** + * async_is_supported - check asynchronous transition + * @attributes: Power domain attributes + * + * Determine if the power transition can be done asynchronously. + * + * Return: true if supported, false if not + */ +static bool async_is_supported(u32 attributes) +{ + if (attributes & SCMI_PWD_ATTR_PSTATE_ASYNC) + return true; + + /* TODO: check attributes && SCMI_PWD_ATTR_PSTATE_SYNC */ + return false; +} + +/** + * scmi_power_domain_on - Enable the power domain + * @power_domain: Power domain + * + * Turn on the power domain. + * + * Return: 0 on success, error code on failure + */ +static int scmi_power_domain_on(struct power_domain *power_domain) +{ + struct scmi_power_domain_priv *priv = dev_get_priv(power_domain->dev); + u32 flags, pstate; + int ret; + + if (power_domain->id > priv->num_pwdoms) + return -EINVAL; + + if (async_is_supported(priv->prop[power_domain->id].attributes)) + flags = SCMI_PWD_SET_FLAGS_ASYNC; + else + flags = 0; + + /* ON */ + pstate = 0; + + ret = scmi_pwd_state_set(power_domain->dev, flags, power_domain->id, + pstate); + if (ret) { + dev_err(power_domain->dev, "failed to set the state on (%d)\n", + ret); + return ret; + } + + return 0; +} + +/** + * scmi_power_domain_off - Disable the power domain + * @power_domain: Power domain + * + * Turn off the power domain. + * + * Return: 0 on success, error code on failure + */ +static int scmi_power_domain_off(struct power_domain *power_domain) +{ + struct scmi_power_domain_priv *priv = dev_get_priv(power_domain->dev); + u32 flags, pstate; + int ret; + + if (power_domain->id > priv->num_pwdoms) + return -EINVAL; + + if (async_is_supported(priv->prop[power_domain->id].attributes)) + flags = SCMI_PWD_SET_FLAGS_ASYNC; + else + flags = 0; + + /* OFF */ + pstate = SCMI_PWD_PSTATE_TYPE_LOST; + + ret = scmi_pwd_state_set(power_domain->dev, flags, power_domain->id, + pstate); + if (ret) { + dev_err(power_domain->dev, "failed to set the state off (%d)\n", + ret); + return ret; + } + + return 0; +} + +/** + * scmi_power_domain_probe - Probe the power domain + * @dev: Power domain device + * + * Probe the power domain and initialize the properties. + * + * Return: 0 on success, error code on failure + */ +static int scmi_power_domain_probe(struct udevice *dev) +{ + struct scmi_power_domain_priv *priv = dev_get_priv(dev); + u32 version; + int i, ret; + + ret = devm_scmi_of_get_channel(dev); + if (ret) { + dev_err(dev, "failed to get channel (%d)\n", ret); + return ret; + } + + ret = scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_POWER_DOMAIN, + &version); +#if 0 /* TODO */ + if (ret || version < SCMI_POWER_DOMAIN_PROTOCOL_VERSION) { + dev_err(dev, "protocol version doesn't match (%d)\n", version); + return -EINVAL; + } +#endif + + ret = scmi_pwd_protocol_attrs(dev, &priv->num_pwdoms, &priv->stats_addr, + &priv->stats_len); + if (ret) { + dev_err(dev, "failed to get protocol attributes (%d)\n", ret); + return ret; + } + + priv->prop = calloc(sizeof(*priv->prop), priv->num_pwdoms); + if (!priv->prop) + return -ENOMEM; + + for (i = 0; i < priv->num_pwdoms; i++) { + ret = scmi_pwd_attrs(dev, i, &priv->prop[i].attributes, + &priv->prop[i].name); + if (ret) { + dev_err(dev, "failed to get attributes pwd:%d (%d)\n", + i, ret); + /* TODO: clean up */ + + return ret; + } + } + + return 0; +} + +struct power_domain_ops scmi_power_domain_ops = { + .on = scmi_power_domain_on, + .off = scmi_power_domain_off, +}; + +U_BOOT_DRIVER(scmi_power_domain) = { + .name = "scmi_power_domain", + .id = UCLASS_POWER_DOMAIN, + .ops = &scmi_power_domain_ops, + .probe = scmi_power_domain_probe, + .priv_auto = sizeof(struct scmi_power_domain_priv), +}; diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h index 35d96069645e..33e0e18c30d4 100644 --- a/include/scmi_agent-uclass.h +++ b/include/scmi_agent-uclass.h @@ -23,6 +23,7 @@ struct scmi_channel; * @agent_name: Agent name * @agent_id: Identifier of agent * @base_dev: SCMI base protocol device + * @pwdom_dev: SCMI power domain management protocol device * @clock_dev: SCMI clock protocol device * @resetdom_dev: SCMI reset domain protocol device * @voltagedom_dev: SCMI voltage domain protocol device @@ -38,6 +39,7 @@ struct scmi_agent_priv { u8 *agent_name; u32 agent_id; struct udevice *base_dev; + struct udevice *pwdom_dev; struct udevice *clock_dev; struct udevice *resetdom_dev; struct udevice *voltagedom_dev; From patchwork Tue Sep 26 07:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726398 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2781324wrm; Tue, 26 Sep 2023 00:02:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMPpUnvnQ212E6WeVQpNHTN+OPKl0VfjllQuH6uE8e5+umiaolsWLO/eLhSXAOp1C288V2 X-Received: by 2002:a5d:4390:0:b0:31f:f432:b541 with SMTP id i16-20020a5d4390000000b0031ff432b541mr8233259wrq.69.1695711726025; Tue, 26 Sep 2023 00:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711726; cv=none; d=google.com; s=arc-20160816; b=r5FJxc9bzDnQbDIdbcgIJdGDu8zJRVQk+K7I4/fA1aJFQ/wuTI9P8fXBA2492+gaaS /nW4pkX0+DRBJBJxcK2acM/Fl+P45T37sWQVAJVYmvBgi2VwV89nUgYzwlxzzpql6sZy 1pCUi5ubG+oVuwAYyyeus+EfcvR9sgOLYrJmMLpsRpCrNs/hslUy5+gUyVLP+DNh/kn1 In14sbuzbQZx5PDZlwSREaIPkXw/heTbk0E3IT31qkzGfplpTboft+A61VFECfrGtH32 U7Y615tB8YmxGSYjiz0KyI2aSdWlQudjxqIc153rppC30HKVPZsFa2V/IvUeYrMgJsR9 68HA== 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=TaNu8QTaKyIx4zU9QPEtFNp1K3jnA2Wr0NHrr1NxNT4=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=vkDguuH7nsO6LyCrhwMORI2vvmc0h6gXVboqnkEtccWa6d9PHylLkd0/R5mYkLqJEn LYFeVPqXs/4/a+m/h2MW++era+3hiheN7P8jehYa2SGu6maZdQHX2ZPLtZPJtHQcz/nq 3BOk1b3rB2AABE6jaE8IXZ4FmHUou6+wOKfWSqhW4xfKS8AZdaZElO+GnHb11R7AM4iy 1GrcjTzzFS0YoLV6cJhcB5TeAVhTP9JwsDgMOqIl7x0l+vEsTy5y9nkxvkpAKwAFBzBp UifBedadHh2S1FkA3alG+6HN4b7XOFauPDTdjuRUOTQ5Vn3H+TpNKTLviZVXFvQA16r7 zwFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QGjiPwsy; 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 h14-20020a5d504e000000b0032320d05f3bsi2340464wrt.756.2023.09.26.00.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:02:05 -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=QGjiPwsy; 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 30A9A86D86; Tue, 26 Sep 2023 09:01:14 +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="QGjiPwsy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 28AD286D8F; Tue, 26 Sep 2023 09:01:13 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (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 ADD4286D85 for ; Tue, 26 Sep 2023 09:01:10 +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-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-27197b0b733so1448012a91.1 for ; Tue, 26 Sep 2023 00:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711669; x=1696316469; darn=lists.denx.de; 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=TaNu8QTaKyIx4zU9QPEtFNp1K3jnA2Wr0NHrr1NxNT4=; b=QGjiPwsyW/MOto8VxZxX6DSqShW8ffq8DivyfIbxoTCXInSk1sEK1uxJgZHqIanut6 NV7HJN/mxsML5wpeSRUxFGXrnzf08TgrgMtKQvx9Yxz+wufjoD7BJaGy448bvpY7agxc EsrrceTo6erbMNc8W7TrnG2OoH2+g52jpb/nwAtGn6J9ON8x8GxxOnADYZXatOPITXEo +FWOpGA5oz0H6d6tJkkrifD6a/QAq5upWP58BeWrK7JCrefG+Z4whvsVJ96R7mZ2DAVC u2kymt7K4ZgydZ1SHwJ57nnHpw0HyFU71j6EnfTignT1/JDHrZq7SBeqrS8/ahAYmzLY cbCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711669; x=1696316469; 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=TaNu8QTaKyIx4zU9QPEtFNp1K3jnA2Wr0NHrr1NxNT4=; b=q4heSGwQ8d6mVav+FEc6Q21jM1jQBlxELE3DVLogAhps49l0KKKUmkb9pb/G6J8EPC lf3EygO4Xfl0N5oG3T0jS7k4mFFr80Am+avoqHcStJ1e/UZUzJGcjQ9/1vGXV31R8uxc qFgRs69KY1SbsR/8kgQQjmQ5RuNG+H1NBdRN+IDL1uSJ00YQI3WStT6io9DDnWtllTOW elpaBtDKVjRwGmbCgs540Z2jEgTip2JfwDccibquPmT86uJuDt/h8EvqaZshkBGWbN+a v4UJwXlFxmV5Vi5nym4W+zQhAAi+4R0yyYzJSJ9zoR7YQOATJ6mjW85LaPpvZsO+FMQS N0Eg== X-Gm-Message-State: AOJu0Yxv8/KTyxuRnJl+1W21IsPoigvVUdGv20Zq1uhy0J6gxV4FDNh2 Gx+hTmOFcHN4ZTf9RVHxyX7YJQ== X-Received: by 2002:a17:90a:bc9:b0:268:38a7:842e with SMTP id x9-20020a17090a0bc900b0026838a7842emr7876358pjd.2.1695711668936; Tue, 26 Sep 2023 00:01:08 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id ge13-20020a17090b0e0d00b0027758c7f585sm3178480pjb.52.2023.09.26.00.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:08 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 3/4] sandbox: add SCMI power domain protocol support for testing Date: Tue, 26 Sep 2023 16:00:42 +0900 Message-Id: <20230926070043.738340-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926070043.738340-1-takahiro.akashi@linaro.org> References: <20230926070043.738340-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 power domain management protocol is supported on sandbox for test purpose. Add fake agent interfaces and associated power domain devices. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- arch/sandbox/dts/test.dts | 6 + arch/sandbox/include/asm/scmi_test.h | 20 ++ configs/sandbox_defconfig | 1 + drivers/firmware/scmi/sandbox-scmi_agent.c | 265 ++++++++++++++++++- drivers/firmware/scmi/sandbox-scmi_devices.c | 10 + 5 files changed, 301 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 36de6a37cf6d..38fcf42cd23d 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -693,6 +693,11 @@ #address-cells = <1>; #size-cells = <0>; + pwrdom_scmi: protocol@11 { + reg = <0x11>; + #power-domain-cells = <1>; + }; + clk_scmi: protocol@14 { reg = <0x14>; #clock-cells = <1>; @@ -1589,6 +1594,7 @@ sandbox_scmi { compatible = "sandbox,scmi-devices"; + power-domains = <&pwrdom_scmi 2>; clocks = <&clk_scmi 2>, <&clk_scmi 0>; resets = <&reset_scmi 3>; regul0-supply = <®ul0_scmi>; diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h index ccb0df6c148f..1b0f4464b98f 100644 --- a/arch/sandbox/include/asm/scmi_test.h +++ b/arch/sandbox/include/asm/scmi_test.h @@ -6,10 +6,21 @@ #ifndef __SANDBOX_SCMI_TEST_H #define __SANDBOX_SCMI_TEST_H +#include + struct udevice; struct sandbox_scmi_agent; struct sandbox_scmi_service; +/** + * struct sandbox_scmi_pwd + * @id: Identifier of the power domain used in the SCMI protocol + */ +struct sandbox_scmi_pwd { + uint id; + u32 pstate; +}; + /** * struct sandbox_scmi_clk - Simulated clock exposed by SCMI * @id: Identifier of the clock used in the SCMI protocol @@ -45,6 +56,8 @@ struct sandbox_scmi_voltd { /** * struct sandbox_scmi_agent - Simulated SCMI service seen by SCMI agent + * @pwdom_version: Implemented power domain protocol version + * @pwdom_count: Simulated power domains array size * @clk: Simulated clocks * @clk_count: Simulated clocks array size * @reset: Simulated reset domains @@ -53,6 +66,9 @@ struct sandbox_scmi_voltd { * @voltd_count: Simulated voltage domains array size */ struct sandbox_scmi_agent { + int pwdom_version; + struct sandbox_scmi_pwd *pwdom; + size_t pwdom_count; struct sandbox_scmi_clk *clk; size_t clk_count; struct sandbox_scmi_reset *reset; @@ -71,6 +87,8 @@ struct sandbox_scmi_service { /** * struct sandbox_scmi_devices - Reference to devices probed through SCMI + * @pwdom: Array of power domains + * @pwdom_count: Number of power domains probed * @clk: Array the clock devices * @clk_count: Number of clock devices probed * @reset: Array the reset controller devices @@ -79,6 +97,8 @@ struct sandbox_scmi_service { * @regul_count: Number of regulator devices probed */ struct sandbox_scmi_devices { + struct power_domain *pwdom; + size_t pwdom_count; struct clk *clk; size_t clk_count; struct reset_ctl *reset; diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 3906476bb4fc..b0a72e63f7da 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -241,6 +241,7 @@ CONFIG_PINCTRL_SANDBOX=y CONFIG_PINCTRL_SINGLE=y CONFIG_POWER_DOMAIN=y CONFIG_SANDBOX_POWER_DOMAIN=y +CONFIG_SCMI_POWER_DOMAIN=y CONFIG_DM_PMIC=y CONFIG_PMIC_ACT8846=y CONFIG_DM_PMIC_PFUZE100=y diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c index eb567dd900d7..9f5f497e0a6c 100644 --- a/drivers/firmware/scmi/sandbox-scmi_agent.c +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c @@ -43,6 +43,8 @@ #define SANDBOX_SCMI_AGENT_NAME "OSPM" #define SANDBOX_SCMI_PLATFORM_NAME "platform" +#define SANDBOX_SCMI_PWD_PROTOCOL_VERSION SCMI_PWD_PROTOCOL_VERSION + /** * struct sandbox_channel - Description of sandbox transport * @channel_id: Channel identifier @@ -64,6 +66,7 @@ struct scmi_channel { }; static u8 protocols[] = { + SCMI_PROTOCOL_ID_POWER_DOMAIN, SCMI_PROTOCOL_ID_CLOCK, SCMI_PROTOCOL_ID_RESET_DOMAIN, SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, @@ -71,6 +74,12 @@ static u8 protocols[] = { #define NUM_PROTOCOLS ARRAY_SIZE(protocols) +static struct sandbox_scmi_pwd scmi_pwdom[] = { + { .id = 0 }, + { .id = 1 }, + { .id = 2 }, +}; + static struct sandbox_scmi_clk scmi_clk[] = { { .rate = 333 }, { .rate = 200 }, @@ -458,6 +467,238 @@ static int sandbox_scmi_base_reset_agent_configuration(struct udevice *dev, return 0; } +/* Power Domain Management Protocol */ + +/** + * sandbox_scmi_pwd_protocol_version - implement SCMI_PROTOCOL_VERSION + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PROTOCOL_VERSION command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_protocol_version(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_protocol_version_out *out = NULL; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_protocol_version_out *)msg->out_msg; + out->version = SANDBOX_SCMI_PWD_PROTOCOL_VERSION; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_pwd_protocol_attribs - implement SCMI_PWD_PROTOCOL_ATTRS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_PROTOCOL_ATTRS command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_protocol_attribs(struct udevice *dev, + struct scmi_msg *msg) +{ + struct scmi_pwd_protocol_attrs_out *out; + + if (!msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + out = (struct scmi_pwd_protocol_attrs_out *)msg->out_msg; + + out->attributes = ARRAY_SIZE(scmi_pwdom); + out->stats_addr_low = 0; + out->stats_addr_high = 0; + out->stats_len = 0; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_pwd_protocol_msg_attribs - implement + SCMI_PWD_PROTOCOL_MESSAGE_ATTRS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_PROTOCOL_MESSAGE_ATTRS command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_protocol_msg_attribs(struct udevice *dev, + struct scmi_msg *msg) +{ + u32 message_id; + struct scmi_pwd_protocol_msg_attrs_out *out; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(message_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + message_id = *(u32 *)msg->in_msg; + + out = (struct scmi_pwd_protocol_msg_attrs_out *)msg->out_msg; + if (message_id <= SCMI_PWD_STATE_GET || + message_id == SCMI_PWD_NAME_GET) { + out->attributes = 0; + out->status = SCMI_SUCCESS; + } else { + out->status = SCMI_NOT_FOUND; + } + + return 0; +} + +/** + * sandbox_scmi_pwd_attribs - implement SCMI_PWD_ATTRS + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_ATTRS command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_attribs(struct udevice *dev, struct scmi_msg *msg) +{ + u32 domain_id; + struct scmi_pwd_attrs_out *out; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(domain_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + domain_id = *(u32 *)msg->in_msg; + out = (struct scmi_pwd_attrs_out *)msg->out_msg; + + if (domain_id > ARRAY_SIZE(scmi_pwdom)) { + out->status = SCMI_NOT_FOUND; + + return 0; + } + + out->attributes = + SCMI_PWD_ATTR_PSTATE_SYNC | SCMI_PWD_ATTR_EXTENDED_NAME; + /* just 15-char + NULL */ + snprintf(out->name, SCMI_PWD_NAME_LENGTH_MAX, "power-domain--%d", + domain_id); + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_pwd_state_set - implement SCMI_PWD_STATE_SET + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_STATE_SET command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_state_set(struct udevice *dev, struct scmi_msg *msg) +{ + struct scmi_pwd_state_set_in *in; + s32 *status; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(in) || + !msg->out_msg || msg->out_msg_sz < sizeof(*status)) + return -EINVAL; + + in = (struct scmi_pwd_state_set_in *)msg->in_msg; + status = (s32 *)msg->out_msg; + + if (in->domain_id > ARRAY_SIZE(scmi_pwdom)) { + *status = SCMI_NOT_FOUND; + + return 0; + } + + if ((in->flags & SCMI_PWD_SET_FLAGS_ASYNC) || + (in->pstate != SCMI_PWD_PSTATE_TYPE_LOST && in->pstate)) { + *status = SCMI_INVALID_PARAMETERS; + + return 0; + } + + scmi_pwdom[in->domain_id].pstate = in->pstate; + *status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_pwd_state_get - implement SCMI_PWD_STATE_GET + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_STATE_GET command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_state_get(struct udevice *dev, struct scmi_msg *msg) +{ + u32 domain_id; + struct scmi_pwd_state_get_out *out; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(domain_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + domain_id = *(u32 *)msg->in_msg; + out = (struct scmi_pwd_state_get_out *)msg->out_msg; + + if (domain_id > ARRAY_SIZE(scmi_pwdom)) { + out->status = SCMI_NOT_FOUND; + + return 0; + } + + out->pstate = scmi_pwdom[domain_id].pstate; + out->status = SCMI_SUCCESS; + + return 0; +} + +/** + * sandbox_scmi_pwd_name_get - implement SCMI_PWD_NAME_GET + * @dev: SCMI device + * @msg: SCMI message + * + * Implement SCMI_PWD_NAME_GET command. + * + * Return: 0 on success, error code on failure + */ +static int sandbox_scmi_pwd_name_get(struct udevice *dev, struct scmi_msg *msg) +{ + u32 domain_id; + struct scmi_pwd_name_get_out *out; + + if (!msg->in_msg || msg->in_msg_sz < sizeof(domain_id) || + !msg->out_msg || msg->out_msg_sz < sizeof(*out)) + return -EINVAL; + + domain_id = *(u32 *)msg->in_msg; + out = (struct scmi_pwd_name_get_out *)msg->out_msg; + + if (domain_id > ARRAY_SIZE(scmi_pwdom)) { + out->status = SCMI_NOT_FOUND; + + return 0; + } + + snprintf(out->extended_name, SCMI_PWD_EXTENDED_NAME_MAX, + "power-domain--%d-extended", domain_id); + out->status = SCMI_SUCCESS; + + return 0; +} + /* Clock Protocol */ static int sandbox_scmi_clock_protocol_attribs(struct udevice *dev, @@ -918,6 +1159,26 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, break; } break; + case SCMI_PROTOCOL_ID_POWER_DOMAIN: + switch (msg->message_id) { + case SCMI_PROTOCOL_VERSION: + return sandbox_scmi_pwd_protocol_version(dev, msg); + case SCMI_PROTOCOL_ATTRIBUTES: + return sandbox_scmi_pwd_protocol_attribs(dev, msg); + case SCMI_PROTOCOL_MESSAGE_ATTRIBUTES: + return sandbox_scmi_pwd_protocol_msg_attribs(dev, msg); + case SCMI_PWD_ATTRIBUTES: + return sandbox_scmi_pwd_attribs(dev, msg); + case SCMI_PWD_STATE_SET: + return sandbox_scmi_pwd_state_set(dev, msg); + case SCMI_PWD_STATE_GET: + return sandbox_scmi_pwd_state_get(dev, msg); + case SCMI_PWD_NAME_GET: + return sandbox_scmi_pwd_name_get(dev, msg); + default: + break; + } + break; case SCMI_PROTOCOL_ID_CLOCK: switch (msg->message_id) { case SCMI_PROTOCOL_ATTRIBUTES: @@ -960,7 +1221,6 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev, break; } break; - case SCMI_PROTOCOL_ID_POWER_DOMAIN: case SCMI_PROTOCOL_ID_SYSTEM: case SCMI_PROTOCOL_ID_PERF: case SCMI_PROTOCOL_ID_SENSOR: @@ -993,6 +1253,9 @@ static int sandbox_scmi_test_probe(struct udevice *dev) struct sandbox_scmi_agent *agent = dev_get_priv(dev); *agent = (struct sandbox_scmi_agent){ + .pwdom_version = SANDBOX_SCMI_PWD_PROTOCOL_VERSION, + .pwdom = scmi_pwdom, + .pwdom_count = ARRAY_SIZE(scmi_pwdom), .clk = scmi_clk, .clk_count = ARRAY_SIZE(scmi_clk), .reset = scmi_reset, diff --git a/drivers/firmware/scmi/sandbox-scmi_devices.c b/drivers/firmware/scmi/sandbox-scmi_devices.c index 9baeb469ec0a..facb5b06ffb5 100644 --- a/drivers/firmware/scmi/sandbox-scmi_devices.c +++ b/drivers/firmware/scmi/sandbox-scmi_devices.c @@ -29,12 +29,14 @@ /* * struct sandbox_scmi_device_priv - Storage for device handles used by test + * @pwdom: Power domain device * @clk: Array of clock instances used by tests * @reset_clt: Array of the reset controller instances used by tests * @regulators: Array of regulator device references used by the tests * @devices: Resources exposed by sandbox_scmi_devices_ctx() */ struct sandbox_scmi_device_priv { + struct power_domain pwdom; struct clk clk[SCMI_TEST_DEVICES_CLK_COUNT]; struct reset_ctl reset_ctl[SCMI_TEST_DEVICES_RD_COUNT]; struct udevice *regulators[SCMI_TEST_DEVICES_VOLTD_COUNT]; @@ -77,6 +79,8 @@ static int sandbox_scmi_devices_probe(struct udevice *dev) size_t n; priv->devices = (struct sandbox_scmi_devices){ + .pwdom = &priv->pwdom, + .pwdom_count = 1, .clk = priv->clk, .clk_count = SCMI_TEST_DEVICES_CLK_COUNT, .reset = priv->reset_ctl, @@ -85,6 +89,12 @@ static int sandbox_scmi_devices_probe(struct udevice *dev) .regul_count = SCMI_TEST_DEVICES_VOLTD_COUNT, }; + ret = power_domain_get_by_index(dev, priv->devices.pwdom, 0); + if (ret) { + dev_err(dev, "%s: Failed on power domain\n", __func__); + return ret; + } + for (n = 0; n < SCMI_TEST_DEVICES_CLK_COUNT; n++) { ret = clk_get_by_index(dev, n, priv->devices.clk + n); if (ret) { From patchwork Tue Sep 26 07:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 726399 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2781409wrm; Tue, 26 Sep 2023 00:02:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvIkE3NRPgXGOEZ+rY+53Vv7hsP8b3JGjZuMWqddR/HI+ekdpC2uoKDxu6XyEDGzeUMiaM X-Received: by 2002:adf:e544:0:b0:31f:f1f4:ca8b with SMTP id z4-20020adfe544000000b0031ff1f4ca8bmr7492093wrm.40.1695711737600; Tue, 26 Sep 2023 00:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711737; cv=none; d=google.com; s=arc-20160816; b=Ci6xtmi1KxTpsR6gh8WgMBEFFhC2s80HULx3lgSqzHWUeBv3buR20a3LSmSK8XkQrK YbpZ/zI2kG4PULa4YMYasPNGIG22XB6OLY96cDK3XiAgS0c2gjk+FE5td5vACLOMRNaL EtJzgcITPjwYYj+5OQ+dWQfbImVu3MPYmezQtNeeiKzB9ZctpCxHG9qIG+zcp+wYIyMn IQpiuOp3jY8xUHv1vRT7vVGvu92sLn0f/OxMUQajSG8WmKgpQoKqs7ahKQs6w5yoHzVw ZySosLVChASJMJ78cDaCBIE3s78F76+uJ7rNv2A0fJnf0yqKPU7Yz24Vhc4vVbapv29q +UIw== 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=mwSwJEm2Sraaao7ArVGRtZyaqBvdJEcgFr5He7VTZEY=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=LHRQ6hwpkvk1U9+OcMzs77FbNxcKTDlLw1uulU7q5nmyLEBRSL2K151uJPLlhIrgJ2 qDUiDz6dccc/bD+ha29OxMtm9rOTD0XpzFfVX+LlyLF36tthdaxXazgxUeo5pbR794zm 2ZlhXlHY0mkTW53/b8v9PKnFGTn4YpP4N/lElS1TlqMZoNyH4LdLeV9lyycKu1YvQwSz qIvoZ0QjqGGCRzBK9GA++2LQOnNJYvsHdCcnON3sFYTFsqJanCSOYTs+dgjSD/0aBq+v +hg+MWY9qBk1FQwaYzDkV0nBsiJiMfTtij2bC6KvdKeLWI/9FEUURUhXIdodLZ4hvIbl XoXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FJUfO+LJ; 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 v5-20020adfedc5000000b0032333ac4463si708802wro.295.2023.09.26.00.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:02: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=FJUfO+LJ; 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 9139986D91; Tue, 26 Sep 2023 09:01:16 +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="FJUfO+LJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3267A86D9D; Tue, 26 Sep 2023 09:01:15 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 ED7E486D88 for ; Tue, 26 Sep 2023 09:01:12 +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-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-277317a0528so931534a91.0 for ; Tue, 26 Sep 2023 00:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695711671; x=1696316471; darn=lists.denx.de; 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=mwSwJEm2Sraaao7ArVGRtZyaqBvdJEcgFr5He7VTZEY=; b=FJUfO+LJoXMd9S9/BugPTixuObU5CuzztPPUg5as8lNgGv4h5dzAMNOuumXF3RB71t AcTh4QD04DoR8HKQMFqKrm+xoCPip9YB5MjNC4IEUKoH2ASvGWdK7bjT43Y1SQqyML+Q cc5MxrZM/x26/k0kZtZegsS32oa7KRb+MjXkCKiBAxd9fgbrqq0JmJ3mYEBUMOzX66XR yAMktLhFGpYrILpUUL6p97kL50y+po4OeLB6S4DzA9gAkGQLbNMxFiTgUUhtA1x8sJ0c Ikc7/kBmPn2Nad5ByYIJGfR5taEiRhBhpSLpezswm/ZgBFONGb6W/EoIVIDFN3z20R+q 2KJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695711671; x=1696316471; 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=mwSwJEm2Sraaao7ArVGRtZyaqBvdJEcgFr5He7VTZEY=; b=jPeFHlMKaMewafXgDuM+IEe/odkGO5PzjN6R/gfFT7nDp+qiKY2XXDA1NZ/zb6GCeq uG8JaAthLYKUrkI3VZFNLPjNttNdbLTMpBHdl1sxZ0kq9tOF+AAnC7FAvOVYUTaIsPVf LdcZLuNrvdgZxHWcttyYklD+hHdCAVklUqi0BEVQOahIc+j4cWJhCP36iLLbLrttzkqh b26drOIVhCVxSmt8s6CB5s4/uAQKE4DB6HspwWJ4nYI19JuzJeOe5/vYJOW41M7fAczt XXftRxsCfoOv3emMN5JD1+6pIR5+s90byXmu6GDm6JeY/046nzRclqpdSnzcZz1W96+3 h4mQ== X-Gm-Message-State: AOJu0YzJ939FuFtz062395wpqUmZG6jOreXIMRg2WOKyAlDY1Q39Hf+d MDcUFtwpwC7fLSUkk0iP0E/xTQ== X-Received: by 2002:a17:90a:d503:b0:277:2566:7ad7 with SMTP id t3-20020a17090ad50300b0027725667ad7mr7379180pju.0.1695711671242; Tue, 26 Sep 2023 00:01:11 -0700 (PDT) Received: from octopus.. ([2400:4050:c3e1:100:6585:aea6:5002:a825]) by smtp.gmail.com with ESMTPSA id ge13-20020a17090b0e0d00b0027758c7f585sm3178480pjb.52.2023.09.26.00.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 00:01:10 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org Cc: etienne.carriere@st.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 4/4] test: dm: add SCMI power domain protocol test Date: Tue, 26 Sep 2023 16:00:43 +0900 Message-Id: <20230926070043.738340-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926070043.738340-1-takahiro.akashi@linaro.org> References: <20230926070043.738340-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 This ut has tests for the SCMI power domain protocol as well as DM interfaces for power domain devices. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- test/dm/scmi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/test/dm/scmi.c b/test/dm/scmi.c index 949e49bd2c35..c2625373d84e 100644 --- a/test/dm/scmi.c +++ b/test/dm/scmi.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -223,7 +224,8 @@ static int dm_test_scmi_cmd(struct unit_test_state *uts) ut_assert_nextline(" # of agents: 2"); ut_assert_nextline(" 0: platform"); ut_assert_nextline(" > 1: OSPM"); - ut_assert_nextline(" # of protocols: 3"); + ut_assert_nextline(" # of protocols: 4"); + ut_assert_nextline(" Power domain management"); ut_assert_nextline(" Clock management"); ut_assert_nextline(" Reset domain management"); ut_assert_nextline(" Voltage domain management"); @@ -259,6 +261,109 @@ static int dm_test_scmi_cmd(struct unit_test_state *uts) DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT); +static int dm_test_scmi_power_domains(struct unit_test_state *uts) +{ + struct sandbox_scmi_agent *agent; + struct sandbox_scmi_devices *scmi_devices; + struct udevice *agent_dev, *pwd, *dev; + u32 version, count, attributes, pstate; + u64 stats_addr; + size_t stats_len; + u8 *name; + int ret; + + /* preparation */ + ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); + ut_assertnonnull(agent); + scmi_devices = sandbox_scmi_devices_ctx(dev); + ut_assertnonnull(scmi_devices); + ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */ + + ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", + &agent_dev)); + ut_assertnonnull(agent_dev); + pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN); + ut_assertnonnull(pwd); + + /* + * SCMI Power domain management protocol interfaces + */ + /* version */ + ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN, + &version); + ut_assertok(ret); + ut_asserteq(agent->pwdom_version, version); + + /* protocol attributes */ + ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len); + ut_assertok(ret); + ut_asserteq(agent->pwdom_count, count); + ut_asserteq(0, stats_len); + + /* protocol message attributes */ + ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET, + &attributes); + ut_assertok(ret); + ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY, + &attributes); + ut_asserteq(-ENOENT, ret); /* the protocol not supported */ + + /* power domain attributes */ + ret = scmi_pwd_attrs(pwd, 0, &attributes, &name); + ut_assertok(ret); + ut_asserteq_str("power-domain--0", name); + free(name); + + ret = scmi_pwd_attrs(pwd, 10, &attributes, &name); + ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ + + /* power domain state set/get */ + ret = scmi_pwd_state_set(pwd, 0, 0, 0); + ut_assertok(ret); + ret = scmi_pwd_state_get(pwd, 0, &pstate); + ut_assertok(ret); + ut_asserteq(0, pstate); /* ON */ + + ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST); + ut_assertok(ret); + ret = scmi_pwd_state_get(pwd, 0, &pstate); + ut_assertok(ret); + ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ + + ret = scmi_pwd_state_set(pwd, 0, 10, 0); + ut_asserteq(-ENOENT, ret); + + /* power domain name get */ + ret = scmi_pwd_name_get(pwd, 0, &name); + ut_assertok(ret); + ut_asserteq_str("power-domain--0-extended", name); + free(name); + + ret = scmi_pwd_name_get(pwd, 10, &name); + ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ + + /* + * U-Boot driver model interfaces + */ + /* power_domain_on */ + ret = power_domain_on(scmi_devices->pwdom); + ut_assertok(ret); + ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); + ut_assertok(ret); + ut_asserteq(0, pstate); /* ON */ + + /* power_domain_off */ + ret = power_domain_off(scmi_devices->pwdom); + ut_assertok(ret); + ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); + ut_assertok(ret); + ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ + + return release_sandbox_scmi_test_devices(uts, dev); +} + +DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT); + static int dm_test_scmi_clocks(struct unit_test_state *uts) { struct sandbox_scmi_agent *agent;