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
scmi_status_response(struct scmi_msg * msg,int32_t status)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
scmi_write_response(struct scmi_msg * msg,void * payload,size_t size)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
scmi_process_message(struct scmi_msg * msg)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 default:
51 break;
52 }
53
54 if (handler) {
55 handler(msg);
56 return;
57 }
58
59 ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported",
60 msg->agent_id, msg->protocol_id, msg->message_id);
61
62 scmi_status_response(msg, SCMI_NOT_SUPPORTED);
63 }
64