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