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