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