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