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 #include <drivers/scmi-msg.h> 7 #include <drivers/scmi.h> 8 #include <trace.h> 9 10 #include "common.h" 11 12 void scmi_status_response(struct scmi_msg *msg, int32_t status) 13 { 14 assert(msg->out && msg->out_size >= sizeof(int32_t)); 15 16 memcpy(msg->out, &status, sizeof(int32_t)); 17 msg->out_size_out = sizeof(int32_t); 18 } 19 20 void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size) 21 { 22 /* 23 * Output payload shall be at least the size of the status 24 * Output buffer shall be at least be the size of the status 25 * Output paylaod shall fit in output buffer 26 */ 27 assert(payload && size >= sizeof(int32_t) && size <= msg->out_size && 28 msg->out && msg->out_size >= sizeof(int32_t)); 29 30 memcpy(msg->out, payload, size); 31 msg->out_size_out = size; 32 } 33 34 void scmi_process_message(struct scmi_msg *msg) 35 { 36 scmi_msg_handler_t handler = NULL; 37 38 switch (msg->protocol_id) { 39 case SCMI_PROTOCOL_ID_BASE: 40 handler = scmi_msg_get_base_handler(msg); 41 break; 42 #ifdef CFG_SCMI_MSG_CLOCK 43 case SCMI_PROTOCOL_ID_CLOCK: 44 handler = scmi_msg_get_clock_handler(msg); 45 break; 46 #endif 47 #ifdef CFG_SCMI_MSG_RESET_DOMAIN 48 case SCMI_PROTOCOL_ID_RESET_DOMAIN: 49 handler = scmi_msg_get_rd_handler(msg); 50 break; 51 #endif 52 default: 53 break; 54 } 55 56 if (handler) { 57 handler(msg); 58 return; 59 } 60 61 DMSG("Agent %u Protocol %#x Message %#x: not supported", 62 msg->agent_id, msg->protocol_id, msg->message_id); 63 64 scmi_status_response(msg, SCMI_NOT_SUPPORTED); 65 } 66