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