Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
Yann Gautier | 3764e03 | 2022-01-27 15:47:11 +0100 | [diff] [blame] | 3 | * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved. |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 4 | * Copyright (c) 2019-2020, Linaro Limited |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
Peng Fan | 8053e07 | 2021-01-20 11:04:08 +0800 | [diff] [blame] | 9 | #include <drivers/scmi-msg.h> |
| 10 | #include <drivers/scmi.h> |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 11 | |
| 12 | #include "common.h" |
| 13 | |
Peng Fan | 1d4a383 | 2021-06-11 11:16:08 +0800 | [diff] [blame] | 14 | #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 Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 18 | #pragma weak scmi_msg_get_sensor_handler |
Peng Fan | 1d4a383 | 2021-06-11 11:16:08 +0800 | [diff] [blame] | 19 | |
| 20 | scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused) |
| 21 | { |
| 22 | return NULL; |
| 23 | } |
| 24 | |
| 25 | scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused) |
| 26 | { |
| 27 | return NULL; |
| 28 | } |
| 29 | |
| 30 | scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused) |
| 31 | { |
| 32 | return NULL; |
| 33 | } |
| 34 | |
| 35 | scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused) |
| 36 | { |
| 37 | return NULL; |
| 38 | } |
| 39 | |
Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 40 | scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg __unused) |
| 41 | { |
| 42 | return NULL; |
| 43 | } |
| 44 | |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 45 | void 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 | |
| 53 | void 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 | |
| 67 | void 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 Carriere | 76b3cc6 | 2020-05-01 10:32:02 +0200 | [diff] [blame] | 75 | case SCMI_PROTOCOL_ID_CLOCK: |
| 76 | handler = scmi_msg_get_clock_handler(msg); |
| 77 | break; |
Etienne Carriere | 02a4ba5 | 2020-05-01 10:33:22 +0200 | [diff] [blame] | 78 | case SCMI_PROTOCOL_ID_RESET_DOMAIN: |
| 79 | handler = scmi_msg_get_rstd_handler(msg); |
| 80 | break; |
Peng Fan | a662df5 | 2021-06-09 20:35:49 +0800 | [diff] [blame] | 81 | case SCMI_PROTOCOL_ID_POWER_DOMAIN: |
| 82 | handler = scmi_msg_get_pd_handler(msg); |
| 83 | break; |
Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 84 | case SCMI_PROTOCOL_ID_SENSOR: |
| 85 | handler = scmi_msg_get_sensor_handler(msg); |
| 86 | break; |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 87 | default: |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | if (handler) { |
| 92 | handler(msg); |
| 93 | return; |
| 94 | } |
| 95 | |
Yann Gautier | 3764e03 | 2022-01-27 15:47:11 +0100 | [diff] [blame] | 96 | ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported\n", |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 97 | msg->agent_id, msg->protocol_id, msg->message_id); |
| 98 | |
| 99 | scmi_status_response(msg, SCMI_NOT_SUPPORTED); |
| 100 | } |