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