blob: 6b186d07d22e20e694487de186ed38e6e51411f6 [file] [log] [blame]
Etienne Carriere13b353c2019-11-28 09:13:34 +01001/* SPDX-License-Identifier: BSD-3-Clause */
2/*
Jacky Baid1806aa2023-09-21 11:06:34 +08003 * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Etienne Carriere13b353c2019-11-28 09:13:34 +01004 * 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 Carriere76b3cc62020-05-01 10:32:02 +020015#include "clock.h"
Peng Fana662df52021-06-09 20:35:49 +080016#include "power_domain.h"
Etienne Carriere02a4ba52020-05-01 10:33:22 +020017#include "reset_domain.h"
Jacky Baid1806aa2023-09-21 11:06:34 +080018#include "sensor.h"
Etienne Carriere13b353c2019-11-28 09:13:34 +010019
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 */
36enum 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 */
43struct scmi_protocol_version_p2a {
44 int32_t status;
45 uint32_t version;
46};
47
48/* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */
49struct scmi_protocol_attributes_p2a {
50 int32_t status;
51 uint32_t attributes;
52};
53
54/* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */
55struct scmi_protocol_message_attributes_a2p {
56 uint32_t message_id;
57};
58
59/* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */
60struct 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 */
77struct 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 */
92typedef 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 */
99scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg);
100
101/*
Etienne Carriere76b3cc62020-05-01 10:32:02 +0200102 * 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 */
106scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg);
107
108/*
Etienne Carriere02a4ba52020-05-01 10:33:22 +0200109 * 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 */
113scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg);
114
115/*
Peng Fana662df52021-06-09 20:35:49 +0800116 * 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 */
120scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg);
121
122/*
Jacky Baid1806aa2023-09-21 11:06:34 +0800123 * 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 */
127scmi_msg_handler_t scmi_msg_get_sensor_handler(struct scmi_msg *msg);
128
129/*
Etienne Carriere13b353c2019-11-28 09:13:34 +0100130 * Process Read, process and write response for input SCMI message
131 *
132 * @msg: SCMI message context
133 */
134void 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 */
143void 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 */
151void scmi_status_response(struct scmi_msg *msg, int32_t status);
152#endif /* SCMI_MSG_COMMON_H */