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 |
| 18 | |
| 19 | scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused) |
| 20 | { |
| 21 | return NULL; |
| 22 | } |
| 23 | |
| 24 | scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused) |
| 25 | { |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused) |
| 30 | { |
| 31 | return NULL; |
| 32 | } |
| 33 | |
| 34 | scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused) |
| 35 | { |
| 36 | return NULL; |
| 37 | } |
| 38 | |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 39 | void 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 | |
| 47 | void 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 | |
| 61 | void 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 Carriere | 76b3cc6 | 2020-05-01 10:32:02 +0200 | [diff] [blame] | 69 | case SCMI_PROTOCOL_ID_CLOCK: |
| 70 | handler = scmi_msg_get_clock_handler(msg); |
| 71 | break; |
Etienne Carriere | 02a4ba5 | 2020-05-01 10:33:22 +0200 | [diff] [blame] | 72 | case SCMI_PROTOCOL_ID_RESET_DOMAIN: |
| 73 | handler = scmi_msg_get_rstd_handler(msg); |
| 74 | break; |
Peng Fan | a662df5 | 2021-06-09 20:35:49 +0800 | [diff] [blame] | 75 | case SCMI_PROTOCOL_ID_POWER_DOMAIN: |
| 76 | handler = scmi_msg_get_pd_handler(msg); |
| 77 | break; |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 78 | default: |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | if (handler) { |
| 83 | handler(msg); |
| 84 | return; |
| 85 | } |
| 86 | |
Yann Gautier | 3764e03 | 2022-01-27 15:47:11 +0100 | [diff] [blame] | 87 | ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported\n", |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 88 | msg->agent_id, msg->protocol_id, msg->message_id); |
| 89 | |
| 90 | scmi_status_response(msg, SCMI_NOT_SUPPORTED); |
| 91 | } |