blob: eefcb31005552ebb5d2c5a3c4964220539493e3d [file] [log] [blame]
Etienne Carriere13b353c2019-11-28 09:13:34 +01001// 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/st/scmi-msg.h>
10#include <drivers/st/scmi.h>
11
12#include "common.h"
13
14void 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
22void 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
36void 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;
Etienne Carriere76b3cc62020-05-01 10:32:02 +020044 case SCMI_PROTOCOL_ID_CLOCK:
45 handler = scmi_msg_get_clock_handler(msg);
46 break;
Etienne Carriere02a4ba52020-05-01 10:33:22 +020047 case SCMI_PROTOCOL_ID_RESET_DOMAIN:
48 handler = scmi_msg_get_rstd_handler(msg);
49 break;
Etienne Carriere13b353c2019-11-28 09:13:34 +010050 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}