Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 3 | * Copyright (c) 2015-2024, 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 | #ifndef SCMI_MSG_COMMON_H |
| 7 | #define SCMI_MSG_COMMON_H |
| 8 | |
| 9 | #include <assert.h> |
| 10 | #include <stdbool.h> |
| 11 | #include <stdint.h> |
| 12 | #include <string.h> |
| 13 | |
| 14 | #include "base.h" |
Etienne Carriere | 76b3cc6 | 2020-05-01 10:32:02 +0200 | [diff] [blame] | 15 | #include "clock.h" |
Peng Fan | a662df5 | 2021-06-09 20:35:49 +0800 | [diff] [blame] | 16 | #include "power_domain.h" |
Etienne Carriere | 02a4ba5 | 2020-05-01 10:33:22 +0200 | [diff] [blame] | 17 | #include "reset_domain.h" |
Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 18 | #include "sensor.h" |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 19 | |
| 20 | #define SCMI_VERSION 0x20000U |
| 21 | #define SCMI_IMPL_VERSION 0U |
| 22 | |
| 23 | #define SCMI_PLAYLOAD_MAX 92U |
| 24 | |
| 25 | /* |
| 26 | * Copy name identifier in target buffer following the SCMI specification |
| 27 | * that state name identifier shall be a null terminated string. |
| 28 | */ |
| 29 | #define COPY_NAME_IDENTIFIER(_dst_array, _name) \ |
| 30 | do { \ |
| 31 | assert(strlen(_name) < sizeof(_dst_array)); \ |
| 32 | strlcpy((_dst_array), (_name), sizeof(_dst_array)); \ |
| 33 | } while (0) |
| 34 | |
| 35 | /* Common command identifiers shared by all procotols */ |
| 36 | enum scmi_common_message_id { |
| 37 | SCMI_PROTOCOL_VERSION = 0x000, |
| 38 | SCMI_PROTOCOL_ATTRIBUTES = 0x001, |
| 39 | SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002 |
| 40 | }; |
| 41 | |
| 42 | /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */ |
| 43 | struct scmi_protocol_version_p2a { |
| 44 | int32_t status; |
| 45 | uint32_t version; |
| 46 | }; |
| 47 | |
| 48 | /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */ |
| 49 | struct scmi_protocol_attributes_p2a { |
| 50 | int32_t status; |
| 51 | uint32_t attributes; |
| 52 | }; |
| 53 | |
| 54 | /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */ |
| 55 | struct scmi_protocol_message_attributes_a2p { |
| 56 | uint32_t message_id; |
| 57 | }; |
| 58 | |
| 59 | /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */ |
| 60 | struct scmi_protocol_message_attributes_p2a { |
| 61 | int32_t status; |
| 62 | uint32_t attributes; |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * struct scmi_msg - SCMI message context |
| 67 | * |
| 68 | * @agent_id: SCMI agent ID, safely set from secure world |
| 69 | * @protocol_id: SCMI protocol ID for the related message, set by caller agent |
| 70 | * @message_id: SCMI message ID for the related message, set by caller agent |
| 71 | * @in: Address of the incoming message payload copied in secure memory |
| 72 | * @in_size: Byte length of the incoming message payload, set by caller agent |
| 73 | * @out: Address of of the output message payload message in non-secure memory |
| 74 | * @out_size: Byte length of the provisionned output buffer |
| 75 | * @out_size_out: Byte length of the output message payload |
| 76 | */ |
| 77 | struct scmi_msg { |
| 78 | unsigned int agent_id; |
| 79 | unsigned int protocol_id; |
| 80 | unsigned int message_id; |
| 81 | char *in; |
| 82 | size_t in_size; |
| 83 | char *out; |
| 84 | size_t out_size; |
| 85 | size_t out_size_out; |
| 86 | }; |
| 87 | |
| 88 | /* |
| 89 | * Type scmi_msg_handler_t is used by procotol drivers to safely find |
| 90 | * the handler function for the incoming message ID. |
| 91 | */ |
| 92 | typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg); |
| 93 | |
| 94 | /* |
| 95 | * scmi_msg_get_base_handler - Return a handler for a base message |
| 96 | * @msg - message to process |
| 97 | * Return a function handler for the message or NULL |
| 98 | */ |
| 99 | scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg); |
| 100 | |
| 101 | /* |
Etienne Carriere | 76b3cc6 | 2020-05-01 10:32:02 +0200 | [diff] [blame] | 102 | * scmi_msg_get_clock_handler - Return a handler for a clock message |
| 103 | * @msg - message to process |
| 104 | * Return a function handler for the message or NULL |
| 105 | */ |
| 106 | scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg); |
| 107 | |
| 108 | /* |
Etienne Carriere | 02a4ba5 | 2020-05-01 10:33:22 +0200 | [diff] [blame] | 109 | * scmi_msg_get_rstd_handler - Return a handler for a reset domain message |
| 110 | * @msg - message to process |
| 111 | * Return a function handler for the message or NULL |
| 112 | */ |
| 113 | scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg); |
| 114 | |
| 115 | /* |
Peng Fan | a662df5 | 2021-06-09 20:35:49 +0800 | [diff] [blame] | 116 | * scmi_msg_get_pd_handler - Return a handler for a power domain message |
| 117 | * @msg - message to process |
| 118 | * Return a function handler for the message or NULL |
| 119 | */ |
| 120 | scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg); |
| 121 | |
| 122 | /* |
Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 123 | * scmi_msg_get_sensor_handler - Return a handler for a sensor message |
| 124 | * @msg - message to process |
| 125 | * Return a function handler for the message or NULL |
| 126 | */ |
| 127 | scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg); |
| 128 | |
| 129 | /* |
Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame] | 130 | * Process Read, process and write response for input SCMI message |
| 131 | * |
| 132 | * @msg: SCMI message context |
| 133 | */ |
| 134 | void scmi_process_message(struct scmi_msg *msg); |
| 135 | |
| 136 | /* |
| 137 | * Write SCMI response payload to output message shared memory |
| 138 | * |
| 139 | * @msg: SCMI message context |
| 140 | * @payload: Output message payload |
| 141 | * @size: Byte size of output message payload |
| 142 | */ |
| 143 | void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size); |
| 144 | |
| 145 | /* |
| 146 | * Write status only SCMI response payload to output message shared memory |
| 147 | * |
| 148 | * @msg: SCMI message context |
| 149 | * @status: SCMI status value returned to caller |
| 150 | */ |
| 151 | void scmi_status_response(struct scmi_msg *msg, int32_t status); |
| 152 | #endif /* SCMI_MSG_COMMON_H */ |