xref: /optee_os/core/drivers/scmi-msg/entry.c (revision 006d89b8f49f0b0a7e22887636ec551c31c432f9)
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 	case SCMI_PROTOCOL_ID_CLOCK:
43 		handler = scmi_msg_get_clock_handler(msg);
44 		break;
45 	case SCMI_PROTOCOL_ID_RESET_DOMAIN:
46 		handler = scmi_msg_get_rd_handler(msg);
47 		break;
48 	case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
49 		handler = scmi_msg_get_voltd_handler(msg);
50 		break;
51 	default:
52 		break;
53 	}
54 
55 	if (handler) {
56 		handler(msg);
57 		return;
58 	}
59 
60 	DMSG("Agent %u Protocol %#x Message %#x: not supported",
61 	     msg->agent_id, msg->protocol_id, msg->message_id);
62 
63 	scmi_status_response(msg, SCMI_NOT_SUPPORTED);
64 }
65