From patchwork Wed Jun 28 00:48:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 697203 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp4080170wrm; Tue, 27 Jun 2023 17:50:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7k4VIfVto+bEZevtUHAVf9i0CsVdamH0gYy/IxuT46OhWr+Vge1PqcQEKO1F23Rjv8go/P X-Received: by 2002:a05:6512:33cf:b0:4f9:74b3:dee8 with SMTP id d15-20020a05651233cf00b004f974b3dee8mr10132093lfg.15.1687913415320; Tue, 27 Jun 2023 17:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687913415; cv=none; d=google.com; s=arc-20160816; b=CAeF+howC0Nl3R1moCAfiegtxkILFQOBECxV7CMrI+ZHIJ/QvxRjTVG+0tLCMQD7a6 6vL7TYAy1maVYJO4B+5cyS2YCQK7tG6mnOlHZenNdMGlblkg1e7ijD8Gg7BAAdeNJNW6 fbBydYkG1QCGQP7I0CONpndAIqmCJhsWdhSjiUFLjfpbpUlq/UPnAKDg3yddjVCvO/tk Wjy4Pj7lMIaOqklV6jQxxvq4x0OrOlC2Omux7kf32eZ/ICsdGAx9Uz8nmKFp8uXhCvOU qfJ9z4P5hs68HdOA7+QG41t/ZMLQKsp7pi8/XaxwZQ9RWYGvb7No6IT1HQOt2OU1no61 1Xgw== 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=wUERDMnx2MAtzW+c7TrgxZhn94CPs/Fg4n/Wz7nEEFA=; fh=+s9SE2w9oguEKAMcR35TXtqntCOeVFhiK9u/Kju91lo=; b=GsDqkbpqZ53h0M/+dWOd2xo6KBmmEjrkVvYuAV9k8K9pTXgPFq9ZIsHTY6s/N4pGVf Kd7CSftM5eG/DPtD9ZfYAaqKwWnRre1PoqhpS77Kys6JLEXOEYcAv4PVblb15lzjl5Ao u9ofC6n8r45PTnUbomty34fycCDOg2mVi+NybLhgnbPgtfk3yutyo8EyqRLhvkaSdyT4 ltWkAMGTDpR5/WBlkTFcdk1bFDZY0NlDhmJ5mWjvSrsk01aQEjWz4EpSW8vg1n8zTV0m VFs00BaUqJr440tN+/j6NFjiPIJzWza5F/pBHSQ4AbxdeC2oE+BxzAc+WcJg4lbOwI5s VkOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DEKQOY+C; 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 d13-20020ac241cd000000b004f860a146cfsi2601087lfi.143.2023.06.27.17.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:50:15 -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=DEKQOY+C; 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 2CA8E86625; Wed, 28 Jun 2023 02:49: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=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="DEKQOY+C"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9880E865F1; Wed, 28 Jun 2023 02:49:44 +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=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 4B36B86380 for ; Wed, 28 Jun 2023 02:49:34 +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-x432.google.com with SMTP id d2e1a72fcca58-66872dbc2efso1324821b3a.0 for ; Tue, 27 Jun 2023 17:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687913372; x=1690505372; 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=wUERDMnx2MAtzW+c7TrgxZhn94CPs/Fg4n/Wz7nEEFA=; b=DEKQOY+C7hFFHnI9+NWQdrmJ+sU9CcBggog6WHhT6msmItJ5epyDzdoYLd4iFiHWBj LOy9dLtEj889pFc3t1yzQIX1/ZOgKYyZGPm334YPrT4lmzPEy8TMrcgtloFfp/qd60FA gKi31Po79Kb0+WiUzi+BXKVm+OakRmenOkJY38QcT9gnbgU5DcKwa3d1GHkQWQTPWfer Szk2dkybaVrCrDncLGCwRz9xxEBb0xlsS7fQSzoue3XNg92ANVyq9814JNqmpQe8CPTd Ndl9ZrolkP1BDA7nBLzuITGwVioNEn9/3DVkGGF7pr2cag461Rl9Y0kO9uDSBRLVJ3Dy y0Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687913372; x=1690505372; 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=wUERDMnx2MAtzW+c7TrgxZhn94CPs/Fg4n/Wz7nEEFA=; b=LNkk7pRpJfPEeKclCf/fKtRvIYh1pynICl0qa//0zSTYwE/Jk1g5zsznE8bTpTxKt2 vZ4yWmJaz4xZygmj1W8v4djptaJaZoZPTDUYXJne0JLWTuklvZiN3pA5ygQXXIO5cAYe 2IwSXWIlMvcKWx5zzsuR9hSiq7pARyiCUlUT497wS/AKdU+DriIC0DkHLny0qtJG8WzT pvhVn+MrrJXsvKvRDOwe/RxqP40wKsoRYVLexGs+5zaaY1qpV+IsOi3ttei07fASbry9 I7cFoB6un2g2D+OrrOvFrcA+cCTVQzcaUnAQXmy3AwCOmXRFAriZy+TErtvclJ9RPqgF 721A== X-Gm-Message-State: AC+VfDy5xaVP56K74wuLplE7LMXbROiChYW4zceSUr1KgQMQWEzEEA98 mG7/FhAbyLZ8RDTMCiFxJJvmzg== X-Received: by 2002:a05:6a20:8e18:b0:11a:dbb3:703b with SMTP id y24-20020a056a208e1800b0011adbb3703bmr4732875pzj.6.1687913372429; Tue, 27 Jun 2023 17:49:32 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:58b2:60ed:38ea:8b1f]) by smtp.gmail.com with ESMTPSA id u13-20020a170903124d00b001b3fb2f0296sm6517278plh.120.2023.06.27.17.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 17:49:32 -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 01/10] firmware: scmi: implement SCMI base protocol Date: Wed, 28 Jun 2023 09:48:32 +0900 Message-ID: <20230628004841.21774-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628004841.21774-1-takahiro.akashi@linaro.org> References: <20230628004841.21774-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 base protocol is mandatory according to the SCMI specification. With this patch, SCMI base protocol can be accessed via SCMI transport layers. All the commands, except SCMI_BASE_NOTIFY_ERRORS, are supported. This is because U-Boot doesn't support interrupts and the current transport layers are not able to handle asynchronous messages properly. Signed-off-by: AKASHI Takahiro --- drivers/firmware/scmi/Makefile | 1 + drivers/firmware/scmi/base.c | 517 +++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/scmi_protocols.h | 201 ++++++++++++- 4 files changed, 718 insertions(+), 2 deletions(-) create mode 100644 drivers/firmware/scmi/base.c diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile index b2ff483c75a1..1a23d4981709 100644 --- a/drivers/firmware/scmi/Makefile +++ b/drivers/firmware/scmi/Makefile @@ -1,4 +1,5 @@ obj-y += scmi_agent-uclass.o +obj-y += base.o obj-y += smt.o obj-$(CONFIG_SCMI_AGENT_SMCCC) += smccc_agent.o obj-$(CONFIG_SCMI_AGENT_MAILBOX) += mailbox_agent.o diff --git a/drivers/firmware/scmi/base.c b/drivers/firmware/scmi/base.c new file mode 100644 index 000000000000..04018eb6ecf3 --- /dev/null +++ b/drivers/firmware/scmi/base.c @@ -0,0 +1,517 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SCMI Base protocol as U-Boot device + * + * Copyright (C) 2023 Linaro Limited + * author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * struct scmi_base_priv - Private data for SCMI base protocol + * @channel: Reference to the SCMI channel to use + */ +struct scmi_base_priv { + struct scmi_channel *channel; +}; + +/** + * scmi_protocol_version - get protocol version + * @dev: Device + * @version: Pointer to protocol version + * + * Obtain the protocol version number in @version. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_protocol_version(struct udevice *dev, u32 *version) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_protocol_version_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_PROTOCOL_VERSION, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *version = out.version; + + return 0; +} + +/** + * scmi_protocol_attrs - get protocol attributes + * @dev: Device + * @num_agents: Number of agents + * @num_protocols: Number of protocols + * + * Obtain the protocol attributes, the number of agents and the number + * of protocols, in @num_agents and @num_protocols respectively, that + * the device provides. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_protocol_attrs(struct udevice *dev, u32 *num_agents, + u32 *num_protocols) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_protocol_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_PROTOCOL_ATTRIBUTES, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *num_agents = SCMI_PROTOCOL_ATTRS_NUM_AGENTS(out.attributes); + *num_protocols = SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(out.attributes); + + return 0; +} + +/** + * scmi_protocol_message_attrs - get message-specific attributes + * @dev: Device + * @message_id: Identifier of message + * @attributes: Message-specific attributes + * + * Obtain the message-specific attributes in @attributes. + * This command succeeds if the message is implemented and available. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_protocol_message_attrs(struct udevice *dev, u32 message_id, + u32 *attributes) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_protocol_msg_attrs_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .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; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *attributes = out.attributes; + + return 0; +} + +/** + * scmi_base_discover_vendor - get vendor name + * @dev: Device + * @vendor: Vendor name + * + * Obtain the vendor's name in @vendor. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_vendor(struct udevice *dev, u8 *vendor) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_discover_vendor_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_VENDOR, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + strcpy(vendor, out.vendor_identifier); + + return 0; +} + +/** + * scmi_base_discover_sub_vendor - get sub-vendor name + * @dev: Device + * @sub_vendor: Sub-vendor name + * + * Obtain the sub-vendor's name in @sub_vendor. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_sub_vendor(struct udevice *dev, u8 *sub_vendor) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_discover_vendor_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_SUB_VENDOR, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + strcpy(sub_vendor, out.vendor_identifier); + + return 0; +} + +/** + * scmi_base_discover_impl_version - get implementation version + * @dev: Device + * @impl_version: Pointer to implementation version + * + * Obtain the implementation version number in @impl_version. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_impl_version(struct udevice *dev, u32 *impl_version) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_discover_impl_version_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_IMPL_VERSION, + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + *impl_version = out.impl_version; + + return 0; +} + +/** + * scmi_base_discover_list_protocols - get list of protocols + * @dev: Device + * @protocols: Pointer to array of protocols + * + * Obtain the list of protocols provided in @protocols. + * The number of elements in @protocols always match to the number of + * protocols returned by smci_protocol_attrs() when this function succeeds. + * It is a caller's responsibility to free @protocols. + * + * Return: the number of protocols in @protocols on success, error code otherwise + */ +static int scmi_base_discover_list_protocols(struct udevice *dev, u8 **protocols) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_discover_list_protocols_out out; + int cur; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_LIST_PROTOCOLS, + .in_msg = (u8 *)&cur, + .in_msg_sz = sizeof(cur), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + u32 num_agents, num_protocols; + u8 *buf; + int i, ret; + + ret = scmi_protocol_attrs(dev, &num_agents, &num_protocols); + if (ret) + return ret; + + buf = calloc(sizeof(u8), num_protocols); + if (!buf) + return -ENOMEM; + + cur = 0; + do { + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + goto err; + if (out.status) { + ret = scmi_to_linux_errno(out.status); + goto err; + } + + for (i = 0; i < out.num_protocols; i++, cur++) + buf[cur] = out.protocols[i / 4] >> ((i % 4) * 8); + } while (cur < num_protocols); + + *protocols = buf; + + return num_protocols; +err: + free(buf); + + return ret; +} + +/** + * scmi_base_discover_agent - identify agent + * @dev: Device + * @agent_id: Identifier of agent + * @ret_agent_id: Pointer to identifier of agent + * @name: Agent name + * + * Obtain the agent's name in @name. If @agent_id is equal to 0xffffffff, + * this function returns the caller's agent id in @ret_agent_id. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_discover_agent(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 *name) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_discover_agent_out out; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_DISCOVER_AGENT, + .in_msg = (u8 *)&agent_id, + .in_msg_sz = sizeof(agent_id), + .out_msg = (u8 *)&out, + .out_msg_sz = sizeof(out), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (out.status) + return scmi_to_linux_errno(out.status); + + strcpy(name, out.name); + *ret_agent_id = out.agent_id; + + return 0; +} + +/** + * scmi_base_notify_errors - configure error notification + * @dev: Device + * @enable: Operation + * + * This function is not yet implemented. + * + * Return: always -EOPNOTSUPP + */ +static int scmi_base_notify_errors(struct udevice *dev, u32 enable) +{ + return -EOPNOTSUPP; +} + +/** + * scmi_base_set_device_permissions - configure access permission to device + * @dev: Device + * @agent_id: Identifier of agent + * @device_id: Identifier of device to access + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_set_device_permissions(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_set_device_permissions_in in = { + .agent_id = agent_id, + .device_id = device_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_SET_DEVICE_PERMISSIONS, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_set_protocol_permissions - configure access permission to protocol + on device + * @dev: Device + * @agent_id: Identifier of agent + * @device_id: Identifier of device to access + * @command_id: Identifier of command + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_set_protocol_permissions(struct udevice *dev, u32 agent_id, + u32 device_id, u32 command_id, + u32 flags) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_set_protocol_permissions_in in = { + .agent_id = agent_id, + .device_id = device_id, + .command_id = command_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_SET_PROTOCOL_PERMISSIONS, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_reset_agent_configuration - reset resource settings + * @dev: Device + * @agent_id: Identifier of agent + * @flags: A set of flags + * + * Ask for allowing or denying access permission to the protocol, @command_id, + * on the device, @device_id. + * The meaning of @flags is defined in SCMI specification. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_reset_agent_configuration(struct udevice *dev, u32 agent_id, + u32 flags) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + struct scmi_base_reset_agent_configuration_in in = { + .agent_id = agent_id, + .flags = flags, + }; + s32 status; + struct scmi_msg msg = { + .protocol_id = SCMI_PROTOCOL_ID_BASE, + .message_id = SCMI_BASE_RESET_AGENT_CONFIGURATION, + .in_msg = (u8 *)&in, + .in_msg_sz = sizeof(in), + .out_msg = (u8 *)&status, + .out_msg_sz = sizeof(status), + }; + int ret; + + ret = devm_scmi_process_msg(dev, priv->channel, &msg); + if (ret) + return ret; + if (status) + return scmi_to_linux_errno(status); + + return 0; +} + +/** + * scmi_base_probe - probe base protocol device + * @dev: Device + * + * Probe the device for SCMI base protocol and initialize the private data. + * + * Return: 0 on success, error code otherwise + */ +static int scmi_base_probe(struct udevice *dev) +{ + struct scmi_base_priv *priv = dev_get_priv(dev); + int ret; + + ret = devm_scmi_of_get_channel(dev, &priv->channel); + if (ret) { + dev_err(dev, "get_channel failed\n"); + return ret; + } + + return ret; +} + +struct scmi_base_ops scmi_base_ops = { + /* Commands */ + .protocol_version = scmi_protocol_version, + .protocol_attrs = scmi_protocol_attrs, + .protocol_message_attrs = scmi_protocol_message_attrs, + .base_discover_vendor = scmi_base_discover_vendor, + .base_discover_sub_vendor = scmi_base_discover_sub_vendor, + .base_discover_impl_version = scmi_base_discover_impl_version, + .base_discover_list_protocols = scmi_base_discover_list_protocols, + .base_discover_agent = scmi_base_discover_agent, + .base_notify_errors = scmi_base_notify_errors, + .base_set_device_permissions = scmi_base_set_device_permissions, + .base_set_protocol_permissions = scmi_base_set_protocol_permissions, + .base_reset_agent_configuration = scmi_base_reset_agent_configuration, +}; + +U_BOOT_DRIVER(scmi_base_drv) = { + .id = UCLASS_SCMI_BASE, + .name = "scmi_base_drv", + .ops = &scmi_base_ops, + .probe = scmi_base_probe, + .priv_auto = sizeof(struct scmi_base_priv *), +}; + +UCLASS_DRIVER(scmi_base) = { + .id = UCLASS_SCMI_BASE, + .name = "scmi_base", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 307ad6931ca7..f7a110852321 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -116,6 +116,7 @@ enum uclass_id { UCLASS_RNG, /* Random Number Generator */ UCLASS_RTC, /* Real time clock device */ UCLASS_SCMI_AGENT, /* Interface with an SCMI server */ + UCLASS_SCMI_BASE, /* Interface for SCMI Base protocol */ UCLASS_SCSI, /* SCSI device */ UCLASS_SERIAL, /* Serial UART */ UCLASS_SIMPLE_BUS, /* Bus with child devices */ diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index a220cb2a91ad..769041654534 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -15,6 +15,8 @@ * https://developer.arm.com/docs/den0056/b */ +#define SCMI_BASE_NAME_LENGTH_MAX 16 + enum scmi_std_protocol { SCMI_PROTOCOL_ID_BASE = 0x10, SCMI_PROTOCOL_ID_POWER_DOMAIN = 0x11, @@ -41,12 +43,207 @@ enum scmi_status_code { }; /* - * Generic message IDs + * SCMI Base Protocol */ -enum scmi_discovery_id { +#define SCMI_BASE_PROTOCOL_VERSION 0x20000 + +enum scmi_base_message_id { SCMI_PROTOCOL_VERSION = 0x0, SCMI_PROTOCOL_ATTRIBUTES = 0x1, SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, + SCMI_BASE_DISCOVER_VENDOR = 0x3, + SCMI_BASE_DISCOVER_SUB_VENDOR = 0x4, + SCMI_BASE_DISCOVER_IMPL_VERSION = 0x5, + SCMI_BASE_DISCOVER_LIST_PROTOCOLS = 0x6, + SCMI_BASE_DISCOVER_AGENT = 0x7, + SCMI_BASE_NOTIFY_ERRORS = 0x8, + SCMI_BASE_SET_DEVICE_PERMISSIONS = 0x9, + SCMI_BASE_SET_PROTOCOL_PERMISSIONS = 0xa, + SCMI_BASE_RESET_AGENT_CONFIGURATION = 0xb, +}; + +/** + * struct scmi_protocol_version_out - Response for SCMI_PROTOCOL_VERSION + * command + * @status: SCMI command status + * @version: Protocol version + */ +struct scmi_protocol_version_out { + s32 status; + u32 version; +}; + +/** + * struct scmi_protocol_attrs_out - Response for SCMI_PROTOCOL_ATTRIBUTES + * command + * @status: SCMI command status + * @attributes: Protocol attributes or implementation details + */ +struct scmi_protocol_attrs_out { + s32 status; + u32 attributes; +}; + +#define SCMI_PROTOCOL_ATTRS_NUM_AGENTS(attributes) \ + (((attributes) & GENMASK(15, 8)) >> 8) +#define SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(attributes) \ + ((attributes) & GENMASK(7, 0)) + +/** + * struct scmi_protocol_msg_attrs_out - Response for + * SCMI_PROTOCOL_MESSAGE_ATTRIBUTES command + * @status: SCMI command status + * @attributes: Message-specific attributes + */ +struct scmi_protocol_msg_attrs_out { + s32 status; + u32 attributes; +}; + +/** + * struct scmi_base_discover_vendor_out - Response for + * SCMI_BASE_DISCOVER_VENDOR or + * SCMI_BASE_DISCOVER_SUB_VENDOR command + * @status: SCMI command status + * @vendor_identifier: Identifier of vendor or sub-vendor in string + */ +struct scmi_base_discover_vendor_out { + s32 status; + u8 vendor_identifier[SCMI_BASE_NAME_LENGTH_MAX]; +}; + +/** + * struct scmi_base_discover_impl_version_out - Response for + * SCMI_BASE_DISCOVER_IMPL_VERSION command + * @status: SCMI command status + * @impl_version: Vendor-specific implementation version + */ +struct scmi_base_discover_impl_version_out { + s32 status; + u32 impl_version; +}; + +/** + * struct scmi_base_discover_list_protocols_out - Response for + * SCMI_BASE_DISCOVER_LIST_PROTOCOLS command + * @status: SCMI command status + * @num_protocols: Number of protocols in @protocol + * @protocols: Array of packed protocol ID's + */ +struct scmi_base_discover_list_protocols_out { + s32 status; + u32 num_protocols; + u32 protocols[3]; +}; + +/** + * struct scmi_base_discover_agent_out - Response for + * SCMI_BASE_DISCOVER_AGENT command + * @status: SCMI command status + * @agent_id: Identifier of agent + * @name: Name of agent in string + */ +struct scmi_base_discover_agent_out { + s32 status; + u32 agent_id; + u8 name[SCMI_BASE_NAME_LENGTH_MAX]; +}; + +#define SCMI_BASE_NOTIFY_ERRORS_ENABLE BIT(0) + +/** + * struct scmi_base_set_device_permissions_in - Parameters for + * SCMI_BASE_SET_DEVICE_PERMISSIONS command + * @agent_id: Identifier of agent + * @device_id: Identifier of device + * @flags: A set of flags + */ +struct scmi_base_set_device_permissions_in { + u32 agent_id; + u32 device_id; + u32 flags; +}; + +#define SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS BIT(0) + +/** + * struct scmi_base_set_protocol_permissions_in - Parameters for + * SCMI_BASE_SET_PROTOCOL_PERMISSIONS command + * @agent_id: Identifier of agent + * @device_id: Identifier of device + * @command_id: Identifier of command + * @flags: A set of flags + */ +struct scmi_base_set_protocol_permissions_in { + u32 agent_id; + u32 device_id; + u32 command_id; + u32 flags; +}; + +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_COMMAND GENMASK(7, 0) +#define SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS BIT(0) + +/** + * struct scmi_base_reset_agent_configuration_in - Parameters for + * SCMI_BASE_RESET_AGENT_CONFIGURATION command + * @agent_id: Identifier of agent + * @flags: A set of flags + */ +struct scmi_base_reset_agent_configuration_in { + u32 agent_id; + u32 flags; +}; + +#define SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS BIT(0) + +/** + * struct scmi_base_ops - SCMI base protocol interfaces + * @protocol_version: Function pointer for + * PROTOCOL_VERSION + * @protocol_attrs: Function pointer for + * PROTOCOL_ATTRIBUTES + * @protocol_message_attrs: Function pointer for + * PROTOCOL_MESSAGE_ATTRIBUTES + * @base_discover_vendor: Function pointer for + * BASE_DISCOVER_VENDOR + * @base_discover_sub_vendor: Function pointer for + * BASE_DISCOVER_SUB_VENDOR + * @base_discover_impl_version: Function pointer for + * BASE_DISCOVER_IMPLEMENTATION_VERSION + * @base_discover_list_protocols: Function pointer for + * BASE_DISCOVER_LIST_PROTOCOLS + * @base_discover_agent: Function pointer for + * BASE_DISCOVER_AGENT + * @base_notify_errors: Function pointer for + * BASE_NOTIFY_ERRORS + * @base_set_device_permissions: Function pointer for + * BASE_SET_DEVICE_PROTOCOLS + * @base_set_protocol_permissions: Function pointer for + * BASE_SET_PROTOCOL_PERMISSIONS + * @base_reset_agent_configuration: Function pointer for + * BASE_RESET_AGENT_CONFIGURATION + */ +struct scmi_base_ops { + int (*protocol_version)(struct udevice *dev, u32 *version); + int (*protocol_attrs)(struct udevice *dev, u32 *num_agents, + u32 *num_protocols); + int (*protocol_message_attrs)(struct udevice *dev, u32 message_id, + u32 *attributes); + int (*base_discover_vendor)(struct udevice *dev, u8 *vendor); + int (*base_discover_sub_vendor)(struct udevice *dev, u8 *sub_vendor); + int (*base_discover_impl_version)(struct udevice *dev, u32 *impl_version); + int (*base_discover_list_protocols)(struct udevice *dev, u8 **protocols); + int (*base_discover_agent)(struct udevice *dev, u32 agent_id, + u32 *ret_agent_id, u8 *name); + int (*base_notify_errors)(struct udevice *dev, u32 enable); + int (*base_set_device_permissions)(struct udevice *dev, u32 agent_id, + u32 device_id, u32 flags); + int (*base_set_protocol_permissions)(struct udevice *dev, u32 agent_id, + u32 device_id, u32 command_id, + u32 flags); + int (*base_reset_agent_configuration)(struct udevice *dev, u32 agent_id, + u32 flags); }; /*