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