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