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