1 /* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2022, 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_scmi.h> 11 #include <mod_resource_perms.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(fwk_id_t service_id, unsigned int *agent_id); 38 39 /*! 40 * \brief Get the type of the agent given its identifier. 41 * 42 * \details This API can be used by SCMI protocols to check the validity 43 * of an agent identifier. 44 * 45 * \param agent_id Identifier of the agent. 46 * \param[out] agent_type Agent type. 47 * 48 * \retval ::FWK_SUCCESS The agent identifier was returned. 49 * \retval ::FWK_E_PARAM An invalid parameter was encountered: 50 * - The `agent_id` parameter was not a valid system entity 51 * identifier. 52 * - The `agent_type` parameter was a null pointer value. 53 */ 54 int mod_scmi_from_protocol_api_get_agent_type(uint32_t agent_id, enum scmi_agent_type *agent_type); 55 56 /*! 57 * \brief Get the maximum permitted payload size of a channel associated 58 * with a service. 59 * 60 * \param service_id Service identifier. 61 * \param[out] size Maximum payload size in bytes. 62 * 63 * \retval ::FWK_SUCCESS The operation succeeded. 64 * \retval ::FWK_E_PARAM An invalid parameter was encountered: 65 * - The `service_id` parameter was not a valid system entity 66 * identifier. 67 * - The `size` parameter was a null pointer value. 68 * \retval ::FWK_E_INIT The service is not initialized. 69 * \retval ::FWK_E_STATE The service is in an invalid sate. 70 * \return One of the standard error codes for implementation-defined 71 * errors. 72 */ 73 int mod_scmi_from_protocol_api_get_max_payload_size(fwk_id_t service_id, size_t *size); 74 75 /*! 76 * \brief Write part of a payload through a service. 77 * 78 * \param service_id Service identifier. 79 * \param offset Offset to begin writing at. 80 * \param payload Payload data to write. 81 * \param size Size of the payload data. 82 * 83 * \retval ::FWK_SUCCESS The operation succeeded. 84 * \retval ::FWK_E_PARAM An invalid parameter was encountered: 85 * - The `service_id` parameter was not a valid system entity 86 * identifier. 87 * - The offset and size given were not within the bounds of the 88 * payload area. 89 * \return One of the standard error codes for implementation-defined 90 * errors. 91 */ 92 int mod_scmi_from_protocol_api_write_payload(fwk_id_t service_id, size_t offset, 93 const void *payload, size_t size); 94 95 /*! 96 * \brief Respond to an SCMI message on a service. 97 * 98 * \param service_id Service identifier. 99 * \param payload Payload data to write, or NULL if a payload has already 100 * been written. 101 * \param size Size of the payload. 102 */ 103 int mod_scmi_from_protocol_api_respond(fwk_id_t service_id, const void *payload, size_t size); 104 105 /*! 106 * \brief Send a notification to the agent on behalf on an SCMI service. 107 * 108 * \param service_id Service identifier. 109 * \param protocol_id Protocol identifier. 110 * \param message_id Message identifier. 111 * \param payload Payload data to write, or NULL if a payload has already 112 * been written. 113 * \param size Size of the payload in bytes. 114 */ 115 void mod_scmi_from_protocol_api_notify(fwk_id_t service_id, int protocol_id, int message_id, 116 const void *payload, size_t size); 117 118 /*! 119 * \brief Send an SCMI message 120 * 121 * \param scmi_message_id SCMI message identifier. 122 * \param scmi_protocol_id SCMI message protocol identifier. 123 * \param token SCMI message token. 124 * \param service_id SCMI service identifier. 125 * \param payload Payload data to write 126 * \param payload_size size of the payload in bytes. 127 * \param request_ack_by_interrupt flag to select whether acknowledgement 128 * interrupt is required for this message. 129 */ 130 int mod_scmi_from_protocol_api_scmi_send_message( 131 uint8_t scmi_message_id, 132 uint8_t scmi_protocol_id, 133 uint8_t token, 134 fwk_id_t service_id, 135 const void *payload, 136 size_t payload_size, 137 bool request_ack_by_interrupt); 138 139 /*! 140 * \brief Handle response SCMI message 141 * 142 * \param service_id Service identifier. 143 * 144 * \retval ::FWK_SUCCESS The operation succeeded. 145 */ 146 int mod_scmi_from_protocol_api_response_message_handler(fwk_id_t service_id); 147 148 /*! 149 * \brief Check whether the agent has permission to access a protocol. 150 * 151 * \param agent_id identifier of the agent. 152 * \param protocol_id identifier of the protocol. 153 * 154 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to 155 * use the protocol. 156 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have 157 * permissions to use the protocol. 158 */ 159 enum mod_res_perms_permissions mod_res_permissions_api_agent_has_protocol_permission( 160 uint32_t agent_id, 161 uint32_t protocol_id); 162 163 /*! 164 * \brief Check whether the agent has permission to access a message. 165 * 166 * \param agent_id identifier of the agent. 167 * \param protocol_id identifier of the protocol. 168 * \param message_id identifier of the message. 169 * 170 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to 171 * use the protocol. 172 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have 173 * permissions to use the message. 174 */ 175 enum mod_res_perms_permissions mod_res_permissions_api_agent_has_message_permission( 176 uint32_t agent_id, 177 uint32_t protocol_id, 178 uint32_t message_id); 179 180 /*! 181 * \brief Check whether the agent has permission to access a resource. 182 * 183 * \param agent_id identifier of the agent. 184 * \param protocol_id identifier of the protocol. 185 * \param message_id identifier of the message. 186 * \param resource_id identifier of the resource. 187 * 188 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to 189 * use the protocol. 190 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have 191 * permissions to use the resource. 192 */ 193 enum mod_res_perms_permissions mod_res_permissions_api_agent_has_resource_permission( 194 uint32_t agent_id, 195 uint32_t protocol_id, 196 uint32_t message_id, 197 uint32_t resource_id); 198 199 /*! 200 * \brief Set device permissions for an agent 201 * 202 * \param agent_id identifier of the agent. 203 * \param device_id identifier of the device. 204 * \param flags permissions to set. 205 * 206 * \retval ::FWK_SUCCESS The operation has completed successfully. 207 * \retval ::FWK_E_ACCESS Unknown agent_id or device_id. 208 * \retval ::FWK_E_PARAM Invalid flags or protocol_ID. 209 */ 210 int mod_res_permissions_api_agent_set_device_permission( 211 uint32_t agent_id, 212 uint32_t device_id, 213 uint32_t flags); 214 215 /*! 216 * \brief Set device protocol permissions for an agent 217 * 218 * \param agent_id identifier of the agent. 219 * \param device_id identifier of the device. 220 * \param device_id identifier of the protocol. 221 * \param flags permissions to set. 222 * 223 * \retval ::FWK_SUCCESS The operation has completed successfully. 224 * \retval ::FWK_E_ACCESS Unknown agent_id or device_id. 225 * \retval ::FWK_E_PARAM Invalid flags or protocol_ID. 226 */ 227 int mod_res_permissions_api_agent_set_device_protocol_permission( 228 uint32_t agent_id, 229 uint32_t device_id, 230 uint32_t protocol_id, 231 uint32_t flags); 232 233 /*! 234 * \brief Reset permissions for an agent 235 * 236 * \param agent_id identifier of the agent. 237 * \param flags permissions to set. 238 * 239 * \retval ::FWK_SUCCESS The operation has completed successfully. 240 * \retval ::FWK_E_ACCESS Unknown agent_id. 241 * \retval ::FWK_E_PARAM Invalid flags. 242 */ 243 int mod_res_permissions_api_agent_reset_config(uint32_t agent_id, uint32_t flags); 244