1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *      System Control and Management Interface (SCMI) unit test support.
9  */
10 #include <mod_dvfs.h>
11 #include <mod_scmi.h>
12 
13 /*!
14  * \brief Get the number of active agents.
15  *
16  * \param[out] agent_count Number of active agents.
17  *
18  * \retval ::FWK_SUCCESS The agent count was returned.
19  * \retval ::FWK_E_PARAM The parameter `agent_count` is equal to `NULL`.
20  */
21 int mod_scmi_from_protocol_api_get_agent_count(unsigned int *agent_count);
22 
23 /*!
24  * \brief Get the identifier of the agent associated with a service
25  *
26  * \param service_id Identifier of the service.
27  * \param[out] agent_id Agent identifier.
28  *
29  * \retval ::FWK_SUCCESS The agent identifier was returned.
30  * \retval ::FWK_E_PARAM An invalid parameter was encountered:
31  *      - The `service_id` parameter was not a valid system entity
32  *        identifier.
33  *      - The `agent_id` parameter was a null pointer value.
34  * \retval ::FWK_E_INIT The service is not initialized.
35  * \retval ::FWK_E_STATE The service is in an invalid state.
36  */
37 int mod_scmi_from_protocol_api_get_agent_id(
38     fwk_id_t service_id,
39     unsigned int *agent_id);
40 
41 /*!
42  * \brief Get the type of the agent given its identifier.
43  *
44  * \details This API can be used by SCMI protocols to check the validity
45  *          of an agent identifier.
46  *
47  * \param agent_id Identifier of the agent.
48  * \param[out] agent_type Agent type.
49  *
50  * \retval ::FWK_SUCCESS The agent identifier was returned.
51  * \retval ::FWK_E_PARAM An invalid parameter was encountered:
52  *      - The `agent_id` parameter was not a valid system entity
53  *        identifier.
54  *      - The `agent_type` parameter was a null pointer value.
55  */
56 int mod_scmi_from_protocol_api_get_agent_type(
57     uint32_t agent_id,
58     enum scmi_agent_type *agent_type);
59 
60 /*!
61  * \brief Get the maximum permitted payload size of a channel associated
62  *        with a service.
63  *
64  * \param service_id Service identifier.
65  * \param[out] size Maximum payload size in bytes.
66  *
67  * \retval ::FWK_SUCCESS The operation succeeded.
68  * \retval ::FWK_E_PARAM An invalid parameter was encountered:
69  *      - The `service_id` parameter was not a valid system entity
70  *        identifier.
71  *      - The `size` parameter was a null pointer value.
72  * \retval ::FWK_E_INIT The service is not initialized.
73  * \retval ::FWK_E_STATE The service is in an invalid sate.
74  * \return One of the standard error codes for implementation-defined
75  *      errors.
76  */
77 int mod_scmi_from_protocol_api_get_max_payload_size(
78     fwk_id_t service_id,
79     size_t *size);
80 
81 /*!
82  * \brief Write part of a payload through a service.
83  *
84  * \param service_id Service identifier.
85  * \param offset Offset to begin writing at.
86  * \param payload Payload data to write.
87  * \param size Size of the payload data.
88  *
89  * \retval ::FWK_SUCCESS The operation succeeded.
90  * \retval ::FWK_E_PARAM An invalid parameter was encountered:
91  *      - The `service_id` parameter was not a valid system entity
92  *        identifier.
93  *      - The offset and size given were not within the bounds of the
94  *        payload area.
95  * \return One of the standard error codes for implementation-defined
96  *      errors.
97  */
98 int mod_scmi_from_protocol_api_write_payload(
99     fwk_id_t service_id,
100     size_t offset,
101     const void *payload,
102     size_t size);
103 
104 /*!
105  * \brief Respond to an SCMI message on a service.
106  *
107  * \param service_id Service identifier.
108  * \param payload Payload data to write, or NULL if a payload has already
109  *      been written.
110  * \param size Size of the payload.
111  */
112 int mod_scmi_from_protocol_api_respond(
113     fwk_id_t service_id,
114     const void *payload,
115     size_t size);
116 
117 /*!
118  * \brief Send a notification to the agent on behalf on an SCMI service.
119  *
120  * \param service_id Service identifier.
121  * \param protocol_id Protocol identifier.
122  * \param message_id Message identifier.
123  * \param payload Payload data to write, or NULL if a payload has already
124  *         been written.
125  * \param size Size of the payload in bytes.
126  */
127 void mod_scmi_from_protocol_api_notify(
128     fwk_id_t service_id,
129     int protocol_id,
130     int message_id,
131     const void *payload,
132     size_t size);
133 
134 /*!
135  * \brief Send an SCMI message
136  *
137  * \param scmi_message_id SCMI message identifier.
138  * \param scmi_protocol_id SCMI message protocol identifier.
139  * \param token SCMI message token.
140  * \param service_id SCMI service identifier.
141  * \param payload Payload data to write
142  * \param payload_size size of the payload in bytes.
143  * \param request_ack_by_interrupt flag to select whether acknowledgement
144  * interrupt is required for this message.
145  */
146 int mod_scmi_from_protocol_api_scmi_send_message(
147     uint8_t scmi_message_id,
148     uint8_t scmi_protocol_id,
149     uint8_t token,
150     fwk_id_t service_id,
151     const void *payload,
152     size_t payload_size,
153     bool request_ack_by_interrupt);
154 
155 /*!
156  * \brief Handle response SCMI message
157  *
158  * \param service_id Service identifier.
159  *
160  * \retval ::FWK_SUCCESS The operation succeeded.
161  */
162 int mod_scmi_from_protocol_api_response_message_handler(fwk_id_t service_id);
163 
164 /*!
165  * \brief Get the current operating point of a domain.
166  *
167  * \param domain_id Element identifier of the domain.
168  * \param [out] opp Current operating point.
169  */
170 int mod_dvfs_domain_api_get_current_opp(
171     fwk_id_t domain_id,
172     struct mod_dvfs_opp *opp);
173 
174 /*!
175  * \brief Get the sustained operating point of a domain.
176  *
177  * \param domain_id Element identifier of the domain.
178  * \param [out] opp Sustained operating point.
179  */
180 int mod_dvfs_domain_api_get_sustained_opp(
181     fwk_id_t domain_id,
182     struct mod_dvfs_opp *opp);
183 
184 /*!
185  * \brief Get an operating point from its index.
186  *
187  * \param domain_id Element identifier of the domain.
188  * \param n Index of the operating point to retrieve.
189  * \param [out] opp Requested operating point.
190  */
191 int mod_dvfs_domain_api_get_nth_opp(
192     fwk_id_t domain_id,
193     size_t n,
194     struct mod_dvfs_opp *opp);
195 
196 /*!
197  * \brief Get the number of operating points of a domain.
198  *
199  * \param domain_id Element identifier of the domain.
200  * \param [out] opp_count Number of operating points.
201  */
202 int mod_dvfs_domain_api_get_opp_count(fwk_id_t domain_id, size_t *opp_count);
203 
204 /*!
205  * \brief Get the level id for the given level.
206  *
207  * \param domain_id Element identifier of the domain.
208  * \param level Requested level.
209  * \param [out] level id inside the OPP table.
210  */
211 int mod_dvfs_domain_api_get_level_id(
212     fwk_id_t domain_id,
213     uint32_t level,
214     size_t *level_id);
215 
216 /*!
217  * \brief Get the worst-case transition latency of a domain.
218  *
219  * \param domain_id Element identifier of the domain.
220  * \param [out] latency Worst-case transition latency.
221  */
222 int mod_dvfs_domain_api_get_latency(fwk_id_t domain_id, uint16_t *latency);
223 
224 /*!
225  * \brief Set the level of a domain.
226  *
227  * \param domain_id Element identifier of the domain.
228  * \param cookie Context-specific value.
229  * \param level Requested level.
230  */
231 int mod_dvfs_domain_api_set_level(
232     fwk_id_t domain_id,
233     uintptr_t cookie,
234     uint32_t level);
235