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