1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-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) support.
9  */
10 
11 #ifndef MOD_INTERNAL_SCMI_H
12 #define MOD_INTERNAL_SCMI_H
13 
14 #include <mod_scmi.h>
15 #include <mod_scmi_header.h>
16 
17 #include <fwk_id.h>
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 /* SCMI service context */
23 struct scmi_service_ctx {
24     /* Pointer to SCMI service configuration data */
25     const struct mod_scmi_service_config *config;
26 
27     /*
28      * Identifier of the transport entity used by the service to read/respond
29      * to SCMI messages.
30      */
31     fwk_id_t transport_id;
32 
33     /* Pointer to the transport API used to read and respond to messages */
34     const struct mod_scmi_to_transport_api *transport_api;
35 
36     /*
37      * Copy of the pointer to the 'respond' function within the transport API.
38      */
39     int (*respond)(fwk_id_t transport_id, const void *payload, size_t size);
40 
41     /*
42      * Copy of the pointer to the 'transmit' function within the transport API.
43      */
44     int (*transmit)(
45         fwk_id_t transport_id,
46         uint32_t message_header,
47         const void *payload,
48         size_t size,
49         bool request_ack_by_interrupt);
50 
51     /* SCMI message token, used by the agent to identify individual messages */
52     uint16_t scmi_token;
53 
54     /* SCMI identifier of the protocol processing the current message */
55     unsigned int scmi_protocol_id;
56 
57     /* SCMI identifier of the message currently being processed */
58     unsigned int scmi_message_id;
59 
60     /* SCMI type of the message currently being processed */
61     enum mod_scmi_message_type scmi_message_type;
62 };
63 
64 struct scmi_protocol {
65     /* SCMI protocol message handler */
66     mod_scmi_message_handler_t *message_handler;
67 
68     /* SCMI protocol framework identifier */
69     fwk_id_t id;
70 };
71 
72 struct mod_scmi_ctx {
73     /* SCMI module configuration data */
74     struct mod_scmi_config *config;
75 
76     /* Table of bound protocols */
77     struct scmi_protocol *protocol_table;
78 
79     /* Number of bound protocols */
80     unsigned int protocol_count;
81 
82     /* Table of bound protocols as requesters */
83     struct scmi_protocol *protocol_requester_table;
84 
85     /* Number of bound protocols as requesters */
86     unsigned int protocol_requester_count;
87 
88     /*
89      * SCMI protocol identifier to the index of the entry in protocol_table[]
90      * dedicated to the protocol.
91      */
92     uint8_t scmi_protocol_id_to_idx[MOD_SCMI_PROTOCOL_ID_MAX + 1];
93 
94     /*
95      * SCMI protocol identifier to the index of the entry in
96      * protocol_requester_table[] dedicated to the protocol.
97      */
98     uint8_t scmi_protocol_requester_id_to_idx[MOD_SCMI_PROTOCOL_ID_MAX + 1];
99 
100     /* Table of service contexts */
101     struct scmi_service_ctx *service_ctx_table;
102 
103 #ifdef BUILD_HAS_MOD_RESOURCE_PERMS
104     /* SCMI Resource Permissions API */
105     const struct mod_res_permissions_api *res_perms_api;
106 #endif
107 #ifdef BUILD_HAS_SCMI_NOTIFICATIONS
108     /* Table of scmi notification subscribers */
109     struct scmi_notification_subscribers *scmi_notif_subscribers;
110 #endif
111 };
112 
113 #endif /* MOD_INTERNAL_SCMI_H */
114