1b4734308SPeng Fan // SPDX-License-Identifier: BSD-3-Clause 2b4734308SPeng Fan /* 3b4734308SPeng Fan * Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved. 4b4734308SPeng Fan * Copyright (c) 2019-2020, Linaro Limited 5b4734308SPeng Fan */ 6b4734308SPeng Fan 7b4734308SPeng Fan #include <assert.h> 8b4734308SPeng Fan 9b4734308SPeng Fan #include <drivers/scmi-msg.h> 10b4734308SPeng Fan #include <drivers/scmi.h> 11b4734308SPeng Fan 12b4734308SPeng Fan #include "common.h" 13b4734308SPeng Fan 14b4734308SPeng Fan void scmi_status_response(struct scmi_msg *msg, int32_t status) 15b4734308SPeng Fan { 16b4734308SPeng Fan assert(msg->out && msg->out_size >= sizeof(int32_t)); 17b4734308SPeng Fan 18b4734308SPeng Fan memcpy(msg->out, &status, sizeof(int32_t)); 19b4734308SPeng Fan msg->out_size_out = sizeof(int32_t); 20b4734308SPeng Fan } 21b4734308SPeng Fan 22b4734308SPeng Fan void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size) 23b4734308SPeng Fan { 24b4734308SPeng Fan /* 25b4734308SPeng Fan * Output payload shall be at least the size of the status 26b4734308SPeng Fan * Output buffer shall be at least be the size of the status 27b4734308SPeng Fan * Output paylaod shall fit in output buffer 28b4734308SPeng Fan */ 29b4734308SPeng Fan assert(payload && size >= sizeof(int32_t) && size <= msg->out_size && 30b4734308SPeng Fan msg->out && msg->out_size >= sizeof(int32_t)); 31b4734308SPeng Fan 32b4734308SPeng Fan memcpy(msg->out, payload, size); 33b4734308SPeng Fan msg->out_size_out = size; 34b4734308SPeng Fan } 35b4734308SPeng Fan 36b4734308SPeng Fan void scmi_process_message(struct scmi_msg *msg) 37b4734308SPeng Fan { 38b4734308SPeng Fan scmi_msg_handler_t handler = NULL; 39b4734308SPeng Fan 40b4734308SPeng Fan switch (msg->protocol_id) { 41b4734308SPeng Fan case SCMI_PROTOCOL_ID_BASE: 42b4734308SPeng Fan handler = scmi_msg_get_base_handler(msg); 43b4734308SPeng Fan break; 44b4734308SPeng Fan case SCMI_PROTOCOL_ID_CLOCK: 45b4734308SPeng Fan handler = scmi_msg_get_clock_handler(msg); 46b4734308SPeng Fan break; 47b4734308SPeng Fan case SCMI_PROTOCOL_ID_RESET_DOMAIN: 48b4734308SPeng Fan handler = scmi_msg_get_rstd_handler(msg); 49b4734308SPeng Fan break; 50*7e4833cdSPeng Fan case SCMI_PROTOCOL_ID_POWER_DOMAIN: 51*7e4833cdSPeng Fan handler = scmi_msg_get_pd_handler(msg); 52*7e4833cdSPeng Fan break; 53b4734308SPeng Fan default: 54b4734308SPeng Fan break; 55b4734308SPeng Fan } 56b4734308SPeng Fan 57b4734308SPeng Fan if (handler) { 58b4734308SPeng Fan handler(msg); 59b4734308SPeng Fan return; 60b4734308SPeng Fan } 61b4734308SPeng Fan 62b4734308SPeng Fan ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported", 63b4734308SPeng Fan msg->agent_id, msg->protocol_id, msg->message_id); 64b4734308SPeng Fan 65b4734308SPeng Fan scmi_status_response(msg, SCMI_NOT_SUPPORTED); 66b4734308SPeng Fan } 67