Etienne Carriere | 13b353c | 2019-11-28 09:13:34 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
| 3 | * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved. |
| 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" |
| 15 | |
| 16 | #define SCMI_VERSION 0x20000U |
| 17 | #define SCMI_IMPL_VERSION 0U |
| 18 | |
| 19 | #define SCMI_PLAYLOAD_MAX 92U |
| 20 | |
| 21 | /* |
| 22 | * Copy name identifier in target buffer following the SCMI specification |
| 23 | * that state name identifier shall be a null terminated string. |
| 24 | */ |
| 25 | #define COPY_NAME_IDENTIFIER(_dst_array, _name) \ |
| 26 | do { \ |
| 27 | assert(strlen(_name) < sizeof(_dst_array)); \ |
| 28 | strlcpy((_dst_array), (_name), sizeof(_dst_array)); \ |
| 29 | } while (0) |
| 30 | |
| 31 | /* Common command identifiers shared by all procotols */ |
| 32 | enum scmi_common_message_id { |
| 33 | SCMI_PROTOCOL_VERSION = 0x000, |
| 34 | SCMI_PROTOCOL_ATTRIBUTES = 0x001, |
| 35 | SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002 |
| 36 | }; |
| 37 | |
| 38 | /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */ |
| 39 | struct scmi_protocol_version_p2a { |
| 40 | int32_t status; |
| 41 | uint32_t version; |
| 42 | }; |
| 43 | |
| 44 | /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */ |
| 45 | struct scmi_protocol_attributes_p2a { |
| 46 | int32_t status; |
| 47 | uint32_t attributes; |
| 48 | }; |
| 49 | |
| 50 | /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */ |
| 51 | struct scmi_protocol_message_attributes_a2p { |
| 52 | uint32_t message_id; |
| 53 | }; |
| 54 | |
| 55 | /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */ |
| 56 | struct scmi_protocol_message_attributes_p2a { |
| 57 | int32_t status; |
| 58 | uint32_t attributes; |
| 59 | }; |
| 60 | |
| 61 | /* |
| 62 | * struct scmi_msg - SCMI message context |
| 63 | * |
| 64 | * @agent_id: SCMI agent ID, safely set from secure world |
| 65 | * @protocol_id: SCMI protocol ID for the related message, set by caller agent |
| 66 | * @message_id: SCMI message ID for the related message, set by caller agent |
| 67 | * @in: Address of the incoming message payload copied in secure memory |
| 68 | * @in_size: Byte length of the incoming message payload, set by caller agent |
| 69 | * @out: Address of of the output message payload message in non-secure memory |
| 70 | * @out_size: Byte length of the provisionned output buffer |
| 71 | * @out_size_out: Byte length of the output message payload |
| 72 | */ |
| 73 | struct scmi_msg { |
| 74 | unsigned int agent_id; |
| 75 | unsigned int protocol_id; |
| 76 | unsigned int message_id; |
| 77 | char *in; |
| 78 | size_t in_size; |
| 79 | char *out; |
| 80 | size_t out_size; |
| 81 | size_t out_size_out; |
| 82 | }; |
| 83 | |
| 84 | /* |
| 85 | * Type scmi_msg_handler_t is used by procotol drivers to safely find |
| 86 | * the handler function for the incoming message ID. |
| 87 | */ |
| 88 | typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg); |
| 89 | |
| 90 | /* |
| 91 | * scmi_msg_get_base_handler - Return a handler for a base message |
| 92 | * @msg - message to process |
| 93 | * Return a function handler for the message or NULL |
| 94 | */ |
| 95 | scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg); |
| 96 | |
| 97 | /* |
| 98 | * Process Read, process and write response for input SCMI message |
| 99 | * |
| 100 | * @msg: SCMI message context |
| 101 | */ |
| 102 | void scmi_process_message(struct scmi_msg *msg); |
| 103 | |
| 104 | /* |
| 105 | * Write SCMI response payload to output message shared memory |
| 106 | * |
| 107 | * @msg: SCMI message context |
| 108 | * @payload: Output message payload |
| 109 | * @size: Byte size of output message payload |
| 110 | */ |
| 111 | void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size); |
| 112 | |
| 113 | /* |
| 114 | * Write status only SCMI response payload to output message shared memory |
| 115 | * |
| 116 | * @msg: SCMI message context |
| 117 | * @status: SCMI status value returned to caller |
| 118 | */ |
| 119 | void scmi_status_response(struct scmi_msg *msg, int32_t status); |
| 120 | #endif /* SCMI_MSG_COMMON_H */ |