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