1b4734308SPeng Fan /* SPDX-License-Identifier: BSD-3-Clause */ 2b4734308SPeng Fan /* 3*e63819f2SJacky Bai * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. 4b4734308SPeng Fan * Copyright (c) 2019-2020, Linaro Limited 5b4734308SPeng Fan */ 6b4734308SPeng Fan #ifndef SCMI_MSG_COMMON_H 7b4734308SPeng Fan #define SCMI_MSG_COMMON_H 8b4734308SPeng Fan 9b4734308SPeng Fan #include <assert.h> 10b4734308SPeng Fan #include <stdbool.h> 11b4734308SPeng Fan #include <stdint.h> 12b4734308SPeng Fan #include <string.h> 13b4734308SPeng Fan 14b4734308SPeng Fan #include "base.h" 15b4734308SPeng Fan #include "clock.h" 167e4833cdSPeng Fan #include "power_domain.h" 17b4734308SPeng Fan #include "reset_domain.h" 18*e63819f2SJacky Bai #include "sensor.h" 19b4734308SPeng Fan 20b4734308SPeng Fan #define SCMI_VERSION 0x20000U 21b4734308SPeng Fan #define SCMI_IMPL_VERSION 0U 22b4734308SPeng Fan 23b4734308SPeng Fan #define SCMI_PLAYLOAD_MAX 92U 24b4734308SPeng Fan 25b4734308SPeng Fan /* 26b4734308SPeng Fan * Copy name identifier in target buffer following the SCMI specification 27b4734308SPeng Fan * that state name identifier shall be a null terminated string. 28b4734308SPeng Fan */ 29b4734308SPeng Fan #define COPY_NAME_IDENTIFIER(_dst_array, _name) \ 30b4734308SPeng Fan do { \ 31b4734308SPeng Fan assert(strlen(_name) < sizeof(_dst_array)); \ 32b4734308SPeng Fan strlcpy((_dst_array), (_name), sizeof(_dst_array)); \ 33b4734308SPeng Fan } while (0) 34b4734308SPeng Fan 35b4734308SPeng Fan /* Common command identifiers shared by all procotols */ 36b4734308SPeng Fan enum scmi_common_message_id { 37b4734308SPeng Fan SCMI_PROTOCOL_VERSION = 0x000, 38b4734308SPeng Fan SCMI_PROTOCOL_ATTRIBUTES = 0x001, 39b4734308SPeng Fan SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002 40b4734308SPeng Fan }; 41b4734308SPeng Fan 42b4734308SPeng Fan /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */ 43b4734308SPeng Fan struct scmi_protocol_version_p2a { 44b4734308SPeng Fan int32_t status; 45b4734308SPeng Fan uint32_t version; 46b4734308SPeng Fan }; 47b4734308SPeng Fan 48b4734308SPeng Fan /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */ 49b4734308SPeng Fan struct scmi_protocol_attributes_p2a { 50b4734308SPeng Fan int32_t status; 51b4734308SPeng Fan uint32_t attributes; 52b4734308SPeng Fan }; 53b4734308SPeng Fan 54b4734308SPeng Fan /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */ 55b4734308SPeng Fan struct scmi_protocol_message_attributes_a2p { 56b4734308SPeng Fan uint32_t message_id; 57b4734308SPeng Fan }; 58b4734308SPeng Fan 59b4734308SPeng Fan /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */ 60b4734308SPeng Fan struct scmi_protocol_message_attributes_p2a { 61b4734308SPeng Fan int32_t status; 62b4734308SPeng Fan uint32_t attributes; 63b4734308SPeng Fan }; 64b4734308SPeng Fan 65b4734308SPeng Fan /* 66b4734308SPeng Fan * struct scmi_msg - SCMI message context 67b4734308SPeng Fan * 68b4734308SPeng Fan * @agent_id: SCMI agent ID, safely set from secure world 69b4734308SPeng Fan * @protocol_id: SCMI protocol ID for the related message, set by caller agent 70b4734308SPeng Fan * @message_id: SCMI message ID for the related message, set by caller agent 71b4734308SPeng Fan * @in: Address of the incoming message payload copied in secure memory 72b4734308SPeng Fan * @in_size: Byte length of the incoming message payload, set by caller agent 73b4734308SPeng Fan * @out: Address of of the output message payload message in non-secure memory 74b4734308SPeng Fan * @out_size: Byte length of the provisionned output buffer 75b4734308SPeng Fan * @out_size_out: Byte length of the output message payload 76b4734308SPeng Fan */ 77b4734308SPeng Fan struct scmi_msg { 78b4734308SPeng Fan unsigned int agent_id; 79b4734308SPeng Fan unsigned int protocol_id; 80b4734308SPeng Fan unsigned int message_id; 81b4734308SPeng Fan char *in; 82b4734308SPeng Fan size_t in_size; 83b4734308SPeng Fan char *out; 84b4734308SPeng Fan size_t out_size; 85b4734308SPeng Fan size_t out_size_out; 86b4734308SPeng Fan }; 87b4734308SPeng Fan 88b4734308SPeng Fan /* 89b4734308SPeng Fan * Type scmi_msg_handler_t is used by procotol drivers to safely find 90b4734308SPeng Fan * the handler function for the incoming message ID. 91b4734308SPeng Fan */ 92b4734308SPeng Fan typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg); 93b4734308SPeng Fan 94b4734308SPeng Fan /* 95b4734308SPeng Fan * scmi_msg_get_base_handler - Return a handler for a base message 96b4734308SPeng Fan * @msg - message to process 97b4734308SPeng Fan * Return a function handler for the message or NULL 98b4734308SPeng Fan */ 99b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg); 100b4734308SPeng Fan 101b4734308SPeng Fan /* 102b4734308SPeng Fan * scmi_msg_get_clock_handler - Return a handler for a clock message 103b4734308SPeng Fan * @msg - message to process 104b4734308SPeng Fan * Return a function handler for the message or NULL 105b4734308SPeng Fan */ 106b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg); 107b4734308SPeng Fan 108b4734308SPeng Fan /* 109b4734308SPeng Fan * scmi_msg_get_rstd_handler - Return a handler for a reset domain message 110b4734308SPeng Fan * @msg - message to process 111b4734308SPeng Fan * Return a function handler for the message or NULL 112b4734308SPeng Fan */ 113b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg); 114b4734308SPeng Fan 115b4734308SPeng Fan /* 1167e4833cdSPeng Fan * scmi_msg_get_pd_handler - Return a handler for a power domain message 1177e4833cdSPeng Fan * @msg - message to process 1187e4833cdSPeng Fan * Return a function handler for the message or NULL 1197e4833cdSPeng Fan */ 1207e4833cdSPeng Fan scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg); 1217e4833cdSPeng Fan 1227e4833cdSPeng Fan /* 123*e63819f2SJacky Bai * scmi_msg_get_sensor_handler - Return a handler for a sensor message 124*e63819f2SJacky Bai * @msg - message to process 125*e63819f2SJacky Bai * Return a function handler for the message or NULL 126*e63819f2SJacky Bai */ 127*e63819f2SJacky Bai scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg); 128*e63819f2SJacky Bai 129*e63819f2SJacky Bai /* 130b4734308SPeng Fan * Process Read, process and write response for input SCMI message 131b4734308SPeng Fan * 132b4734308SPeng Fan * @msg: SCMI message context 133b4734308SPeng Fan */ 134b4734308SPeng Fan void scmi_process_message(struct scmi_msg *msg); 135b4734308SPeng Fan 136b4734308SPeng Fan /* 137b4734308SPeng Fan * Write SCMI response payload to output message shared memory 138b4734308SPeng Fan * 139b4734308SPeng Fan * @msg: SCMI message context 140b4734308SPeng Fan * @payload: Output message payload 141b4734308SPeng Fan * @size: Byte size of output message payload 142b4734308SPeng Fan */ 143b4734308SPeng Fan void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size); 144b4734308SPeng Fan 145b4734308SPeng Fan /* 146b4734308SPeng Fan * Write status only SCMI response payload to output message shared memory 147b4734308SPeng Fan * 148b4734308SPeng Fan * @msg: SCMI message context 149b4734308SPeng Fan * @status: SCMI status value returned to caller 150b4734308SPeng Fan */ 151b4734308SPeng Fan void scmi_status_response(struct scmi_msg *msg, int32_t status); 152b4734308SPeng Fan #endif /* SCMI_MSG_COMMON_H */ 153