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