blob: 5ac68e1e6b56301b33d4e04ba4a69b984cad06e2 [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
Jacky Baid1806aa2023-09-21 11:06:34 +080018#pragma weak scmi_msg_get_sensor_handler
Peng Fan1d4a3832021-06-11 11:16:08 +080019
20scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
21{
22 return NULL;
23}
24
25scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused)
26{
27 return NULL;
28}
29
30scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused)
31{
32 return NULL;
33}
34
35scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused)
36{
37 return NULL;
38}
39
Jacky Baid1806aa2023-09-21 11:06:34 +080040scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg __unused)
41{
42 return NULL;
43}
44
Etienne Carriere13b353c2019-11-28 09:13:34 +010045void scmi_status_response(struct scmi_msg *msg, int32_t status)
46{
47 assert(msg->out && msg->out_size >= sizeof(int32_t));
48
49 memcpy(msg->out, &status, sizeof(int32_t));
50 msg->out_size_out = sizeof(int32_t);
51}
52
53void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size)
54{
55 /*
56 * Output payload shall be at least the size of the status
57 * Output buffer shall be at least be the size of the status
58 * Output paylaod shall fit in output buffer
59 */
60 assert(payload && size >= sizeof(int32_t) && size <= msg->out_size &&
61 msg->out && msg->out_size >= sizeof(int32_t));
62
63 memcpy(msg->out, payload, size);
64 msg->out_size_out = size;
65}
66
67void scmi_process_message(struct scmi_msg *msg)
68{
69 scmi_msg_handler_t handler = NULL;
70
71 switch (msg->protocol_id) {
72 case SCMI_PROTOCOL_ID_BASE:
73 handler = scmi_msg_get_base_handler(msg);
74 break;
Etienne Carriere76b3cc62020-05-01 10:32:02 +020075 case SCMI_PROTOCOL_ID_CLOCK:
76 handler = scmi_msg_get_clock_handler(msg);
77 break;
Etienne Carriere02a4ba52020-05-01 10:33:22 +020078 case SCMI_PROTOCOL_ID_RESET_DOMAIN:
79 handler = scmi_msg_get_rstd_handler(msg);
80 break;
Peng Fana662df52021-06-09 20:35:49 +080081 case SCMI_PROTOCOL_ID_POWER_DOMAIN:
82 handler = scmi_msg_get_pd_handler(msg);
83 break;
Jacky Baid1806aa2023-09-21 11:06:34 +080084 case SCMI_PROTOCOL_ID_SENSOR:
85 handler = scmi_msg_get_sensor_handler(msg);
86 break;
Etienne Carriere13b353c2019-11-28 09:13:34 +010087 default:
88 break;
89 }
90
91 if (handler) {
92 handler(msg);
93 return;
94 }
95
Yann Gautier3764e032022-01-27 15:47:11 +010096 ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported\n",
Etienne Carriere13b353c2019-11-28 09:13:34 +010097 msg->agent_id, msg->protocol_id, msg->message_id);
98
99 scmi_status_response(msg, SCMI_NOT_SUPPORTED);
100}