blob: 399115c6d5d58f40f8d0487bb2ffbbcdc40360a8 [file] [log] [blame]
Etienne Carriere13b353c2019-11-28 09:13:34 +01001// SPDX-License-Identifier: BSD-3-Clause
2/*
Yann Gautier3764e032022-01-27 15:47:11 +01003 * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
Etienne Carriere13b353c2019-11-28 09:13:34 +01004 * Copyright (c) 2019-2020, Linaro Limited
5 */
6
7#include <assert.h>
8
Peng Fan8053e072021-01-20 11:04:08 +08009#include <drivers/scmi-msg.h>
10#include <drivers/scmi.h>
Etienne Carriere13b353c2019-11-28 09:13:34 +010011
12#include "common.h"
13
Peng Fan1d4a3832021-06-11 11:16:08 +080014#pragma weak scmi_msg_get_clock_handler
15#pragma weak scmi_msg_get_rstd_handler
16#pragma weak scmi_msg_get_pd_handler
17#pragma weak scmi_msg_get_voltage_handler
18
19scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
20{
21 return NULL;
22}
23
24scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused)
25{
26 return NULL;
27}
28
29scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused)
30{
31 return NULL;
32}
33
34scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused)
35{
36 return NULL;
37}
38
Etienne Carriere13b353c2019-11-28 09:13:34 +010039void scmi_status_response(struct scmi_msg *msg, int32_t status)
40{
41 assert(msg->out && msg->out_size >= sizeof(int32_t));
42
43 memcpy(msg->out, &status, sizeof(int32_t));
44 msg->out_size_out = sizeof(int32_t);
45}
46
47void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size)
48{
49 /*
50 * Output payload shall be at least the size of the status
51 * Output buffer shall be at least be the size of the status
52 * Output paylaod shall fit in output buffer
53 */
54 assert(payload && size >= sizeof(int32_t) && size <= msg->out_size &&
55 msg->out && msg->out_size >= sizeof(int32_t));
56
57 memcpy(msg->out, payload, size);
58 msg->out_size_out = size;
59}
60
61void scmi_process_message(struct scmi_msg *msg)
62{
63 scmi_msg_handler_t handler = NULL;
64
65 switch (msg->protocol_id) {
66 case SCMI_PROTOCOL_ID_BASE:
67 handler = scmi_msg_get_base_handler(msg);
68 break;
Etienne Carriere76b3cc62020-05-01 10:32:02 +020069 case SCMI_PROTOCOL_ID_CLOCK:
70 handler = scmi_msg_get_clock_handler(msg);
71 break;
Etienne Carriere02a4ba52020-05-01 10:33:22 +020072 case SCMI_PROTOCOL_ID_RESET_DOMAIN:
73 handler = scmi_msg_get_rstd_handler(msg);
74 break;
Peng Fana662df52021-06-09 20:35:49 +080075 case SCMI_PROTOCOL_ID_POWER_DOMAIN:
76 handler = scmi_msg_get_pd_handler(msg);
77 break;
Etienne Carriere13b353c2019-11-28 09:13:34 +010078 default:
79 break;
80 }
81
82 if (handler) {
83 handler(msg);
84 return;
85 }
86
Yann Gautier3764e032022-01-27 15:47:11 +010087 ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported\n",
Etienne Carriere13b353c2019-11-28 09:13:34 +010088 msg->agent_id, msg->protocol_id, msg->message_id);
89
90 scmi_status_response(msg, SCMI_NOT_SUPPORTED);
91}